Skip to content

Commit

Permalink
Fixed problem with text settings in designer (#2529)
Browse files Browse the repository at this point in the history
  • Loading branch information
breiler authored May 28, 2024
1 parent fcf901f commit f584b13
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<EntitySetting> DEFAULT_LASER_SETTINGS = List.of(
EntitySetting.CUT_TYPE,
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public Entity copy() {

@Override
public List<EntitySetting> getSettings() {
ArrayList<EntitySetting> entitySettings = new ArrayList<>(super.getSettings());
List<EntitySetting> entitySettings = new ArrayList<>(super.getSettings());
entitySettings.add(EntitySetting.TEXT);
return entitySettings;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -116,84 +119,73 @@ 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;
}

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);
}

Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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");
}

Expand All @@ -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);
}

Expand Down

0 comments on commit f584b13

Please sign in to comment.