Skip to content

Commit

Permalink
Fixed a couple of small issues (#2144)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
breiler authored Jan 26, 2023
1 parent e484f34 commit c6b1c76
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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).
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion ugs-core/src/resources/MessagesBundle_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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 <b>Universal Gcode Sender</b>. 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.<br> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -48,11 +49,13 @@ public ExportGcodeAction() {

@Override
public void actionPerformed(ActionEvent e) {
Optional<File> fileOptional = SwingHelpers.createFile("");
Optional<File> 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,7 +89,7 @@ public void redo() {
} else {
controller.getDrawing().insertEntity(group);
}

controller.getDrawing().notifyListeners(DrawingEvent.ENTITY_ADDED);
controller.getSelectionManager().setSelection(Collections.singletonList(group));
}

Expand All @@ -104,7 +105,7 @@ public void undo() {
} else {
controller.getDrawing().insertEntities(entities);
}

controller.getDrawing().notifyListeners(DrawingEvent.ENTITY_ADDED);
controller.getSelectionManager().setSelection(entities);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,17 @@ public List<Entity> 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<Entity> entities) {
entities.forEach(entitiesRoot::addChild);
listeners.forEach(l -> l.onDrawingEvent(DrawingEvent.ENTITY_ADDED));
refresh();
notifyListeners(DrawingEvent.ENTITY_ADDED);
}

public List<Entity> getEntities() {
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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("<html><body><p>" + Localization.getString("platform.plugin.setupwizard.connection.not-supported") + "</p></body></html>");
labelNotSupported.setIcon(ImageUtilities.loadImageIcon("icons/information24.png", false));
labelNotSupported.setVisible(false);
}
Expand Down

0 comments on commit c6b1c76

Please sign in to comment.