[#2485] Add show all action

This commit is contained in:
Ahanu Dewhirst 2024-07-19 12:31:42 +10:00
parent 3f3352302f
commit a9456be0fb
7 changed files with 73 additions and 19 deletions

View File

@ -50,6 +50,7 @@ RocketActions.MoveDownAct.ttip.Movedown = Move this component downwards.
RocketActions.ExportOBJAct.ExportOBJ = Export as OBJ (.obj)
RocketActions.ExportOBJAct.ttip.ExportOBJ = Export the selected components as a Wavefront OBJ 3D file.
RocketActions.Visibility = Visibility
RocketActions.VisibilityAct.ShowAll = Show all
RocketActions.VisibilityAct.ttip.ShowAll = Show all components.
RocketActions.VisibilityAct.HideAll = Hide all

View File

@ -607,9 +607,15 @@ public class BasicFrame extends JFrame {
item = new JMenuItem(actions.getScaleAction());
editMenu.add(item);
//// Visibility
JMenu visibilitySubMenu = new JMenu(trans.get("RocketActions.Visibility"));
editMenu.add(visibilitySubMenu);
item = new JMenuItem(actions.getToggleVisibilityAction());
editMenu.add(item);
visibilitySubMenu.add(item);
item = new JMenuItem(actions.getShowAllComponentsAction());
visibilitySubMenu.add(item);
editMenu.addSeparator();
//// Preferences
item = new JMenuItem(trans.get("main.menu.edit.preferences"));

View File

@ -75,6 +75,7 @@ public class RocketActions {
private final RocketAction moveDownAction;
private final RocketAction exportOBJAction;
private final RocketAction toggleVisibilityAction;
private final RocketAction showAllComponentsAction;
private static final Translator trans = Application.getTranslator();
private static final Logger log = LoggerFactory.getLogger(RocketActions.class);
@ -101,6 +102,7 @@ public class RocketActions {
this.moveDownAction = new MoveDownAction();
this.exportOBJAction = new ExportOBJAction();
this.toggleVisibilityAction = new ToggleVisibilityAction();
this.showAllComponentsAction = new ShowAllComponentsAction();
OpenRocketClipboard.addClipboardListener(new ClipboardListener() {
@Override
@ -150,6 +152,7 @@ public class RocketActions {
moveDownAction.clipboardChanged();
exportOBJAction.clipboardChanged();
toggleVisibilityAction.clipboardChanged();
showAllComponentsAction.clipboardChanged();
}
@ -207,6 +210,10 @@ public class RocketActions {
return toggleVisibilityAction;
}
public Action getShowAllComponentsAction() {
return showAllComponentsAction;
}
/**
* Tie an action to a JButton, without using the icon or text of the action for the button.
*
@ -482,7 +489,26 @@ public class RocketActions {
return result;
}
/**
* Returns all descendants of the specified component.
*
* @param component Component to query
* @return All descendants
* @apiNote Returns an empty set if the component does not have children.
*/
private Set<RocketComponent> getDescendants(RocketComponent component) {
Objects.requireNonNull(component);
var result = new LinkedHashSet<RocketComponent>();
var queue = new ArrayDeque<>(component.getChildren());
while (!queue.isEmpty()) {
var node = queue.pop();
result.add(node);
node.getChildren().stream().filter(c -> !result.contains(c)).forEach(queue::add);
}
return result;
}
/////// Action classes
@ -1343,26 +1369,24 @@ public class RocketActions {
var allComponentsSelected = getDescendants(rocket).size() == components.size();
return rocketSelected || allComponentsSelected;
}
}
/**
* Returns all descendants of the specified component.
*
* @param component Component to query
* @return All descendants
* @apiNote Returns an empty set if the component does not have children.
*/
private Set<RocketComponent> getDescendants(RocketComponent component) {
Objects.requireNonNull(component);
private class ShowAllComponentsAction extends RocketAction {
public ShowAllComponentsAction() {
super.putValue(NAME, trans.get("RocketActions.VisibilityAct.ShowAll"));
super.putValue(SHORT_DESCRIPTION, trans.get("RocketActions.VisibilityAct.ttip.ShowAll"));
super.putValue(SMALL_ICON, GUIUtil.getUITheme().getVisibilityShowingIcon());
clipboardChanged();
}
var result = new LinkedHashSet<RocketComponent>();
var queue = new ArrayDeque<>(component.getChildren());
@Override
public void clipboardChanged() {
super.setEnabled(getDescendants(rocket).stream().anyMatch(c -> !c.isVisible()));
}
while (!queue.isEmpty()) {
var node = queue.pop();
result.add(node);
node.getChildren().stream().filter(c -> !result.contains(c)).forEach(queue::add);
}
return result;
@Override
public void actionPerformed(ActionEvent e) {
getDescendants(rocket).forEach(descendant -> descendant.setVisible(true));
}
}
}

View File

@ -101,6 +101,7 @@ public class UITheme {
Icon getCDOverrideSubcomponentIcon();
Icon getVisibilityHiddenIcon();
Icon getVisibilityShowingIcon();
Border getBorder();
Border getMarginBorder();
@ -437,6 +438,11 @@ public class UITheme {
return Icons.COMPONENT_HIDDEN_LIGHT;
}
@Override
public Icon getVisibilityShowingIcon() {
return Icons.COMPONENT_SHOWING_LIGHT;
}
@Override
public Border getBorder() {
return new FlatBorder();
@ -833,6 +839,11 @@ public class UITheme {
return Icons.COMPONENT_HIDDEN_DARK;
}
@Override
public Icon getVisibilityShowingIcon() {
return Icons.COMPONENT_SHOWING_DARK;
}
@Override
public Border getBorder() {
return new FlatBorder();
@ -1229,6 +1240,11 @@ public class UITheme {
return Icons.COMPONENT_HIDDEN_DARK;
}
@Override
public Icon getVisibilityShowingIcon() {
return Icons.COMPONENT_SHOWING_DARK;
}
@Override
public Border getBorder() {
return new FlatBorder();
@ -1644,6 +1660,11 @@ public class UITheme {
return getCurrentTheme().getVisibilityHiddenIcon();
}
@Override
public Icon getVisibilityShowingIcon() {
return getCurrentTheme().getVisibilityHiddenIcon();
}
@Override
public Border getBorder() {
return getCurrentTheme().getBorder();

View File

@ -120,6 +120,8 @@ public class Icons {
public static final Icon COMPONENT_HIDDEN = loadImageIcon("pix/icons/component-hidden.png", "Component Hidden");
public static final Icon COMPONENT_HIDDEN_DARK = loadImageIcon("pix/icons/component-hidden_dark.png", "Component Hidden");
public static final Icon COMPONENT_HIDDEN_LIGHT = loadImageIcon("pix/icons/component-hidden_light.png", "Component Hidden");
public static final Icon COMPONENT_SHOWING_DARK = loadImageIcon("pix/icons/component-showing_dark.png", "Component Showing");
public static final Icon COMPONENT_SHOWING_LIGHT = loadImageIcon("pix/icons/component-showing_light.png", "Component Showing");
// MANUFACTURERS ICONS
public static final Icon RASAERO = loadImageIcon("pix/icons/RASAero_16.png", "RASAero Icon");

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 306 B