From 58c2df4336f9f69d7d4fe0d0e0eb3b2acd2aa269 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Thu, 21 Jul 2022 01:12:57 +0200 Subject: [PATCH 1/9] [#1516] Reselect preset row after favorite change --- .../sf/openrocket/gui/dialogs/preset/ComponentPresetTable.java | 2 ++ .../gui/dialogs/preset/ComponentPresetTableColumn.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/swing/src/net/sf/openrocket/gui/dialogs/preset/ComponentPresetTable.java b/swing/src/net/sf/openrocket/gui/dialogs/preset/ComponentPresetTable.java index c361baebf..62c1bb31b 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/preset/ComponentPresetTable.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/preset/ComponentPresetTable.java @@ -77,9 +77,11 @@ public class ComponentPresetTable extends JTable { if ( columnIndex != 0 ) { return; } + int selectedRow = ComponentPresetTable.this.getSelectedRow(); ComponentPreset preset = ComponentPresetTable.this.presets.get(rowIndex); Application.getComponentPresetDao().setFavorite(preset, presetType, (Boolean) aValue); ComponentPresetTable.this.updateFavorites(); + ComponentPresetTable.this.setRowSelectionInterval(selectedRow, selectedRow); } @Override diff --git a/swing/src/net/sf/openrocket/gui/dialogs/preset/ComponentPresetTableColumn.java b/swing/src/net/sf/openrocket/gui/dialogs/preset/ComponentPresetTableColumn.java index 6bf137b28..04821f75d 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/preset/ComponentPresetTableColumn.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/preset/ComponentPresetTableColumn.java @@ -33,7 +33,7 @@ public abstract class ComponentPresetTableColumn extends TableColumn { @Override public Object getValueFromPreset( Set favorites, ComponentPreset preset ) { - return Boolean.valueOf(favorites.contains(preset.preferenceKey())); + return favorites.contains(preset.preferenceKey()); } } From a9ede4b9728043e32f185ea350989505de644729 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Thu, 21 Jul 2022 01:20:57 +0200 Subject: [PATCH 2/9] Add clarifying text for applying preset selection --- core/resources/l10n/messages.properties | 2 +- .../gui/dialogs/preset/ComponentPresetChooserDialog.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index e70342af9..93872611c 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -2099,7 +2099,7 @@ ComponentPresetChooserDialog.menu.sortDesc = Sort Descending ComponentPresetChooserDialog.menu.units = Units ComponentPresetChooserDialog.checkbox.showAllCompatible = Show all compatible ComponentPresetChooserDialog.checkbox.showLegacyCheckBox = Show Legacy Database -ComponentPresetChooserDialog.lbl.favorites = Check to add preset to the preset drop-down menu in the component edit dialog +ComponentPresetChooserDialog.lbl.favorites = Check to add preset to the preset drop-down menu in the component edit dialog
Directly apply a preset by double-clicking it or by selecting it and closing this window. table.column.Favorite = Favorite table.column.Legacy = Legacy table.column.Manufacturer = Manufacturer diff --git a/swing/src/net/sf/openrocket/gui/dialogs/preset/ComponentPresetChooserDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/preset/ComponentPresetChooserDialog.java index 3061d6d62..6a1c417ad 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/preset/ComponentPresetChooserDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/preset/ComponentPresetChooserDialog.java @@ -25,6 +25,7 @@ import javax.swing.table.TableColumn; import javax.swing.table.TableModel; import net.miginfocom.swing.MigLayout; +import net.sf.openrocket.gui.components.StyledLabel; import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.preset.ComponentPreset; @@ -149,7 +150,7 @@ public class ComponentPresetChooserDialog extends JDialog { scrollpane.setViewportView(componentSelectionTable); panel.add(scrollpane, "grow, width 700lp, height 300lp, pushy, spanx, wrap rel"); - panel.add(new JLabel(Chars.UP_ARROW + " " + trans.get("lbl.favorites")), "spanx, gapleft 5px, wrap para"); + panel.add(new StyledLabel(String.format("%s %s", Chars.UP_ARROW, trans.get("lbl.favorites")), -1), "spanx, gapleft 5px, wrap para"); // Close buttons From 9b6f4bdeac9e31cacfd3fcf7a7aea2cce9edb099 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Fri, 22 Jul 2022 23:11:16 +0200 Subject: [PATCH 3/9] Fix sim button state not updating right --- .../net/sf/openrocket/gui/main/SimulationPanel.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java b/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java index f8ac84ec5..b7f8fa649 100644 --- a/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java @@ -496,11 +496,14 @@ public class SimulationPanel extends JPanel { }); simulationTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { - private int previousRow = -1; + private int previousSelectedRow = -1; + private int previousSelectedRowCount = 0; public void valueChanged(ListSelectionEvent event) { - if (simulationTable.getSelectedRow() != previousRow) { + if ((simulationTable.getSelectedRow() != previousSelectedRow) || + (simulationTable.getSelectedRowCount() != previousSelectedRowCount)) { updateButtonStates(); - previousRow = simulationTable.getSelectedRow(); + previousSelectedRow = simulationTable.getSelectedRow(); + previousSelectedRowCount = simulationTable.getSelectedRowCount(); } } }); @@ -699,10 +702,11 @@ public class SimulationPanel extends JPanel { } else { if (selection.length > 1) { plotButton.setEnabled(false); + editButton.setEnabled(false); } else { plotButton.setEnabled(true); + editButton.setEnabled(true); } - editButton.setEnabled(true); runButton.setEnabled(true); deleteButton.setEnabled(true); } From 97a891ae1908722c2947a72a9cc225f551aafb26 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Sat, 23 Jul 2022 00:09:10 +0200 Subject: [PATCH 4/9] [#1549] Allow ctr/cmd + A command for sim table --- .../net/sf/openrocket/gui/main/SimulationPanel.java | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java b/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java index b7f8fa649..447b6c0da 100644 --- a/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java @@ -19,6 +19,7 @@ import java.util.Arrays; import java.util.Comparator; import javax.swing.AbstractAction; +import javax.swing.InputMap; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComponent; @@ -31,6 +32,7 @@ import javax.swing.JTable; import javax.swing.KeyStroke; import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities; +import javax.swing.UIManager; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import javax.swing.table.DefaultTableCellRenderer; @@ -433,16 +435,7 @@ public class SimulationPanel extends JPanel { // Override processKeyBinding so that the JTable does not catch // key bindings used in menu accelerators simulationTable = new ColumnTable(simulationTableModel) { - private static final long serialVersionUID = -5799340181229735630L; - - @Override - protected boolean processKeyBinding(KeyStroke ks, - KeyEvent e, - int condition, - boolean pressed) { - return false; - } }; ColumnTableRowSorter simulationTableSorter = new ColumnTableRowSorter(simulationTableModel); simulationTable.setRowSorter(simulationTableSorter); From 3602700ff3c9f06c83e5504ca6fe8b30dea420cd Mon Sep 17 00:00:00 2001 From: SiboVG Date: Sat, 23 Jul 2022 00:15:19 +0200 Subject: [PATCH 5/9] [#1549] Select all shortcut in ComponentTree --- .../gui/main/componenttree/ComponentTree.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/swing/src/net/sf/openrocket/gui/main/componenttree/ComponentTree.java b/swing/src/net/sf/openrocket/gui/main/componenttree/ComponentTree.java index a02e626f9..a638ba8d0 100644 --- a/swing/src/net/sf/openrocket/gui/main/componenttree/ComponentTree.java +++ b/swing/src/net/sf/openrocket/gui/main/componenttree/ComponentTree.java @@ -6,6 +6,9 @@ import javax.swing.ToolTipManager; import net.sf.openrocket.document.OpenRocketDocument; import net.sf.openrocket.gui.components.BasicTree; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; + @SuppressWarnings("serial") public class ComponentTree extends BasicTree { @@ -13,7 +16,21 @@ public class ComponentTree extends BasicTree { public ComponentTree(OpenRocketDocument document) { super(); this.setModel(new ComponentTreeModel(document.getRocket(), this)); - + + addKeyListener(new KeyListener() { + @Override + public void keyTyped(KeyEvent e) { } + + @Override + public void keyPressed(KeyEvent e) { + if ((e.getKeyCode() == KeyEvent.VK_A) && ((e.getModifiersEx() & KeyEvent.META_DOWN_MASK) != 0)) { + setSelectionInterval(1, getRowCount()); // Don't select the rocket (row 0) + } + } + + @Override + public void keyReleased(KeyEvent e) { } + }); this.setCellRenderer(new ComponentTreeRenderer()); this.setDragEnabled(true); From ada48369e443f1e0195238ffe2b36de733b55d09 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Sat, 23 Jul 2022 13:44:07 +0200 Subject: [PATCH 6/9] Update sim panel context menu item state --- .../openrocket/gui/main/SimulationPanel.java | 207 ++++++++++-------- 1 file changed, 117 insertions(+), 90 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java b/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java index 447b6c0da..a0904b7d1 100644 --- a/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java @@ -19,7 +19,7 @@ import java.util.Arrays; import java.util.Comparator; import javax.swing.AbstractAction; -import javax.swing.InputMap; +import javax.swing.Action; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComponent; @@ -32,7 +32,6 @@ import javax.swing.JTable; import javax.swing.KeyStroke; import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities; -import javax.swing.UIManager; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import javax.swing.table.DefaultTableCellRenderer; @@ -100,83 +99,55 @@ public class SimulationPanel extends JPanel { private final JButton plotButton; private final JPopupMenu pm; + private final SimulationAction editSimulationAction; + private final SimulationAction runSimulationAction; + private final SimulationAction plotSimulationAction; + private final SimulationAction duplicateSimulationAction; + private final SimulationAction deleteSimulationAction; + public SimulationPanel(OpenRocketDocument doc) { super(new MigLayout("fill", "[grow][][][][][][grow]")); this.document = doc; + // Simulation actions + SimulationAction newSimulationAction = new NewSimulationAction(); + editSimulationAction = new EditSimulationAction(); + runSimulationAction = new RunSimulationAction(); + plotSimulationAction = new PlotSimulationAction(); + duplicateSimulationAction = new DuplicateSimulationAction(); + deleteSimulationAction = new DeleteSimulationAction(); - //////// The simulation action buttons + //////// The simulation action buttons //////// //// New simulation button - { - JButton button = new SelectColorButton(trans.get("simpanel.but.newsimulation")); - //// Add a new simulation - button.setToolTipText(trans.get("simpanel.but.ttip.newsimulation")); - button.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - Simulation sim = new Simulation(document.getRocket()); - sim.setName(document.getNextSimulationName()); - - int n = document.getSimulationCount(); - document.addSimulation(sim); - simulationTableModel.fireTableDataChanged(); - simulationTable.clearSelection(); - simulationTable.addRowSelectionInterval(n, n); - - openDialog(false, sim); - } - }); - this.add(button, "skip 1, gapright para"); - } + JButton newButton = new SelectColorButton(); + tieActionToButtonNoIcon(newButton, newSimulationAction, trans.get("simpanel.but.newsimulation")); + newButton.setToolTipText(trans.get("simpanel.but.ttip.newsimulation")); + this.add(newButton, "skip 1, gapright para"); //// Edit simulation button - editButton = new SelectColorButton(trans.get("simpanel.but.editsimulation")); - //// Edit the selected simulation + editButton = new SelectColorButton(); + tieActionToButtonNoIcon(editButton, editSimulationAction, trans.get("simpanel.but.editsimulation")); editButton.setToolTipText(trans.get("simpanel.but.ttip.editsim")); - editButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - editSimulation(); - } - }); this.add(editButton, "gapright para"); //// Run simulations - runButton = new SelectColorButton(trans.get("simpanel.but.runsimulations")); - //// Re-run the selected simulations + runButton = new SelectColorButton(); + tieActionToButtonNoIcon(runButton, runSimulationAction, trans.get("simpanel.but.runsimulations")); runButton.setToolTipText(trans.get("simpanel.but.ttip.runsimu")); - runButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - runSimulation(); - } - }); this.add(runButton, "gapright para"); //// Delete simulations button - deleteButton = new SelectColorButton(trans.get("simpanel.but.deletesimulations")); - //// Delete the selected simulations + deleteButton = new SelectColorButton(); + tieActionToButtonNoIcon(deleteButton, deleteSimulationAction, trans.get("simpanel.but.deletesimulations")); deleteButton.setToolTipText(trans.get("simpanel.but.ttip.deletesim")); - deleteButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - deleteSimulation(); - } - }); this.add(deleteButton, "gapright para"); //// Plot / export button - plotButton = new SelectColorButton(trans.get("simpanel.but.plotexport")); - // button = new SelectColorButton("Plot flight"); - plotButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - plotSimulation(); - } - }); + plotButton = new SelectColorButton(); + tieActionToButtonNoIcon(plotButton, plotSimulationAction, trans.get("simpanel.but.plotexport")); this.add(plotButton, "wrap para"); @@ -268,7 +239,7 @@ public class SimulationPanel extends JPanel { if (row < 0 || row >= document.getSimulationCount()){ return null; } - + Rocket rkt = document.getRocket(); FlightConfigurationId fcid = document.getSimulation(row).getId(); return descriptor.format( rkt, fcid); @@ -423,7 +394,7 @@ public class SimulationPanel extends JPanel { } ) { - + private static final long serialVersionUID = 8686456963492628476L; @Override @@ -442,14 +413,15 @@ public class SimulationPanel extends JPanel { simulationTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); simulationTable.setDefaultRenderer(Object.class, new JLabelRenderer()); simulationTableModel.setColumnWidths(simulationTable.getColumnModel()); - - pm = new JPopupMenu(); - pm.add(new EditSimulationAction()); - pm.add(new DuplicateSimulationAction()); - pm.add(new DeleteSimulationAction()); - pm.addSeparator(); - pm.add(new RunSimulationAction()); - pm.add(new PlotSimulationAction()); + + // Context menu + pm = new JPopupMenu(); + pm.add(editSimulationAction); + pm.add(duplicateSimulationAction); + pm.add(deleteSimulationAction); + pm.addSeparator(); + pm.add(runSimulationAction); + pm.add(plotSimulationAction); // Mouse listener to act on double-clicks @@ -528,6 +500,19 @@ public class SimulationPanel extends JPanel { updateButtonStates(); } + private void newSimulation() { + Simulation sim = new Simulation(document.getRocket()); + sim.setName(document.getNextSimulationName()); + + int n = document.getSimulationCount(); + document.addSimulation(sim); + simulationTableModel.fireTableDataChanged(); + simulationTable.clearSelection(); + simulationTable.addRowSelectionInterval(n, n); + + openDialog(false, sim); + } + private void plotSimulation() { int selected = simulationTable.getSelectedRow(); if (selected < 0) { @@ -686,24 +671,11 @@ public class SimulationPanel extends JPanel { } private void updateButtonStates() { - int[] selection = simulationTable.getSelectedRows(); - if (selection.length == 0) { - editButton.setEnabled(false); - runButton.setEnabled(false); - deleteButton.setEnabled(false); - plotButton.setEnabled(false); - } else { - if (selection.length > 1) { - plotButton.setEnabled(false); - editButton.setEnabled(false); - } else { - plotButton.setEnabled(true); - editButton.setEnabled(true); - } - runButton.setEnabled(true); - deleteButton.setEnabled(true); - } - + editSimulationAction.updateEnabledState(); + deleteSimulationAction.updateEnabledState(); + runSimulationAction.updateEnabledState(); + plotSimulationAction.updateEnabledState(); + duplicateSimulationAction.updateEnabledState(); } /// when the simulation tab is selected this run outdated simulated if appropriate. @@ -775,7 +747,37 @@ public class SimulationPanel extends JPanel { } } - class EditSimulationAction extends AbstractAction { + private void tieActionToButtonNoIcon(JButton button, Action action, String text) { + button.setAction(action); + button.setIcon(null); + button.setText(text); + } + + private abstract static class SimulationAction extends AbstractAction { + private static final long serialVersionUID = 1L; + + public abstract void updateEnabledState(); + } + + class NewSimulationAction extends SimulationAction { + public NewSimulationAction() { + putValue(NAME, trans.get("simpanel.but.newsimulation")); + this.putValue(MNEMONIC_KEY, KeyEvent.VK_N); + this.putValue(SMALL_ICON, Icons.FILE_NEW); + } + + @Override + public void actionPerformed(ActionEvent e) { + newSimulation(); + } + + @Override + public void updateEnabledState() { + setEnabled(true); + } + } + + class EditSimulationAction extends SimulationAction { public EditSimulationAction() { putValue(NAME, trans.get("simpanel.pop.edit")); this.putValue(MNEMONIC_KEY, KeyEvent.VK_E); @@ -787,9 +789,14 @@ public class SimulationPanel extends JPanel { public void actionPerformed(ActionEvent e) { editSimulation(); } + + @Override + public void updateEnabledState() { + setEnabled(simulationTable.getSelectedRowCount() == 1); + } } - class RunSimulationAction extends AbstractAction { + class RunSimulationAction extends SimulationAction { public RunSimulationAction() { putValue(NAME, trans.get("simpanel.pop.run")); putValue(SMALL_ICON, Icons.SIM_RUN); @@ -799,9 +806,14 @@ public class SimulationPanel extends JPanel { public void actionPerformed(ActionEvent e) { runSimulation(); } + + @Override + public void updateEnabledState() { + setEnabled(simulationTable.getSelectedRowCount() > 0); + } } - class DeleteSimulationAction extends AbstractAction { + class DeleteSimulationAction extends SimulationAction { public DeleteSimulationAction() { putValue(NAME, trans.get("simpanel.pop.delete")); putValue(MNEMONIC_KEY, KeyEvent.VK_D); @@ -813,9 +825,14 @@ public class SimulationPanel extends JPanel { public void actionPerformed(ActionEvent e) { deleteSimulation(); } + + @Override + public void updateEnabledState() { + setEnabled(simulationTable.getSelectedRowCount() > 0); + } } - class PlotSimulationAction extends AbstractAction { + class PlotSimulationAction extends SimulationAction { public PlotSimulationAction() { putValue(NAME, trans.get("simpanel.pop.plot")); putValue(SMALL_ICON, Icons.SIM_PLOT); @@ -825,9 +842,14 @@ public class SimulationPanel extends JPanel { public void actionPerformed(ActionEvent e) { plotSimulation(); } + + @Override + public void updateEnabledState() { + setEnabled(simulationTable.getSelectedRowCount() == 1); + } } - class DuplicateSimulationAction extends AbstractAction { + class DuplicateSimulationAction extends SimulationAction { public DuplicateSimulationAction() { putValue(NAME, trans.get("simpanel.pop.duplicate")); putValue(MNEMONIC_KEY, KeyEvent.VK_D); @@ -839,7 +861,12 @@ public class SimulationPanel extends JPanel { public void actionPerformed(ActionEvent e) { duplicateSimulation(); } - } + + @Override + public void updateEnabledState() { + setEnabled(simulationTable.getSelectedRowCount() > 0); + } + } public static class CellTransferable implements Transferable { From c29955b7f859ae597a6f22298b80fe8f6b2165f6 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Sat, 23 Jul 2022 14:04:09 +0200 Subject: [PATCH 7/9] Move method to RocketActions --- .../sf/openrocket/gui/main/RocketActions.java | 30 +++++++++++++++++++ .../openrocket/gui/main/SimulationPanel.java | 18 ++++------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/main/RocketActions.java b/swing/src/net/sf/openrocket/gui/main/RocketActions.java index 86a3ea6bf..15ed1d597 100644 --- a/swing/src/net/sf/openrocket/gui/main/RocketActions.java +++ b/swing/src/net/sf/openrocket/gui/main/RocketActions.java @@ -12,6 +12,7 @@ import java.util.List; import javax.swing.AbstractAction; import javax.swing.Action; +import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JOptionPane; import javax.swing.JPanel; @@ -189,6 +190,35 @@ public class RocketActions { return moveDownAction; } + /** + * Tie an action to a JButton, without using the icon or text of the action for the button. + * + * For any smartass that wants to know why you don't just initialize the JButton with the action and then set the + * icon to null and set the button text: this causes a bug where the text of the icon becomes much smaller than is intended. + * + * @param button button to tie the action to + * @param action action to tie to the button + * @param text text to display on the button + */ + public static void tieActionToButtonNoIcon(JButton button, Action action, String text) { + button.setAction(action); + button.setIcon(null); + button.setText(text); + } + + /** + * Tie an action to a JButton, without using the icon of the action for the button. + * + * For any smartass that wants to know why you don't just initialize the JButton with the action and then set the + * icon to null: this causes a bug where the text of the icon becomes much smaller than is intended. + * + * @param button button to tie the action to + * @param action action to tie to the button + */ + public static void tieActionToButtonNoIcon(JButton button, Action action) { + button.setAction(action); + button.setIcon(null); + } //////// Helper methods for the actions diff --git a/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java b/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java index a0904b7d1..be9359509 100644 --- a/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java @@ -10,7 +10,6 @@ import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.Transferable; import java.awt.datatransfer.UnsupportedFlavorException; import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; @@ -19,7 +18,6 @@ import java.util.Arrays; import java.util.Comparator; import javax.swing.AbstractAction; -import javax.swing.Action; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComponent; @@ -123,31 +121,31 @@ public class SimulationPanel extends JPanel { //// New simulation button JButton newButton = new SelectColorButton(); - tieActionToButtonNoIcon(newButton, newSimulationAction, trans.get("simpanel.but.newsimulation")); + RocketActions.tieActionToButtonNoIcon(newButton, newSimulationAction, trans.get("simpanel.but.newsimulation")); newButton.setToolTipText(trans.get("simpanel.but.ttip.newsimulation")); this.add(newButton, "skip 1, gapright para"); //// Edit simulation button editButton = new SelectColorButton(); - tieActionToButtonNoIcon(editButton, editSimulationAction, trans.get("simpanel.but.editsimulation")); + RocketActions.tieActionToButtonNoIcon(editButton, editSimulationAction, trans.get("simpanel.but.editsimulation")); editButton.setToolTipText(trans.get("simpanel.but.ttip.editsim")); this.add(editButton, "gapright para"); //// Run simulations runButton = new SelectColorButton(); - tieActionToButtonNoIcon(runButton, runSimulationAction, trans.get("simpanel.but.runsimulations")); + RocketActions.tieActionToButtonNoIcon(runButton, runSimulationAction, trans.get("simpanel.but.runsimulations")); runButton.setToolTipText(trans.get("simpanel.but.ttip.runsimu")); this.add(runButton, "gapright para"); //// Delete simulations button deleteButton = new SelectColorButton(); - tieActionToButtonNoIcon(deleteButton, deleteSimulationAction, trans.get("simpanel.but.deletesimulations")); + RocketActions.tieActionToButtonNoIcon(deleteButton, deleteSimulationAction, trans.get("simpanel.but.deletesimulations")); deleteButton.setToolTipText(trans.get("simpanel.but.ttip.deletesim")); this.add(deleteButton, "gapright para"); //// Plot / export button plotButton = new SelectColorButton(); - tieActionToButtonNoIcon(plotButton, plotSimulationAction, trans.get("simpanel.but.plotexport")); + RocketActions.tieActionToButtonNoIcon(plotButton, plotSimulationAction, trans.get("simpanel.but.plotexport")); this.add(plotButton, "wrap para"); @@ -747,12 +745,6 @@ public class SimulationPanel extends JPanel { } } - private void tieActionToButtonNoIcon(JButton button, Action action, String text) { - button.setAction(action); - button.setIcon(null); - button.setText(text); - } - private abstract static class SimulationAction extends AbstractAction { private static final long serialVersionUID = 1L; From 587babb5669ef3c590128eab827f479dad83287f Mon Sep 17 00:00:00 2001 From: SiboVG Date: Sat, 23 Jul 2022 14:07:23 +0200 Subject: [PATCH 8/9] Use getDeleteAction in BasicFrame Fixes the bug of the text for edit, delete and duplicate button to become smaller --- swing/src/net/sf/openrocket/gui/main/BasicFrame.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/main/BasicFrame.java b/swing/src/net/sf/openrocket/gui/main/BasicFrame.java index 6f76a838d..e5e31ce87 100644 --- a/swing/src/net/sf/openrocket/gui/main/BasicFrame.java +++ b/swing/src/net/sf/openrocket/gui/main/BasicFrame.java @@ -418,18 +418,18 @@ public class BasicFrame extends JFrame { button = new SelectColorButton(actions.getMoveDownAction()); panel.add(button, "sizegroup buttons, aligny 0%"); - button = new SelectColorButton(actions.getEditAction()); - button.setIcon(null); + button = new SelectColorButton(); + RocketActions.tieActionToButtonNoIcon(button, actions.getEditAction()); button.setMnemonic(0); panel.add(button, "sizegroup buttons, gaptop 20%"); - button = new SelectColorButton(actions.getDuplicateAction()); - button.setIcon(null); + button = new SelectColorButton(); + RocketActions.tieActionToButtonNoIcon(button, actions.getDuplicateAction()); button.setMnemonic(0); panel.add(button, "sizegroup buttons"); - button = new SelectColorButton(actions.getDeleteAction()); - button.setIcon(null); + button = new SelectColorButton(); + RocketActions.tieActionToButtonNoIcon(button, actions.getDeleteAction()); button.setMnemonic(0); panel.add(button, "sizegroup buttons"); From 651ba88a475daa8ec504eb0bd5e23e10a96cc038 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Sat, 23 Jul 2022 14:36:33 +0200 Subject: [PATCH 9/9] Clean up code... --- .../openrocket/gui/main/SimulationPanel.java | 498 +++++++++--------- 1 file changed, 249 insertions(+), 249 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java b/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java index be9359509..efd353b90 100644 --- a/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java @@ -151,255 +151,7 @@ public class SimulationPanel extends JPanel { //////// The simulation table - - simulationTableModel = new ColumnTableModel( - - //// Status and warning column - new Column("") { - private JLabel label = null; - - @Override - public Object getValueAt(int row) { - if (row < 0 || row >= document.getSimulationCount()) - return null; - - // Initialize the label - if (label == null) { - label = new StyledLabel(2f); - label.setIconTextGap(1); - // label.setFont(label.getFont().deriveFont(Font.BOLD)); - } - - // Set simulation status icon - Simulation.Status status = document.getSimulation(row).getStatus(); - label.setIcon(Icons.SIMULATION_STATUS_ICON_MAP.get(status)); - - - // Set warning marker - if (status == Simulation.Status.NOT_SIMULATED || - status == Simulation.Status.EXTERNAL) { - - label.setText(""); - - } else { - - WarningSet w = document.getSimulation(row).getSimulatedWarnings(); - if (w == null) { - label.setText(""); - } else if (w.isEmpty()) { - label.setForeground(OK_COLOR); - label.setText(OK_TEXT); - } else { - label.setForeground(WARNING_COLOR); - label.setText(WARNING_TEXT); - } - } - - return label; - } - - @Override - public int getExactWidth() { - return 36; - } - - @Override - public Class getColumnClass() { - return JLabel.class; - } - }, - - //// Simulation name - //// Name - new Column(trans.get("simpanel.col.Name")) { - @Override - public Object getValueAt(int row) { - if (row < 0 || row >= document.getSimulationCount()) - return null; - return document.getSimulation(row).getName(); - } - - @Override - public int getDefaultWidth() { - return 125; - } - - @Override - public Comparator getComparator() { - return new AlphanumComparator(); - } - }, - - //// Simulation configuration - new Column(trans.get("simpanel.col.Configuration")) { - @Override - public Object getValueAt(int row) { - if (row < 0 || row >= document.getSimulationCount()){ - return null; - } - - Rocket rkt = document.getRocket(); - FlightConfigurationId fcid = document.getSimulation(row).getId(); - return descriptor.format( rkt, fcid); - } - - @Override - public int getDefaultWidth() { - return 125; - } - }, - - //// Launch rod velocity - new ValueColumn(trans.get("simpanel.col.Velocityoffrod"), UnitGroup.UNITS_VELOCITY) { - @Override - public Double valueAt(int row) { - if (row < 0 || row >= document.getSimulationCount()) - return null; - - FlightData data = document.getSimulation(row).getSimulatedData(); - if (data == null) - return null; - - return data.getLaunchRodVelocity(); - } - - }, - - //// Apogee - new ValueColumn(trans.get("simpanel.col.Apogee"), UnitGroup.UNITS_DISTANCE) { - @Override - public Double valueAt(int row) { - if (row < 0 || row >= document.getSimulationCount()) - return null; - - FlightData data = document.getSimulation(row).getSimulatedData(); - if (data == null) - return null; - - return data.getMaxAltitude(); - } - }, - - //// Velocity at deployment - new ValueColumn(trans.get("simpanel.col.Velocityatdeploy"), UnitGroup.UNITS_VELOCITY) { - @Override - public Double valueAt(int row) { - if (row < 0 || row >= document.getSimulationCount()) - return null; - - FlightData data = document.getSimulation(row).getSimulatedData(); - if (data == null) - return null; - - return data.getDeploymentVelocity(); - } - }, - - //// Deployment Time from Apogee - new ValueColumn(trans.get("simpanel.col.OptimumCoastTime"), - trans.get("simpanel.col.OptimumCoastTime.ttip"), - UnitGroup.UNITS_SHORT_TIME) { - @Override - public Double valueAt(int row) { - if (row < 0 || row >= document.getSimulationCount()) - return null; - - FlightData data = document.getSimulation(row).getSimulatedData(); - if (data == null || data.getBranchCount() == 0) - return null; - - double val = data.getBranch(0).getOptimumDelay(); - if ( Double.isNaN(val) ) { - return null; - } - return val; - } - }, - - //// Maximum velocity - new ValueColumn(trans.get("simpanel.col.Maxvelocity"), UnitGroup.UNITS_VELOCITY) { - @Override - public Double valueAt(int row) { - if (row < 0 || row >= document.getSimulationCount()) - return null; - - FlightData data = document.getSimulation(row).getSimulatedData(); - if (data == null) - return null; - - return data.getMaxVelocity(); - } - }, - - //// Maximum acceleration - new ValueColumn(trans.get("simpanel.col.Maxacceleration"), UnitGroup.UNITS_ACCELERATION) { - @Override - public Double valueAt(int row) { - if (row < 0 || row >= document.getSimulationCount()) - return null; - - FlightData data = document.getSimulation(row).getSimulatedData(); - if (data == null) - return null; - - return data.getMaxAcceleration(); - } - }, - - //// Time to apogee - new ValueColumn(trans.get("simpanel.col.Timetoapogee"), UnitGroup.UNITS_FLIGHT_TIME) { - @Override - public Double valueAt(int row) { - if (row < 0 || row >= document.getSimulationCount()) - return null; - - FlightData data = document.getSimulation(row).getSimulatedData(); - if (data == null) - return null; - - return data.getTimeToApogee(); - } - }, - - //// Flight time - new ValueColumn(trans.get("simpanel.col.Flighttime"), UnitGroup.UNITS_FLIGHT_TIME) { - @Override - public Double valueAt(int row) { - if (row < 0 || row >= document.getSimulationCount()) - return null; - - FlightData data = document.getSimulation(row).getSimulatedData(); - if (data == null) - return null; - - return data.getFlightTime(); - } - }, - - //// Ground hit velocity - new ValueColumn(trans.get("simpanel.col.Groundhitvelocity"), UnitGroup.UNITS_VELOCITY) { - @Override - public Double valueAt(int row) { - if (row < 0 || row >= document.getSimulationCount()) - return null; - - FlightData data = document.getSimulation(row).getSimulatedData(); - if (data == null) - return null; - - return data.getGroundHitVelocity(); - } - } - - ) { - - private static final long serialVersionUID = 8686456963492628476L; - - @Override - public int getRowCount() { - return document.getSimulationCount(); - } - }; + simulationTableModel = new SimulationTableModel(); // Override processKeyBinding so that the JTable does not catch // key bindings used in menu accelerators @@ -971,6 +723,254 @@ public class SimulationPanel extends JPanel { return tip; } + } + private class SimulationTableModel extends ColumnTableModel { + private static final long serialVersionUID = 8686456963492628476L; + + public SimulationTableModel() { + super( + //// Status and warning column + new Column("") { + private JLabel label = null; + + @Override + public Object getValueAt(int row) { + if (row < 0 || row >= document.getSimulationCount()) + return null; + + // Initialize the label + if (label == null) { + label = new StyledLabel(2f); + label.setIconTextGap(1); + // label.setFont(label.getFont().deriveFont(Font.BOLD)); + } + + // Set simulation status icon + Simulation.Status status = document.getSimulation(row).getStatus(); + label.setIcon(Icons.SIMULATION_STATUS_ICON_MAP.get(status)); + + + // Set warning marker + if (status == Simulation.Status.NOT_SIMULATED || + status == Simulation.Status.EXTERNAL) { + + label.setText(""); + + } else { + + WarningSet w = document.getSimulation(row).getSimulatedWarnings(); + if (w == null) { + label.setText(""); + } else if (w.isEmpty()) { + label.setForeground(OK_COLOR); + label.setText(OK_TEXT); + } else { + label.setForeground(WARNING_COLOR); + label.setText(WARNING_TEXT); + } + } + + return label; + } + + @Override + public int getExactWidth() { + return 36; + } + + @Override + public Class getColumnClass() { + return JLabel.class; + } + }, + + //// Simulation name + //// Name + new Column(trans.get("simpanel.col.Name")) { + @Override + public Object getValueAt(int row) { + if (row < 0 || row >= document.getSimulationCount()) + return null; + return document.getSimulation(row).getName(); + } + + @Override + public int getDefaultWidth() { + return 125; + } + + @Override + public Comparator getComparator() { + return new AlphanumComparator(); + } + }, + + //// Simulation configuration + new Column(trans.get("simpanel.col.Configuration")) { + @Override + public Object getValueAt(int row) { + if (row < 0 || row >= document.getSimulationCount()) { + return null; + } + + Rocket rkt = document.getRocket(); + FlightConfigurationId fcid = document.getSimulation(row).getId(); + return descriptor.format(rkt, fcid); + } + + @Override + public int getDefaultWidth() { + return 125; + } + }, + + //// Launch rod velocity + new ValueColumn(trans.get("simpanel.col.Velocityoffrod"), UnitGroup.UNITS_VELOCITY) { + @Override + public Double valueAt(int row) { + if (row < 0 || row >= document.getSimulationCount()) + return null; + + FlightData data = document.getSimulation(row).getSimulatedData(); + if (data == null) + return null; + + return data.getLaunchRodVelocity(); + } + + }, + + //// Apogee + new ValueColumn(trans.get("simpanel.col.Apogee"), UnitGroup.UNITS_DISTANCE) { + @Override + public Double valueAt(int row) { + if (row < 0 || row >= document.getSimulationCount()) + return null; + + FlightData data = document.getSimulation(row).getSimulatedData(); + if (data == null) + return null; + + return data.getMaxAltitude(); + } + }, + + //// Velocity at deployment + new ValueColumn(trans.get("simpanel.col.Velocityatdeploy"), UnitGroup.UNITS_VELOCITY) { + @Override + public Double valueAt(int row) { + if (row < 0 || row >= document.getSimulationCount()) + return null; + + FlightData data = document.getSimulation(row).getSimulatedData(); + if (data == null) + return null; + + return data.getDeploymentVelocity(); + } + }, + + //// Deployment Time from Apogee + new ValueColumn(trans.get("simpanel.col.OptimumCoastTime"), + trans.get("simpanel.col.OptimumCoastTime.ttip"), UnitGroup.UNITS_SHORT_TIME) { + @Override + public Double valueAt(int row) { + if (row < 0 || row >= document.getSimulationCount()) + return null; + + FlightData data = document.getSimulation(row).getSimulatedData(); + if (data == null || data.getBranchCount() == 0) + return null; + + double val = data.getBranch(0).getOptimumDelay(); + if (Double.isNaN(val)) { + return null; + } + return val; + } + }, + + //// Maximum velocity + new ValueColumn(trans.get("simpanel.col.Maxvelocity"), UnitGroup.UNITS_VELOCITY) { + @Override + public Double valueAt(int row) { + if (row < 0 || row >= document.getSimulationCount()) + return null; + + FlightData data = document.getSimulation(row).getSimulatedData(); + if (data == null) + return null; + + return data.getMaxVelocity(); + } + }, + + //// Maximum acceleration + new ValueColumn(trans.get("simpanel.col.Maxacceleration"), UnitGroup.UNITS_ACCELERATION) { + @Override + public Double valueAt(int row) { + if (row < 0 || row >= document.getSimulationCount()) + return null; + + FlightData data = document.getSimulation(row).getSimulatedData(); + if (data == null) + return null; + + return data.getMaxAcceleration(); + } + }, + + //// Time to apogee + new ValueColumn(trans.get("simpanel.col.Timetoapogee"), UnitGroup.UNITS_FLIGHT_TIME) { + @Override + public Double valueAt(int row) { + if (row < 0 || row >= document.getSimulationCount()) + return null; + + FlightData data = document.getSimulation(row).getSimulatedData(); + if (data == null) + return null; + + return data.getTimeToApogee(); + } + }, + + //// Flight time + new ValueColumn(trans.get("simpanel.col.Flighttime"), UnitGroup.UNITS_FLIGHT_TIME) { + @Override + public Double valueAt(int row) { + if (row < 0 || row >= document.getSimulationCount()) + return null; + + FlightData data = document.getSimulation(row).getSimulatedData(); + if (data == null) + return null; + + return data.getFlightTime(); + } + }, + + //// Ground hit velocity + new ValueColumn(trans.get("simpanel.col.Groundhitvelocity"), UnitGroup.UNITS_VELOCITY) { + @Override + public Double valueAt(int row) { + if (row < 0 || row >= document.getSimulationCount()) + return null; + + FlightData data = document.getSimulation(row).getSimulatedData(); + if (data == null) + return null; + + return data.getGroundHitVelocity(); + } + } + ); + } + + @Override + public int getRowCount() { + return document.getSimulationCount(); + } } }