Skip to content

Commit

Permalink
topcat: improve cds xmatch window cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
mbtaylor authored and mmpcn committed Nov 27, 2014
1 parent 9f93a51 commit 5888838
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 37 deletions.
19 changes: 19 additions & 0 deletions topcat/src/main/uk/ac/starlink/topcat/ColumnSelector.java
Expand Up @@ -208,6 +208,25 @@ public JLabel getLabel() {
return label_;
}

/**
* Returns the component displaying selection of the actual column or
* expression.
*
* @return column selection component
*/
public JComboBox getColumnComponent() {
return colComboBox_;
}

/**
* Returns the component displaying selection of the unit, if any.
*
* @return converter selection component
*/
public JComboBox getUnitComponent() {
return convComboBox_;
}

/**
* Adds a listener for changes on the state of this component.
*
Expand Down
21 changes: 21 additions & 0 deletions topcat/src/main/uk/ac/starlink/topcat/TopcatUtils.java
@@ -1,5 +1,6 @@
package uk.ac.starlink.topcat;

import java.awt.Dimension;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
Expand Down Expand Up @@ -526,6 +527,26 @@ public static String formatLong( long num ) {
return longFormat_.format( num );
}

/**
* Reshapes a set of components so that they all have the same
* preferred size (that of the largest one).
*
* @param comps components to align
*/
public static void alignComponents( JComponent[] comps ) {
int maxw = 0;
int maxh = 0;
for ( int i = 0; i < comps.length; i++ ) {
Dimension prefSize = comps[ i ].getPreferredSize();
maxw = Math.max( maxw, prefSize.width );
maxh = Math.max( maxh, prefSize.height );
}
Dimension prefSize = new Dimension( maxw, maxh );
for ( int i = 0; i < comps.length; i++ ) {
comps[ i ].setPreferredSize( prefSize );
}
}

/**
* Using input from the user, adds a new (or reused) Row Subset
* to the given TopcatModel based on a given BitSet.
Expand Down
12 changes: 11 additions & 1 deletion topcat/src/main/uk/ac/starlink/topcat/join/CdsTableSelector.java
Expand Up @@ -17,6 +17,7 @@
*/
public class CdsTableSelector extends JPanel {

private final JLabel label_;
private final JComboBox nameSelector_;

/**
Expand All @@ -29,7 +30,8 @@ public CdsTableSelector() {
nameSelector_.setSelectedItem( null );

setLayout( new BoxLayout( this, BoxLayout.X_AXIS ) );
add( new JLabel( "VizieR Table Name: " ) );
label_ = new JLabel( "VizieR Table Name: " );
add( label_ );
add( nameSelector_ );
}

Expand All @@ -41,4 +43,12 @@ public CdsTableSelector() {
public String getTableName() {
return (String) nameSelector_.getSelectedItem();
}

@Override
public void setEnabled( boolean isEnabled ) {
super.setEnabled( isEnabled );
nameSelector_.setEnabled( isEnabled );
label_.setEnabled( isEnabled );
}

}
30 changes: 5 additions & 25 deletions topcat/src/main/uk/ac/starlink/topcat/join/DalMultiPanel.java
Expand Up @@ -3,7 +3,6 @@
import gnu.jel.CompilationException;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
Expand Down Expand Up @@ -187,10 +186,11 @@ public void itemStateChanged( ItemEvent evt ) {
cList.add( srSysLabel );

/* Align the positional fields. */
alignLabels( new JLabel[] { raSelector_.getLabel(),
decSelector_.getLabel(),
srSelector_.getLabel(), } );
alignLabels( new JLabel[] { raSysLabel, decSysLabel, srSysLabel, } );
TopcatUtils.alignComponents( new JLabel[] { raSelector_.getLabel(),
decSelector_.getLabel(),
srSelector_.getLabel(), } );
TopcatUtils.alignComponents( new JLabel[] { raSysLabel, decSysLabel,
srSysLabel, } );

/* Custom service controls. */
JComponent servicePanel = service_.getControlPanel();
Expand Down Expand Up @@ -720,26 +720,6 @@ private MulticoneMode[] getMulticoneModes() {
};
}

/**
* Reshapes a set of components so that they all have the same
* preferred size (that of the largest one).
*
* @param labels labels to align
*/
private static void alignLabels( JLabel[] labels ) {
int maxw = 0;
int maxh = 0;
for ( int i = 0; i < labels.length; i++ ) {
Dimension prefSize = labels[ i ].getPreferredSize();
maxw = Math.max( maxw, prefSize.width );
maxh = Math.max( maxh, prefSize.height );
}
Dimension prefSize = new Dimension( maxw, maxh );
for ( int i = 0; i < labels.length; i++ ) {
labels[ i ].setPreferredSize( prefSize );
}
}

/**
* Turns a table into a TableProducer.
*
Expand Down
55 changes: 44 additions & 11 deletions topcat/src/main/uk/ac/starlink/topcat/join/UploadMatchPanel.java
@@ -1,6 +1,7 @@
package uk.ac.starlink.topcat.join;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
Expand Down Expand Up @@ -38,6 +39,7 @@
import uk.ac.starlink.topcat.Scheduler;
import uk.ac.starlink.topcat.TablesListComboBox;
import uk.ac.starlink.topcat.TopcatModel;
import uk.ac.starlink.topcat.TopcatUtils;
import uk.ac.starlink.ttools.cone.BlockUploader;
import uk.ac.starlink.ttools.cone.ConeQueryRowSequence;
import uk.ac.starlink.ttools.cone.CdsUploadMatcher;
Expand Down Expand Up @@ -68,7 +70,7 @@ public class UploadMatchPanel extends JPanel {
private final ColumnSelector raSelector_;
private final ColumnSelector decSelector_;
private final DoubleValueField srField_;
private final JTextField blockField_;
private final JComboBox blockSelector_;
private final JComboBox modeSelector_;
private final JComponent[] components_;
private final Action startAction_;
Expand All @@ -77,6 +79,8 @@ public class UploadMatchPanel extends JPanel {
private volatile MatchWorker matchWorker_;

private static final long MAXREC = -1;
private static final int[] BLOCK_SIZES =
{ 500000, 200000, 100000, 50000, 20000, 10000, 5000, 1000, 100 };
private static final int DEFAULT_BLOCKSIZE = 10000;
private static final ValueInfo SR_INFO =
new DefaultValueInfo( "Radius", Double.class, "Search Radius" );
Expand Down Expand Up @@ -145,8 +149,11 @@ public void itemStateChanged( ItemEvent evt ) {
srField_ = DoubleValueField.makeSizeDegreesField( SR_INFO );
Box srLine = Box.createHorizontalBox();
srLine.add( srField_.getLabel() );
srLine.add( Box.createHorizontalStrut( 5 ) );
srLine.add( srField_.getEntryField() );
srLine.add( srField_.getConverterSelector() );
srLine.add( Box.createHorizontalStrut( 5 ) );
srLine.add( new ShrinkWrapper( srField_.getConverterSelector() ) );
srLine.add( Box.createHorizontalGlue() );
srField_.getConverterSelector().setSelectedIndex( 2 );
srField_.getEntryField().setText( "1.0" );
main.add( srLine );
Expand All @@ -155,22 +162,47 @@ public void itemStateChanged( ItemEvent evt ) {
cList.add( srField_.getLabel() );
cList.add( srField_.getConverterSelector() );

/* Align some of the components for cosmetic reasons. */
TopcatUtils.alignComponents( new JComponent[] {
raSelector_.getLabel(),
decSelector_.getLabel(),
srField_.getLabel()
} );
TopcatUtils.alignComponents( new JComponent[] {
raSelector_.getColumnComponent(),
decSelector_.getColumnComponent(),
srField_.getEntryField(),
} );
TopcatUtils.alignComponents( new JComponent[] {
raSelector_.getUnitComponent(),
decSelector_.getUnitComponent(),
srField_.getConverterSelector(),
} );

/* Service access parameters. */
Box modeLine = Box.createHorizontalBox();
modeSelector_ = new JComboBox( UploadFindMode.getInstances() );
modeLine.add( new JLabel( "Find mode: " ) );
JLabel modeLabel = new JLabel( "Find mode: " );
modeLine.add( modeLabel );
modeLine.add( new ShrinkWrapper( modeSelector_ ) );
modeLine.add( Box.createHorizontalGlue() );
cList.add( modeLabel );
cList.add( modeSelector_ );
main.add( modeLine );
main.add( Box.createVerticalStrut( 5 ) );
Box blockLine = Box.createHorizontalBox();
blockField_ = new JTextField( 10 );
blockField_.setText( Integer.toString( DEFAULT_BLOCKSIZE ) );
blockLine.add( new JLabel( "Block size: " ) );
blockLine.add( blockField_ );
blockSelector_ = new JComboBox();
for ( int i = 0; i < BLOCK_SIZES.length; i++ ) {
blockSelector_.addItem( Integer.toString( BLOCK_SIZES[ i ] ) );
}
blockSelector_.setSelectedItem( Integer.toString( DEFAULT_BLOCKSIZE ) );
blockSelector_.setEditable( true );
JLabel blockLabel = new JLabel( "Block size: " );
blockLine.add( blockLabel );
blockLine.add( blockSelector_ );
blockLine.add( Box.createHorizontalGlue() );
cList.add( blockField_ );
cList.add( blockLabel );
cList.add( blockSelector_ );
main.add( blockLine );

/* Actions to start/stop match. */
Expand Down Expand Up @@ -326,14 +358,15 @@ private MatchWorker createMatchWorker() {
}

/* Get other search parameters. */
String bfTxt = blockField_.getText();
Object bf = blockSelector_.getSelectedItem();
String bfTxt = bf == null ? null : bf.toString();
int blocksize;
try {
blocksize = Integer.parseInt( bfTxt );
}
catch ( NumberFormatException e ) {
blockField_.setText( "" );
throw new IllegalArgumentException( "Bad blocksize" );
blockSelector_.setSelectedItem( null );
throw new IllegalArgumentException( "Bad blocksize: " + bfTxt );
}
UploadFindMode upMode =
(UploadFindMode) modeSelector_.getSelectedItem();
Expand Down

0 comments on commit 5888838

Please sign in to comment.