Add select None action

This commit is contained in:
SiboVG 2023-03-20 22:52:42 +01:00
parent daf6189c8f
commit 84689df283
3 changed files with 41 additions and 4 deletions

View File

@ -42,6 +42,8 @@ RocketActions.EditAct.ttip.Edit = Edit the selected component.
RocketActions.Select = Select
RocketActions.Select.SelectSameColorAct = Components with same color
RocketActions.Select.SelectSameColorAct.ttip = Select all components with the same color as this component.
RocketActions.Select.SelectNoneAct = None
RocketActions.Select.SelectNoneAct.ttip = Deselect all components.
RocketActions.ScaleAct.Scale = Scale
RocketActions.ScaleAct.ttip.Scale = Scale parts of the rocket design
RocketActions.NewStageAct.Newstage = New stage

View File

@ -240,6 +240,7 @@ public class BasicFrame extends JFrame {
popupMenu.addSeparator();
JMenu selectMenu = new JMenu(trans.get("RocketActions.Select"));
selectMenu.add(actions.getSelectSameColorAction());
selectMenu.add(actions.getSelectNoneAction());
popupMenu.add(selectMenu);
popupMenu.addSeparator();
@ -663,9 +664,11 @@ public class BasicFrame extends JFrame {
menu.addSeparator();
JMenu subMenu = new JMenu(trans.get("RocketActions.Select"));
menu.add(subMenu);
item = new JMenuItem(actions.getSelectSameColorAction());
subMenu.add(item);
menu.add(subMenu);
item = new JMenuItem(actions.getSelectNoneAction());
subMenu.add(item);
menu.addSeparator();

View File

@ -76,6 +76,7 @@ public class RocketActions {
private final RocketAction duplicateAction;
private final RocketAction editAction;
private final RocketAction selectSameColorAction;
private final RocketAction selectNoneAction;
private final RocketAction scaleAction;
private final RocketAction moveUpAction;
private final RocketAction moveDownAction;
@ -100,7 +101,8 @@ public class RocketActions {
this.pasteAction = new PasteAction();
this.duplicateAction = new DuplicateAction();
this.editAction = new EditAction();
this.selectSameColorAction = new SelectSameColor();
this.selectSameColorAction = new SelectSameColorAction();
this.selectNoneAction = new SelectNoneAction();
this.scaleAction = new ScaleAction();
this.moveUpAction = new MoveUpAction();
this.moveDownAction = new MoveDownAction();
@ -135,6 +137,7 @@ public class RocketActions {
duplicateAction.clipboardChanged();
editAction.clipboardChanged();
selectSameColorAction.clipboardChanged();
selectNoneAction.clipboardChanged();
scaleAction.clipboardChanged();
moveUpAction.clipboardChanged();
moveDownAction.clipboardChanged();
@ -179,6 +182,10 @@ public class RocketActions {
return selectSameColorAction;
}
public Action getSelectNoneAction() {
return selectNoneAction;
}
public Action getScaleAction() {
return scaleAction;
}
@ -1014,13 +1021,14 @@ public class RocketActions {
}
}
/**
* Action to select all components with the same color as the currently selected component.
*/
private class SelectSameColor extends RocketAction {
private class SelectSameColorAction extends RocketAction {
private static final long serialVersionUID = 1L;
public SelectSameColor() {
public SelectSameColorAction() {
//// Select same color
this.putValue(NAME, trans.get("RocketActions.Select.SelectSameColorAct"));
this.putValue(SHORT_DESCRIPTION, trans.get("RocketActions.Select.SelectSameColorAct.ttip"));
@ -1095,6 +1103,30 @@ public class RocketActions {
}
}
/**
* Action to select all components with the same color as the currently selected component.
*/
private class SelectNoneAction extends RocketAction {
private static final long serialVersionUID = 1L;
public SelectNoneAction() {
//// Select none
this.putValue(NAME, trans.get("RocketActions.Select.SelectNoneAct"));
this.putValue(SHORT_DESCRIPTION, trans.get("RocketActions.Select.SelectNoneAct.ttip"));
clipboardChanged();
}
@Override
public void actionPerformed(ActionEvent e) {
selectionModel.clearComponentSelection();
}
@Override
public void clipboardChanged() {
List<RocketComponent> components = selectionModel.getSelectedComponents();
this.setEnabled(components.size() > 0);
}
}