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());
|
int selRow = tree.getRowForLocation(e.getX(), e.getY());
|
||||||
TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
|
TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
|
||||||
if (selRow != -1) {
|
if (selRow != -1) {
|
||||||
if ((e.getButton() == MouseEvent.BUTTON1) && (e.getClickCount() == 2) && !ComponentConfigDialog.isDialogVisible()) {
|
if (selPath == null) return;
|
||||||
|
|
||||||
// Double-click
|
// Double-click
|
||||||
RocketComponent c = (RocketComponent) selPath.getLastPathComponent();
|
if ((e.getButton() == MouseEvent.BUTTON1) && (e.getClickCount() == 2) && !ComponentConfigDialog.isDialogVisible()) {
|
||||||
ComponentConfigDialog.showDialog(BasicFrame.this,
|
RocketComponent component = (RocketComponent) selPath.getLastPathComponent();
|
||||||
BasicFrame.this.document, c);
|
|
||||||
} else if ((e.getButton() == MouseEvent.BUTTON3) && (e.getClickCount() == 1)) {
|
// 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)) {
|
if (!tree.isPathSelected(selPath)) {
|
||||||
// Select new path
|
// Select new path
|
||||||
tree.setSelectionPath(selPath);
|
tree.setSelectionPath(selPath);
|
||||||
@ -316,7 +333,7 @@ public class BasicFrame extends JFrame {
|
|||||||
|
|
||||||
doComponentTreePopup(e);
|
doComponentTreePopup(e);
|
||||||
}
|
}
|
||||||
} else {
|
} else { // Clicked on blank space
|
||||||
tree.clearSelection();
|
tree.clearSelection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -609,6 +609,33 @@ 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
|
// 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 (clickCount == 2) {
|
||||||
|
if (event.isShiftDown() || event.isMetaDown()) {
|
||||||
|
List<TreePath> paths = new ArrayList<>(Arrays.asList(selectionModel.getSelectionPaths()));
|
||||||
|
RocketComponent component = selectedComponents.get(0);
|
||||||
|
|
||||||
|
// 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])) {
|
if (!selectedComponents.contains(clicked[0])) {
|
||||||
clickCount = 1;
|
clickCount = 1;
|
||||||
} else {
|
} else {
|
||||||
@ -621,6 +648,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If the shift-button is held, add a newly clicked component to the selection path
|
// If the shift-button is held, add a newly clicked component to the selection path
|
||||||
if (clickCount == 1 && (event.isShiftDown() || event.isMetaDown())) {
|
if (clickCount == 1 && (event.isShiftDown() || event.isMetaDown())) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user