Fix up the logic for showing and using the aft/fore match diameter switches.
This commit is contained in:
parent
8b9ead892c
commit
a9bbe0f642
@ -35,16 +35,16 @@ import net.sf.openrocket.rocketcomponent.SymmetricComponent;
|
|||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
|
|
||||||
public class ComponentPresetChooserDialog extends JDialog {
|
public class ComponentPresetChooserDialog extends JDialog {
|
||||||
|
|
||||||
private static final Translator trans = Application.getTranslator();
|
private static final Translator trans = Application.getTranslator();
|
||||||
|
|
||||||
private final RocketComponent component;
|
private final RocketComponent component;
|
||||||
|
|
||||||
private ComponentPresetTable componentSelectionTable;
|
private ComponentPresetTable componentSelectionTable;
|
||||||
private final JTextField filterText;
|
private final JTextField filterText;
|
||||||
private final JCheckBox foreDiameterFilterCheckBox;
|
private final JCheckBox foreDiameterFilterCheckBox;
|
||||||
private final JCheckBox aftDiameterFilterCheckBox;
|
private final JCheckBox aftDiameterFilterCheckBox;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* outerDiamtereColumnIndex is the index of the column associated with the OUTER_DIAMETER
|
* outerDiamtereColumnIndex is the index of the column associated with the OUTER_DIAMETER
|
||||||
* field. This index is needed by the matchOuterDiameterCheckBox to implement filtering.
|
* field. This index is needed by the matchOuterDiameterCheckBox to implement filtering.
|
||||||
@ -53,40 +53,35 @@ public class ComponentPresetChooserDialog extends JDialog {
|
|||||||
int foreDiameterColumnIndex = -1;
|
int foreDiameterColumnIndex = -1;
|
||||||
|
|
||||||
private List<ComponentPreset> presets;
|
private List<ComponentPreset> presets;
|
||||||
|
|
||||||
private boolean okClicked = false;
|
private boolean okClicked = false;
|
||||||
|
|
||||||
|
|
||||||
public ComponentPresetChooserDialog(Window owner, RocketComponent component) {
|
public ComponentPresetChooserDialog(Window owner, RocketComponent component) {
|
||||||
super(owner, trans.get("title"), Dialog.ModalityType.APPLICATION_MODAL);
|
super(owner, trans.get("title"), Dialog.ModalityType.APPLICATION_MODAL);
|
||||||
this.component = component;
|
this.component = component;
|
||||||
|
this.presets = Application.getComponentPresetDao().listForType(component.getPresetType());
|
||||||
|
|
||||||
final TypedKey<?>[] columnKeys = component.getPresetType().getDisplayedColumns();
|
List<TypedKey<?>> displayedColumnKeys = Arrays.<TypedKey<?>>asList(component.getPresetType().getDisplayedColumns());
|
||||||
|
{
|
||||||
presets = Application.getComponentPresetDao().listForType(component.getPresetType());
|
final List<TypedKey<?>> columnKeys = ComponentPreset.orderedKeyList;
|
||||||
|
int i=0; // We start at 0 but use preincrement because the first column is favorite.
|
||||||
for (int i = 0; i < columnKeys.length; i++) {
|
for (final TypedKey<?> key : columnKeys) {
|
||||||
final TypedKey<?> key = columnKeys[i];
|
// Note the increment early in the loop. This really means that initial loop i=1
|
||||||
if ( key == ComponentPreset.OUTER_DIAMETER ) {
|
// we do it here so the continue below doesn't mess up the counting.
|
||||||
// magic +1 is because we have inserted the column for favorites above.
|
i++;
|
||||||
aftDiameterColumnIndex = i+1;
|
// Don't allow the matching filters if the column is not part of the default set for
|
||||||
|
// this kind of preset.
|
||||||
|
if ( ! displayedColumnKeys.contains(key) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( key == ComponentPreset.OUTER_DIAMETER || key == ComponentPreset.AFT_OUTER_DIAMETER ) {
|
||||||
|
aftDiameterColumnIndex = i;
|
||||||
|
}
|
||||||
|
if ( key == ComponentPreset.OUTER_DIAMETER || key == ComponentPreset.FORE_OUTER_DIAMETER ) {
|
||||||
|
foreDiameterColumnIndex = i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ( key == ComponentPreset.FORE_OUTER_DIAMETER ) {
|
|
||||||
// magic +1 is because we have inserted the column for favorites above.
|
|
||||||
foreDiameterColumnIndex = i+1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* perhaps there is a better way for this.
|
|
||||||
*
|
|
||||||
* This check basically says that if a component does not have a fore diameter, use the
|
|
||||||
* outer_diameter when filtering. The problem this introduced is when this dialog is
|
|
||||||
* created for nose cones (which are aft of a body tube), you will be given the option
|
|
||||||
* to filter based on matching fore diameter.
|
|
||||||
*/
|
|
||||||
if ( foreDiameterColumnIndex < 0 ) {
|
|
||||||
foreDiameterColumnIndex = aftDiameterColumnIndex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -132,10 +127,10 @@ public class ComponentPresetChooserDialog extends JDialog {
|
|||||||
componentSelectionTable.updateData( presets );
|
componentSelectionTable.updateData( presets );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add filter by fore diameter
|
* Add filter by fore diameter
|
||||||
*/
|
*/
|
||||||
@ -151,11 +146,16 @@ public class ComponentPresetChooserDialog extends JDialog {
|
|||||||
|
|
||||||
RocketComponent previousComponent = component.getPreviousComponent();
|
RocketComponent previousComponent = component.getPreviousComponent();
|
||||||
/* hide the fore diameter filter if it is not applicable */
|
/* hide the fore diameter filter if it is not applicable */
|
||||||
if ( foreDiameterColumnIndex < 0 || previousComponent == null ) {
|
if ( foreDiameterColumnIndex < 0 ) {
|
||||||
if ( !(previousComponent instanceof ExternalComponent) && !(previousComponent instanceof InternalComponent) )
|
|
||||||
foreDiameterFilterCheckBox.setVisible(false);
|
foreDiameterFilterCheckBox.setVisible(false);
|
||||||
}
|
}
|
||||||
|
if ( previousComponent == null ) {
|
||||||
|
foreDiameterFilterCheckBox.setVisible(false);
|
||||||
|
} else {
|
||||||
|
if ( !(previousComponent instanceof ExternalComponent) && !(previousComponent instanceof InternalComponent) )
|
||||||
|
foreDiameterFilterCheckBox.setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add filter by aft diameter
|
* Add filter by aft diameter
|
||||||
*/
|
*/
|
||||||
@ -169,18 +169,24 @@ public class ComponentPresetChooserDialog extends JDialog {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
RocketComponent nextComponent = component.getNextComponent();
|
||||||
/* hide the aft diameter filter if it is not applicable */
|
/* hide the aft diameter filter if it is not applicable */
|
||||||
if ( aftDiameterColumnIndex < 0 || component.getNextComponent() == null ) {
|
if ( aftDiameterColumnIndex < 0 ) {
|
||||||
aftDiameterFilterCheckBox.setVisible(false);
|
aftDiameterFilterCheckBox.setVisible(false);
|
||||||
}
|
}
|
||||||
|
if ( nextComponent == null ) {
|
||||||
componentSelectionTable = new ComponentPresetTable( presets, Arrays.<TypedKey<?>>asList(columnKeys) );
|
aftDiameterFilterCheckBox.setVisible(false);
|
||||||
|
} else if ( !(nextComponent instanceof ExternalComponent) && !(nextComponent instanceof InternalComponent)) {
|
||||||
|
aftDiameterFilterCheckBox.setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentSelectionTable = new ComponentPresetTable( presets, displayedColumnKeys );
|
||||||
|
|
||||||
JScrollPane scrollpane = new JScrollPane();
|
JScrollPane scrollpane = new JScrollPane();
|
||||||
scrollpane.setViewportView(componentSelectionTable);
|
scrollpane.setViewportView(componentSelectionTable);
|
||||||
panel.add(scrollpane, "grow, width :500:, height :300:, spanx, wrap para");
|
panel.add(scrollpane, "grow, width :500:, height :300:, spanx, wrap para");
|
||||||
|
|
||||||
|
|
||||||
// OK / Cancel buttons
|
// OK / Cancel buttons
|
||||||
JButton okButton = new JButton(trans.get("dlg.but.ok"));
|
JButton okButton = new JButton(trans.get("dlg.but.ok"));
|
||||||
okButton.addActionListener(new ActionListener() {
|
okButton.addActionListener(new ActionListener() {
|
||||||
@ -190,7 +196,7 @@ public class ComponentPresetChooserDialog extends JDialog {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
panel.add(okButton, "tag ok, spanx, split");
|
panel.add(okButton, "tag ok, spanx, split");
|
||||||
|
|
||||||
//// Cancel button
|
//// Cancel button
|
||||||
JButton cancelButton = new JButton(trans.get("dlg.but.cancel"));
|
JButton cancelButton = new JButton(trans.get("dlg.but.cancel"));
|
||||||
cancelButton.addActionListener(new ActionListener() {
|
cancelButton.addActionListener(new ActionListener() {
|
||||||
@ -200,16 +206,16 @@ public class ComponentPresetChooserDialog extends JDialog {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
panel.add(cancelButton, "tag cancel");
|
panel.add(cancelButton, "tag cancel");
|
||||||
|
|
||||||
this.add(panel);
|
this.add(panel);
|
||||||
|
|
||||||
this.setModal(true);
|
this.setModal(true);
|
||||||
this.pack();
|
this.pack();
|
||||||
this.setLocationByPlatform(true);
|
this.setLocationByPlatform(true);
|
||||||
GUIUtil.setDisposableDialogOptions(this, okButton);
|
GUIUtil.setDisposableDialogOptions(this, okButton);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the motor selected by this chooser dialog, or <code>null</code> if the selection has been aborted.
|
* Return the motor selected by this chooser dialog, or <code>null</code> if the selection has been aborted.
|
||||||
*
|
*
|
||||||
@ -222,12 +228,12 @@ public class ComponentPresetChooserDialog extends JDialog {
|
|||||||
row = componentSelectionTable.convertRowIndexToModel(row);
|
row = componentSelectionTable.convertRowIndexToModel(row);
|
||||||
return presets.get(row);
|
return presets.get(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close(boolean ok) {
|
public void close(boolean ok) {
|
||||||
okClicked = ok;
|
okClicked = ok;
|
||||||
this.setVisible(false);
|
this.setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateFilters() {
|
private void updateFilters() {
|
||||||
List<RowFilter<TableModel,Object>> filters = new ArrayList<RowFilter<TableModel,Object>> (2);
|
List<RowFilter<TableModel,Object>> filters = new ArrayList<RowFilter<TableModel,Object>> (2);
|
||||||
String filterTextRegex = filterText.getText();
|
String filterTextRegex = filterText.getText();
|
||||||
@ -275,7 +281,7 @@ public class ComponentPresetChooserDialog extends JDialog {
|
|||||||
filters.add(outerDiameterFilter);
|
filters.add(outerDiameterFilter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentSelectionTable.setRowFilter( RowFilter.andFilter(filters) );
|
componentSelectionTable.setRowFilter( RowFilter.andFilter(filters) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user