Add click action for right-click
This commit is contained in:
parent
d5420820fa
commit
34b2a0a221
@ -304,8 +304,15 @@ public class BasicFrame extends JFrame {
|
|||||||
ComponentConfigDialog.showDialog(BasicFrame.this,
|
ComponentConfigDialog.showDialog(BasicFrame.this,
|
||||||
BasicFrame.this.document, c);
|
BasicFrame.this.document, c);
|
||||||
} else if ((e.getButton() == MouseEvent.BUTTON3) && (e.getClickCount() == 1)) {
|
} else if ((e.getButton() == MouseEvent.BUTTON3) && (e.getClickCount() == 1)) {
|
||||||
|
if (!tree.isPathSelected(selPath)) {
|
||||||
|
// Select new path
|
||||||
|
tree.setSelectionPath(selPath);
|
||||||
|
}
|
||||||
|
|
||||||
doComponentTreePopup(e);
|
doComponentTreePopup(e);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
tree.clearSelection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -222,6 +222,22 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
|
|||||||
selectMotor();
|
selectMotor();
|
||||||
}
|
}
|
||||||
} else if (e.getButton() == MouseEvent.BUTTON3 && e.getClickCount() == 1) {
|
} else if (e.getButton() == MouseEvent.BUTTON3 && e.getClickCount() == 1) {
|
||||||
|
// Get the row and column of the selected cell
|
||||||
|
int r = configurationTable.rowAtPoint(e.getPoint());
|
||||||
|
int c = configurationTable.columnAtPoint(e.getPoint());
|
||||||
|
|
||||||
|
// Select new cell
|
||||||
|
if (!configurationTable.isCellSelected(r, c)) {
|
||||||
|
if (r >= 0 && r < configurationTable.getRowCount() &&
|
||||||
|
c >= 0 && c < configurationTable.getColumnCount()) {
|
||||||
|
configurationTable.setRowSelectionInterval(r, r);
|
||||||
|
configurationTable.setColumnSelectionInterval(c, c);
|
||||||
|
} else {
|
||||||
|
configurationTable.clearSelection();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (selectedColumn > 0) {
|
if (selectedColumn > 0) {
|
||||||
doPopupFull(e);
|
doPopupFull(e);
|
||||||
} else {
|
} else {
|
||||||
|
@ -120,6 +120,22 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
|
|||||||
selectDeployment();
|
selectDeployment();
|
||||||
}
|
}
|
||||||
} else if (e.getButton() == MouseEvent.BUTTON3 && e.getClickCount() == 1) {
|
} else if (e.getButton() == MouseEvent.BUTTON3 && e.getClickCount() == 1) {
|
||||||
|
// Get the row and column of the selected cell
|
||||||
|
int r = recoveryTable.rowAtPoint(e.getPoint());
|
||||||
|
int c = recoveryTable.columnAtPoint(e.getPoint());
|
||||||
|
|
||||||
|
// Select new cell
|
||||||
|
if (!recoveryTable.isCellSelected(r, c)) {
|
||||||
|
if (r >= 0 && r < recoveryTable.getRowCount() &&
|
||||||
|
c >= 0 && c < recoveryTable.getColumnCount()) {
|
||||||
|
recoveryTable.setRowSelectionInterval(r, r);
|
||||||
|
recoveryTable.setColumnSelectionInterval(c, c);
|
||||||
|
} else {
|
||||||
|
recoveryTable.clearSelection();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (selectedColumn > 0) {
|
if (selectedColumn > 0) {
|
||||||
doPopupFull(e);
|
doPopupFull(e);
|
||||||
} else {
|
} else {
|
||||||
|
@ -140,6 +140,22 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel<AxialS
|
|||||||
selectSeparation();
|
selectSeparation();
|
||||||
}
|
}
|
||||||
} else if (e.getButton() == MouseEvent.BUTTON3 && e.getClickCount() == 1) {
|
} else if (e.getButton() == MouseEvent.BUTTON3 && e.getClickCount() == 1) {
|
||||||
|
// Get the row and column of the selected cell
|
||||||
|
int r = separationTable.rowAtPoint(e.getPoint());
|
||||||
|
int c = separationTable.columnAtPoint(e.getPoint());
|
||||||
|
|
||||||
|
// Select new cell
|
||||||
|
if (!separationTable.isCellSelected(r, c)) {
|
||||||
|
if (r >= 0 && r < separationTable.getRowCount() &&
|
||||||
|
c >= 0 && c < separationTable.getColumnCount()) {
|
||||||
|
separationTable.setRowSelectionInterval(r, r);
|
||||||
|
separationTable.setColumnSelectionInterval(c, c);
|
||||||
|
} else {
|
||||||
|
separationTable.clearSelection();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (selectedColumn > 0) {
|
if (selectedColumn > 0) {
|
||||||
doPopupFull(e);
|
doPopupFull(e);
|
||||||
} else {
|
} else {
|
||||||
|
@ -554,33 +554,48 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
|
|||||||
public static final int CYCLE_SELECTION_MODIFIER = InputEvent.SHIFT_DOWN_MASK;
|
public static final int CYCLE_SELECTION_MODIFIER = InputEvent.SHIFT_DOWN_MASK;
|
||||||
|
|
||||||
private void handleMouseClick(MouseEvent event) {
|
private void handleMouseClick(MouseEvent event) {
|
||||||
if (event.getButton() == MouseEvent.BUTTON1) {
|
// Get the component that is clicked on
|
||||||
// Get the component that is clicked on
|
Point p0 = event.getPoint();
|
||||||
Point p0 = event.getPoint();
|
Point p1 = scrollPane.getViewport().getViewPosition();
|
||||||
Point p1 = scrollPane.getViewport().getViewPosition();
|
int x = p0.x + p1.x;
|
||||||
int x = p0.x + p1.x;
|
int y = p0.y + p1.y;
|
||||||
int y = p0.y + p1.y;
|
|
||||||
|
|
||||||
RocketComponent[] clicked = figure.getComponentsByPoint(x, y);
|
RocketComponent[] clicked = figure.getComponentsByPoint(x, y);
|
||||||
|
|
||||||
handleComponentClick(clicked, event);
|
|
||||||
} else if (event.getButton() == MouseEvent.BUTTON3) {
|
|
||||||
List<RocketComponent> selectedComponents = Arrays.stream(selectionModel.getSelectionPaths())
|
|
||||||
.map(c -> (RocketComponent) c.getLastPathComponent()).collect(Collectors.toList());
|
|
||||||
|
|
||||||
if (selectedComponents.size() == 0) return;
|
|
||||||
|
|
||||||
basicFrame.doComponentTreePopup(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleComponentClick(RocketComponent[] clicked, MouseEvent event) {
|
|
||||||
// If no component is clicked, do nothing
|
// If no component is clicked, do nothing
|
||||||
if (clicked.length == 0) {
|
if (clicked.length == 0) {
|
||||||
selectionModel.setSelectionPath(null);
|
selectionModel.setSelectionPath(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.getButton() == MouseEvent.BUTTON1) {
|
||||||
|
handleComponentClick(clicked, event);
|
||||||
|
} else if (event.getButton() == MouseEvent.BUTTON3) {
|
||||||
|
List<RocketComponent> selectedComponents = Arrays.stream(selectionModel.getSelectionPaths())
|
||||||
|
.map(c -> (RocketComponent) c.getLastPathComponent()).collect(Collectors.toList());
|
||||||
|
|
||||||
|
boolean newClick = true;
|
||||||
|
for (RocketComponent component : clicked) {
|
||||||
|
if (selectedComponents.contains(component)) {
|
||||||
|
newClick = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newClick) {
|
||||||
|
for (RocketComponent rocketComponent : clicked) {
|
||||||
|
if (!selectedComponents.contains(rocketComponent)) {
|
||||||
|
TreePath path = ComponentTreeModel.makeTreePath(rocketComponent);
|
||||||
|
selectionModel.setSelectionPath(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
basicFrame.doComponentTreePopup(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleComponentClick(RocketComponent[] clicked, MouseEvent event) {
|
||||||
List<RocketComponent> selectedComponents = Arrays.stream(selectionModel.getSelectionPaths())
|
List<RocketComponent> selectedComponents = Arrays.stream(selectionModel.getSelectionPaths())
|
||||||
.map(c -> (RocketComponent) c.getLastPathComponent()).collect(Collectors.toList());
|
.map(c -> (RocketComponent) c.getLastPathComponent()).collect(Collectors.toList());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user