Add icons to buttons

This commit is contained in:
SiboVG 2022-08-16 22:23:43 +02:00
parent b3a08555fa
commit 685a1b0342
7 changed files with 49 additions and 12 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 912 B

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 906 B

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -83,12 +83,11 @@ public final class FlightConfigurationId implements Comparable<FlightConfigurati
}
//extracted this method because maybe, just maybe, this info could be used somewhere else
/**
* gets if the id is the default
* @return if the id is default
*/
private boolean isDefaultId() {
public boolean isDefaultId() {
return this.key == FlightConfigurationId.DEFAULT_VALUE_UUID;
}

View File

@ -412,24 +412,31 @@ public class BasicFrame extends JFrame {
// Buttons
JButton button = new SelectColorButton(actions.getMoveUpAction());
JButton button = new SelectColorButton();
button.setHorizontalAlignment(SwingConstants.LEFT);
RocketActions.tieActionToButton(button, actions.getMoveUpAction());
panel.add(button, "sizegroup buttons, aligny 65%");
button = new SelectColorButton(actions.getMoveDownAction());
button = new SelectColorButton();
button.setHorizontalAlignment(SwingConstants.LEFT);
RocketActions.tieActionToButton(button, actions.getMoveDownAction());
panel.add(button, "sizegroup buttons, aligny 0%");
button = new SelectColorButton();
RocketActions.tieActionToButtonNoIcon(button, actions.getEditAction());
button.setHorizontalAlignment(SwingConstants.LEFT);
RocketActions.tieActionToButton(button, actions.getEditAction());
button.setMnemonic(0);
panel.add(button, "sizegroup buttons, gaptop 20%");
button = new SelectColorButton();
RocketActions.tieActionToButtonNoIcon(button, actions.getDuplicateAction());
button.setHorizontalAlignment(SwingConstants.LEFT);
RocketActions.tieActionToButton(button, actions.getDuplicateAction());
button.setMnemonic(0);
panel.add(button, "sizegroup buttons");
button = new SelectColorButton();
RocketActions.tieActionToButtonNoIcon(button, actions.getDeleteAction());
button.setHorizontalAlignment(SwingConstants.LEFT);
RocketActions.tieActionToButton(button, actions.getDeleteAction());
button.setMnemonic(0);
panel.add(button, "sizegroup buttons");

View File

@ -219,6 +219,34 @@ public class RocketActions {
button.setAction(action);
button.setIcon(null);
}
/**
* Tie an action to a JButton, without using the 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:
* 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 tieActionToButton(JButton button, Action action, String text) {
button.setAction(action);
button.setText(text);
}
/**
* Tie an action to a JButton.
*
* For any smartass that wants to know why you don't just initialize the JButton with the action:
* 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 tieActionToButton(JButton button, Action action) {
button.setAction(action);
}
//////// Helper methods for the actions
@ -1061,6 +1089,7 @@ public class RocketActions {
public MoveUpAction() {
//// Move up
this.putValue(NAME, trans.get("RocketActions.MoveUpAct.Moveup"));
this.putValue(SMALL_ICON, Icons.UP);
//// Move this component upwards.
this.putValue(SHORT_DESCRIPTION, trans.get("RocketActions.MoveUpAct.ttip.Moveup"));
clipboardChanged();
@ -1136,6 +1165,7 @@ public class RocketActions {
public MoveDownAction() {
//// Move down
this.putValue(NAME, trans.get("RocketActions.MoveDownAct.Movedown"));
this.putValue(SMALL_ICON, Icons.DOWN);
//// Move this component downwards.
this.putValue(SHORT_DESCRIPTION, trans.get("RocketActions.MoveDownAct.ttip.Movedown"));
clipboardChanged();

View File

@ -125,31 +125,31 @@ public class SimulationPanel extends JPanel {
//// New simulation button
JButton newButton = new SelectColorButton();
RocketActions.tieActionToButtonNoIcon(newButton, newSimulationAction, trans.get("simpanel.but.newsimulation"));
RocketActions.tieActionToButton(newButton, newSimulationAction, trans.get("simpanel.but.newsimulation"));
newButton.setToolTipText(trans.get("simpanel.but.ttip.newsimulation"));
this.add(newButton, "skip 1, gapright para");
//// Edit simulation button
editButton = new SelectColorButton();
RocketActions.tieActionToButtonNoIcon(editButton, editSimulationAction, trans.get("simpanel.but.editsimulation"));
RocketActions.tieActionToButton(editButton, editSimulationAction, trans.get("simpanel.but.editsimulation"));
editButton.setToolTipText(trans.get("simpanel.but.ttip.editsim"));
this.add(editButton, "gapright para");
//// Run simulations
runButton = new SelectColorButton();
RocketActions.tieActionToButtonNoIcon(runButton, runSimulationAction, trans.get("simpanel.but.runsimulations"));
RocketActions.tieActionToButton(runButton, runSimulationAction, trans.get("simpanel.but.runsimulations"));
runButton.setToolTipText(trans.get("simpanel.but.ttip.runsimu"));
this.add(runButton, "gapright para");
//// Delete simulations button
deleteButton = new SelectColorButton();
RocketActions.tieActionToButtonNoIcon(deleteButton, deleteSimulationAction, trans.get("simpanel.but.deletesimulations"));
RocketActions.tieActionToButton(deleteButton, deleteSimulationAction, trans.get("simpanel.but.deletesimulations"));
deleteButton.setToolTipText(trans.get("simpanel.but.ttip.deletesim"));
this.add(deleteButton, "gapright para");
//// Plot / export button
plotButton = new SelectColorButton();
RocketActions.tieActionToButtonNoIcon(plotButton, plotSimulationAction, trans.get("simpanel.but.plotexport"));
RocketActions.tieActionToButton(plotButton, plotSimulationAction, trans.get("simpanel.but.plotexport"));
this.add(plotButton, "wrap para");

View File

@ -59,6 +59,7 @@ public class Icons {
public static final Icon EDIT_UNDO = loadImageIcon("pix/icons/edit-undo.png", trans.get("Icons.Undo"));
public static final Icon EDIT_REDO = loadImageIcon("pix/icons/edit-redo.png", trans.get("Icons.Redo"));
public static final Icon EDIT_EDIT = loadImageIcon("pix/icons/edit-edit.png", "Edit");
public static final Icon EDIT_RENAME = loadImageIcon("pix/icons/edit-rename.png", "Rename");
public static final Icon EDIT_CUT = loadImageIcon("pix/icons/edit-cut.png", "Cut");
public static final Icon EDIT_COPY = loadImageIcon("pix/icons/edit-copy.png", "Copy");
public static final Icon EDIT_PASTE = loadImageIcon("pix/icons/edit-paste.png", "Paste");