From ed29c9a9cd1f4606c9675c4f99a72eeac0d2e7d3 Mon Sep 17 00:00:00 2001 From: Joacim Breiler Date: Tue, 28 May 2024 07:56:59 +0200 Subject: [PATCH] Fixed problem with text settings in designer --- .../nbp/designer/entities/EntitySetting.java | 6 +- .../nbp/designer/entities/cuttable/Text.java | 2 +- .../SelectionSettingsPanel.java | 67 +++++++++---------- .../platform/SettingsTopComponent.java | 11 ++- 4 files changed, 44 insertions(+), 42 deletions(-) diff --git a/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/entities/EntitySetting.java b/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/entities/EntitySetting.java index f90b8844bd..1bd5ec1c2c 100644 --- a/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/entities/EntitySetting.java +++ b/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/entities/EntitySetting.java @@ -54,7 +54,8 @@ public enum EntitySetting { EntitySetting.POSITION_Y, EntitySetting.ROTATION, EntitySetting.START_DEPTH, - EntitySetting.TARGET_DEPTH); + EntitySetting.TARGET_DEPTH, + EntitySetting.TEXT); public static final List DEFAULT_LASER_SETTINGS = List.of( EntitySetting.CUT_TYPE, @@ -68,7 +69,8 @@ public enum EntitySetting { EntitySetting.ROTATION, EntitySetting.SPINDLE_SPEED, EntitySetting.PASSES, - EntitySetting.FEED_RATE); + EntitySetting.FEED_RATE, + EntitySetting.TEXT); private final String label; diff --git a/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/entities/cuttable/Text.java b/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/entities/cuttable/Text.java index 4e4ee4f12f..21b1267a43 100644 --- a/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/entities/cuttable/Text.java +++ b/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/entities/cuttable/Text.java @@ -107,7 +107,7 @@ public Entity copy() { @Override public List getSettings() { - ArrayList entitySettings = new ArrayList<>(super.getSettings()); + List entitySettings = new ArrayList<>(super.getSettings()); entitySettings.add(EntitySetting.TEXT); return entitySettings; } diff --git a/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/gui/selectionsettings/SelectionSettingsPanel.java b/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/gui/selectionsettings/SelectionSettingsPanel.java index 69494e7c5b..0e50da13de 100644 --- a/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/gui/selectionsettings/SelectionSettingsPanel.java +++ b/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/gui/selectionsettings/SelectionSettingsPanel.java @@ -52,7 +52,10 @@ This file is part of Universal Gcode Sender (UGS). * @author Joacim Breiler */ public class SelectionSettingsPanel extends JPanel implements SelectionListener, EntityListener, SelectionSettingsModelListener { - private static final String FIELD_CONSTRAINTS = "grow, wrap"; + private static final String LABEL_CONSTRAINTS = "grow, hmin 32, hmax 36"; + private static final String FIELD_CONSTRAINTS_NO_WRAP = "grow, w 60:60:300, hmin 32, hmax 36"; + private static final String FIELD_CONSTRAINTS = FIELD_CONSTRAINTS_NO_WRAP + ", wrap"; + private static final String SLIDER_FIELD_CONSTRAINTS = "grow, w 60:60:300, hmin 32, hmax 44"; private final SelectionSettingsModel model = new SelectionSettingsModel(); private final transient FieldEventDispatcher fieldEventDispatcher; private transient Controller controller; @@ -84,7 +87,7 @@ public class SelectionSettingsPanel extends JPanel implements SelectionListener, public SelectionSettingsPanel(Controller controller) { fieldEventDispatcher = new FieldEventDispatcher(); - setLayout(new MigLayout("fill, hidemode 3, insets 5", "[sg label] 5 [grow] 5 [60px]" )); + setLayout(new MigLayout("hidemode 3, insets 10, gap 10", "[sg label] 10 [grow] 10 [60px]")); addTextSettingFields(); addPositionFields(); addCutFields(); @@ -106,7 +109,7 @@ private void addPositionFields() { anchorSelector = new AnchorSelectorPanel(); anchorSelector.setAnchor(model.getAnchor()); anchorSelector.addListener((model::setAnchor)); - add(anchorSelector, "span 1 2, grow, wrap" ); + add(anchorSelector, "span 1 2, grow, wrap"); createAndAddLabel(EntitySetting.POSITION_Y); posYTextField = createAndAddField(EntitySetting.POSITION_Y, TextFieldUnit.MM, true); @@ -116,26 +119,26 @@ private void addPositionFields() { lockRatioButton = new JToggleButton(ImageUtilities.loadImageIcon("img/link.svg", false)); lockRatioButton.setSelectedIcon(ImageUtilities.loadImageIcon("img/link-off.svg", false)); lockRatioButton.addActionListener(l -> model.setLockRatio(!lockRatioButton.isSelected())); - add(lockRatioButton, "span 1 2, growy, wrap" ); + add(lockRatioButton, "span 1 2, growy, wrap"); heightLabel = createAndAddLabel(EntitySetting.HEIGHT); heightTextField = createAndAddField(EntitySetting.HEIGHT, TextFieldUnit.MM, true); createAndAddLabel(EntitySetting.ROTATION); rotation = createAndAddField(EntitySetting.ROTATION, TextFieldUnit.DEGREE, true); - add(new JSeparator(), "grow, spanx, wrap" ); + add(new JSeparator(), "hmin 2, grow, spanx, wrap"); } private JLabel createAndAddLabel(EntitySetting entitySetting) { JLabel label = new JLabel(entitySetting.getLabel(), SwingConstants.RIGHT); - add(label, "grow" ); + add(label, LABEL_CONSTRAINTS); return label; } private TextFieldWithUnit createAndAddField(EntitySetting setting, TextFieldUnit units, boolean wrap) { TextFieldWithUnit field = new TextFieldWithUnit(units, 4, 0); fieldEventDispatcher.registerListener(setting, field); - add(field, wrap ? FIELD_CONSTRAINTS : "grow" ); + add(field, wrap ? FIELD_CONSTRAINTS : FIELD_CONSTRAINTS_NO_WRAP); return field; } @@ -143,57 +146,46 @@ private void addCutFields() { cutTypeComboBox = new CutTypeCombo(); fieldEventDispatcher.registerListener(EntitySetting.CUT_TYPE, cutTypeComboBox); - JLabel cutTypeLabel = new JLabel("Cut type", SwingConstants.RIGHT); - add(cutTypeLabel, "grow" ); - add(cutTypeComboBox, FIELD_CONSTRAINTS); - - feedRateLabel = new JLabel("Feed rate", SwingConstants.RIGHT); - add(feedRateLabel, "grow" ); + createAndAddLabel(EntitySetting.CUT_TYPE); + add(cutTypeComboBox, FIELD_CONSTRAINTS + ", spanx"); + feedRateLabel = createAndAddLabel(EntitySetting.FEED_RATE); feedRateSpinner = new UnitSpinner(50, TextFieldUnit.MM_PER_MINUTE, 50d, 10000d, 10d); - add(feedRateSpinner, FIELD_CONSTRAINTS); + add(feedRateSpinner, FIELD_CONSTRAINTS + ", spanx"); fieldEventDispatcher.registerListener(EntitySetting.FEED_RATE, feedRateSpinner); - spindleSpeedLabel = new JLabel("Power", SwingConstants.RIGHT); - add(spindleSpeedLabel, "grow" ); - + spindleSpeedLabel = createAndAddLabel(EntitySetting.SPINDLE_SPEED); spindleSpeedSlider = new JSlider(0, 100, 0); spindleSpeedSlider.setPaintLabels(true); spindleSpeedSlider.setPaintTicks(true); spindleSpeedSlider.setMinorTickSpacing(5); - spindleSpeedSlider.setMajorTickSpacing(20); + spindleSpeedSlider.setMajorTickSpacing(25); - add(spindleSpeedSlider, FIELD_CONSTRAINTS); + add(spindleSpeedSlider, SLIDER_FIELD_CONSTRAINTS + ", spanx"); fieldEventDispatcher.registerListener(EntitySetting.SPINDLE_SPEED, spindleSpeedSlider); - laserPassesLabel = new JLabel("Passes", SwingConstants.RIGHT); - add(laserPassesLabel, "grow" ); - + laserPassesLabel = createAndAddLabel(EntitySetting.PASSES); passesSlider = new JSlider(0, 10, 1); passesSlider.setPaintLabels(true); passesSlider.setPaintTicks(true); passesSlider.setMinorTickSpacing(1); passesSlider.setMajorTickSpacing(5); - add(passesSlider, FIELD_CONSTRAINTS); + add(passesSlider, SLIDER_FIELD_CONSTRAINTS + ", spanx"); fieldEventDispatcher.registerListener(EntitySetting.PASSES, passesSlider); - startDepthLabel = new JLabel("Start depth", SwingConstants.RIGHT); - add(startDepthLabel, "grow" ); - + startDepthLabel = createAndAddLabel(EntitySetting.START_DEPTH); startDepthSpinner = new UnitSpinner(0, TextFieldUnit.MM, null, null, 0.1d); startDepthSpinner.setPreferredSize(startDepthSpinner.getPreferredSize()); fieldEventDispatcher.registerListener(EntitySetting.START_DEPTH, startDepthSpinner); - add(startDepthSpinner, FIELD_CONSTRAINTS); - - targetDepthLabel = new JLabel("Target depth", SwingConstants.RIGHT); - add(targetDepthLabel, "grow" ); + add(startDepthSpinner, FIELD_CONSTRAINTS + ", spanx"); + targetDepthLabel = createAndAddLabel(EntitySetting.TARGET_DEPTH); targetDepthSpinner = new UnitSpinner(0, TextFieldUnit.MM, 0d, null, 0.1d); targetDepthSpinner.setPreferredSize(targetDepthSpinner.getPreferredSize()); fieldEventDispatcher.registerListener(EntitySetting.TARGET_DEPTH, targetDepthSpinner); - add(targetDepthSpinner, FIELD_CONSTRAINTS); + add(targetDepthSpinner, FIELD_CONSTRAINTS + ", spanx"); setEnabled(false); } @@ -206,25 +198,25 @@ private void setController(Controller controller) { private void addTextSettingFields() { textLabel = new JLabel("Text", SwingConstants.RIGHT); textLabel.setVisible(false); - add(textLabel, "grow" ); + add(textLabel, "grow"); textTextField = new JTextField(); textTextField.setVisible(false); fieldEventDispatcher.registerListener(EntitySetting.TEXT, textTextField); - add(textTextField, FIELD_CONSTRAINTS); + add(textTextField, FIELD_CONSTRAINTS + ", spanx"); fontLabel = new JLabel("Font", SwingConstants.RIGHT); fontLabel.setVisible(false); - add(fontLabel, "grow" ); + add(fontLabel, "grow"); fontDropDown = new FontCombo(); fieldEventDispatcher.registerListener(EntitySetting.FONT_FAMILY, fontDropDown); fontDropDown.setVisible(false); - add(fontDropDown, FIELD_CONSTRAINTS); + add(fontDropDown, FIELD_CONSTRAINTS + ", spanx"); fontSeparator = new JSeparator(SwingConstants.HORIZONTAL); fontSeparator.setVisible(false); - add(fontSeparator, "grow, spanx, wrap" ); + add(fontSeparator, "hmin 2, grow, spanx, wrap"); } @Override @@ -333,7 +325,7 @@ private void handleComponentVisibility(Group selectionGroup) { targetDepthSpinner.setEnabled(hasCutTypeSelection); targetDepthLabel.setEnabled(hasCutTypeSelection); - boolean isTextCuttable = cutType.getSettings().contains(EntitySetting.TEXT); + boolean isTextCuttable = firstChildHasSetting(selectionGroup, EntitySetting.TEXT); textTextField.setVisible(isTextCuttable); textLabel.setVisible(isTextCuttable); fontLabel.setVisible(isTextCuttable); @@ -360,6 +352,7 @@ private void handleComponentVisibility(Group selectionGroup) { targetDepthLabel.setVisible(hasTargetDepth); boolean hasLaserPower = cutType.getSettings().contains(EntitySetting.SPINDLE_SPEED); + spindleSpeedLabel.setText(cutType == CutType.LASER_FILL || cutType == CutType.LASER_ON_PATH ? "Power" : EntitySetting.SPINDLE_SPEED.getLabel()); spindleSpeedLabel.setVisible(hasLaserPower); spindleSpeedSlider.setVisible(hasLaserPower); diff --git a/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/platform/SettingsTopComponent.java b/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/platform/SettingsTopComponent.java index 3c48025c87..421e0feafb 100644 --- a/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/platform/SettingsTopComponent.java +++ b/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/platform/SettingsTopComponent.java @@ -26,6 +26,10 @@ This file is part of Universal Gcode Sender (UGS). import com.willwinder.ugs.nbp.lib.Mode; import org.openide.windows.TopComponent; +import javax.swing.JScrollPane; +import javax.swing.ScrollPaneConstants; +import java.awt.BorderLayout; + /** * @author Joacim Breiler */ @@ -42,7 +46,7 @@ public class SettingsTopComponent extends TopComponent implements ControllerList public SettingsTopComponent() { setMinimumSize(new java.awt.Dimension(50, 50)); setPreferredSize(new java.awt.Dimension(200, 200)); - setLayout(new java.awt.BorderLayout()); + setLayout(new BorderLayout()); setDisplayName("Cut settings"); } @@ -62,7 +66,10 @@ protected void componentOpened() { removeAll(); Controller controller = ControllerFactory.getController(); selectionSettingsPanel = new SelectionSettingsPanel(controller); - add(selectionSettingsPanel); + JScrollPane scrollPane = new JScrollPane(selectionSettingsPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); + scrollPane.getVerticalScrollBar().setUnitIncrement(10); + scrollPane.getHorizontalScrollBar().setUnitIncrement(10); + add(scrollPane); controller.addListener(this); }