-
-
Notifications
You must be signed in to change notification settings - Fork 770
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added a text tool to the designer * Added possibility to change font and and save/load designs with texts * Prevent sending files when in alarm mode * Made some functions generic and fixed saving and loading geometries so that it will preserve rotation and scale. * Added measurements to the grid * Updated test file to reflect new format * Fixed broken tests
- Loading branch information
Showing
38 changed files
with
2,247 additions
and
2,562 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...in-designer/src/main/java/com/willwinder/ugs/nbp/designer/actions/ToolDrawTextAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
Copyright 2021 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 com.willwinder.ugs.nbp.designer.logic.Controller; | ||
import com.willwinder.ugs.nbp.designer.logic.Tool; | ||
import org.openide.util.ImageUtilities; | ||
|
||
import javax.swing.*; | ||
import java.awt.event.ActionEvent; | ||
|
||
/** | ||
* @author Joacim Breiler | ||
*/ | ||
public class ToolDrawTextAction extends AbstractAction { | ||
private static final String SMALL_ICON_PATH = "img/text.png"; | ||
private static final String LARGE_ICON_PATH = "img/text24.png"; | ||
private final Controller controller; | ||
|
||
public ToolDrawTextAction(Controller controller) { | ||
putValue("iconBase", SMALL_ICON_PATH); | ||
putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false)); | ||
putValue(LARGE_ICON_KEY, ImageUtilities.loadImageIcon(LARGE_ICON_PATH, false)); | ||
putValue("menuText", "Draw text"); | ||
putValue(NAME, "Draw text"); | ||
this.controller = controller; | ||
} | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
controller.setTool(Tool.TEXT); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...ugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/entities/EntityException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
Copyright 2021 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.entities; | ||
|
||
/** | ||
* @author Joacim Breiler | ||
*/ | ||
public class EntityException extends RuntimeException { | ||
public EntityException(Exception e) { | ||
super(e); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
...er/src/main/java/com/willwinder/ugs/nbp/designer/entities/controls/CreateTextControl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
Copyright 2021 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.entities.controls; | ||
|
||
import com.willwinder.ugs.nbp.designer.actions.AddAction; | ||
import com.willwinder.ugs.nbp.designer.entities.EntityEvent; | ||
import com.willwinder.ugs.nbp.designer.entities.EventType; | ||
import com.willwinder.ugs.nbp.designer.entities.cuttable.Text; | ||
import com.willwinder.ugs.nbp.designer.gui.Drawing; | ||
import com.willwinder.ugs.nbp.designer.gui.MouseEntityEvent; | ||
import com.willwinder.ugs.nbp.designer.logic.Controller; | ||
import com.willwinder.ugs.nbp.designer.logic.Tool; | ||
import com.willwinder.universalgcodesender.uielements.helpers.ThemeColors; | ||
|
||
import java.awt.*; | ||
import java.awt.event.ActionEvent; | ||
import java.awt.geom.Point2D; | ||
import java.awt.geom.Rectangle2D; | ||
|
||
/** | ||
* A control that will create a new ellipse | ||
* | ||
* @author Joacim Breiler | ||
*/ | ||
public class CreateTextControl extends AbstractControl { | ||
|
||
private final Controller controller; | ||
private Point2D startPosition; | ||
private Point2D endPosition; | ||
private boolean isPressed; | ||
|
||
public CreateTextControl(Controller controller) { | ||
super(controller.getSelectionManager()); | ||
this.controller = controller; | ||
} | ||
|
||
@Override | ||
public void render(Graphics2D graphics, Drawing drawing) { | ||
if (isPressed) { | ||
double startX = Math.min(startPosition.getX(), endPosition.getX()); | ||
double endX = Math.max(startPosition.getX(), endPosition.getX()); | ||
double startY = Math.min(startPosition.getY(), endPosition.getY()); | ||
double endY = Math.max(startPosition.getY(), endPosition.getY()); | ||
Rectangle2D.Double rect = new Rectangle2D.Double(startX, startY, endX - startX, endY - startY); | ||
graphics.setColor(ThemeColors.LIGHT_BLUE_GREY); | ||
graphics.draw(rect); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isWithin(Point2D point) { | ||
return controller.getTool() == Tool.TEXT; | ||
} | ||
|
||
@Override | ||
public void onEvent(EntityEvent entityEvent) { | ||
if (entityEvent instanceof MouseEntityEvent) { | ||
MouseEntityEvent mouseEntityEvent = (MouseEntityEvent) entityEvent; | ||
startPosition = mouseEntityEvent.getStartMousePosition(); | ||
endPosition = mouseEntityEvent.getCurrentMousePosition(); | ||
|
||
if (mouseEntityEvent.getType() == EventType.MOUSE_PRESSED) { | ||
isPressed = true; | ||
} else if (mouseEntityEvent.getType() == EventType.MOUSE_DRAGGED) { | ||
isPressed = true; | ||
} else if (mouseEntityEvent.getType() == EventType.MOUSE_RELEASED) { | ||
isPressed = false; | ||
createEntity(); | ||
} | ||
} | ||
} | ||
|
||
private void createEntity() { | ||
double startX = Math.min(startPosition.getX(), endPosition.getX()); | ||
double startY = Math.min(startPosition.getY(), endPosition.getY()); | ||
|
||
Text text = new Text(startX, startY); | ||
AddAction addAction = new AddAction(controller, text); | ||
addAction.actionPerformed(new ActionEvent(this, 0, "")); | ||
controller.addEntity(text); | ||
controller.setTool(Tool.SELECT); | ||
controller.getSelectionManager().addSelection(text); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "CreateTextControl"; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...gner/src/main/java/com/willwinder/ugs/nbp/designer/entities/controls/EditTextControl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.willwinder.ugs.nbp.designer.entities.controls; | ||
|
||
import com.willwinder.ugs.nbp.designer.entities.Entity; | ||
import com.willwinder.ugs.nbp.designer.entities.EntityEvent; | ||
import com.willwinder.ugs.nbp.designer.entities.cuttable.Text; | ||
import com.willwinder.ugs.nbp.designer.gui.Colors; | ||
import com.willwinder.ugs.nbp.designer.gui.Drawing; | ||
import com.willwinder.ugs.nbp.designer.logic.Controller; | ||
|
||
import java.awt.*; | ||
import java.awt.geom.Line2D; | ||
import java.awt.geom.Point2D; | ||
import java.awt.geom.Rectangle2D; | ||
import java.util.List; | ||
|
||
public class EditTextControl extends AbstractControl { | ||
|
||
private final Controller controller; | ||
private long previousTime = 0; | ||
|
||
public EditTextControl(Controller controller) { | ||
super(controller.getSelectionManager()); | ||
this.controller = controller; | ||
this.previousTime = System.currentTimeMillis(); | ||
} | ||
|
||
@Override | ||
public boolean isWithin(Point2D point) { | ||
return isTextEntitySelected(); | ||
} | ||
|
||
private boolean isTextEntitySelected() { | ||
boolean isTextEntity = false; | ||
List<Entity> selection = controller.getSelectionManager().getSelection(); | ||
if (!selection.isEmpty()) { | ||
Entity entity = selection.get(0); | ||
isTextEntity = entity instanceof Text; | ||
} | ||
return isTextEntity; | ||
} | ||
|
||
@Override | ||
public void render(Graphics2D graphics, Drawing drawing) { | ||
if (!isTextEntitySelected()) { | ||
return; | ||
} | ||
|
||
if (previousTime + 600 < System.currentTimeMillis()) { | ||
graphics.setColor(Colors.CURSOR); | ||
graphics.setStroke(new BasicStroke(Double.valueOf(1 / drawing.getScale()).floatValue())); | ||
Rectangle2D bounds = getRelativeShape().getBounds2D(); | ||
Line2D line = new Line2D.Double(bounds.getX() + bounds.getWidth(), bounds.getY(), bounds.getX() + bounds.getWidth(), bounds.getY() + bounds.getHeight()); | ||
graphics.draw(getSelectionManager().getTransform().createTransformedShape(line)); | ||
|
||
} | ||
|
||
if (previousTime + 1200 < System.currentTimeMillis()) { | ||
previousTime = System.currentTimeMillis(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onEvent(EntityEvent entityEvent) { | ||
|
||
} | ||
} |
Oops, something went wrong.