Add right-click actions to recovery table
This commit is contained in:
parent
84e7c951e6
commit
c62320931f
@ -1,7 +1,6 @@
|
|||||||
package net.sf.openrocket.gui.main.flightconfigpanel;
|
package net.sf.openrocket.gui.main.flightconfigpanel;
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
@ -12,6 +11,7 @@ import javax.swing.JButton;
|
|||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JDialog;
|
import javax.swing.JDialog;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPopupMenu;
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JTable;
|
import javax.swing.JTable;
|
||||||
import javax.swing.KeyStroke;
|
import javax.swing.KeyStroke;
|
||||||
@ -36,6 +36,13 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
|
|||||||
private final JButton selectDeploymentButton;
|
private final JButton selectDeploymentButton;
|
||||||
private final JButton resetDeploymentButton;
|
private final JButton resetDeploymentButton;
|
||||||
|
|
||||||
|
private final JPopupMenu popupMenuFull; // popup menu containing all the options
|
||||||
|
private final AbstractAction selectDeploymentAction;
|
||||||
|
private final AbstractAction resetDeploymentAction;
|
||||||
|
private final AbstractAction renameConfigAction;
|
||||||
|
private final AbstractAction removeConfigAction;
|
||||||
|
private final AbstractAction duplicateConfigAction;
|
||||||
|
|
||||||
|
|
||||||
RecoveryConfigurationPanel(FlightConfigurationPanel flightConfigurationPanel, Rocket rocket) {
|
RecoveryConfigurationPanel(FlightConfigurationPanel flightConfigurationPanel, Rocket rocket) {
|
||||||
super(flightConfigurationPanel,rocket);
|
super(flightConfigurationPanel,rocket);
|
||||||
@ -43,26 +50,30 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
|
|||||||
JScrollPane scroll = new JScrollPane(table);
|
JScrollPane scroll = new JScrollPane(table);
|
||||||
this.add(scroll, "span, grow, pushy, wrap");
|
this.add(scroll, "span, grow, pushy, wrap");
|
||||||
|
|
||||||
|
// Get all the actions
|
||||||
|
selectDeploymentAction = new SelectDeploymentAction();
|
||||||
|
resetDeploymentAction = new ResetDeploymentAction();
|
||||||
|
renameConfigAction = flightConfigurationPanel.getRenameConfigAction();
|
||||||
|
removeConfigAction = flightConfigurationPanel.getRemoveConfigAction();
|
||||||
|
duplicateConfigAction = flightConfigurationPanel.getDuplicateConfigAction();
|
||||||
|
|
||||||
|
// Populate the popup menu
|
||||||
|
popupMenuFull = new JPopupMenu();
|
||||||
|
popupMenuFull.add(selectDeploymentAction);
|
||||||
|
popupMenuFull.add(resetDeploymentAction);
|
||||||
|
popupMenuFull.addSeparator();
|
||||||
|
popupMenuFull.add(renameConfigAction);
|
||||||
|
popupMenuFull.add(removeConfigAction);
|
||||||
|
popupMenuFull.add(duplicateConfigAction);
|
||||||
|
|
||||||
//// Select deployment
|
//// Select deployment
|
||||||
selectDeploymentButton = new SelectColorButton(trans.get("edtmotorconfdlg.but.Selectdeployment"));
|
selectDeploymentButton = new SelectColorButton(selectDeploymentAction);
|
||||||
selectDeploymentButton.setEnabled(false);
|
selectDeploymentButton.setEnabled(false);
|
||||||
selectDeploymentButton.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
selectDeployment();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.add(selectDeploymentButton, "split, align right, sizegroup button");
|
this.add(selectDeploymentButton, "split, align right, sizegroup button");
|
||||||
|
|
||||||
//// Reset deployment
|
//// Reset deployment
|
||||||
resetDeploymentButton = new SelectColorButton(trans.get("edtmotorconfdlg.but.Resetdeployment"));
|
resetDeploymentButton = new SelectColorButton(resetDeploymentAction);
|
||||||
resetDeploymentButton.setEnabled(false);
|
resetDeploymentButton.setEnabled(false);
|
||||||
resetDeploymentButton.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
resetDeployment();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.add(resetDeploymentButton, "sizegroup button, wrap");
|
this.add(resetDeploymentButton, "sizegroup button, wrap");
|
||||||
|
|
||||||
// Set 'Enter' key action to open the recovery selection dialog
|
// Set 'Enter' key action to open the recovery selection dialog
|
||||||
@ -88,10 +99,18 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
|
|||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
updateButtonState();
|
updateButtonState();
|
||||||
|
int selectedColumn = table.getSelectedColumn();
|
||||||
|
|
||||||
if (e.getClickCount() == 2) {
|
if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
|
||||||
// Double-click edits
|
if (selectedColumn > 0) {
|
||||||
selectDeployment();
|
selectDeployment();
|
||||||
|
}
|
||||||
|
} else if (e.getButton() == MouseEvent.BUTTON3 && e.getClickCount() == 1) {
|
||||||
|
if (selectedColumn > 0) {
|
||||||
|
doPopupFull(e);
|
||||||
|
} else {
|
||||||
|
flightConfigurationPanel.doPopupConfig(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -185,6 +204,10 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void doPopupFull(MouseEvent e) {
|
||||||
|
popupMenuFull.show(e.getComponent(), e.getX(), e.getY());
|
||||||
|
}
|
||||||
|
|
||||||
public void updateButtonState() {
|
public void updateButtonState() {
|
||||||
boolean componentSelected = getSelectedComponent() != null;
|
boolean componentSelected = getSelectedComponent() != null;
|
||||||
selectDeploymentButton.setEnabled(componentSelected);
|
selectDeploymentButton.setEnabled(componentSelected);
|
||||||
@ -221,4 +244,25 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class SelectDeploymentAction extends AbstractAction {
|
||||||
|
public SelectDeploymentAction() {
|
||||||
|
putValue(NAME, trans.get("edtmotorconfdlg.but.Selectdeployment"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
selectDeployment();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private class ResetDeploymentAction extends AbstractAction {
|
||||||
|
public ResetDeploymentAction() {
|
||||||
|
putValue(NAME, trans.get("edtmotorconfdlg.but.Resetdeployment"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
resetDeployment();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user