Move method to RocketActions
This commit is contained in:
parent
ada48369e4
commit
c29955b7f8
@ -12,6 +12,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import javax.swing.AbstractAction;
|
import javax.swing.AbstractAction;
|
||||||
import javax.swing.Action;
|
import javax.swing.Action;
|
||||||
|
import javax.swing.JButton;
|
||||||
import javax.swing.JCheckBox;
|
import javax.swing.JCheckBox;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
@ -189,6 +190,35 @@ public class RocketActions {
|
|||||||
return moveDownAction;
|
return moveDownAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tie an action to a JButton, without using the icon or text of the action for the button.
|
||||||
|
*
|
||||||
|
* For any smartass that wants to know why you don't just initialize the JButton with the action and then set the
|
||||||
|
* icon to null and set the button text: this causes a bug where the text of the icon becomes much smaller than is intended.
|
||||||
|
*
|
||||||
|
* @param button button to tie the action to
|
||||||
|
* @param action action to tie to the button
|
||||||
|
* @param text text to display on the button
|
||||||
|
*/
|
||||||
|
public static void tieActionToButtonNoIcon(JButton button, Action action, String text) {
|
||||||
|
button.setAction(action);
|
||||||
|
button.setIcon(null);
|
||||||
|
button.setText(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tie an action to a JButton, without using the icon of the action for the button.
|
||||||
|
*
|
||||||
|
* For any smartass that wants to know why you don't just initialize the JButton with the action and then set the
|
||||||
|
* icon to null: this causes a bug where the text of the icon becomes much smaller than is intended.
|
||||||
|
*
|
||||||
|
* @param button button to tie the action to
|
||||||
|
* @param action action to tie to the button
|
||||||
|
*/
|
||||||
|
public static void tieActionToButtonNoIcon(JButton button, Action action) {
|
||||||
|
button.setAction(action);
|
||||||
|
button.setIcon(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//////// Helper methods for the actions
|
//////// Helper methods for the actions
|
||||||
|
@ -10,7 +10,6 @@ import java.awt.datatransfer.StringSelection;
|
|||||||
import java.awt.datatransfer.Transferable;
|
import java.awt.datatransfer.Transferable;
|
||||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||||
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;
|
||||||
@ -19,7 +18,6 @@ import java.util.Arrays;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
||||||
import javax.swing.AbstractAction;
|
import javax.swing.AbstractAction;
|
||||||
import javax.swing.Action;
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JCheckBox;
|
import javax.swing.JCheckBox;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
@ -123,31 +121,31 @@ public class SimulationPanel extends JPanel {
|
|||||||
|
|
||||||
//// New simulation button
|
//// New simulation button
|
||||||
JButton newButton = new SelectColorButton();
|
JButton newButton = new SelectColorButton();
|
||||||
tieActionToButtonNoIcon(newButton, newSimulationAction, trans.get("simpanel.but.newsimulation"));
|
RocketActions.tieActionToButtonNoIcon(newButton, newSimulationAction, trans.get("simpanel.but.newsimulation"));
|
||||||
newButton.setToolTipText(trans.get("simpanel.but.ttip.newsimulation"));
|
newButton.setToolTipText(trans.get("simpanel.but.ttip.newsimulation"));
|
||||||
this.add(newButton, "skip 1, gapright para");
|
this.add(newButton, "skip 1, gapright para");
|
||||||
|
|
||||||
//// Edit simulation button
|
//// Edit simulation button
|
||||||
editButton = new SelectColorButton();
|
editButton = new SelectColorButton();
|
||||||
tieActionToButtonNoIcon(editButton, editSimulationAction, trans.get("simpanel.but.editsimulation"));
|
RocketActions.tieActionToButtonNoIcon(editButton, editSimulationAction, trans.get("simpanel.but.editsimulation"));
|
||||||
editButton.setToolTipText(trans.get("simpanel.but.ttip.editsim"));
|
editButton.setToolTipText(trans.get("simpanel.but.ttip.editsim"));
|
||||||
this.add(editButton, "gapright para");
|
this.add(editButton, "gapright para");
|
||||||
|
|
||||||
//// Run simulations
|
//// Run simulations
|
||||||
runButton = new SelectColorButton();
|
runButton = new SelectColorButton();
|
||||||
tieActionToButtonNoIcon(runButton, runSimulationAction, trans.get("simpanel.but.runsimulations"));
|
RocketActions.tieActionToButtonNoIcon(runButton, runSimulationAction, trans.get("simpanel.but.runsimulations"));
|
||||||
runButton.setToolTipText(trans.get("simpanel.but.ttip.runsimu"));
|
runButton.setToolTipText(trans.get("simpanel.but.ttip.runsimu"));
|
||||||
this.add(runButton, "gapright para");
|
this.add(runButton, "gapright para");
|
||||||
|
|
||||||
//// Delete simulations button
|
//// Delete simulations button
|
||||||
deleteButton = new SelectColorButton();
|
deleteButton = new SelectColorButton();
|
||||||
tieActionToButtonNoIcon(deleteButton, deleteSimulationAction, trans.get("simpanel.but.deletesimulations"));
|
RocketActions.tieActionToButtonNoIcon(deleteButton, deleteSimulationAction, trans.get("simpanel.but.deletesimulations"));
|
||||||
deleteButton.setToolTipText(trans.get("simpanel.but.ttip.deletesim"));
|
deleteButton.setToolTipText(trans.get("simpanel.but.ttip.deletesim"));
|
||||||
this.add(deleteButton, "gapright para");
|
this.add(deleteButton, "gapright para");
|
||||||
|
|
||||||
//// Plot / export button
|
//// Plot / export button
|
||||||
plotButton = new SelectColorButton();
|
plotButton = new SelectColorButton();
|
||||||
tieActionToButtonNoIcon(plotButton, plotSimulationAction, trans.get("simpanel.but.plotexport"));
|
RocketActions.tieActionToButtonNoIcon(plotButton, plotSimulationAction, trans.get("simpanel.but.plotexport"));
|
||||||
this.add(plotButton, "wrap para");
|
this.add(plotButton, "wrap para");
|
||||||
|
|
||||||
|
|
||||||
@ -747,12 +745,6 @@ public class SimulationPanel extends JPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tieActionToButtonNoIcon(JButton button, Action action, String text) {
|
|
||||||
button.setAction(action);
|
|
||||||
button.setIcon(null);
|
|
||||||
button.setText(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
private abstract static class SimulationAction extends AbstractAction {
|
private abstract static class SimulationAction extends AbstractAction {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user