[fixes #244] Implement multi-selection for motor mounts
This does not have a direct effect yet. Once multi-component selection is implemented from #358, this will work
This commit is contained in:
parent
08eeac5236
commit
4ba92905b4
@ -1694,6 +1694,11 @@ public class BasicFrame extends JFrame {
|
||||
this.selectionModel.setSelectedComponent(component);
|
||||
}
|
||||
|
||||
public void setSelectedComponents(List<RocketComponent> components) {
|
||||
this.selectionModel.setSelectedComponents(components);
|
||||
}
|
||||
|
||||
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
JTabbedPane tabSource = (JTabbedPane) e.getSource();
|
||||
int tab = tabSource.getSelectedIndex();
|
||||
|
@ -2,6 +2,7 @@ package net.sf.openrocket.gui.main;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.ListSelectionModel;
|
||||
@ -29,7 +30,7 @@ public class DocumentSelectionModel {
|
||||
|
||||
private final OpenRocketDocument document;
|
||||
|
||||
private RocketComponent componentSelection = null;
|
||||
private final List<RocketComponent> componentSelection = new LinkedList<>();
|
||||
private Simulation[] simulationSelection = NO_SIMULATION;
|
||||
|
||||
private TreeSelectionModel componentTreeSelectionModel = null;
|
||||
@ -72,23 +73,33 @@ public class DocumentSelectionModel {
|
||||
|
||||
/**
|
||||
* Return the currently selected rocket component. Returns <code>null</code>
|
||||
* if no rocket component is selected.
|
||||
* if no rocket component is selected. If there is more than one component selected,
|
||||
* the first selected component is returned.
|
||||
*
|
||||
* @return the currently selected rocket component, or <code>null</code>.
|
||||
*/
|
||||
public RocketComponent getSelectedComponent() {
|
||||
return componentSelection;
|
||||
if (componentSelection == null || componentSelection.size() == 0) return null;
|
||||
return componentSelection.get(0);
|
||||
}
|
||||
|
||||
public void setSelectedComponent(RocketComponent component) {
|
||||
componentSelection = component;
|
||||
componentSelection.clear();
|
||||
componentSelection.add(component);
|
||||
clearSimulationSelection();
|
||||
|
||||
TreePath path = ComponentTreeModel.makeTreePath(component);
|
||||
componentTreeSelectionModel.setSelectionPath(path);
|
||||
}
|
||||
|
||||
public void setSelectedComponents(List<RocketComponent> components) {
|
||||
componentSelection.clear();
|
||||
componentSelection.addAll(components);
|
||||
clearSimulationSelection();
|
||||
|
||||
List<TreePath> paths = ComponentTreeModel.makeTreePaths(components);
|
||||
componentTreeSelectionModel.setSelectionPaths(paths.toArray(new TreePath[0]));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -131,10 +142,10 @@ public class DocumentSelectionModel {
|
||||
|
||||
|
||||
public void clearComponentSelection() {
|
||||
if (componentSelection == null)
|
||||
if (componentSelection == null || componentSelection.size() == 0)
|
||||
return;
|
||||
|
||||
componentSelection = null;
|
||||
componentSelection.clear();
|
||||
if (componentTreeSelectionModel != null)
|
||||
componentTreeSelectionModel.clearSelection();
|
||||
|
||||
@ -168,12 +179,13 @@ public class DocumentSelectionModel {
|
||||
public void valueChanged(TreeSelectionEvent e) {
|
||||
TreePath path = componentTreeSelectionModel.getSelectionPath();
|
||||
if (path == null) {
|
||||
componentSelection = null;
|
||||
componentSelection.clear();
|
||||
fireDocumentSelection(DocumentSelectionListener.COMPONENT_SELECTION_CHANGE);
|
||||
return;
|
||||
}
|
||||
|
||||
componentSelection = (RocketComponent)path.getLastPathComponent();
|
||||
|
||||
componentSelection.clear();
|
||||
componentSelection.add((RocketComponent)path.getLastPathComponent());
|
||||
|
||||
clearSimulationSelection();
|
||||
fireDocumentSelection(DocumentSelectionListener.COMPONENT_SELECTION_CHANGE);
|
||||
|
@ -199,6 +199,21 @@ public class ComponentTreeModel implements TreeModel, ComponentChangeListener {
|
||||
|
||||
return new TreePath(list.toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return TreePaths corresponding to the specified rocket components.
|
||||
*
|
||||
* @param components the rocket components
|
||||
* @return a list of TreePaths corresponding to the different RocketComponents (one path for each component)
|
||||
*/
|
||||
public static List<TreePath> makeTreePaths(List<RocketComponent> components) {
|
||||
List<TreePath> result = new LinkedList<>();
|
||||
|
||||
for (RocketComponent component : components) {
|
||||
result.add(makeTreePath(component));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -297,6 +297,10 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
|
||||
this.basicFrame.setSelectedComponent(component);
|
||||
}
|
||||
|
||||
public void setSelectedComponents(List<RocketComponent> components) {
|
||||
this.basicFrame.setSelectedComponents(components);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stateChanged(EventObject e) {
|
||||
updateButtonState();
|
||||
|
@ -45,6 +45,7 @@ import net.sf.openrocket.rocketcomponent.MotorMount;
|
||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||
import net.sf.openrocket.unit.UnitGroup;
|
||||
import net.sf.openrocket.util.ArrayList;
|
||||
import net.sf.openrocket.util.Chars;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@ -237,10 +238,16 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
|
||||
if (e.getValueIsAdjusting()) {
|
||||
return;
|
||||
}
|
||||
MotorMount mount = getSelectedComponent();
|
||||
if (mount instanceof RocketComponent) {
|
||||
flightConfigurationPanel.setSelectedComponent((RocketComponent) mount);
|
||||
List<MotorMount> mounts = getSelectedComponents();
|
||||
if (mounts == null || mounts.size() == 0) return;
|
||||
List<RocketComponent> components = new ArrayList<>();
|
||||
for (MotorMount mount : mounts) {
|
||||
if (mount instanceof RocketComponent) {
|
||||
components.add((RocketComponent) mount);
|
||||
}
|
||||
}
|
||||
|
||||
flightConfigurationPanel.setSelectedComponents(components);
|
||||
}
|
||||
|
||||
protected void updateButtonState() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user