Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add menu for opening recent files #2132

Merged
merged 2 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
import java.util.Iterator;
import java.util.List;
import java.util.Spliterator;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.function.Consumer;

public class CommandProcessorList implements CommandProcessor, Iterable<CommandProcessor> {

private List<CommandProcessor> commandProcessors = new ArrayList<>();
private final BlockingDeque<CommandProcessor> commandProcessors = new LinkedBlockingDeque<>();

/**
* Applies all command processors to a given command and returns the
Expand Down
1 change: 1 addition & 0 deletions ugs-core/src/resources/MessagesBundle_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ toolbar.icon.small = Small Icons
toolbar.icon.large = Large Icons
sender.help.verbose.console = Show additional information in the controller console.
platform.menu.open = Open...
platform.menu.open.recent = Open recent
platform.menu.save = Save
platform.menu.edit = Edit Gcode File...
mainWindow.swing.reset = Reset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ This file is part of Universal Gcode Sender (UGS).
@ActionReferences({
@ActionReference(
path = LocalizingService.OpenWindowPath,
position = 11)
position = 12)
})

public final class CloudStorageOpenAction implements ActionListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This file is part of Universal Gcode Sender (UGS).
*/
package com.willwinder.ugs.nbp.designer.actions;

import com.willwinder.ugs.nbp.designer.entities.Entity;
import com.willwinder.ugs.nbp.designer.entities.cuttable.Cuttable;
import com.willwinder.ugs.nbp.designer.entities.selection.SelectionEvent;
import com.willwinder.ugs.nbp.designer.entities.selection.SelectionListener;
Expand Down Expand Up @@ -46,15 +47,19 @@ This file is part of Universal Gcode Sender (UGS).
public class ToggleHidden extends AbstractDesignAction implements SelectionListener {
public static final String SMALL_ICON_PATH = "img/eye.svg";
public static final String LARGE_ICON_PATH = "img/eye24.svg";
public static final String SMALL_ICON_HIDDEN_PATH = "img/eyeoff.svg";
public static final String LARGE_ICON_HIDDEN_PATH = "img/eyeoff24.svg";
public static final String PROPERTY_MENU_TEXT = "menuText";

public ToggleHidden() {
putValue("menuText", "Toggle hidden");
putValue(PROPERTY_MENU_TEXT, "Toggle hidden");
putValue(NAME, "Toggle hidden");
putValue("iconBase", SMALL_ICON_PATH);
putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false));
putValue(LARGE_ICON_KEY, ImageUtilities.loadImageIcon(LARGE_ICON_PATH, false));

ControllerFactory.getSelectionManager().addSelectionListener(this);
ControllerFactory.getController().addListener(e -> onSelectionEvent(null));
}

@Override
Expand All @@ -63,7 +68,7 @@ public void actionPerformed(ActionEvent e) {
.findFirst()
.map(Cuttable::isHidden)
.orElse(true);

UndoableShowHideAction action = new UndoableShowHideAction(getCuttableStream().collect(Collectors.toList()), !isHidden);
action.redo();
ControllerFactory.getUndoManager().addAction(action);
Expand All @@ -78,6 +83,19 @@ private Stream<Cuttable> getCuttableStream() {
public void onSelectionEvent(SelectionEvent selectionEvent) {
SelectionManager selectionManager = ControllerFactory.getSelectionManager();
setEnabled(!selectionManager.getSelection().isEmpty());

boolean allIsHidden = getCuttableStream().allMatch(Cuttable::isHidden);
if (allIsHidden) {
putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false));
putValue(LARGE_ICON_KEY, ImageUtilities.loadImageIcon(LARGE_ICON_PATH, false));
putValue(PROPERTY_MENU_TEXT, "Show");
putValue(NAME, "Show");
} else {
putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_HIDDEN_PATH, false));
putValue(LARGE_ICON_KEY, ImageUtilities.loadImageIcon(LARGE_ICON_HIDDEN_PATH, false));
putValue(PROPERTY_MENU_TEXT, "Hide");
putValue(NAME, "Hide");
}
}

private static class UndoableShowHideAction implements UndoableAction {
Expand All @@ -92,11 +110,20 @@ public UndoableShowHideAction(List<Cuttable> entities, boolean setAsHidden) {
@Override
public void redo() {
entities.forEach(entity -> entity.setHidden(setAsHidden));
triggerSelectionEvent();
}

@Override
public void undo() {
entities.forEach(entity -> entity.setHidden(!setAsHidden));
triggerSelectionEvent();
}

private void triggerSelectionEvent() {
SelectionManager selectionManager = ControllerFactory.getSelectionManager();
List<Entity> selection = selectionManager.getSelection();
selectionManager.clearSelection();
selectionManager.setSelection(selection);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ This file is part of Universal Gcode Sender (UGS).
id = "ToolDrawCircleAction")
@ActionRegistration(
iconBase = ToolDrawCircleAction.ICON_SMALL_PATH,
displayName = "Draw circle",
displayName = "Draw ellipse",
lazy = false)
public class ToolDrawCircleAction extends AbstractDesignAction {
public static final String ICON_SMALL_PATH = "img/circle.svg";
Expand All @@ -46,8 +46,8 @@ public ToolDrawCircleAction() {
putValue("iconBase", ICON_SMALL_PATH);
putValue(SMALL_ICON, ImageUtilities.loadImageIcon(ICON_SMALL_PATH, false));
putValue(LARGE_ICON_KEY, ImageUtilities.loadImageIcon(ICON_LARGE_PATH, false));
putValue("menuText", "Draw circle");
putValue(NAME, "Draw circle");
putValue("menuText", "Draw ellipse");
putValue(NAME, "Draw ellipse");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ This file is part of Universal Gcode Sender (UGS).
id = "ToolImportAction")
@ActionRegistration(
iconBase = ToolImportAction.SMALL_ICON_PATH,
displayName = "Import",
displayName = "Import file",
lazy = false)
public final class ToolImportAction extends AbstractDesignAction {

Expand All @@ -60,8 +60,8 @@ public ToolImportAction() {
putValue("iconBase", SMALL_ICON_PATH);
putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false));
putValue(LARGE_ICON_KEY, ImageUtilities.loadImageIcon(LARGE_ICON_PATH, false));
putValue("menuText", "Import");
putValue(NAME, "Import");
putValue("menuText", "Import file");
putValue(NAME, "Import file");
this.controller = ControllerFactory.getController();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ This file is part of Universal Gcode Sender (UGS).
lazy = false)
public class ToolSelectAction extends AbstractDesignAction {
public static final String SMALL_ICON_PATH = "img/pointer.svg";
private static final String LARGE_ICON_PATH = "img/pointer24.svg";
public static final String LARGE_ICON_PATH = "img/pointer24.svg";
private final transient Controller controller;

public ToolSelectAction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ This file is part of Universal Gcode Sender (UGS).
import com.willwinder.ugs.nbp.designer.actions.FlipHorizontallyAction;
import com.willwinder.ugs.nbp.designer.actions.FlipVerticallyAction;
import com.willwinder.ugs.nbp.designer.actions.IntersectionAction;
import com.willwinder.ugs.nbp.designer.actions.JogMachineToCenterAction;
import com.willwinder.ugs.nbp.designer.actions.MultiplyAction;
import com.willwinder.ugs.nbp.designer.actions.SubtractAction;
import com.willwinder.ugs.nbp.designer.actions.ToggleHidden;
import com.willwinder.ugs.nbp.designer.actions.ToolClipartAction;
import com.willwinder.ugs.nbp.designer.actions.ToolDrawCircleAction;
import com.willwinder.ugs.nbp.designer.actions.ToolDrawPointAction;
Expand All @@ -37,16 +39,25 @@ This file is part of Universal Gcode Sender (UGS).
import com.willwinder.ugs.nbp.designer.actions.UnionAction;
import com.willwinder.ugs.nbp.designer.logic.Controller;
import com.willwinder.ugs.nbp.designer.logic.ControllerEventType;
import org.openide.awt.DropDownButtonFactory;
import org.openide.util.ImageUtilities;

import javax.swing.Action;
import javax.swing.ButtonGroup;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JToggleButton;
import java.awt.event.ActionListener;

/**
* @author Joacim Breiler
*/
public class ToolBox extends ToolBar {

private JToggleButton toolDropDownButton = null;

public ToolBox(Controller controller) {
setFloatable(false);

Expand All @@ -56,46 +67,7 @@ public ToolBox(Controller controller) {
select.setToolTipText("Select and move shapes");
add(select);

JToggleButton point = new JToggleButton(new ToolDrawPointAction());
point.setText("");
point.setToolTipText("Draw points");
add(point);

JToggleButton rectangle = new JToggleButton(new ToolDrawRectangleAction());
rectangle.setText("");
rectangle.setToolTipText("Draw squares and rectangles");
add(rectangle);

JToggleButton circle = new JToggleButton(new ToolDrawCircleAction());
circle.setText("");
circle.setToolTipText("Draw circles and ellipses");
add(circle);

JToggleButton text = new JToggleButton(new ToolDrawTextAction());
text.setText("");
text.setToolTipText("Write text");
add(text);

JButton importButton = new JButton(new ToolImportAction());
importButton.setText("");
importButton.setToolTipText("Imports a drawing");
importButton.setContentAreaFilled(false);
importButton.setBorderPainted(false);
add(importButton);

JButton insertButton = new JButton(new ToolClipartAction());
insertButton.setText("");
insertButton.setToolTipText("Inserts a clipart");
insertButton.setContentAreaFilled(false);
insertButton.setBorderPainted(false);
add(insertButton);

insertButton = new JButton(new TraceImageAction());
insertButton.setText("");
insertButton.setToolTipText("Traces a bitmap image");
insertButton.setContentAreaFilled(false);
insertButton.setBorderPainted(false);
add(insertButton);
add(createToolDropDownButton());

addSeparator();

Expand Down Expand Up @@ -139,12 +111,24 @@ public ToolBox(Controller controller) {

addSeparator();

JButton visible = new JButton(new ToggleHidden());
visible.setToolTipText("Toggles if the object should be hidden");
visible.setBorderPainted(false);
visible.setHideActionText(true);
add(visible);

JButton multiply = new JButton(new MultiplyAction());
multiply.setText("");
multiply.setToolTipText("Multiplies the selection");
multiply.setBorderPainted(false);
add(multiply);

JButton jogTo = new JButton(new JogMachineToCenterAction());
jogTo.setText("");
jogTo.setToolTipText("Jog machine to center");
jogTo.setBorderPainted(false);
add(jogTo);

addSeparator();

JToggleButton zoom = new JToggleButton(new ToolZoomAction());
Expand All @@ -155,10 +139,7 @@ public ToolBox(Controller controller) {

ButtonGroup buttons = new ButtonGroup();
buttons.add(select);
buttons.add(circle);
buttons.add(rectangle);
buttons.add(text);
buttons.add(importButton);
buttons.add(toolDropDownButton);
buttons.add(zoom);

controller.addListener(event -> {
Expand All @@ -170,27 +151,55 @@ public ToolBox(Controller controller) {
select.setSelected(true);
break;
case POINT:
point.setSelected(true);
break;
case RECTANGLE:
rectangle.setSelected(true);
break;
case CIRCLE:
circle.setSelected(true);
break;
case TEXT:
text.setSelected(true);
break;
case INSERT:
importButton.setSelected(true);
toolDropDownButton.setSelected(true);
break;
case ZOOM:
zoom.setSelected(true);
break;
default:
toolDropDownButton.setSelected(false);
}
repaint();
}
});
}

private JToggleButton createToolDropDownButton() {
// An action listener that listens to the popup menu items and changes the current action
ActionListener toolMenuListener = e -> {
if (toolDropDownButton == null) {
return;
}

JMenuItem source = (JMenuItem) e.getSource();
toolDropDownButton.setIcon((Icon) source.getAction().getValue(Action.LARGE_ICON_KEY));
toolDropDownButton.setSelected(true);
toolDropDownButton.setAction(source.getAction());
};

ToolDrawRectangleAction toolDrawRectangleAction = new ToolDrawRectangleAction();
JPopupMenu popupMenu = new JPopupMenu();
addDropDownAction(popupMenu, toolDrawRectangleAction, toolMenuListener);
addDropDownAction(popupMenu, new ToolDrawCircleAction(), toolMenuListener);
addDropDownAction(popupMenu, new ToolDrawPointAction(), toolMenuListener);
addDropDownAction(popupMenu, new ToolDrawTextAction(), toolMenuListener);
popupMenu.addSeparator();
addDropDownAction(popupMenu, new ToolImportAction(), null);
addDropDownAction(popupMenu, new ToolClipartAction(), null);
addDropDownAction(popupMenu, new TraceImageAction(), null);
toolDropDownButton = DropDownButtonFactory.createDropDownToggleButton(ImageUtilities.loadImageIcon(ToolDrawRectangleAction.LARGE_ICON_PATH, false), popupMenu);
toolDropDownButton.setAction(toolDrawRectangleAction);
return toolDropDownButton;
}

private void addDropDownAction(JPopupMenu popupMenu, Action action, ActionListener actionListener) {
JMenuItem menuItem = new JMenuItem(action);
if (actionListener != null) {
menuItem.addActionListener(actionListener);
}
popupMenu.add(menuItem);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class InsertClipartDialog extends JDialog implements ListSelectionListene

public InsertClipartDialog() {
super((JFrame) null, true);
setTitle("Insert shape");
setTitle("Insert clipart");
setPreferredSize(new Dimension(700, 480));
setLayout(new MigLayout("fill, insets 5", "[][grow, fill]", ""));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2018-2021 Will Winder
Copyright 2018-2023 Will Winder

This file is part of Universal Gcode Sender (UGS).

Expand Down Expand Up @@ -34,7 +34,6 @@ This file is part of Universal Gcode Sender (UGS).
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2018-2021 Will Winder
Copyright 2018-2023 Will Winder

This file is part of Universal Gcode Sender (UGS).

Expand Down Expand Up @@ -149,10 +149,7 @@ private void checkAxisEnabled(Axis axis) {
}

private void updateControls() {
boolean canJog = jogService.canJog();
if (canJog != jogPanel.isEnabled()) {
jogPanel.setEnabled(canJog);
}
jogPanel.setEnabled(jogService.canJog());
}

@Override
Expand Down
Loading