Add click action for right-click

This commit is contained in:
SiboVG 2022-06-01 22:09:03 +02:00
parent d5420820fa
commit 34b2a0a221
5 changed files with 89 additions and 19 deletions

View File

@ -304,8 +304,15 @@ public class BasicFrame extends JFrame {
ComponentConfigDialog.showDialog(BasicFrame.this,
BasicFrame.this.document, c);
} else if ((e.getButton() == MouseEvent.BUTTON3) && (e.getClickCount() == 1)) {
if (!tree.isPathSelected(selPath)) {
// Select new path
tree.setSelectionPath(selPath);
}
doComponentTreePopup(e);
}
} else {
tree.clearSelection();
}
}
};

View File

@ -222,6 +222,22 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
selectMotor();
}
} 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) {
doPopupFull(e);
} else {

View File

@ -120,6 +120,22 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
selectDeployment();
}
} 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) {
doPopupFull(e);
} else {

View File

@ -140,6 +140,22 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel<AxialS
selectSeparation();
}
} 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) {
doPopupFull(e);
} else {

View File

@ -554,33 +554,48 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
public static final int CYCLE_SELECTION_MODIFIER = InputEvent.SHIFT_DOWN_MASK;
private void handleMouseClick(MouseEvent event) {
if (event.getButton() == MouseEvent.BUTTON1) {
// Get the component that is clicked on
Point p0 = event.getPoint();
Point p1 = scrollPane.getViewport().getViewPosition();
int x = p0.x + p1.x;
int y = p0.y + p1.y;
// Get the component that is clicked on
Point p0 = event.getPoint();
Point p1 = scrollPane.getViewport().getViewPosition();
int x = p0.x + p1.x;
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 (clicked.length == 0) {
selectionModel.setSelectionPath(null);
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())
.map(c -> (RocketComponent) c.getLastPathComponent()).collect(Collectors.toList());