Add multi-component
This commit is contained in:
parent
c542b72b33
commit
e1bd4c07d1
@ -303,12 +303,29 @@ public class BasicFrame extends JFrame {
|
||||
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()) {
|
||||
// Double-click
|
||||
RocketComponent c = (RocketComponent) selPath.getLastPathComponent();
|
||||
ComponentConfigDialog.showDialog(BasicFrame.this,
|
||||
BasicFrame.this.document, c);
|
||||
} else if ((e.getButton() == MouseEvent.BUTTON3) && (e.getClickCount() == 1)) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
@ -316,7 +333,7 @@ public class BasicFrame extends JFrame {
|
||||
|
||||
doComponentTreePopup(e);
|
||||
}
|
||||
} else {
|
||||
} else { // Clicked on blank space
|
||||
tree.clearSelection();
|
||||
}
|
||||
}
|
||||
|
@ -609,16 +609,44 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
|
||||
|
||||
// Check for double-click. If the component was not already selected, ignore the double click and treat it as a single click
|
||||
if (clickCount == 2) {
|
||||
if (!selectedComponents.contains(clicked[0])) {
|
||||
clickCount = 1;
|
||||
} else {
|
||||
TreePath path = ComponentTreeModel.makeTreePath(clicked[0]);
|
||||
selectionModel.setSelectionPath(path); // Revert to single selection
|
||||
RocketComponent component = (RocketComponent) path.getLastPathComponent();
|
||||
if (event.isShiftDown() || event.isMetaDown()) {
|
||||
List<TreePath> paths = new ArrayList<>(Arrays.asList(selectionModel.getSelectionPaths()));
|
||||
RocketComponent component = selectedComponents.get(0);
|
||||
|
||||
ComponentConfigDialog.showDialog(SwingUtilities.getWindowAncestor(this),
|
||||
document, component);
|
||||
return;
|
||||
// Make sure the clicked component is selected
|
||||
for (RocketComponent c : clicked) {
|
||||
if (!selectedComponents.contains(c)) {
|
||||
TreePath path = ComponentTreeModel.makeTreePath(c);
|
||||
paths.add(path);
|
||||
selectionModel.setSelectionPaths(paths.toArray(new TreePath[0]));
|
||||
selectedComponents = Arrays.stream(selectionModel.getSelectionPaths())
|
||||
.map(c1 -> (RocketComponent) c1.getLastPathComponent()).collect(Collectors.toList());
|
||||
component = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Multi-component edit if shift/meta key is pressed
|
||||
for (RocketComponent c : selectedComponents) {
|
||||
if (c == component) continue;
|
||||
c.clearConfigListeners();
|
||||
component.addConfigListener(c);
|
||||
}
|
||||
ComponentConfigDialog.showDialog(SwingUtilities.getWindowAncestor(this), document, component);
|
||||
}
|
||||
// Normal double click (no shift or meta key)
|
||||
else {
|
||||
if (!selectedComponents.contains(clicked[0])) {
|
||||
clickCount = 1;
|
||||
} else {
|
||||
TreePath path = ComponentTreeModel.makeTreePath(clicked[0]);
|
||||
selectionModel.setSelectionPath(path); // Revert to single selection
|
||||
RocketComponent component = (RocketComponent) path.getLastPathComponent();
|
||||
|
||||
ComponentConfigDialog.showDialog(SwingUtilities.getWindowAncestor(this),
|
||||
document, component);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user