From c6b1c760b57c057e2f28fa4ad54ae33d761b6c53 Mon Sep 17 00:00:00 2001 From: Joacim Breiler Date: Thu, 26 Jan 2023 18:01:29 +0100 Subject: [PATCH] Fixed a couple of small issues (#2144) * Fix problems with corrupt settings files * Tried to clarify that the setup wizard can not be used for certain controllers * Fixed problem with the console becoming broken when "Restoring Windows" * The export gcode action will now remember the last directory used for exporting gcode files * Fixed problem with the entity list not being updated when creating a group --- .../universalgcodesender/utils/SettingsFactory.java | 5 +++-- .../src/resources/MessagesBundle_en_US.properties | 2 +- .../willwinder/ugs/nbp/console/ConsoleProvider.java | 3 ++- .../ugs/nbp/console/ConsoleTopComponent.java | 1 + .../ugs/nbp/designer/actions/ExportGcodeAction.java | 7 +++++-- .../ugs/nbp/designer/actions/GroupAction.java | 5 +++-- .../com/willwinder/ugs/nbp/designer/gui/Drawing.java | 12 +++++++----- .../setupwizard/panels/WizardPanelConnection.java | 4 ++-- 8 files changed, 24 insertions(+), 15 deletions(-) diff --git a/ugs-core/src/com/willwinder/universalgcodesender/utils/SettingsFactory.java b/ugs-core/src/com/willwinder/universalgcodesender/utils/SettingsFactory.java index ed26ffeffd..900a624b09 100644 --- a/ugs-core/src/com/willwinder/universalgcodesender/utils/SettingsFactory.java +++ b/ugs-core/src/com/willwinder/universalgcodesender/utils/SettingsFactory.java @@ -1,5 +1,5 @@ /* - Copyright 2013-2020 Christian Moll, Will Winder, Bob Jones + Copyright 2013-2023 Christian Moll, Will Winder, Bob Jones This file is part of Universal Gcode Sender (UGS). @@ -20,6 +20,7 @@ This file is part of Universal Gcode Sender (UGS). import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.JsonSyntaxException; import com.willwinder.universalgcodesender.i18n.Localization; import org.apache.commons.io.FileUtils; @@ -60,7 +61,7 @@ public static Settings loadSettings() { if (settings != null) { settings.finalizeInitialization(); } - } catch (IOException ex) { + } catch (IOException | IllegalStateException | JsonSyntaxException ex) { logger.log(Level.SEVERE, "Can't load settings, using defaults.", ex); } } diff --git a/ugs-core/src/resources/MessagesBundle_en_US.properties b/ugs-core/src/resources/MessagesBundle_en_US.properties index ef97a45834..22aabb4763 100644 --- a/ugs-core/src/resources/MessagesBundle_en_US.properties +++ b/ugs-core/src/resources/MessagesBundle_en_US.properties @@ -526,7 +526,7 @@ platform.plugin.setupwizard.update = Update platform.plugin.setupwizard.update-settings = Update settings platform.plugin.setupwizard.connection.title = Connection platform.plugin.setupwizard.connection.intro = This guide will help you set up your CNC controller with Universal Gcode Sender. Let's start with connecting to your controller. -platform.plugin.setupwizard.connection.not-supported = The setup wizard is not supported for this controller +platform.plugin.setupwizard.connection.not-supported = The setup wizard does not know how to configure this type of controller.
It needs to be configured manually. platform.plugin.setupwizard.connection.connecting = Connecting... platform.plugin.setupwizard.connection.connected-to = Connected to platform.plugin.setupwizard.import-settings.title = Import settings diff --git a/ugs-platform/ugs-platform-plugin-console/src/main/java/com/willwinder/ugs/nbp/console/ConsoleProvider.java b/ugs-platform/ugs-platform-plugin-console/src/main/java/com/willwinder/ugs/nbp/console/ConsoleProvider.java index 5dec4f29c1..d71e2f2092 100644 --- a/ugs-platform/ugs-platform-plugin-console/src/main/java/com/willwinder/ugs/nbp/console/ConsoleProvider.java +++ b/ugs-platform/ugs-platform-plugin-console/src/main/java/com/willwinder/ugs/nbp/console/ConsoleProvider.java @@ -25,6 +25,7 @@ This file is part of Universal Gcode Sender (UGS). import javax.swing.JComponent; import javax.swing.JScrollPane; import javax.swing.text.JTextComponent; +import java.awt.BorderLayout; /** * A hack to be able to get access to the JTextComponent in the @@ -59,7 +60,7 @@ public boolean isActivated() { @Override public void add(JComponent comp, IOContainer.CallBacks cb) { - component.add(comp); + component.add(comp, BorderLayout.CENTER); } @Override diff --git a/ugs-platform/ugs-platform-plugin-console/src/main/java/com/willwinder/ugs/nbp/console/ConsoleTopComponent.java b/ugs-platform/ugs-platform-plugin-console/src/main/java/com/willwinder/ugs/nbp/console/ConsoleTopComponent.java index 1826a754a9..2f7b34037a 100644 --- a/ugs-platform/ugs-platform-plugin-console/src/main/java/com/willwinder/ugs/nbp/console/ConsoleTopComponent.java +++ b/ugs-platform/ugs-platform-plugin-console/src/main/java/com/willwinder/ugs/nbp/console/ConsoleTopComponent.java @@ -76,6 +76,7 @@ public ConsoleTopComponent() { @Override public void componentOpened() { + removeAll(); BackendAPI backendAPI = CentralLookup.getDefault().lookup(BackendAPI.class); consolePanel = new ConsolePanel(backendAPI); add(consolePanel, BorderLayout.CENTER); diff --git a/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/actions/ExportGcodeAction.java b/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/actions/ExportGcodeAction.java index 66673b43a3..8879bd7578 100644 --- a/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/actions/ExportGcodeAction.java +++ b/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/actions/ExportGcodeAction.java @@ -37,6 +37,7 @@ This file is part of Universal Gcode Sender (UGS). public class ExportGcodeAction extends AbstractDesignAction { public static final String SMALL_ICON_PATH = "img/export.svg"; public static final String LARGE_ICON_PATH = "img/export24.svg"; + public static String lastDirectory = ""; public ExportGcodeAction() { putValue("iconBase", SMALL_ICON_PATH); @@ -48,11 +49,13 @@ public ExportGcodeAction() { @Override public void actionPerformed(ActionEvent e) { - Optional fileOptional = SwingHelpers.createFile(""); + Optional fileOptional = SwingHelpers.createFile(lastDirectory); if (fileOptional.isPresent()) { Controller controller = ControllerFactory.getController(); + File file = new File(getFilePath(fileOptional.get())); + lastDirectory = file.getAbsolutePath(); DesignWriter designWriter = new GcodeDesignWriter(); - designWriter.write(new File(getFilePath(fileOptional.get())), controller); + designWriter.write(file, controller); } } diff --git a/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/actions/GroupAction.java b/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/actions/GroupAction.java index 7b77acc87c..14f1481008 100644 --- a/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/actions/GroupAction.java +++ b/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/actions/GroupAction.java @@ -6,6 +6,7 @@ import com.willwinder.ugs.nbp.designer.entities.selection.SelectionEvent; import com.willwinder.ugs.nbp.designer.entities.selection.SelectionListener; import com.willwinder.ugs.nbp.designer.entities.selection.SelectionManager; +import com.willwinder.ugs.nbp.designer.gui.DrawingEvent; import com.willwinder.ugs.nbp.designer.logic.Controller; import com.willwinder.ugs.nbp.designer.logic.ControllerFactory; import org.openide.awt.ActionID; @@ -88,7 +89,7 @@ public void redo() { } else { controller.getDrawing().insertEntity(group); } - + controller.getDrawing().notifyListeners(DrawingEvent.ENTITY_ADDED); controller.getSelectionManager().setSelection(Collections.singletonList(group)); } @@ -104,7 +105,7 @@ public void undo() { } else { controller.getDrawing().insertEntities(entities); } - + controller.getDrawing().notifyListeners(DrawingEvent.ENTITY_ADDED); controller.getSelectionManager().setSelection(entities); } diff --git a/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/gui/Drawing.java b/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/gui/Drawing.java index 304919a311..5568b70bcc 100644 --- a/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/gui/Drawing.java +++ b/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/gui/Drawing.java @@ -129,14 +129,17 @@ public List getEntitiesIntersecting(Shape shape) { public void insertEntity(Entity entity) { entitiesRoot.addChild(entity); - listeners.forEach(l -> l.onDrawingEvent(DrawingEvent.ENTITY_ADDED)); + notifyListeners(DrawingEvent.ENTITY_ADDED); + } + + public void notifyListeners(DrawingEvent event) { + listeners.forEach(l -> l.onDrawingEvent(event)); refresh(); } public void insertEntities(List entities) { entities.forEach(entitiesRoot::addChild); - listeners.forEach(l -> l.onDrawingEvent(DrawingEvent.ENTITY_ADDED)); - refresh(); + notifyListeners(DrawingEvent.ENTITY_ADDED); } public List getEntities() { @@ -212,8 +215,7 @@ public void setScale(double scale) { double newScale = Math.max(Math.abs(scale), MIN_SCALE); if (this.scale != newScale) { this.scale = newScale; - listeners.forEach(l -> l.onDrawingEvent(DrawingEvent.SCALE_CHANGED)); - refresh(); + notifyListeners(DrawingEvent.SCALE_CHANGED); } } diff --git a/ugs-platform/ugs-platform-plugin-setup-wizard/src/main/java/com/willwinder/ugs/nbp/setupwizard/panels/WizardPanelConnection.java b/ugs-platform/ugs-platform-plugin-setup-wizard/src/main/java/com/willwinder/ugs/nbp/setupwizard/panels/WizardPanelConnection.java index 39fa834308..ff0c9e5257 100644 --- a/ugs-platform/ugs-platform-plugin-setup-wizard/src/main/java/com/willwinder/ugs/nbp/setupwizard/panels/WizardPanelConnection.java +++ b/ugs-platform/ugs-platform-plugin-setup-wizard/src/main/java/com/willwinder/ugs/nbp/setupwizard/panels/WizardPanelConnection.java @@ -123,7 +123,7 @@ private void initComponents() { labelPort = new JLabel(Localization.getString("platform.plugin.setupwizard.port")); connectButton = new JButton(Localization.getString("platform.plugin.setupwizard.connect")); - connectButton.addActionListener((e) -> { + connectButton.addActionListener(e -> { try { Settings settings = getBackend().getSettings(); getBackend().connect(settings.getFirmwareVersion(), settings.getPort(), Integer.parseInt(settings.getPortRate())); @@ -135,7 +135,7 @@ private void initComponents() { labelVersion = new JLabel(Localization.getString("platform.plugin.setupwizard.unknown-version")); labelVersion.setVisible(false); - labelNotSupported = new JLabel(Localization.getString("platform.plugin.setupwizard.connection.not-supported")); + labelNotSupported = new JLabel("

" + Localization.getString("platform.plugin.setupwizard.connection.not-supported") + "

"); labelNotSupported.setIcon(ImageUtilities.loadImageIcon("icons/information24.png", false)); labelNotSupported.setVisible(false); }