diff --git a/src/main/java/com/github/creme332/controller/CanvasController.java b/src/main/java/com/github/creme332/controller/CanvasController.java index 726e8cc5..c6a6a747 100644 --- a/src/main/java/com/github/creme332/controller/CanvasController.java +++ b/src/main/java/com/github/creme332/controller/CanvasController.java @@ -90,7 +90,6 @@ public void mouseMoved(MouseEvent e) { if (roundedRadius == 0) return; - currentWrapper.setShape(getCircle((int) center.getX(), (int) center.getY(), roundedRadius)); canvas.repaint(); return; @@ -174,7 +173,8 @@ private void handleMousePressed(MouseEvent e) { // first coordinate of line has been selected // create a shape wrapper - currentWrapper = new ShapeWrapper(); + currentWrapper = new ShapeWrapper(model.getFillColor(), model.getFillColor(), model.getLineType(), + model.getLineThickness()); currentWrapper.getPlottedPoints().add(polySpaceMousePosition); // save wrapper @@ -201,7 +201,8 @@ private void handleMousePressed(MouseEvent e) { // center has been selected // create a shape wrapper - currentWrapper = new ShapeWrapper(); + currentWrapper = new ShapeWrapper(model.getFillColor(), model.getFillColor(), model.getLineType(), + model.getLineThickness()); currentWrapper.getPlottedPoints().add(polySpaceMousePosition); // save wrapper @@ -229,7 +230,8 @@ private void handleMousePressed(MouseEvent e) { // first foci has been selected // create a shape wrapper - currentWrapper = new ShapeWrapper(); + currentWrapper = new ShapeWrapper(model.getFillColor(), model.getFillColor(), model.getLineType(), + model.getLineThickness()); currentWrapper.getPlottedPoints().add(polySpaceMousePosition); // save wrapper diff --git a/src/main/java/com/github/creme332/view/Canvas.java b/src/main/java/com/github/creme332/view/Canvas.java index aefa39b6..adfe672f 100644 --- a/src/main/java/com/github/creme332/view/Canvas.java +++ b/src/main/java/com/github/creme332/view/Canvas.java @@ -3,6 +3,7 @@ import javax.swing.JPanel; import com.github.creme332.model.CanvasModel; +import com.github.creme332.model.LineType; import com.github.creme332.model.ShapeWrapper; import java.awt.BasicStroke; @@ -12,6 +13,7 @@ import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.Shape; +import java.awt.Stroke; import java.awt.geom.Ellipse2D; import java.awt.geom.Point2D; @@ -178,6 +180,8 @@ public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; setAntialiasing(g2); + final Stroke defaultStroke = g2.getStroke(); + if (model.isGuidelinesEnabled()) { drawGuidelines(g2); } @@ -189,6 +193,7 @@ public void paintComponent(Graphics g) { for (ShapeWrapper wrapper : model.getShapes()) { g2.setColor(wrapper.getLineColor()); + g2.setStroke(getStroke(wrapper.getLineType(), wrapper.getLineThickness())); if (wrapper.getShape() != null) { Shape s1 = model.toUserSpace(wrapper.getShape()); @@ -196,6 +201,7 @@ public void paintComponent(Graphics g) { } // plot points + g2.setStroke(defaultStroke); g2.setColor(wrapper.getFillColor()); for (Point2D p : wrapper.getPlottedPoints()) { Shape point = createPointAsShape(model.toUserSpace(p)); @@ -207,6 +213,24 @@ public void paintComponent(Graphics g) { } } + private Stroke getStroke(LineType lineType, int thickness) { + switch (lineType) { + case SOLID: + // Set the stroke of the copy, not the original + return new BasicStroke(thickness, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, + 0, new float[] { 1 }, 0); + case DASHED: + return new BasicStroke(thickness, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, + 0, new float[] { 12 }, 0); + case DOTTED: + return new BasicStroke(thickness, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, + 0, new float[] { 4 }, 0); + default: + return new BasicStroke(thickness, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, + 0, new float[] { 1 }, 0); + } + } + /** * * @param mySpaceCoord