Merge branch 'unstable' into remove->delete

This commit is contained in:
SiboVG 2022-08-23 14:53:03 +02:00
commit dafeaf065a
34 changed files with 942 additions and 741 deletions

View File

@ -2099,7 +2099,6 @@ ComponentPresetChooserDialog.checkbox.filterForeDiameter = Match fore diameter
ComponentPresetChooserDialog.menu.sortAsc = Sort Ascending
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<br>Directly apply a preset by double-clicking it or by selecting it and closing this window.
table.column.Favorite = Favorite

View File

@ -1598,7 +1598,6 @@ ComponentPresetChooserDialog.checkbox.filterForeDiameter = Shoda predn
ComponentPresetChooserDialog.menu.sortAsc = Serad vzestupne
ComponentPresetChooserDialog.menu.sortDesc = Serad sestupne
ComponentPresetChooserDialog.menu.units = Jednotky
ComponentPresetChooserDialog.checkbox.showAllCompatible = Uka\u017E v\u0161e co je kompaktibilní
table.column.Favorite = Oblíbené
table.column.Manufacturer = Výrobce
table.column.PartNo = Císlo soucástky

View File

@ -1656,7 +1656,6 @@ ComponentPresetChooserDialog.checkbox.filterForeDiameter = Vorderer Durchmesser
ComponentPresetChooserDialog.menu.sortAsc = Aufsteigend sortieren
ComponentPresetChooserDialog.menu.sortDesc = Absteigend sortieren
ComponentPresetChooserDialog.menu.units = Einheiten
ComponentPresetChooserDialog.checkbox.showAllCompatible = Alle kompatiblen anzeigen
table.column.Favorite = Favorit
table.column.Manufacturer = Hersteller
table.column.PartNo = Teile-Nummer

View File

@ -153,7 +153,6 @@ ComponentIcons.disabled = (Deshabilitado)
ComponentPresetChooserDialog.checkbox.filterAftDiameter = Ajustado al di\u00e1metro trasero
ComponentPresetChooserDialog.checkbox.filterForeDiameter = Ajustado al di\u00e1metro delantero
ComponentPresetChooserDialog.checkbox.showAllCompatible = Mostrar todos los compatibles
ComponentPresetChooserDialog.filter.label = Filtro:
ComponentPresetChooserDialog.lbl.favorites = Seleccione los items que aparecer\u00e1n en el desplegable de materiales.
ComponentPresetChooserDialog.menu.sortAsc = Orden ascendente

View File

@ -143,7 +143,6 @@ ComponentIcons.disabled = (d\u00E9sactiv\u00E9)
ComponentPresetChooserDialog.checkbox.filterAftDiameter = Match aft diameter
ComponentPresetChooserDialog.checkbox.filterForeDiameter = Match fore diameter
ComponentPresetChooserDialog.checkbox.showAllCompatible = Montrer tous ceux qui sont compatibles
ComponentPresetChooserDialog.filter.label = Filtrer:
ComponentPresetChooserDialog.lbl.favorites = Select to add preset to drop-down menu
ComponentPresetChooserDialog.menu.sortAsc = Trier par ordre croissant

View File

@ -1662,7 +1662,6 @@ ComponentPresetChooserDialog.checkbox.filterForeDiameter = Allinea al diametro a
ComponentPresetChooserDialog.menu.sortAsc = Ordine ascendente
ComponentPresetChooserDialog.menu.sortDesc = Ordine decrescente
ComponentPresetChooserDialog.menu.units = Unit\u00e0
ComponentPresetChooserDialog.checkbox.showAllCompatible = Mostra tutti i compatibili
table.column.Favorite = Preferito
table.column.Manufacturer = Produttore
table.column.PartNo = Numero del pezzo

View File

@ -1724,7 +1724,6 @@ ComponentPresetChooserDialog.checkbox.filterForeDiameter = \u524D\u65B9\u306E\u
ComponentPresetChooserDialog.menu.sortAsc = \u6607\u9806\u30BD\u30FC\u30C8
ComponentPresetChooserDialog.menu.sortDesc = \u964D\u9806\u30BD\u30FC\u30C8
ComponentPresetChooserDialog.menu.units = \u5358\u4F4D
ComponentPresetChooserDialog.checkbox.showAllCompatible = \u3059\u3079\u3066\u306E\u90E8\u54C1\u3092\u8868\u793A
ComponentPresetChooserDialog.lbl.favorites = Select to add preset to drop-down menu
table.column.Favorite = \u304A\u6C17\u306B\u5165\u308A
table.column.Manufacturer = \u88FD\u9020\u4F1A\u793E

View File

@ -1985,7 +1985,6 @@ ComponentPresetChooserDialog.checkbox.filterForeDiameter = Gelijke voordiameter
ComponentPresetChooserDialog.menu.sortAsc = Sorteer oplopend
ComponentPresetChooserDialog.menu.sortDesc = Sorteer aflopend
ComponentPresetChooserDialog.menu.units = Eenheden
ComponentPresetChooserDialog.checkbox.showAllCompatible = Toon alle compatibele
ComponentPresetChooserDialog.lbl.favorites = Selecteer om preset aan drop-down menu toe te voegen
table.column.Favorite = Favoriet
table.column.Manufacturer = Fabrikant

View File

@ -1603,7 +1603,6 @@ update.dlg.latestVersion = Korzystasz z najnowszej wersji OpenRocket: %s.
ComponentPresetChooserDialog.menu.sortAsc = Szereguj rosn\u0105co
ComponentPresetChooserDialog.menu.sortDesc = Szereguj malej\u0105co
ComponentPresetChooserDialog.menu.units = Jednostki
ComponentPresetChooserDialog.checkbox.showAllCompatible = Poka\u017C wszystkie kompatybilne
table.column.Favorite = Ulubione
table.column.Manufacturer = Producent
table.column.PartNo = Numer cz\u0119\u015Bci

View File

@ -135,7 +135,6 @@ ComponentIcons.disabled = (desabilitado)
ComponentPresetChooserDialog.checkbox.filterAftDiameter = Ajuste do di\u00e2metro traseiro
ComponentPresetChooserDialog.checkbox.filterForeDiameter = Ajustar di\u00e2metro dianteiro
ComponentPresetChooserDialog.checkbox.showAllCompatible = Mostrar todos compat\u00edveis
ComponentPresetChooserDialog.filter.label = Filtrar por texto:
ComponentPresetChooserDialog.lbl.favorites = Selecione para adicionar predefinido para menu drop-down
ComponentPresetChooserDialog.menu.sortAsc = Classifica\u00e7\u00e3o Crescente

View File

@ -2103,7 +2103,6 @@ ComponentPresetChooserDialog.checkbox.filterForeDiameter = \u0418\u0441\u043A\u0
ComponentPresetChooserDialog.menu.sortAsc = \u041F\u043E \u0432\u043E\u0437\u0440\u0430\u0441\u0442\u0430\u043D\u0438\u044E
ComponentPresetChooserDialog.menu.sortDesc = \u041F\u043E \u0443\u0431\u044B\u0432\u0430\u043D\u0438\u044E
ComponentPresetChooserDialog.menu.units = \u0415\u0434\u0438\u043D\u0438\u0446\u044B \u0438\u0437\u043C\u0435\u0440\u0435\u043D\u0438\u044F
ComponentPresetChooserDialog.checkbox.showAllCompatible = \u041F\u043E\u043A\u0430\u0437\u0430\u0442\u044C \u0432\u0441\u0435 \u0441\u043E\u0432\u043C\u0435\u0441\u0442\u0438\u043C\u044B\u0435
ComponentPresetChooserDialog.checkbox.showLegacyCheckBox = \u041F\u043E\u043A\u0430\u0437\u0430\u0442\u044C \u0431\u0430\u0437\u0443 \u0434\u0430\u043D\u043D\u044B\u0445 \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u0445
ComponentPresetChooserDialog.lbl.favorites = \u0423\u0441\u0442\u0430\u043D\u043E\u0432\u0438\u0442\u0435 \u044D\u0442\u043E\u0442 \u0444\u043B\u0430\u0436\u043E\u043A, \u0447\u0442\u043E\u0431\u044B \u0434\u043E\u0431\u0430\u0432\u0438\u0442\u044C \u0437\u0430\u0433\u043E\u0442\u043E\u0432\u043A\u0443 \u0432 \u0440\u0430\u0441\u043A\u0440\u044B\u0432\u0430\u044E\u0449\u0435\u0435\u0441\u044F \u043C\u0435\u043D\u044E \u0437\u0430\u0433\u043E\u0442\u043E\u0432\u043E\u043A \u0432 \u0434\u0438\u0430\u043B\u043E\u0433\u043E\u0432\u043E\u043C \u043E\u043A\u043D\u0435 \u0440\u0435\u0434\u0430\u043A\u0442\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u044F \u043A\u043E\u043C\u043F\u043E\u043D\u0435\u043D\u0442\u0430.
table.column.Favorite = \u0418\u0437\u0431\u0440\u0430\u043D\u043D\u043E\u0435

View File

@ -1830,7 +1830,6 @@ ComponentPresetChooserDialog.checkbox.filterForeDiameter = Match fore diameter
ComponentPresetChooserDialog.menu.sortAsc = Sort Ascending
ComponentPresetChooserDialog.menu.sortDesc = Sort Descending
ComponentPresetChooserDialog.menu.units = Units
ComponentPresetChooserDialog.checkbox.showAllCompatible = Show all compatible
ComponentPresetChooserDialog.lbl.favorites = Select to add preset to drop-down menu
table.column.Favorite = Favorite
table.column.Manufacturer = Manufacturer

View File

@ -158,7 +158,6 @@ ComponentIcons.disabled = (\u5DF2\u7981\u7528)
ComponentPresetChooserDialog.checkbox.filterAftDiameter = \u5339\u914D\u540E\u76F4\u5F84
ComponentPresetChooserDialog.checkbox.filterForeDiameter = \u5339\u914D\u524D\u76F4\u5F84
ComponentPresetChooserDialog.checkbox.showAllCompatible = \u663E\u793A\u6240\u6709\u517C\u5BB9\u7EC4\u4EF6
ComponentPresetChooserDialog.filter.label = \u6587\u672C\u8FC7\u6EE4:
ComponentPresetChooserDialog.lbl.favorites = \u6DFB\u52A0\u5230\u9884\u8BBE\u4E0B\u62C9\u6846
ComponentPresetChooserDialog.menu.sortAsc = \u5347\u5E8F

View File

@ -174,24 +174,10 @@ public class ComponentPreset implements Comparable<ComponentPreset>, Serializabl
this.displayedColumns = displayedColumns;
}
public List<Type> getCompatibleTypes() {
return compatibleTypeMap.get(Type.this);
}
public TypedKey<?>[] getDisplayedColumns() {
return displayedColumns;
}
private static final Map<Type, List<Type>> compatibleTypeMap = new HashMap<Type, List<Type>>();
static {
compatibleTypeMap.put(BODY_TUBE, Arrays.asList(BODY_TUBE, TUBE_COUPLER, LAUNCH_LUG));
compatibleTypeMap.put(TUBE_COUPLER, Arrays.asList(BODY_TUBE, TUBE_COUPLER, LAUNCH_LUG));
compatibleTypeMap.put(LAUNCH_LUG, Arrays.asList(BODY_TUBE, TUBE_COUPLER, LAUNCH_LUG));
compatibleTypeMap.put(CENTERING_RING, Arrays.asList(CENTERING_RING, ENGINE_BLOCK));
compatibleTypeMap.put(NOSE_CONE, Arrays.asList(NOSE_CONE, TRANSITION));
}
}
public final static TypedKey<Boolean> LEGACY = new TypedKey<Boolean>("Legacy", Boolean.class);

View File

@ -305,6 +305,9 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
while (!toProcess.isEmpty()) {
RocketComponent comp = toProcess.poll();
if (comp == null) {
continue;
}
toReturn.add(comp);
for (RocketComponent child : comp.getChildren()) {

@ -1 +1 @@
Subproject commit 4c3604313f0cc8f52274c8fa07e4970e6bfaa273
Subproject commit 89d5452fa1f21db46719b8e42de0330fac391f0d

View File

@ -381,7 +381,7 @@ public class DebugLogDialog extends JDialog {
});
GUIUtil.setDisposableDialogOptions(this, close);
setLocationRelativeTo(null);
setLocationRelativeTo(parent);
followBox.requestFocus();
}

View File

@ -163,9 +163,11 @@ public class EditDecalDialog extends JDialog {
panel.add(cancelButton, "tag cancel");
this.add(panel);
GUIUtil.rememberWindowSize(this);
GUIUtil.setDisposableDialogOptions(this, okButton);
GUIUtil.rememberWindowSize(this);
this.setLocationByPlatform(true);
GUIUtil.rememberWindowPosition(this);
}

View File

@ -116,6 +116,8 @@ public class OptimizationPlotDialog extends JDialog {
GUIUtil.setDisposableDialogOptions(this, close);
GUIUtil.rememberWindowSize(this);
this.setLocationByPlatform(true);
GUIUtil.rememberWindowPosition(this);
}

View File

@ -2,6 +2,7 @@ package net.sf.openrocket.gui.dialogs.preset;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@ -82,7 +83,11 @@ public class ComponentPresetChooserDialog extends JDialog {
this.presetType = component.getPresetType();
this.presetModel = presetModel;
this.presets = Application.getComponentPresetDao().listForType(component.getPresetType());
if (owner.getParent() != null) {
this.setPreferredSize(new Dimension((int)(0.7 * owner.getParent().getWidth()), (int) (0.7 * owner.getParent().getHeight())));
this.setLocationRelativeTo(owner.getParent());
}
List<TypedKey<?>> displayedColumnKeys = Arrays.asList(component.getPresetType().getDisplayedColumns());
{
@ -143,7 +148,7 @@ public class ComponentPresetChooserDialog extends JDialog {
// need to create componentSelectionTable before filter checkboxes,
// but add to panel after
componentSelectionTable = new ComponentPresetTable(presetType, presets, displayedColumnKeys);
// GUIUtil.setAutomaticColumnTableWidths(componentSelectionTable, 20);
GUIUtil.setAutomaticColumnTableWidths(componentSelectionTable, 20);
int w = componentSelectionTable.getRowHeight() + 4;
XTableColumnModel tm = componentSelectionTable.getXColumnModel();
//TableColumn tc = componentSelectionTable.getColumnModel().getColumn(0);
@ -156,7 +161,7 @@ public class ComponentPresetChooserDialog extends JDialog {
JScrollPane scrollpane = new JScrollPane();
scrollpane.setViewportView(componentSelectionTable);
panel.add(scrollpane, "grow, width 700lp, height 300lp, pushy, spanx, wrap rel");
panel.add(scrollpane, "grow, pushy, spanx, wrap rel");
panel.add(new StyledLabel(String.format("<html>%s %s</html>", Chars.UP_ARROW, trans.get("lbl.favorites")), -1), "spanx, gapleft 5px, wrap para");
@ -183,9 +188,12 @@ public class ComponentPresetChooserDialog extends JDialog {
panel.add(closeButton, "spanx, right, tag close");
this.add(panel);
GUIUtil.rememberWindowSize(this);
GUIUtil.setDisposableDialogOptions(this, closeButton);
GUIUtil.rememberWindowSize(this);
this.setLocationByPlatform(true);
GUIUtil.rememberWindowPosition(this);
GUIUtil.rememberTableColumnWidths(componentSelectionTable, "Presets" + component.getClass().getCanonicalName());
updateFilters();
}
@ -208,28 +216,6 @@ public class ComponentPresetChooserDialog extends JDialog {
private JPanel getFilterCheckboxes(XTableColumnModel tm, int legacyColumnIndex) {
JPanel panel = new JPanel(new MigLayout("ins 0"));
/*
* Add show all compatible check box.
*/
final List<ComponentPreset.Type> compatibleTypes = component.getPresetType().getCompatibleTypes();
final ComponentPreset.Type nativeType = component.getPresetType();
if (compatibleTypes != null && compatibleTypes.size() > 0) {
JCheckBox showAll = new JCheckBox();
showAll.setText(trans.get("ComponentPresetChooserDialog.checkbox.showAllCompatible"));
panel.add(showAll, "wrap");
showAll.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (((JCheckBox) e.getItem()).isSelected()) {
presets = Application.getComponentPresetDao().listForTypes(compatibleTypes);
} else {
presets = Application.getComponentPresetDao().listForType(nativeType);
}
componentSelectionTable.updateData(presets);
}
});
}
/*
* Add legacy component filter checkbox

View File

@ -393,7 +393,7 @@ public class PhotoPanel extends JPanel implements GLEventListener {
gl.glTranslated(dx - p.getAdvance(), 0, 0);
if (p.isFlame()) {
if (p.isFlame() && configuration.hasMotors()) {
convertColor(p.getFlameColor(), color);
gl.glLightfv(GLLightingFunc.GL_LIGHT2, GLLightingFunc.GL_AMBIENT,

View File

@ -94,8 +94,9 @@ public class SlideShowDialog extends JDialog {
addKeyActions();
GUIUtil.setDisposableDialogOptions(this, nextButton);
nextButton.grabFocus();
GUIUtil.rememberWindowPosition(this);
GUIUtil.rememberWindowSize(this);
this.setLocationByPlatform(true);
GUIUtil.rememberWindowPosition(this);
// this.setAlwaysOnTop(true);
}

View File

@ -4,9 +4,7 @@ import java.awt.*;
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;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
@ -19,16 +17,12 @@ import java.net.URL;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultTreeSelectionModel;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;
@ -60,7 +54,6 @@ import net.sf.openrocket.gui.dialogs.preferences.PreferencesDialog;
import net.sf.openrocket.gui.figure3d.photo.PhotoFrame;
import net.sf.openrocket.gui.help.tours.GuidedTourSelectionDialog;
import net.sf.openrocket.gui.main.componenttree.ComponentTree;
import net.sf.openrocket.gui.main.flightconfigpanel.FlightConfigurationPanel;
import net.sf.openrocket.gui.scalefigure.RocketPanel;
import net.sf.openrocket.gui.util.DummyFrameMenuOSX;
import net.sf.openrocket.gui.util.FileHelper;
@ -69,13 +62,11 @@ import net.sf.openrocket.gui.util.Icons;
import net.sf.openrocket.gui.util.OpenFileWorker;
import net.sf.openrocket.gui.util.SaveFileWorker;
import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.gui.widgets.SelectColorButton;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.logging.Markers;
import net.sf.openrocket.rocketcomponent.AxialStage;
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
import net.sf.openrocket.rocketcomponent.ComponentChangeListener;
import net.sf.openrocket.rocketcomponent.PodSet;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.startup.Application;
@ -108,9 +99,10 @@ public class BasicFrame extends JFrame {
public static final int SHIFT_SHORTCUT_KEY = Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx() |
SHIFT_DOWN_MASK;
public static final int COMPONENT_TAB = 0;
public static final int CONFIGURATION_TAB = 1;
public static final int DESIGN_TAB = 0;
public static final int FLIGHT_CONFIGURATION_TAB = 1;
public static final int SIMULATION_TAB = 2;
private int previousTab = DESIGN_TAB;
/**
@ -142,7 +134,9 @@ public class BasicFrame extends JFrame {
/** Actions available for rocket modifications */
private final RocketActions actions;
private SimulationPanel simulationPanel;
private final DesignPanel designPanel;
private final FlightConfigurationPanel flightConfigurationPanel;
private final SimulationPanel simulationPanel;
public static BasicFrame lastFrameInstance = null; // Latest BasicFrame that was created
private static boolean quitCalled = false; // Keeps track whether the quit action has been called
@ -166,57 +160,64 @@ public class BasicFrame extends JFrame {
componentSelectionModel = new DefaultTreeSelectionModel();
componentSelectionModel.setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
// Obtain the simulation selection model that will be used
simulationPanel = new SimulationPanel(document);
simulationSelectionModel = simulationPanel.getSimulationListSelectionModel();
// Combine into a DocumentSelectionModel
selectionModel = new DocumentSelectionModel(document);
selectionModel.attachComponentTreeSelectionModel(componentSelectionModel);
selectionModel.attachSimulationListSelectionModel(simulationSelectionModel);
actions = new RocketActions(document, selectionModel, this, simulationPanel);
// Populate the popup menu
popupMenu = new JPopupMenu();
popupMenu.add(actions.getEditAction());
popupMenu.add(actions.getCutAction());
popupMenu.add(actions.getCopyAction());
popupMenu.add(actions.getPasteAction());
popupMenu.add(actions.getDuplicateAction());
popupMenu.add(actions.getDeleteAction());
popupMenu.addSeparator();
popupMenu.add(actions.getScaleAction());
// ----- Create the different BasicFrame panels -----
log.debug("Constructing the BasicFrame UI");
// The main vertical split pane
JSplitPane vertical = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true);
vertical.setResizeWeight(0.5);
this.add(vertical);
//// Top segment, tabbed pane
simulationPanel = new SimulationPanel(document);
{
// Obtain the simulation selection model that will be used
simulationSelectionModel = simulationPanel.getSimulationListSelectionModel();
// The top tabbed pane
// Combine into a DocumentSelectionModel
selectionModel = new DocumentSelectionModel(document);
selectionModel.attachComponentTreeSelectionModel(componentSelectionModel);
selectionModel.attachSimulationListSelectionModel(simulationSelectionModel);
// Create RocketActions
actions = new RocketActions(document, selectionModel, this, simulationPanel);
}
{
// Create the component tree
tree = new ComponentTree(document);
tree.setSelectionModel(componentSelectionModel);
}
designPanel = new DesignPanel(this, document, tree);
flightConfigurationPanel = new FlightConfigurationPanel(this, document);
tabbedPane = new JTabbedPane();
//// Rocket design
tabbedPane.addTab(trans.get("BasicFrame.tab.Rocketdesign"), null, designTab());
//// Flight configurations
tabbedPane.addTab(trans.get("BasicFrame.tab.Flightconfig"), null, new FlightConfigurationPanel(this, document));
//// Flight simulations
tabbedPane.addTab(trans.get("BasicFrame.tab.Rocketdesign"), null, designPanel);
tabbedPane.addTab(trans.get("BasicFrame.tab.Flightconfig"), null, flightConfigurationPanel);
tabbedPane.addTab(trans.get("BasicFrame.tab.Flightsim"), null, simulationPanel);
// Add change listener to catch when the tabs are changed. This is to run simulations
// automatically when the simulation tab is selected.
tabbedPane.addChangeListener(new BasicFrame_changeAdapter(this));
vertical.setTopComponent(tabbedPane);
// Bottom segment, rocket figure
//// Bottom segment, rocket figure
rocketpanel = new RocketPanel(document, this);
vertical.setBottomComponent(rocketpanel);
rocketpanel.setSelectionModel(tree.getSelectionModel());
//// The main vertical split pane
JSplitPane vertical = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true);
vertical.setResizeWeight(0.5);
vertical.setTopComponent(tabbedPane);
vertical.setBottomComponent(rocketpanel);
this.add(vertical);
// Populate the popup menu
{
popupMenu = new JPopupMenu();
popupMenu.add(actions.getEditAction());
popupMenu.add(actions.getCutAction());
popupMenu.add(actions.getCopyAction());
popupMenu.add(actions.getPasteAction());
popupMenu.add(actions.getDuplicateAction());
popupMenu.add(actions.getDeleteAction());
popupMenu.addSeparator();
popupMenu.add(actions.getScaleAction());
}
createMenu();
@ -241,6 +242,7 @@ public class BasicFrame extends JFrame {
GUIUtil.rememberWindowSize(this);
this.setLocationByPlatform(true);
GUIUtil.rememberWindowPosition(this);
GUIUtil.setWindowIcons(this);
@ -271,194 +273,6 @@ public class BasicFrame extends JFrame {
}
/**
* Construct the "Rocket design" tab. This contains a horizontal split pane
* with the left component the design tree and the right component buttons
* for adding components.
*/
private JComponent designTab() {
JSplitPane horizontal = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true);
horizontal.setResizeWeight(0.5);
// Upper-left segment, component tree
JPanel panel = new JPanel(new MigLayout("fill, flowy", "[grow][grow 0]","[grow]"));
tree = new ComponentTree(document);
tree.setSelectionModel(componentSelectionModel);
// Remove JTree key events that interfere with menu accelerators
InputMap im = SwingUtilities.getUIInputMap(tree, JComponent.WHEN_FOCUSED);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, SHORTCUT_KEY), null);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, SHORTCUT_KEY), null);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, SHORTCUT_KEY), null);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_A, SHORTCUT_KEY), null);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_S, SHORTCUT_KEY), null);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_O, SHORTCUT_KEY), null);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_N, SHORTCUT_KEY), null);
// Visually select all child components of a stage/rocket/podset when it is selected
componentSelectionModel.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
if (tree == null || tree.getSelectionPaths() == null || tree.getSelectionPaths().length == 0
|| rocketpanel == null) return;
// Get all the components that need to be selected = currently selected components + children of stages/boosters/podsets
List<RocketComponent> children = new ArrayList<>(Arrays.asList(rocketpanel.getFigure().getSelection()));
for (TreePath p : tree.getSelectionPaths()) {
if (p != null) {
RocketComponent c = (RocketComponent) p.getLastPathComponent();
if (c instanceof AxialStage || c instanceof Rocket || c instanceof PodSet) {
Iterator<RocketComponent> iter = c.iterator(false);
while (iter.hasNext()) {
RocketComponent child = iter.next();
children.add(child);
}
}
}
}
// Select all the child components
if (rocketpanel.getFigure() != null && rocketpanel.getFigure3d() != null) {
rocketpanel.getFigure().setSelection(children.toArray(new RocketComponent[0]));
rocketpanel.getFigure3d().setSelection(children.toArray(new RocketComponent[0]));
}
}
});
// Double-click opens config dialog
MouseListener ml = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
int selRow = tree.getRowForLocation(e.getX(), e.getY());
TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
if (selRow != -1) {
if (selPath == null) return;
// Double-click
if ((e.getButton() == MouseEvent.BUTTON1) && (e.getClickCount() == 2) && !ComponentConfigDialog.isDialogVisible()) {
RocketComponent component = (RocketComponent) selPath.getLastPathComponent();
// Multi-component edit if shift/meta key is pressed
if ((e.isShiftDown() || e.isMetaDown()) && tree.getSelectionPaths() != null) {
// Add the other selected components as listeners to the last selected component
for (TreePath p : tree.getSelectionPaths()) {
if (p != null) {
if (p.getLastPathComponent() == component) continue;
RocketComponent c = (RocketComponent) p.getLastPathComponent();
c.clearConfigListeners();
component.addConfigListener(c);
}
}
// Add the selection path to the tree selection
List<TreePath> paths = new LinkedList<>(Arrays.asList(tree.getSelectionPaths()));
paths.add(selPath);
tree.setSelectionPaths(paths.toArray(new TreePath[0]));
}
ComponentConfigDialog.showDialog(BasicFrame.this, BasicFrame.this.document, component);
}
// Context menu
else if ((e.getButton() == MouseEvent.BUTTON3) && (e.getClickCount() == 1)) {
if (!tree.isPathSelected(selPath)) {
// Select new path
tree.setSelectionPath(selPath);
}
doComponentTreePopup(e);
}
} else { // Clicked on blank space
tree.clearSelection();
}
}
};
tree.addMouseListener(ml);
// Update dialog when selection is changed
componentSelectionModel.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
// Scroll tree to the selected item
TreePath[] paths = componentSelectionModel.getSelectionPaths();
if (paths == null || paths.length == 0)
return;
for (TreePath path : paths) {
tree.scrollPathToVisible(path);
}
if (!ComponentConfigDialog.isDialogVisible())
return;
else
ComponentConfigDialog.disposeDialog();
RocketComponent c = (RocketComponent) paths[0].getLastPathComponent();
c.clearConfigListeners();
for (int i = 1; i < paths.length; i++) {
RocketComponent listener = (RocketComponent) paths[i].getLastPathComponent();
listener.clearConfigListeners();
c.addConfigListener(listener);
}
ComponentConfigDialog.showDialog(BasicFrame.this, BasicFrame.this.document, c);
}
});
// Place tree inside scroll pane
JScrollPane scroll = new JScrollPane(tree);
panel.add(scroll, "spany, grow, wrap");
// Buttons
JButton button = new SelectColorButton(actions.getMoveUpAction());
panel.add(button, "sizegroup buttons, aligny 65%");
button = new SelectColorButton(actions.getMoveDownAction());
panel.add(button, "sizegroup buttons, aligny 0%");
button = new SelectColorButton();
RocketActions.tieActionToButtonNoIcon(button, actions.getEditAction());
button.setMnemonic(0);
panel.add(button, "sizegroup buttons, gaptop 20%");
button = new SelectColorButton();
RocketActions.tieActionToButtonNoIcon(button, actions.getDuplicateAction());
button.setMnemonic(0);
panel.add(button, "sizegroup buttons");
button = new SelectColorButton();
RocketActions.tieActionToButtonNoIcon(button, actions.getDeleteAction());
button.setMnemonic(0);
panel.add(button, "sizegroup buttons");
horizontal.setLeftComponent(panel);
// Upper-right segment, component addition buttons
panel = new JPanel(new MigLayout("fill, insets 0", "[0::]"));
scroll = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scroll.setViewportView(new ComponentAddButtons(document, componentSelectionModel,
scroll.getViewport()));
scroll.setBorder(null);
scroll.setViewportBorder(null);
TitledBorder border = BorderFactory.createTitledBorder(trans.get("BasicFrame.title.Addnewcomp"));
GUIUtil.changeFontStyle(border, Font.BOLD);
scroll.setBorder(border);
panel.add(scroll, "grow");
horizontal.setRightComponent(panel);
return horizontal;
}
/**
* Return the currently selected rocket component, or <code>null</code> if none selected.
*/
@ -984,6 +798,10 @@ public class BasicFrame extends JFrame {
this.setJMenuBar(menubar);
}
public RocketActions getRocketActions() {
return actions;
}
public void doComponentTreePopup(MouseEvent e) {
popupMenu.show(e.getComponent(), e.getX(), e.getY());
}
@ -1249,7 +1067,7 @@ public class BasicFrame extends JFrame {
/**
* Select the tab on the main pane.
*
* @param tab one of {@link #COMPONENT_TAB} or {@link #SIMULATION_TAB}.
* @param tab one of {@link #DESIGN_TAB}, {@link #FLIGHT_CONFIGURATION_TAB} or {@link #SIMULATION_TAB}.
*/
public void selectTab(int tab) {
tabbedPane.setSelectedIndex(tab);
@ -1933,8 +1751,21 @@ public class BasicFrame extends JFrame {
public void stateChanged(ChangeEvent e) {
JTabbedPane tabSource = (JTabbedPane) e.getSource();
int tab = tabSource.getSelectedIndex();
if (tab == SIMULATION_TAB) {
simulationPanel.activating();
if (previousTab == SIMULATION_TAB) {
simulationPanel.updatePreviousSelection();
}
previousTab = tab;
switch (tab) {
case DESIGN_TAB:
designPanel.takeTheSpotlight();
break;
case FLIGHT_CONFIGURATION_TAB:
flightConfigurationPanel.takeTheSpotlight();
break;
case SIMULATION_TAB:
simulationPanel.takeTheSpotlight();
simulationPanel.activating();
break;
}
}

View File

@ -0,0 +1,237 @@
package net.sf.openrocket.gui.main;
import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.gui.configdialog.ComponentConfigDialog;
import net.sf.openrocket.gui.main.componenttree.ComponentTree;
import net.sf.openrocket.gui.scalefigure.RocketPanel;
import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.widgets.SelectColorButton;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.AxialStage;
import net.sf.openrocket.rocketcomponent.PodSet;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.startup.Application;
import javax.swing.BorderFactory;
import javax.swing.InputMap;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.KeyStroke;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingUtilities;
import javax.swing.border.TitledBorder;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.TreePath;
import java.awt.Component;
import java.awt.Font;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import static net.sf.openrocket.gui.main.BasicFrame.SHORTCUT_KEY;
/**
* Construct the "Rocket design" tab. This contains a horizontal split pane
* with the left component the design tree and the right component buttons
* for adding components.
*/
public class DesignPanel extends JSplitPane {
private static final Translator trans = Application.getTranslator();
private final Component tree;
public DesignPanel(final BasicFrame parent, final OpenRocketDocument document, final ComponentTree tree) {
super(JSplitPane.HORIZONTAL_SPLIT, true);
setResizeWeight(0.5);
this.tree = tree;
// Upper-left segment, component tree
JPanel panel = new JPanel(new MigLayout("fill, flowy", "[grow][grow 0]","[grow]"));
// Remove JTree key events that interfere with menu accelerators
InputMap im = SwingUtilities.getUIInputMap(tree, JComponent.WHEN_FOCUSED);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, SHORTCUT_KEY), null);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, SHORTCUT_KEY), null);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, SHORTCUT_KEY), null);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_A, SHORTCUT_KEY), null);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_S, SHORTCUT_KEY), null);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_O, SHORTCUT_KEY), null);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_N, SHORTCUT_KEY), null);
// Visually select all child components of a stage/rocket/podset when it is selected
tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
if (tree == null || tree.getSelectionPaths() == null || tree.getSelectionPaths().length == 0
|| parent.getRocketPanel() == null) return;
// Get all the components that need to be selected = currently selected components + children of stages/boosters/podsets
List<RocketComponent> children = new ArrayList<>(Arrays.asList(parent.getRocketPanel().getFigure().getSelection()));
for (TreePath p : tree.getSelectionPaths()) {
if (p != null) {
RocketComponent c = (RocketComponent) p.getLastPathComponent();
if (c instanceof AxialStage || c instanceof Rocket || c instanceof PodSet) {
Iterator<RocketComponent> iter = c.iterator(false);
while (iter.hasNext()) {
RocketComponent child = iter.next();
children.add(child);
}
}
}
}
// Select all the child components
if (parent.getRocketPanel().getFigure() != null && parent.getRocketPanel().getFigure3d() != null) {
parent.getRocketPanel().getFigure().setSelection(children.toArray(new RocketComponent[0]));
parent.getRocketPanel().getFigure3d().setSelection(children.toArray(new RocketComponent[0]));
}
}
});
// Double-click opens config dialog
MouseListener ml = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
int selRow = tree.getRowForLocation(e.getX(), e.getY());
TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
if (selRow != -1) {
if (selPath == null) return;
// Double-click
if ((e.getButton() == MouseEvent.BUTTON1) && (e.getClickCount() == 2) && !ComponentConfigDialog.isDialogVisible()) {
RocketComponent component = (RocketComponent) selPath.getLastPathComponent();
// Multi-component edit if shift/meta key is pressed
if ((e.isShiftDown() || e.isMetaDown()) && tree.getSelectionPaths() != null) {
// Add the other selected components as listeners to the last selected component
for (TreePath p : tree.getSelectionPaths()) {
if (p != null) {
if (p.getLastPathComponent() == component) continue;
RocketComponent c = (RocketComponent) p.getLastPathComponent();
c.clearConfigListeners();
component.addConfigListener(c);
}
}
// Add the selection path to the tree selection
List<TreePath> paths = new LinkedList<>(Arrays.asList(tree.getSelectionPaths()));
paths.add(selPath);
tree.setSelectionPaths(paths.toArray(new TreePath[0]));
}
ComponentConfigDialog.showDialog(parent, document, component);
}
// Context menu
else if ((e.getButton() == MouseEvent.BUTTON3) && (e.getClickCount() == 1)) {
if (!tree.isPathSelected(selPath)) {
// Select new path
tree.setSelectionPath(selPath);
}
parent.doComponentTreePopup(e);
}
} else { // Clicked on blank space
tree.clearSelection();
}
}
};
tree.addMouseListener(ml);
// Update dialog when selection is changed
tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
// Scroll tree to the selected item
TreePath[] paths = tree.getSelectionModel().getSelectionPaths();
if (paths == null || paths.length == 0)
return;
for (TreePath path : paths) {
tree.scrollPathToVisible(path);
}
if (!ComponentConfigDialog.isDialogVisible())
return;
else
ComponentConfigDialog.disposeDialog();
RocketComponent c = (RocketComponent) paths[0].getLastPathComponent();
c.clearConfigListeners();
for (int i = 1; i < paths.length; i++) {
RocketComponent listener = (RocketComponent) paths[i].getLastPathComponent();
listener.clearConfigListeners();
c.addConfigListener(listener);
}
ComponentConfigDialog.showDialog(parent, document, c);
}
});
// Place tree inside scroll pane
JScrollPane scroll = new JScrollPane(tree);
panel.add(scroll, "spany, grow, wrap");
// Buttons
JButton button = new SelectColorButton(parent.getRocketActions().getMoveUpAction());
panel.add(button, "sizegroup buttons, aligny 65%");
button = new SelectColorButton(parent.getRocketActions().getMoveDownAction());
panel.add(button, "sizegroup buttons, aligny 0%");
button = new SelectColorButton(parent.getRocketActions().getEditAction());
button.setIcon(null);
button.setMnemonic(0);
panel.add(button, "sizegroup buttons, gaptop 20%");
button = new SelectColorButton(parent.getRocketActions().getDuplicateAction());
button.setIcon(null);
button.setMnemonic(0);
panel.add(button, "sizegroup buttons");
button = new SelectColorButton(parent.getRocketActions().getDeleteAction());
button.setIcon(null);
button.setMnemonic(0);
panel.add(button, "sizegroup buttons");
this.setLeftComponent(panel);
// Upper-right segment, component addition buttons
panel = new JPanel(new MigLayout("fill, insets 0", "[0::]"));
scroll = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scroll.setViewportView(new ComponentAddButtons(document, tree.getSelectionModel(),
scroll.getViewport()));
scroll.setBorder(null);
scroll.setViewportBorder(null);
TitledBorder border = BorderFactory.createTitledBorder(trans.get("BasicFrame.title.Addnewcomp"));
GUIUtil.changeFontStyle(border, Font.BOLD);
scroll.setBorder(border);
panel.add(scroll, "grow");
this.setRightComponent(panel);
}
/**
* Focus on the component tree.
*/
public void takeTheSpotlight() {
tree.requestFocusInWindow();
}
}

View File

@ -1,4 +1,4 @@
package net.sf.openrocket.gui.main.flightconfigpanel;
package net.sf.openrocket.gui.main;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
@ -20,7 +20,10 @@ import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.document.Simulation;
import net.sf.openrocket.gui.dialogs.flightconfiguration.RenameConfigDialog;
import net.sf.openrocket.gui.main.BasicFrame;
import net.sf.openrocket.gui.main.flightconfigpanel.FlightConfigurablePanel;
import net.sf.openrocket.gui.main.flightconfigpanel.MotorConfigurationPanel;
import net.sf.openrocket.gui.main.flightconfigpanel.RecoveryConfigurationPanel;
import net.sf.openrocket.gui.main.flightconfigpanel.SeparationConfigurationPanel;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
import net.sf.openrocket.rocketcomponent.FlightConfigurableComponent;
@ -111,20 +114,30 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
this.add(duplicateConfButton, "wrap");
tabs.addChangeListener(new ChangeListener() {
private FlightConfigurablePanel<?> previousPanel = motorConfigurationPanel;
@Override
public void stateChanged(ChangeEvent e) {
// Trigger a selection of the motor/recovery/configuration item
FlightConfigurablePanel<?> panel = null;
switch (tabs.getSelectedIndex()) {
case MOTOR_TAB_INDEX:
motorConfigurationPanel.updateButtonState();
panel = motorConfigurationPanel;
break;
case RECOVERY_TAB_INDEX:
recoveryConfigurationPanel.updateButtonState();
panel = recoveryConfigurationPanel;
break;
case SEPARATION_TAB_INDEX:
separationConfigurationPanel.updateButtonState();
panel = separationConfigurationPanel;
break;
}
// Update the panel selection, focus, and button state
if (panel == null) return;
synchronizePanelSelection(previousPanel, panel);
panel.updateButtonState();
panel.takeTheSpotlight();
panel.updateRocketViewSelection();
previousPanel = panel;
}
});
@ -230,6 +243,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
}
configurationChanged(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
takeTheSpotlight();
}
public void doPopupConfig(MouseEvent e) {
@ -294,6 +308,19 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
}
/**
* Synchronize the table row selection of a target panel with the selection in the source panel.
*/
private void synchronizePanelSelection(FlightConfigurablePanel<?> source, FlightConfigurablePanel<?> target) {
if (source == null || target == null) return;
List<FlightConfigurationId> fids = source.getSelectedConfigurationIds();
if (fids == null || fids.isEmpty()) {
target.clearSelection();
} else {
target.setSelectedConfigurationIds(fids);
}
}
private List<FlightConfigurationId> getSelectedConfigurationIds() {
switch (tabs.getSelectedIndex()) {
case MOTOR_TAB_INDEX:
@ -366,4 +393,24 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
newOrDuplicateConfigAction(true);
}
}
/**
* Focus on the table of the config panel that is currently opened.
*/
public void takeTheSpotlight() {
switch (tabs.getSelectedIndex()) {
case MOTOR_TAB_INDEX:
motorConfigurationPanel.takeTheSpotlight();
motorConfigurationPanel.updateRocketViewSelection();
break;
case RECOVERY_TAB_INDEX:
recoveryConfigurationPanel.takeTheSpotlight();
recoveryConfigurationPanel.updateRocketViewSelection();
break;
case SEPARATION_TAB_INDEX:
separationConfigurationPanel.takeTheSpotlight();
separationConfigurationPanel.updateRocketViewSelection();
break;
}
}
}

View File

@ -608,7 +608,7 @@ public class RocketActions {
parentFrame.selectTab(BasicFrame.SIMULATION_TAB);
} else {
deleteComponentAction.actionPerformed(e);
parentFrame.selectTab(BasicFrame.COMPONENT_TAB);
parentFrame.selectTab(BasicFrame.DESIGN_TAB);
}
}
@ -662,7 +662,7 @@ public class RocketActions {
OpenRocketClipboard.setClipboard(copiedComponents);
delete(components);
parentFrame.selectTab(BasicFrame.COMPONENT_TAB);
parentFrame.selectTab(BasicFrame.DESIGN_TAB);
} else if (isSimulationSelected()) {
Simulation[] simsCopy = new Simulation[sims.length];
@ -719,7 +719,7 @@ public class RocketActions {
List<RocketComponent> copiedComponents = new LinkedList<>(copyComponentsMaintainParent(components));
OpenRocketClipboard.setClipboard(copiedComponents);
parentFrame.selectTab(BasicFrame.COMPONENT_TAB);
parentFrame.selectTab(BasicFrame.DESIGN_TAB);
} else if (sims != null && sims.length > 0) {
Simulation[] simsCopy = new Simulation[sims.length];
for (int i=0; i < sims.length; i++) {
@ -799,7 +799,7 @@ public class RocketActions {
selectionModel.setSelectedComponents(successfullyPasted);
parentFrame.selectTab(BasicFrame.COMPONENT_TAB);
parentFrame.selectTab(BasicFrame.DESIGN_TAB);
} else if (sims != null) {
@ -896,7 +896,7 @@ public class RocketActions {
selectionModel.setSelectedComponents(duplicateComponents);
parentFrame.selectTab(BasicFrame.COMPONENT_TAB);
parentFrame.selectTab(BasicFrame.DESIGN_TAB);
} else if (sims != null && sims.length > 0) {
ArrayList<Simulation> copySims = new ArrayList<Simulation>();

View File

@ -107,6 +107,8 @@ public class SimulationPanel extends JPanel {
private final SimulationAction duplicateSimulationAction;
private final SimulationAction deleteSimulationAction;
private int[] previousSelection = null;
public SimulationPanel(OpenRocketDocument doc) {
super(new MigLayout("fill", "[grow][][][][][][grow]"));
@ -165,6 +167,7 @@ public class SimulationPanel extends JPanel {
simulationTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
simulationTable.setDefaultRenderer(Object.class, new JLabelRenderer());
simulationTableModel.setColumnWidths(simulationTable.getColumnModel());
simulationTable.setFillsViewportHeight(true);
// Context menu
pm = new JPopupMenu();
@ -193,19 +196,33 @@ public class SimulationPanel extends JPanel {
public void mouseClicked(MouseEvent e) {
int selectedRow = simulationTable.getSelectedRow();
if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
int selected = simulationTable.convertRowIndexToModel(selectedRow);
if (e.getButton() == MouseEvent.BUTTON1) {
// Clear the table selection when clicked outside the table rows.
if (e.getClickCount() == 1) {
int row = simulationTable.rowAtPoint(e.getPoint());
int column = simulationTable.columnAtPoint(e.getPoint());
int column = simulationTable.columnAtPoint(e.getPoint());
if (column == 0) {
SimulationWarningDialog.showWarningDialog(SimulationPanel.this, document.getSimulations().get(selected));
} else {
simulationTable.clearSelection();
simulationTable.addRowSelectionInterval(selectedRow, selectedRow);
openDialog(document.getSimulations().get(selected));
if (row == -1 || column == -1) {
simulationTable.clearSelection();
}
}
} else if (e.getButton() == MouseEvent.BUTTON3 && e.getClickCount() == 1) {
// Edit the simulation or plot/export
else if (e.getClickCount() == 2) {
int selected = simulationTable.convertRowIndexToModel(selectedRow);
int column = simulationTable.columnAtPoint(e.getPoint());
if (column == 0) {
SimulationWarningDialog.showWarningDialog(SimulationPanel.this, document.getSimulations().get(selected));
} else {
simulationTable.clearSelection();
simulationTable.addRowSelectionInterval(selectedRow, selectedRow);
openDialog(document.getSimulations().get(selected));
}
}
}
// Show context menu
else if (e.getButton() == MouseEvent.BUTTON3 && e.getClickCount() == 1) {
// Get the row that the right-click action happened on
int r = simulationTable.rowAtPoint(e.getPoint());
@ -263,6 +280,10 @@ public class SimulationPanel extends JPanel {
updateButtonStates();
}
public void updatePreviousSelection() {
this.previousSelection = simulationTable.getSelectedRows();
}
private void newSimulation() {
Simulation sim = new Simulation(document.getRocket());
sim.setName(document.getNextSimulationName());
@ -294,6 +315,7 @@ public class SimulationPanel extends JPanel {
}
fireMaintainSelection();
takeTheSpotlight();
openDialog(true, sim);
}
@ -343,6 +365,7 @@ public class SimulationPanel extends JPanel {
document.removeSimulation(selection[i]);
}
simulationTableModel.fireTableDataChanged();
takeTheSpotlight();
}
private void runSimulation() {
@ -354,6 +377,7 @@ public class SimulationPanel extends JPanel {
SimulationPanel.this), document, sims).setVisible(true);
log.info("Running simulations took " + (System.currentTimeMillis() - t) + " ms");
fireMaintainSelection();
takeTheSpotlight();
}
public void editSimulation() {
@ -490,11 +514,13 @@ public class SimulationPanel extends JPanel {
}
d.setVisible(true);
fireMaintainSelection();
takeTheSpotlight();
}
private void openDialog(final Simulation sim) {
boolean plotMode = false;
if (sim.hasSimulationData() && (sim.getStatus() == Status.UPTODATE || sim.getStatus() == Status.EXTERNAL)) {
if (sim.hasSimulationData() && (sim.getStatus() == Status.UPTODATE || sim.getStatus() == Status.LOADED
|| sim.getStatus() == Status.EXTERNAL)) {
plotMode = true;
}
openDialog(plotMode, sim);
@ -987,6 +1013,24 @@ public class SimulationPanel extends JPanel {
}
}
/**
* Focus on the simulation table and maintain the previous row selection(s).
*/
public void takeTheSpotlight() {
simulationTable.requestFocusInWindow();
if (simulationTable.getSelectedRows().length > 0) {
return;
}
if (previousSelection == null || previousSelection.length == 0) {
simulationTable.setRowSelectionInterval(0, 0);
} else {
simulationTable.clearSelection();
for (int row : previousSelection) {
simulationTable.addRowSelectionInterval(row, row);
}
}
}
private static class NextRowAction extends AbstractAction {
private final JTable table;
private final boolean cycle;
@ -1048,6 +1092,5 @@ public class SimulationPanel extends JPanel {
table.getSelectionModel().setSelectionInterval(nextRow, nextRow);
table.getColumnModel().getSelectionModel().setSelectionInterval(0, 0);
}
}
}

View File

@ -1,333 +1,408 @@
package net.sf.openrocket.gui.main.flightconfigpanel;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import net.sf.openrocket.util.ArrayList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.formatting.RocketDescriptor;
import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
import net.sf.openrocket.rocketcomponent.ComponentChangeListener;
import net.sf.openrocket.rocketcomponent.FlightConfigurableComponent;
import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.util.Pair;
@SuppressWarnings("serial")
public abstract class FlightConfigurablePanel<T extends FlightConfigurableComponent> extends JPanel implements ComponentChangeListener {
protected static final Translator trans = Application.getTranslator();
private static final Logger log = LoggerFactory.getLogger(FlightConfigurablePanel.class);
protected RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class);
protected final FlightConfigurationPanel flightConfigurationPanel;
protected final Rocket rocket;
protected final JTable table;
public FlightConfigurablePanel(final FlightConfigurationPanel flightConfigurationPanel, Rocket rocket) {
super(new MigLayout("fill"));
this.flightConfigurationPanel = flightConfigurationPanel;
this.rocket = rocket;
table = doTableInitialization();
installTableListener();
synchronizeConfigurationSelection();
}
/**
* Update the data in the table, with component change event type {cce}
* @param cce index of the ComponentChangeEvent to use (e.g. ComponentChangeEvent.NONFUNCTIONAL_CHANGE)
*/
public void fireTableDataChanged(int cce) {
int selectedRow = table.getSelectedRow();
int selectedColumn = table.getSelectedColumn();
this.rocket.fireComponentChangeEvent(cce);
((AbstractTableModel)table.getModel()).fireTableDataChanged();
restoreSelection(selectedRow,selectedColumn);
updateButtonState();
}
protected abstract void updateButtonState();
@Override
public void componentChanged(ComponentChangeEvent e) {
this.synchronizeConfigurationSelection();
}
/**
* Initialize the table using the specific implementation's initializeTable
* method and then select the row to match what the rocket's current selected
* configuration is.
*
* @return the JTable created
*/
private final JTable doTableInitialization() {
JTable table = this.initializeTable();
FlightConfigurationId current = this.rocket.getSelectedConfiguration().getFlightConfigurationID();
int col = (table.getColumnCount() > 1) ? table.getColumnCount() - 1 : 0;
for (int row = 0; row < table.getRowCount(); row++) {
FlightConfigurationId rowFCID = rocket.getId(row);
if (rowFCID.equals(current)) {
table.changeSelection(row, col, false, false);
break;
}
}
return table;
}
protected final void synchronizeConfigurationSelection() {
FlightConfigurationId currentRocketFCID = rocket.getSelectedConfiguration().getFlightConfigurationID();
FlightConfigurationId selectedFCID = getSelectedConfigurationId();
if ( currentRocketFCID == FlightConfigurationId.DEFAULT_VALUE_FCID ) {
// need to unselect
table.clearSelection();
} else if ( !currentRocketFCID.equals(selectedFCID)){
// Need to change selection
// We'll select the correct row, in the currently selected column.
int col = table.getSelectedColumn();
if ( col < 0 ) {
col = (table.getColumnCount() > 1) ? table.getColumnCount() - 1 : 0;
}
for( int rowNum = 0; rowNum < table.getRowCount(); rowNum++ ) {
FlightConfigurationId rowFCID = rocket.getId(rowNum );
if ( rowFCID.equals(currentRocketFCID) ) {
table.changeSelection(rowNum, col, false, false);
break;
}
}
}
}
protected void restoreSelection( int row, int col ) {
if ( row <= 0 || col <= 0 ) {
synchronizeConfigurationSelection();
return;
}
if ( row >= table.getRowCount() || col >= table.getColumnCount() ) {
synchronizeConfigurationSelection();
return;
}
table.changeSelection(row, col, true, false);
}
protected void installTableListener() {
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if ( e.getValueIsAdjusting() ) {
return;
}
/* Find the selected row and set it as the current selected configuration
* for the rocket. This will propagate the event to ensure that other
* pieces of the UI are updated and match the table selection.
*/
int firstrow = e.getFirstIndex();
int lastrow = e.getLastIndex();
ListSelectionModel model = (ListSelectionModel) e.getSource();
for( int row = firstrow; row <= lastrow; row ++) {
if ( model.isSelectedIndex(row) ) {
FlightConfigurationId fcid = (FlightConfigurationId) table.getValueAt(row, table.convertColumnIndexToView(0));
rocket.setSelectedConfiguration(fcid);
return;
}
}
}
});
}
/**
* Override this method to create the embedded JTable and it's backing Model.
*
* @return
*/
protected abstract JTable initializeTable();
protected T getSelectedComponent() {
int col = table.convertColumnIndexToModel(table.getSelectedColumn());
int row = table.convertRowIndexToModel(table.getSelectedRow());
if ( row < 0 || col < 0 ) {
return null;
}
Object tableValue = table.getModel().getValueAt(row, col);
if ( tableValue instanceof Pair ) {
@SuppressWarnings("unchecked")
Pair<String,T> selectedComponent = (Pair<String,T>) tableValue;
return selectedComponent.getV();
}
return null;
}
protected List<T> getSelectedComponents() {
int[] cols = Arrays.stream(table.getSelectedColumns()).map(table::convertRowIndexToModel).toArray();
int[] rows = Arrays.stream(table.getSelectedRows()).map(table::convertRowIndexToModel).toArray();
if (Arrays.stream(cols).min().isEmpty() || Arrays.stream(rows).min().isEmpty() ||
Arrays.stream(cols).min().getAsInt() < 0 || Arrays.stream(rows).min().getAsInt() < 0) {
return null;
}
List<T> components = new ArrayList<>();
for (int row : rows) {
for (int col : cols) {
Object tableValue = table.getModel().getValueAt(row, col);
if (tableValue instanceof Pair) {
@SuppressWarnings("unchecked")
Pair<String, T> selectedComponent = (Pair<String, T>) tableValue;
components.add(selectedComponent.getV());
}
}
}
return components;
}
protected FlightConfigurationId getSelectedConfigurationId() {
int col = table.convertColumnIndexToModel(table.getSelectedColumn());
int row = table.convertRowIndexToModel(table.getSelectedRow());
if ( row < 0 || col < 0 || row >= table.getRowCount() || col >= table.getColumnCount() ) {
return null;
}
Object tableValue = table.getModel().getValueAt(row, col);
if ( tableValue instanceof Pair ) {
@SuppressWarnings("unchecked")
Pair<FlightConfigurationId,T> selectedComponent = (Pair<FlightConfigurationId,T>) tableValue;
FlightConfigurationId fcid = selectedComponent.getU();
return fcid;
} else if ( tableValue instanceof FlightConfigurationId ){
return (FlightConfigurationId) tableValue;
}
return FlightConfigurationId.ERROR_FCID;
}
protected List<FlightConfigurationId> getSelectedConfigurationIds() {
int col = table.convertColumnIndexToModel(table.getSelectedColumn());
int[] rows = Arrays.stream(table.getSelectedRows()).map(table::convertRowIndexToModel).toArray();
if (Arrays.stream(rows).min().isEmpty() || Arrays.stream(rows).min().getAsInt() < 0 || col < 0 ||
Arrays.stream(rows).max().getAsInt() >= table.getRowCount() || col >= table.getColumnCount() ) {
return null;
}
Object[] tableValues = Arrays.stream(rows).mapToObj(c -> table.getModel().getValueAt(c, col)).toArray();
List<FlightConfigurationId> Ids = new ArrayList<>();
for (Object tableValue : tableValues) {
if (tableValue instanceof Pair) {
@SuppressWarnings("unchecked")
Pair<FlightConfigurationId, T> selectedComponent = (Pair<FlightConfigurationId, T>) tableValue;
FlightConfigurationId fcid = selectedComponent.getU();
Ids.add(fcid);
} else if (tableValue instanceof FlightConfigurationId) {
Ids.add((FlightConfigurationId) tableValue);
} else {
Ids.add(FlightConfigurationId.ERROR_FCID);
}
}
return Ids;
}
protected abstract class FlightConfigurableCellRenderer extends DefaultTableCellRenderer {
@Override
public Component getTableCellRendererComponent(JTable table, Object newValue, boolean isSelected, boolean hasFocus, int row, int column) {
JLabel label = (JLabel) super.getTableCellRendererComponent(table, newValue, isSelected, hasFocus, row, column);
Object oldValue = table.getModel().getValueAt(row, column);
// this block is more for the benefit of the reader than the computer --
// this assignment is technically redundant, but useful to point out that the new value here is often null,
// while the old value seems to always be valid.
if( null == newValue ){
log.warn("Detected null newValue to render... (oldValue: "+oldValue+")");
newValue = oldValue;
}
column = table.convertColumnIndexToModel(column);
switch (column) {
case 0: {
label.setText(descriptor.format(rocket, (FlightConfigurationId) oldValue));
regular(label);
setSelected(label, table, isSelected, hasFocus);
return label;
}
default: {
@SuppressWarnings("unchecked")
Pair<FlightConfigurationId, T> v = (Pair<FlightConfigurationId, T>) oldValue;
if(v!=null){
FlightConfigurationId fcid = v.getU();
T component = v.getV();
label = format(component, fcid, label );
}
for (Component c : label.getComponents()) {
if (c instanceof JLabel) {
setSelected((JLabel)c, table, isSelected, hasFocus);
}
}
setSelected(label, table, isSelected, hasFocus);
return label;
}
}
}
private final void setSelected( JComponent c, JTable table, boolean isSelected, boolean hasFocus ) {
c.setOpaque(true);
if ( isSelected) {
c.setBackground(table.getSelectionBackground());
c.setForeground((Color)UIManager.get("Table.selectionForeground"));
} else {
c.setBackground(table.getBackground());
c.setForeground(c.getForeground());
}
Border b = null;
if ( hasFocus ) {
if (isSelected) {
b = UIManager.getBorder("Table.focusSelectedCellHighlightBorder");
} else {
b = UIManager.getBorder("Table.focusCellHighligtBorder");
}
} else {
b = new EmptyBorder(1,1,1,1);
}
c.setBorder(b);
}
protected final void shaded(JLabel label) {
GUIUtil.changeFontStyle(label, Font.ITALIC);
label.setForeground(Color.GRAY);
}
protected final void regular(JLabel label) {
GUIUtil.changeFontStyle(label, Font.PLAIN);
label.setForeground(Color.BLACK);
}
protected abstract JLabel format( T component, FlightConfigurationId configId, JLabel label );
}
package net.sf.openrocket.gui.main.flightconfigpanel;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import net.sf.openrocket.gui.main.FlightConfigurationPanel;
import net.sf.openrocket.util.ArrayList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.formatting.RocketDescriptor;
import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
import net.sf.openrocket.rocketcomponent.ComponentChangeListener;
import net.sf.openrocket.rocketcomponent.FlightConfigurableComponent;
import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.util.Pair;
@SuppressWarnings("serial")
public abstract class FlightConfigurablePanel<T extends FlightConfigurableComponent> extends JPanel implements ComponentChangeListener {
protected static final Translator trans = Application.getTranslator();
private static final Logger log = LoggerFactory.getLogger(FlightConfigurablePanel.class);
protected RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class);
protected final FlightConfigurationPanel flightConfigurationPanel;
protected final Rocket rocket;
protected final JTable table;
public FlightConfigurablePanel(final FlightConfigurationPanel flightConfigurationPanel, Rocket rocket) {
super(new MigLayout("fill"));
this.flightConfigurationPanel = flightConfigurationPanel;
this.rocket = rocket;
table = doTableInitialization();
installTableListener();
synchronizeConfigurationSelection();
}
/**
* Update the data in the table, with component change event type {cce}
* @param cce index of the ComponentChangeEvent to use (e.g. ComponentChangeEvent.NONFUNCTIONAL_CHANGE)
*/
public void fireTableDataChanged(int cce) {
int selectedRow = table.getSelectedRow();
int selectedColumn = table.getSelectedColumn();
this.rocket.fireComponentChangeEvent(cce);
((AbstractTableModel)table.getModel()).fireTableDataChanged();
restoreSelection(selectedRow,selectedColumn);
updateButtonState();
}
public abstract void updateButtonState();
@Override
public void componentChanged(ComponentChangeEvent e) {
this.synchronizeConfigurationSelection();
}
/**
* Initialize the table using the specific implementation's initializeTable
* method and then select the row to match what the rocket's current selected
* configuration is.
*
* @return the JTable created
*/
private final JTable doTableInitialization() {
JTable table = this.initializeTable();
table.setFillsViewportHeight(true);
FlightConfigurationId current = this.rocket.getSelectedConfiguration().getFlightConfigurationID();
int col = (table.getColumnCount() > 1) ? table.getColumnCount() - 1 : 0;
for (int row = 0; row < table.getRowCount(); row++) {
FlightConfigurationId rowFCID = rocket.getId(row);
if (rowFCID.equals(current)) {
table.changeSelection(row, col, false, false);
break;
}
}
return table;
}
public final void synchronizeConfigurationSelection() {
FlightConfigurationId currentRocketFCID = rocket.getSelectedConfiguration().getFlightConfigurationID();
FlightConfigurationId selectedFCID = getSelectedConfigurationId();
if ( currentRocketFCID == FlightConfigurationId.DEFAULT_VALUE_FCID ) {
// need to unselect
table.clearSelection();
} else if ( !currentRocketFCID.equals(selectedFCID)){
// Need to change selection
// We'll select the correct row, in the currently selected column.
int col = table.getSelectedColumn();
if ( col < 0 ) {
col = (table.getColumnCount() > 1) ? table.getColumnCount() - 1 : 0;
}
for( int rowNum = 0; rowNum < table.getRowCount(); rowNum++ ) {
FlightConfigurationId rowFCID = rocket.getId(rowNum );
if ( rowFCID.equals(currentRocketFCID) ) {
table.changeSelection(rowNum, col, false, false);
break;
}
}
}
}
protected void restoreSelection( int row, int col ) {
if ( row <= 0 || col <= 0 ) {
synchronizeConfigurationSelection();
return;
}
if ( row >= table.getRowCount() || col >= table.getColumnCount() ) {
synchronizeConfigurationSelection();
return;
}
table.changeSelection(row, col, true, false);
table.requestFocusInWindow();
}
protected void installTableListener() {
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if ( e.getValueIsAdjusting() ) {
return;
}
// Don't update the flight configuration for multi-selections
if (table.getSelectionModel().getSelectedItemsCount() > 1) {
return;
}
/* Find the selected row and set it as the current selected configuration
* for the rocket. This will propagate the event to ensure that other
* pieces of the UI are updated and match the table selection.
*/
int firstrow = e.getFirstIndex();
int lastrow = e.getLastIndex();
ListSelectionModel model = (ListSelectionModel) e.getSource();
for( int row = firstrow; row <= lastrow; row ++) {
if ( model.isSelectedIndex(row) ) {
FlightConfigurationId fcid = (FlightConfigurationId) table.getValueAt(row, table.convertColumnIndexToView(0));
rocket.setSelectedConfiguration(fcid);
return;
}
}
}
});
// Clear the table selection when clicked outside the table rows.
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 1) {
int row = table.rowAtPoint(e.getPoint());
int col = table.columnAtPoint(e.getPoint());
if (row == -1 || col == -1) {
clearSelection();
}
}
}
});
table.getColumnModel().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
updateRocketViewSelection(e);
}
});
}
/**
* Override this method to create the embedded JTable and it's backing Model.
*
* @return
*/
protected abstract JTable initializeTable();
public void clearSelection() {
table.clearSelection();
}
public void updateRocketViewSelection() {
ListSelectionEvent e = new ListSelectionEvent(this, 0, 0, false);
updateRocketViewSelection(e);
}
/**
* Update the selection in the rocket design view, based on the currently selected motor, recovery device, or stage.
*/
public abstract void updateRocketViewSelection(ListSelectionEvent e);
protected T getSelectedComponent() {
int col = table.convertColumnIndexToModel(table.getSelectedColumn());
int row = table.convertRowIndexToModel(table.getSelectedRow());
if ( row < 0 || col < 0 ) {
return null;
}
Object tableValue = table.getModel().getValueAt(row, col);
if ( tableValue instanceof Pair ) {
@SuppressWarnings("unchecked")
Pair<String,T> selectedComponent = (Pair<String,T>) tableValue;
return selectedComponent.getV();
}
return null;
}
protected List<T> getSelectedComponents() {
int[] cols = Arrays.stream(table.getSelectedColumns()).map(table::convertRowIndexToModel).toArray();
int[] rows = Arrays.stream(table.getSelectedRows()).map(table::convertRowIndexToModel).toArray();
if (Arrays.stream(cols).min().isEmpty() || Arrays.stream(rows).min().isEmpty() ||
Arrays.stream(cols).min().getAsInt() < 0 || Arrays.stream(rows).min().getAsInt() < 0) {
return null;
}
List<T> components = new ArrayList<>();
for (int row : rows) {
for (int col : cols) {
Object tableValue = table.getModel().getValueAt(row, col);
if (tableValue instanceof Pair) {
@SuppressWarnings("unchecked")
Pair<String, T> selectedComponent = (Pair<String, T>) tableValue;
components.add(selectedComponent.getV());
}
}
}
return components;
}
protected FlightConfigurationId getSelectedConfigurationId() {
int col = table.convertColumnIndexToModel(table.getSelectedColumn());
int row = table.convertRowIndexToModel(table.getSelectedRow());
if ( row < 0 || col < 0 || row >= table.getRowCount() || col >= table.getColumnCount() ) {
return null;
}
Object tableValue = table.getModel().getValueAt(row, col);
if ( tableValue instanceof Pair ) {
@SuppressWarnings("unchecked")
Pair<FlightConfigurationId,T> selectedComponent = (Pair<FlightConfigurationId,T>) tableValue;
FlightConfigurationId fcid = selectedComponent.getU();
return fcid;
} else if ( tableValue instanceof FlightConfigurationId ){
return (FlightConfigurationId) tableValue;
}
return FlightConfigurationId.ERROR_FCID;
}
public List<FlightConfigurationId> getSelectedConfigurationIds() {
int col = table.convertColumnIndexToModel(table.getSelectedColumn());
int[] rows = Arrays.stream(table.getSelectedRows()).map(table::convertRowIndexToModel).toArray();
if (Arrays.stream(rows).min().isEmpty() || Arrays.stream(rows).min().getAsInt() < 0 || col < 0 ||
Arrays.stream(rows).max().getAsInt() >= table.getRowCount() || col >= table.getColumnCount() ) {
return null;
}
Object[] tableValues = Arrays.stream(rows).mapToObj(c -> table.getModel().getValueAt(c, col)).toArray();
List<FlightConfigurationId> Ids = new ArrayList<>();
for (Object tableValue : tableValues) {
if (tableValue instanceof Pair) {
@SuppressWarnings("unchecked")
Pair<FlightConfigurationId, T> selectedComponent = (Pair<FlightConfigurationId, T>) tableValue;
FlightConfigurationId fcid = selectedComponent.getU();
Ids.add(fcid);
} else if (tableValue instanceof FlightConfigurationId) {
Ids.add((FlightConfigurationId) tableValue);
} else {
Ids.add(FlightConfigurationId.ERROR_FCID);
}
}
return Ids;
}
/**
* Select the rows of the table that correspond to the given FlightConfigurationIds. The second column of the table
* will be used for the selection.
* @param fids flight configuration ids to select
*/
public void setSelectedConfigurationIds(List<FlightConfigurationId> fids) {
if (fids == null || fids.isEmpty() || table.getColumnCount() == 0) return;
if (getSelectedConfigurationIds() != null && new HashSet<>(getSelectedConfigurationIds()).containsAll(fids)) return;
table.clearSelection();
for (FlightConfigurationId id : fids) {
if (id == FlightConfigurationId.DEFAULT_VALUE_FCID) continue;
for (int rowNum = 0; rowNum < table.getRowCount(); rowNum++) {
FlightConfigurationId rowFCID = rocket.getId(rowNum );
if (rowFCID.equals(id)) {
table.changeSelection(rowNum, 1, true, false);
break;
}
}
}
}
protected abstract class FlightConfigurableCellRenderer extends DefaultTableCellRenderer {
@Override
public Component getTableCellRendererComponent(JTable table, Object newValue, boolean isSelected, boolean hasFocus, int row, int column) {
JLabel label = (JLabel) super.getTableCellRendererComponent(table, newValue, isSelected, hasFocus, row, column);
Object oldValue = table.getModel().getValueAt(row, column);
// this block is more for the benefit of the reader than the computer --
// this assignment is technically redundant, but useful to point out that the new value here is often null,
// while the old value seems to always be valid.
if( null == newValue ){
log.warn("Detected null newValue to render... (oldValue: "+oldValue+")");
newValue = oldValue;
}
column = table.convertColumnIndexToModel(column);
switch (column) {
case 0: {
label.setText(descriptor.format(rocket, (FlightConfigurationId) oldValue));
regular(label);
setSelected(label, table, isSelected, hasFocus);
return label;
}
default: {
@SuppressWarnings("unchecked")
Pair<FlightConfigurationId, T> v = (Pair<FlightConfigurationId, T>) oldValue;
if(v!=null){
FlightConfigurationId fcid = v.getU();
T component = v.getV();
label = format(component, fcid, label );
}
for (Component c : label.getComponents()) {
if (c instanceof JLabel) {
setSelected((JLabel)c, table, isSelected, hasFocus);
}
}
setSelected(label, table, isSelected, hasFocus);
return label;
}
}
}
private final void setSelected( JComponent c, JTable table, boolean isSelected, boolean hasFocus ) {
c.setOpaque(true);
if ( isSelected) {
c.setBackground(table.getSelectionBackground());
c.setForeground((Color)UIManager.get("Table.selectionForeground"));
} else {
c.setBackground(table.getBackground());
c.setForeground(c.getForeground());
}
Border b = null;
if ( hasFocus ) {
if (isSelected) {
b = UIManager.getBorder("Table.focusSelectedCellHighlightBorder");
} else {
b = UIManager.getBorder("Table.focusCellHighligtBorder");
}
} else {
b = new EmptyBorder(1,1,1,1);
}
c.setBorder(b);
}
protected final void shaded(JLabel label) {
GUIUtil.changeFontStyle(label, Font.ITALIC);
label.setForeground(Color.GRAY);
}
protected final void regular(JLabel label) {
GUIUtil.changeFontStyle(label, Font.PLAIN);
label.setForeground(Color.BLACK);
}
protected abstract JLabel format( T component, FlightConfigurationId configId, JLabel label );
}
/**
* Focus on the table
*/
public void takeTheSpotlight() {
table.requestFocusInWindow();
}
}

View File

@ -3,8 +3,6 @@ package net.sf.openrocket.gui.main.flightconfigpanel;
import java.awt.CardLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
@ -33,6 +31,7 @@ import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.gui.dialogs.flightconfiguration.IgnitionSelectionDialog;
import net.sf.openrocket.gui.dialogs.flightconfiguration.MotorMountConfigurationPanel;
import net.sf.openrocket.gui.dialogs.motor.MotorChooserDialog;
import net.sf.openrocket.gui.main.FlightConfigurationPanel;
import net.sf.openrocket.gui.widgets.SelectColorButton;
import net.sf.openrocket.motor.IgnitionEvent;
import net.sf.openrocket.motor.Motor;
@ -65,7 +64,7 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
private final JPopupMenu popupMenuFull; // popup menu containing all the options
MotorConfigurationPanel(final FlightConfigurationPanel flightConfigurationPanel, Rocket rocket) {
public MotorConfigurationPanel(final FlightConfigurationPanel flightConfigurationPanel, Rocket rocket) {
super(flightConfigurationPanel, rocket);
motorChooserDialog = new MotorChooserDialog(SwingUtilities.getWindowAncestor(flightConfigurationPanel));
@ -250,35 +249,11 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
return configurationTable;
}
@Override
protected void installTableListener() {
super.installTableListener();
table.getColumnModel().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
updateComponentSelection(e);
}
});
table.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
updateComponentSelection(new ListSelectionEvent(this, 0, 0, false));
}
@Override
public void focusLost(FocusEvent e) {
}
});
}
private void doPopupFull(MouseEvent e) {
popupMenuFull.show(e.getComponent(), e.getX(), e.getY());
}
public void updateComponentSelection(ListSelectionEvent e) {
public void updateRocketViewSelection(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) {
return;
}
@ -294,7 +269,7 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
flightConfigurationPanel.setSelectedComponents(components);
}
protected void updateButtonState() {
public void updateButtonState() {
if( configurationTableModel.getColumnCount() > 1 ) {
showContent();
@ -356,6 +331,8 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
if (update) {
fireTableDataChanged(ComponentChangeEvent.MOTOR_CHANGE);
} else {
table.requestFocusInWindow();
}
}
@ -420,6 +397,8 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
if (update) {
fireTableDataChanged(ComponentChangeEvent.MOTOR_CHANGE);
} else {
table.requestFocusInWindow();
}
}
@ -448,6 +427,8 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
if (update) {
fireTableDataChanged(ComponentChangeEvent.MOTOR_CHANGE);
} else {
table.requestFocusInWindow();
}
}

View File

@ -1,8 +1,6 @@
package net.sf.openrocket.gui.main.flightconfigpanel;
import java.awt.event.ActionEvent;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
@ -25,6 +23,7 @@ import javax.swing.event.ListSelectionListener;
import net.sf.openrocket.formatting.RocketDescriptor;
import net.sf.openrocket.gui.dialogs.flightconfiguration.DeploymentSelectionDialog;
import net.sf.openrocket.gui.main.FlightConfigurationPanel;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.*;
import net.sf.openrocket.rocketcomponent.DeploymentConfiguration.DeployEvent;
@ -43,7 +42,7 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
private final JPopupMenu popupMenuFull; // popup menu containing all the options
RecoveryConfigurationPanel(FlightConfigurationPanel flightConfigurationPanel, Rocket rocket) {
public RecoveryConfigurationPanel(FlightConfigurationPanel flightConfigurationPanel, Rocket rocket) {
super(flightConfigurationPanel,rocket);
JScrollPane scroll = new JScrollPane(table);
@ -165,30 +164,6 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
return recoveryTable;
}
@Override
protected void installTableListener() {
super.installTableListener();
table.getColumnModel().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
updateComponentSelection(e);
}
});
table.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
updateComponentSelection(new ListSelectionEvent(this, 0, 0, false));
}
@Override
public void focusLost(FocusEvent e) {
}
});
}
public void selectDeployment() {
List<RecoveryDevice> devices = getSelectedComponents();
List<FlightConfigurationId> fcIds = getSelectedConfigurationIds();
@ -235,6 +210,8 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
if (update) {
fireTableDataChanged(ComponentChangeEvent.AERODYNAMIC_CHANGE);
} else {
table.requestFocusInWindow();
}
}
@ -259,6 +236,8 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
}
if (update) {
fireTableDataChanged(ComponentChangeEvent.AERODYNAMIC_CHANGE);
} else {
table.requestFocusInWindow();
}
}
@ -266,7 +245,7 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
popupMenuFull.show(e.getComponent(), e.getX(), e.getY());
}
public void updateComponentSelection(ListSelectionEvent e) {
public void updateRocketViewSelection(ListSelectionEvent e) {
if (e.getValueIsAdjusting() || getSelectedComponents() == null) {
return;
}

View File

@ -1,8 +1,6 @@
package net.sf.openrocket.gui.main.flightconfigpanel;
import java.awt.event.ActionEvent;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
@ -25,6 +23,7 @@ import javax.swing.event.ListSelectionListener;
import net.sf.openrocket.formatting.RocketDescriptor;
import net.sf.openrocket.gui.dialogs.flightconfiguration.SeparationSelectionDialog;
import net.sf.openrocket.gui.main.FlightConfigurationPanel;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.AxialStage;
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
@ -48,7 +47,7 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel<AxialS
private final JPopupMenu popupMenuFull; // popup menu containing all the options
SeparationConfigurationPanel(FlightConfigurationPanel flightConfigurationPanel, Rocket rocket) {
public SeparationConfigurationPanel(FlightConfigurationPanel flightConfigurationPanel, Rocket rocket) {
super(flightConfigurationPanel,rocket);
JScrollPane scroll = new JScrollPane(table);
@ -174,30 +173,6 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel<AxialS
return separationTable;
}
@Override
protected void installTableListener() {
super.installTableListener();
table.getColumnModel().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
updateComponentSelection(e);
}
});
table.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
updateComponentSelection(new ListSelectionEvent(this, 0, 0, false));
}
@Override
public void focusLost(FocusEvent e) {
}
});
}
public void selectSeparation() {
List<AxialStage> stages = getSelectedComponents();
List<FlightConfigurationId> fcIds = getSelectedConfigurationIds();
@ -245,6 +220,8 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel<AxialS
if (update) {
fireTableDataChanged(ComponentChangeEvent.AEROMASS_CHANGE);
} else {
table.requestFocusInWindow();
}
}
@ -269,6 +246,8 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel<AxialS
if (update) {
fireTableDataChanged(ComponentChangeEvent.AEROMASS_CHANGE);
} else {
table.requestFocusInWindow();
}
}
@ -276,7 +255,7 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel<AxialS
popupMenuFull.show(e.getComponent(), e.getX(), e.getY());
}
public void updateComponentSelection(ListSelectionEvent e) {
public void updateRocketViewSelection(ListSelectionEvent e) {
if (e.getValueIsAdjusting() || getSelectedComponents() == null) {
return;
}

View File

@ -168,6 +168,8 @@ public class SimulationPlotDialog extends JDialog {
GUIUtil.setDisposableDialogOptions(this, button);
GUIUtil.rememberWindowSize(this);
this.setLocationByPlatform(true);
GUIUtil.rememberWindowPosition(this);
}
private boolean doPngExport(ChartPanel chartPanel, JFreeChart chart){

View File

@ -13,12 +13,14 @@ import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
@ -52,9 +54,11 @@ import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeListener;
import javax.swing.event.TableColumnModelListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;
import javax.swing.tree.DefaultMutableTreeNode;
@ -65,6 +69,7 @@ import javax.swing.tree.TreeSelectionModel;
import net.sf.openrocket.gui.Resettable;
import net.sf.openrocket.logging.Markers;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.util.BugException;
import net.sf.openrocket.util.Invalidatable;
@ -347,6 +352,33 @@ public class GUIUtil {
}
}
}
public static void rememberTableColumnWidths(final JTable table, String keyName) {
final String key = keyName == null ? table.getClass().getName() : keyName;
for (int i = 0; i < table.getColumnCount(); i++) {
final int column = i;
table.getColumnModel().getColumn(i).addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals("width")) {
log.debug("Storing width of " + table.getName() + "-" + table.getColumnName(column) + ": " + table.getColumnModel().getColumn(column).getWidth());
((SwingPreferences) Application.getPreferences()).setTableColumnWidth(
key, column, table.getColumnModel().getColumn(column).getWidth());
}
}
});
final Integer width = ((SwingPreferences) Application.getPreferences()).getTableColumnWidth(
key, column);
if (width != null) {
table.getColumnModel().getColumn(column).setPreferredWidth(width);
}
}
}
public static void rememberTableColumnWidths(final JTable table) {
rememberTableColumnWidths(table, null);
}
/**

View File

@ -401,6 +401,34 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences {
PREFNODE.node("windows").put("size." + c.getCanonicalName(), "max");
storeVersion();
}
public Integer getTableColumnWidth(String keyName, int columnIdx) {
String pref = PREFNODE.node("tables").get(
"cw." + keyName + "." + columnIdx, null);
if (pref == null)
return null;
try {
return Integer.parseInt(pref);
} catch (NumberFormatException e) {
return null;
}
}
public Integer getTableColumnWidth(Class<?> c, int columnIdx) {
return getTableColumnWidth(c.getCanonicalName(), columnIdx);
}
public void setTableColumnWidth(String keyName, int columnIdx, Integer width) {
PREFNODE.node("tables").put(
"cw." + keyName + "." + columnIdx, width.toString());
storeVersion();
}
public void setTableColumnWidth(Class<?> c, int columnIdx, Integer width) {
setTableColumnWidth(c.getCanonicalName(), columnIdx, width);
}
/**
* this class returns a java.awt.Color object for the specified key.