[#1539] Apply preset after double-click
This commit is contained in:
parent
81561dae76
commit
12c2d5bf4f
@ -264,12 +264,9 @@ public class RocketComponentConfig extends JPanel {
|
|||||||
if (presetComboBox == null || presetModel == null) return;
|
if (presetComboBox == null || presetModel == null) return;
|
||||||
((ComponentPresetDatabase) Application.getComponentPresetDao()).addDatabaseListener(presetModel);
|
((ComponentPresetDatabase) Application.getComponentPresetDao()).addDatabaseListener(presetModel);
|
||||||
ComponentPresetChooserDialog dialog =
|
ComponentPresetChooserDialog dialog =
|
||||||
new ComponentPresetChooserDialog(SwingUtilities.getWindowAncestor(RocketComponentConfig.this), component);
|
new ComponentPresetChooserDialog(SwingUtilities.getWindowAncestor(RocketComponentConfig.this),
|
||||||
|
component, presetModel);
|
||||||
dialog.setVisible(true);
|
dialog.setVisible(true);
|
||||||
ComponentPreset preset = dialog.getSelectedComponentPreset();
|
|
||||||
if (preset != null) {
|
|
||||||
presetModel.setSelectedItem(preset);
|
|
||||||
}
|
|
||||||
((ComponentPresetDatabase) Application.getComponentPresetDao()).removeChangeListener(presetModel);
|
((ComponentPresetDatabase) Application.getComponentPresetDao()).removeChangeListener(presetModel);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -7,6 +7,8 @@ import java.awt.event.ActionEvent;
|
|||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.ItemEvent;
|
import java.awt.event.ItemEvent;
|
||||||
import java.awt.event.ItemListener;
|
import java.awt.event.ItemListener;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -25,6 +27,7 @@ import javax.swing.table.TableColumn;
|
|||||||
import javax.swing.table.TableModel;
|
import javax.swing.table.TableModel;
|
||||||
|
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
|
import net.sf.openrocket.gui.adaptors.PresetModel;
|
||||||
import net.sf.openrocket.gui.util.GUIUtil;
|
import net.sf.openrocket.gui.util.GUIUtil;
|
||||||
import net.sf.openrocket.l10n.Translator;
|
import net.sf.openrocket.l10n.Translator;
|
||||||
import net.sf.openrocket.preset.ComponentPreset;
|
import net.sf.openrocket.preset.ComponentPreset;
|
||||||
@ -45,8 +48,8 @@ public class ComponentPresetChooserDialog extends JDialog {
|
|||||||
|
|
||||||
private final RocketComponent component;
|
private final RocketComponent component;
|
||||||
|
|
||||||
private ComponentPresetTable componentSelectionTable;
|
private final ComponentPresetTable componentSelectionTable;
|
||||||
private JTextField filterText;
|
private final JTextField filterText;
|
||||||
private JCheckBox foreDiameterFilterCheckBox;
|
private JCheckBox foreDiameterFilterCheckBox;
|
||||||
private JCheckBox aftDiameterFilterCheckBox;
|
private JCheckBox aftDiameterFilterCheckBox;
|
||||||
private JCheckBox showLegacyCheckBox;
|
private JCheckBox showLegacyCheckBox;
|
||||||
@ -66,12 +69,14 @@ public class ComponentPresetChooserDialog extends JDialog {
|
|||||||
|
|
||||||
private List<ComponentPreset> presets;
|
private List<ComponentPreset> presets;
|
||||||
private ComponentPreset.Type presetType;
|
private ComponentPreset.Type presetType;
|
||||||
|
private PresetModel presetModel;
|
||||||
|
|
||||||
|
|
||||||
public ComponentPresetChooserDialog(Window owner, RocketComponent component) {
|
public ComponentPresetChooserDialog(Window owner, RocketComponent component, PresetModel presetModel) {
|
||||||
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.presetType = component.getPresetType();
|
this.presetType = component.getPresetType();
|
||||||
|
this.presetModel = presetModel;
|
||||||
this.presets = Application.getComponentPresetDao().listForType(component.getPresetType());
|
this.presets = Application.getComponentPresetDao().listForType(component.getPresetType());
|
||||||
|
|
||||||
List<TypedKey<?>> displayedColumnKeys = Arrays.asList(component.getPresetType().getDisplayedColumns());
|
List<TypedKey<?>> displayedColumnKeys = Arrays.asList(component.getPresetType().getDisplayedColumns());
|
||||||
@ -151,6 +156,16 @@ public class ComponentPresetChooserDialog extends JDialog {
|
|||||||
|
|
||||||
panel.add(new JLabel(Chars.UP_ARROW + " " + trans.get("lbl.favorites")), "spanx, gapleft 5px, wrap para");
|
panel.add(new JLabel(Chars.UP_ARROW + " " + trans.get("lbl.favorites")), "spanx, gapleft 5px, wrap para");
|
||||||
|
|
||||||
|
// When double-clicking a preset row, apply the preset and close this dialog
|
||||||
|
componentSelectionTable.addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
// Don't do anything when double-clicking the first column
|
||||||
|
if (e.getClickCount() == 2 && componentSelectionTable.getSelectedColumn() > 0 && applySelectedPreset()) {
|
||||||
|
ComponentPresetChooserDialog.this.setVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Close buttons
|
// Close buttons
|
||||||
JButton closeButton = new SelectColorButton(trans.get("dlg.but.close"));
|
JButton closeButton = new SelectColorButton(trans.get("dlg.but.close"));
|
||||||
@ -158,6 +173,7 @@ public class ComponentPresetChooserDialog extends JDialog {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
ComponentPresetChooserDialog.this.setVisible(false);
|
ComponentPresetChooserDialog.this.setVisible(false);
|
||||||
|
applySelectedPreset();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
panel.add(closeButton, "spanx, right, tag close");
|
panel.add(closeButton, "spanx, right, tag close");
|
||||||
@ -170,6 +186,21 @@ public class ComponentPresetChooserDialog extends JDialog {
|
|||||||
updateFilters();
|
updateFilters();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies the currently selected preset to presetModel.
|
||||||
|
*
|
||||||
|
* @return true if the preset was applied, false if otherwise.
|
||||||
|
*/
|
||||||
|
private boolean applySelectedPreset() {
|
||||||
|
if (presetModel == null) return false;
|
||||||
|
ComponentPreset preset = getSelectedComponentPreset();
|
||||||
|
if (preset != null) {
|
||||||
|
presetModel.setSelectedItem(preset);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private JPanel getFilterCheckboxes(XTableColumnModel tm, int legacyColumnIndex) {
|
private JPanel getFilterCheckboxes(XTableColumnModel tm, int legacyColumnIndex) {
|
||||||
JPanel panel = new JPanel(new MigLayout("ins 0"));
|
JPanel panel = new JPanel(new MigLayout("ins 0"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user