From 84689df28359c37cba90af5c0f37e1d8c2286000 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Mon, 20 Mar 2023 22:52:42 +0100 Subject: [PATCH] Add select None action --- core/resources/l10n/messages.properties | 2 + .../sf/openrocket/gui/main/BasicFrame.java | 5 ++- .../sf/openrocket/gui/main/RocketActions.java | 38 +++++++++++++++++-- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index 0aaca5e6c..057634612 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -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 diff --git a/swing/src/net/sf/openrocket/gui/main/BasicFrame.java b/swing/src/net/sf/openrocket/gui/main/BasicFrame.java index 7a19f6a01..44a381457 100644 --- a/swing/src/net/sf/openrocket/gui/main/BasicFrame.java +++ b/swing/src/net/sf/openrocket/gui/main/BasicFrame.java @@ -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(); diff --git a/swing/src/net/sf/openrocket/gui/main/RocketActions.java b/swing/src/net/sf/openrocket/gui/main/RocketActions.java index d4f1dd9b9..8d52e5901 100644 --- a/swing/src/net/sf/openrocket/gui/main/RocketActions.java +++ b/swing/src/net/sf/openrocket/gui/main/RocketActions.java @@ -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 components = selectionModel.getSelectedComponents(); + this.setEnabled(components.size() > 0); + } + }