Skip to content

Commit

Permalink
Rework of the designer settings panel (#2434)
Browse files Browse the repository at this point in the history
It will now fetch available settings for the selected entities and show only them in the settings panel. To avoid getting circular updates a new settings model has been created.
  • Loading branch information
breiler authored Jan 22, 2024
1 parent 90a735a commit 5feaebe
Show file tree
Hide file tree
Showing 37 changed files with 1,688 additions and 560 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 Will Winder
Copyright 2021-2024 Will Winder
This file is part of Universal Gcode Sender (UGS).
Expand All @@ -18,11 +18,11 @@ This file is part of Universal Gcode Sender (UGS).
*/
package com.willwinder.universalgcodesender.uielements;

import com.willwinder.universalgcodesender.uielements.TextFieldUnit;
import com.willwinder.universalgcodesender.uielements.TextFieldUnitFormatter;
import com.willwinder.universalgcodesender.Utils;

import javax.swing.*;
import javax.swing.JFormattedTextField;
import javax.swing.text.DefaultFormatterFactory;
import java.text.ParseException;

/**
* @author Joacim Breiler
Expand All @@ -35,4 +35,23 @@ public TextFieldWithUnit(TextFieldUnit unit, int numberOfDecimals, double value)
new TextFieldUnitFormatter(unit, numberOfDecimals, false)
), value);
}

public String getStringValue() {
return getValue().toString();
}

public double getDoubleValue() {
try {
return Utils.formatter.parse(getStringValue()).doubleValue();
} catch (ParseException e) {
return 0;
}
}

public void setDoubleValue(double value) {
double previousValue = (double) getValue();
if (previousValue != value) {
setValue(value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import com.willwinder.ugs.nbp.designer.gui.DrawingContainer;
import com.willwinder.ugs.nbp.designer.gui.MainMenu;
import com.willwinder.ugs.nbp.designer.gui.PopupMenuFactory;
import com.willwinder.ugs.nbp.designer.gui.SelectionSettingsPanel;
import com.willwinder.ugs.nbp.designer.gui.ToolBox;
import com.willwinder.ugs.nbp.designer.gui.selectionsettings.SelectionSettingsPanel;
import com.willwinder.ugs.nbp.designer.gui.tree.EntitiesTree;
import com.willwinder.ugs.nbp.designer.gui.tree.EntityTreeModel;
import com.willwinder.ugs.nbp.designer.io.svg.SvgReader;
Expand All @@ -18,6 +18,7 @@
import javax.swing.JMenuBar;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
import java.awt.BorderLayout;
import java.awt.Dimension;
Expand All @@ -37,8 +38,7 @@ public class DesignerMain extends JFrame {
* Constructs a new graphical user interface for the program and shows it.
*/
public DesignerMain() {
System.setProperty(PROPERTY_USE_SCREEN_MENU, "true");
System.setProperty(PROPERTY_IS_STANDALONE, "true");
setupLookAndFeel();

setTitle("UGS Designer");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Expand Down Expand Up @@ -79,6 +79,13 @@ public DesignerMain() {
controller.getDrawing().repaint();
}

private static void setupLookAndFeel() {
System.setProperty(PROPERTY_USE_SCREEN_MENU, "true");
System.setProperty(PROPERTY_IS_STANDALONE, "true");

UIManager.put( "MenuBar.background", "@background");
}

private JSplitPane createRightPanel(Controller controller) {
EntityTreeModel entityTreeModel = new EntityTreeModel(controller);
JSplitPane toolsSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JScrollPane(new EntitiesTree(controller, entityTreeModel)), new SelectionSettingsPanel(controller));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ This file is part of Universal Gcode Sender (UGS).
*/
package com.willwinder.ugs.nbp.designer;

import static com.willwinder.ugs.nbp.designer.DesignerMain.PROPERTY_IS_STANDALONE;
import org.apache.commons.lang3.StringUtils;

import java.awt.geom.Point2D;
import java.text.ParseException;

import static com.willwinder.ugs.nbp.designer.DesignerMain.PROPERTY_IS_STANDALONE;

/**
* @author Joacim Breiler
*/
public class Utils {
public static final int MAX_DECIMALS = 4;

private Utils() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,9 @@ public void actionPerformed(ActionEvent e) {
@Override
public void onChanged() {
setEnabled(undoManager.canRedo());
if (undoManager.canRedo()) {
putValue("menuText", "Redo " + undoManager.getRedoPresentationName());
putValue(NAME, "Redo " + undoManager.getRedoPresentationName());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class RotateAction implements DrawAction, UndoableAction {
*
* @param entityList a selection which contains the shapes to be moved
* @param center the center to rotate around
* @param rotation the amount the shapes should be rotated, relative to the
* @param rotation the amount the shapes should be rotated
*/
public RotateAction(List<Entity> entityList, Point2D center, double rotation) {
this.entityList = new ArrayList<>(entityList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@ public void actionPerformed(ActionEvent e) {
@Override
public void onChanged() {
setEnabled(undoManager.canUndo());
if (undoManager.canUndo()) {
putValue("menuText", "Undo " + undoManager.getUndoPresentationName());
putValue(NAME, "Undo " + undoManager.getUndoPresentationName());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
Copyright 2024 Will Winder
This file is part of Universal Gcode Sender (UGS).
UGS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
UGS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with UGS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.willwinder.ugs.nbp.designer.actions;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class UndoActionList implements UndoableAction {

public final List<UndoableAction> actionList;

public UndoActionList(List<? extends UndoableAction> actionList) {
this.actionList = new ArrayList<>(actionList);
}

@Override
public void redo() {
actionList.forEach(UndoableAction::redo);
}

@Override
public void undo() {
actionList.forEach(UndoableAction::undo);
}

@Override
public String toString() {
return actionList.stream()
.findFirst()
.map(Object::toString)
.orElse("action");
}

public List<UndoableAction> getActions() {
return Collections.unmodifiableList(actionList);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 Will Winder
Copyright 2021-2024 Will Winder
This file is part of Universal Gcode Sender (UGS).
Expand All @@ -22,11 +22,13 @@ This file is part of Universal Gcode Sender (UGS).
import com.willwinder.ugs.nbp.designer.Utils;
import com.willwinder.ugs.nbp.designer.model.Size;

import java.awt.*;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.Collections;
import java.util.List;
import java.util.Set;

/**
Expand Down Expand Up @@ -287,4 +289,9 @@ public Point2D getLastPoint() {
}
return new Point2D.Double(coord[0], coord[1]);
}

@Override
public List<EntitySetting> getSettings() {
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.google.common.collect.Sets;

import java.awt.geom.Rectangle2D;
import java.util.HashSet;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
Expand All @@ -18,7 +17,7 @@
*/
public class BoundsCollector implements Collector<Rectangle2D, Rectangle2D, Rectangle2D> {

public static final HashSet<Characteristics> CHARACTERISTICS = Sets.newHashSet(Characteristics.UNORDERED);
protected static final Set<Characteristics> CHARACTERISTICS = Sets.newHashSet(Characteristics.UNORDERED);

public static BoundsCollector toBounds() {
return new BoundsCollector();
Expand Down Expand Up @@ -53,7 +52,7 @@ public BinaryOperator<Rectangle2D> combiner() {

@Override
public Function<Rectangle2D, Rectangle2D> finisher() {
return (target) -> {
return target -> {
if (isIncomplete(target)) {
return new Rectangle2D.Double(0, 0, 0, 0);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 Will Winder
Copyright 2021-2024 Will Winder
This file is part of Universal Gcode Sender (UGS).
Expand All @@ -21,10 +21,12 @@ This file is part of Universal Gcode Sender (UGS).
import com.willwinder.ugs.nbp.designer.gui.Drawing;
import com.willwinder.ugs.nbp.designer.model.Size;

import java.awt.*;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.List;

/**
* An entity is something that can be drawn in a {@link Drawing} which has a position, rotation and size.
Expand Down Expand Up @@ -107,24 +109,24 @@ public interface Entity {
Point2D getPosition();

/**
* Returns the real position of the entity at the given anchor
* Sets the real position of the entity
*
* @param anchor the anchor point to get the position for
* @return the real position at the anchor
* @param position the new position
*/
Point2D getPosition(Anchor anchor);
void setPosition(Point2D position);

/**
* Sets the real position of the entity
* Returns the real position of the entity at the given anchor
*
* @param position the new position
* @param anchor the anchor point to get the position for
* @return the real position at the anchor
*/
void setPosition(Point2D position);
Point2D getPosition(Anchor anchor);

/**
* Sets the real position of the entity at the given anchor
*
* @param anchor the anchor to set the position of
* @param anchor the anchor to set the position of
* @param position the new position
*/
void setPosition(Anchor anchor, Point2D position);
Expand Down Expand Up @@ -169,6 +171,13 @@ public interface Entity {
*/
double getRotation();

/**
* Sets the rotation of the object in degrees
*
* @param rotation the rotation in degrees
*/
void setRotation(double rotation);

/**
* Rotate the object around its center point in the given degrees
*
Expand All @@ -184,13 +193,6 @@ public interface Entity {
*/
void rotate(Point2D center, double angle);

/**
* Sets the rotation of the object in degrees
*
* @param rotation the rotation in degrees
*/
void setRotation(double rotation);

/**
* Gets the center point of this object using its real bounds
*
Expand Down Expand Up @@ -243,18 +245,18 @@ public interface Entity {
Entity copy();

/**
* An optional description
* Returns an optional description
*
* @param description
* @return the description or null
*/
void setDescription(String description);
String getDescription();

/**
* Returns an optional description
* An optional description
*
* @return the description or null
* @param description
*/
String getDescription();
void setDescription(String description);

/**
* Get the first point in the shape
Expand All @@ -269,4 +271,11 @@ public interface Entity {
* @return the point in the shape
*/
Point2D getLastPoint();

/**
* Return a list of possible settings for this entity
*
* @return a list of settings
*/
List<EntitySetting> getSettings();
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,6 @@ public Rectangle2D getBounds() {
return cachedBounds;
}

@Override
public Point2D getPosition(Anchor anchor) {
Rectangle2D bounds = getBounds();
return new Point2D.Double(bounds.getX(), bounds.getY());
}

@Override
public Shape getRelativeShape() {
try {
Expand Down
Loading

0 comments on commit 5feaebe

Please sign in to comment.