[#1831] Don't highlight sustainer stage at startup
This commit is contained in:
parent
f3b8459f37
commit
c79a75f9bb
@ -279,11 +279,13 @@ public class BasicFrame extends JFrame {
|
|||||||
if( componentSelectionModel.isSelectionEmpty() ){
|
if( componentSelectionModel.isSelectionEmpty() ){
|
||||||
final Rocket rocket = document.getRocket();
|
final Rocket rocket = document.getRocket();
|
||||||
if( rocket != null ) {
|
if( rocket != null ) {
|
||||||
final AxialStage topStage = (AxialStage) rocket.getChild(0);
|
final RocketComponent topStage = rocket.getChild(0);
|
||||||
if (topStage != null) {
|
if (topStage != null) {
|
||||||
final TreePath selectionPath = new TreePath(topStage);
|
final TreePath selectionPath = new TreePath(topStage);
|
||||||
componentSelectionModel.setSelectionPath(selectionPath);
|
componentSelectionModel.setSelectionPath(selectionPath);
|
||||||
tree.setSelectionRow(1);
|
tree.setSelectionRow(1);
|
||||||
|
// Don't select children components at startup (so override the default behavior with this new selection)
|
||||||
|
rocketpanel.getFigure().setSelection(new RocketComponent[] { topStage });
|
||||||
log.debug("... Setting Initial Selection: " + tree.getSelectionPath() );
|
log.debug("... Setting Initial Selection: " + tree.getSelectionPath() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,36 +69,30 @@ public class DesignPanel extends JSplitPane {
|
|||||||
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_O, SHORTCUT_KEY), null);
|
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_O, SHORTCUT_KEY), null);
|
||||||
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_N, 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
|
// Highlight all child components of a stage/rocket/podset when it is selected
|
||||||
tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
|
tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void valueChanged(TreeSelectionEvent e) {
|
public void valueChanged(TreeSelectionEvent e) {
|
||||||
if (tree == null || tree.getSelectionPaths() == null || tree.getSelectionPaths().length == 0
|
highlightAssemblyChildren(tree, parent);
|
||||||
|| 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]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Add a mouse listener for when the sustainer is selected at startup, to ensure that its children are highlighted.
|
||||||
|
// This is necessary because we force the children to not be highlighted when the tree is first created, and
|
||||||
|
// re-clicking the sustainer would not fire a change event in the tree (which normally highlights the children).
|
||||||
|
MouseAdapter mouseAdapter = new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
if (tree.getSelectionPath() != null &&
|
||||||
|
tree.getSelectionPath().getLastPathComponent() == document.getRocket().getChild(0)) {
|
||||||
|
highlightAssemblyChildren(tree, parent);
|
||||||
|
}
|
||||||
|
// Delete the listener again. We only need it at start-up, i.e. when the first click is registered.
|
||||||
|
tree.removeMouseListener(this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
tree.addMouseListener(mouseAdapter);
|
||||||
|
|
||||||
// Double-click opens config dialog
|
// Double-click opens config dialog
|
||||||
MouseListener ml = new MouseAdapter() {
|
MouseListener ml = new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
@ -234,6 +228,37 @@ public class DesignPanel extends JSplitPane {
|
|||||||
this.setRightComponent(panel);
|
this.setRightComponent(panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Highlight all child components of a stage/rocket/podset when it is selected
|
||||||
|
* @param tree the tree in which the component selection took place
|
||||||
|
* @param parent the parent frame to highlight the components in
|
||||||
|
*/
|
||||||
|
private static void highlightAssemblyChildren(ComponentTree tree, BasicFrame parent) {
|
||||||
|
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]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Focus on the component tree.
|
* Focus on the component tree.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user