-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
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
49 changes: 49 additions & 0 deletions
49
src/main/java/com/defano/jmonet/tools/FreeformShapeTool.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 @@ | ||
package com.defano.jmonet.tools; | ||
|
||
import com.defano.jmonet.model.PaintToolType; | ||
import com.defano.jmonet.tools.base.AbstractPathTool; | ||
|
||
import java.awt.*; | ||
import java.awt.geom.Path2D; | ||
|
||
/** | ||
* Tool allowing user to draw a free-form path (like a paintbrush) that is closed upon completion | ||
* and can thusly be filled with paint. | ||
*/ | ||
public class FreeformShapeTool extends AbstractPathTool { | ||
|
||
private Path2D path; | ||
|
||
public FreeformShapeTool() { | ||
super(PaintToolType.FREEFORM); | ||
} | ||
|
||
@Override | ||
protected void startPath(Graphics2D g, Stroke stroke, Paint paint, Point initialPoint) { | ||
path = new Path2D.Double(); | ||
path.moveTo(initialPoint.getX(), initialPoint.getY()); | ||
} | ||
|
||
@Override | ||
protected void addPoint(Graphics2D g, Stroke stroke, Paint paint, Point point) { | ||
path.lineTo(point.getX(), point.getY()); | ||
|
||
g.setStroke(stroke); | ||
g.setPaint(getStrokePaint()); | ||
g.draw(path); | ||
} | ||
|
||
@Override | ||
protected void completePath(Graphics2D g, Stroke stroke, Paint paint) { | ||
path.closePath(); | ||
|
||
if (getFillPaint() != null) { | ||
g.setPaint(getFillPaint()); | ||
g.fill(path); | ||
} | ||
|
||
g.setStroke(stroke); | ||
g.setPaint(getStrokePaint()); | ||
g.draw(path); | ||
} | ||
} |
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