Class FxRubberPen
public class FxRubberPen extends FxPen
{
// Constructors
public FxRubberPen(Color c);
public FxRubberPen(FxColor c);
// Methods
public void drawLast(FxGraphics g);
public boolean drawLineCallback(FxGraphics g, int x1, int y1, int
x2, int y2);
public boolean drawOvalCallback(FxGraphics g, int x1, int y1, int
w, int h);
public boolean drawPolygonCallback(FxGraphics g, int xPoints[],
int yPoints[], int nPoints);
public boolean drawRectCallback(FxGraphics g, int x1, int y1, int
w, int h);
public boolean drawRoundRectCallback(FxGraphics g, int x1,
int y1, int w, int h, int aw, int ah);
}
This class provides a rubber pen (typically, a pen that draws a shape or line after a drag-and-release mouse event and erases its previous drawing operation when performing a new one). Rubber pen objects are used in graphics applications where a non-permanent pen is needed as a template for operations with another permanent pen.
The FxRubberPen object is not actually dependant on mouse events, as arrow keys may also direct the pen. Although a pen will erase its previous operation before performing a new one, you can use more than one FxRubberPen at a time.
Note The callback methods used in this and other classes that are derived from FxColor are used internally only. An FxRubberPen object is selected into a graphics context the same way a Color is selected and will perform the operations that the graphics object requires. For more information on the use of callback methods in the com.ms.fx package, see the overview information at the beginning of this package.
The following examples show you how to create and use an FxRubberPen object.
// Create an FxRubberPen by either using a Color or FxColor
// object. If a Color or FxColor is used, the pen draws lines that
// are one pixel wide. You can use an FxPen object, however, as the
// selected color to draw wider lines.
FxRubberPen fxrp1 = new FxRubberPen(Color.blue);
FxRubberPen fxrp2 = new FxRubberPen(new FxPen(5, Color.blue));
// Set the rubber pen as the current graphics object's color,
// and then draw any supported primitives as you normally would.
fxGraf.setColor(fxrp2);
fxGraf.drawLine(1, 1, 30, 40);
fxGraf.drawPolygon(xPtsArray, yPtsArray, numPts);
// Note that it's easy to create the object and set the graphics on one line.
// The following example sets the graphics object's color as a red
// FxRubberPen that is 10 pixels wide.
fxGraf.setColor( new FxRubberPen( new FxPen( 10, 255, 0 ,0)));
BaseColor
|
+--FxColor
|
+--FxFill
|
+--FxPen
|
+--FxRubberPen
public FxRubberPen(Color c);
Creates a rubber pen object with a specified. Color
Parameter | Description |
c
| The FxRubberPen. The color specified is the background color required for the banding.
|
public FxRubberPen(FxColor c);
Creates a rubber pen object with a specified FxColor.
Parameter | Description |
c
| The FxRubberPen. The color specified is the background color required for the banding.
|
public void drawLast(FxGraphics g);
Erases the last action performed by the pen.
Return Value:
No return value.
Parameter | Description |
g
| The graphics object to use.
|
public boolean drawLineCallback(FxGraphics g, int x1, int y1, int x2,
int y2);
Draws a temporary line when called by an FxGraphics object.
Note This method is called by FxGraphics if drawLine is called and an FxRubberPen object is the selected color. The callback methods are used internally and are not intended to be called by applications. They are made public so that derived classes can extend the callback functionality.
Return Value:
Returns true if successful; otherwise, returns false.
Parameter | Description |
g
| The graphics object to use.
|
x1
| The x coordinate of the starting point of the line.
|
y1
| The y coordinate of the starting point of the line.
|
x2
| The x coordinate of the ending point of the line.
|
y2
| The y coordinate of the ending point of the line.
|
Overrides:
drawLineCallback(FxGraphics,int,int,int,int) in FxPen.
See Also: java.awt.Graphics.drawLine, com.ms.fx.FxFill.drawLineCallback
public boolean drawOvalCallback(FxGraphics g, int x1, int y1, int w, int h);
Draws a temporary ellipse when called by an FxGraphics object.
Note This method is called by FxGraphics if drawOval is called and if an FxRubberPen object is the selected color. The callback methods are used internally and are not intended to be called by applications. They are made public so that derived classes can extend the callback functionality.
Return Value:
Returns true if successful; otherwise, returns false.
Parameter | Description |
g
| The graphics object to use.
|
x1
| The upper-left x coordinate of the oval's bounding rectangle
|
y1
| The upper-left y coordinate of the oval's bounding rectangle.
|
w
| The width of the oval (in pixels).
|
h
| The height of the oval (in pixels).
|
Overrides:
drawOvalCallback(FxGraphics,int,int,int,int) in FxPen.
See Also: java.awt.Graphics.drawOval, com.ms.fx.FxFill.drawOvalCallback
public boolean drawPolygonCallback(FxGraphics g, int xPoints[],
int yPoints[], int nPoints);
Draws a temporary polygon when called by an FxGraphics object.
Note This method is called by FxGraphics if drawPolygon is called and if an FxRubberPen object is the selected color. The callback methods are used internally and are not intended to be called by applications. They are made public so that derived classes can extend the callback functionality.
Return Value:
Returns true if successful; otherwise, returns false.
Parameter | Description |
g
| The graphics object to use.
|
xPoints
| An array containing the polygon's x coordinates.
|
yPoints
| An array containing the polygon's y coordinates.
|
nPoints
| The number of points in the polygon.
|
Overrides:
drawPolygonCallback(FxGraphics,int[],int[],int) in FxPen.
See Also: java.awt.Graphics.drawPolygon, com.ms.fx.FxFill.drawPolygonCallback
public boolean drawRectCallback(FxGraphics g, int x1, int y1, int w, int h);
Draws a temporary rectangle when called by an FxGraphics object.
Note This method is called by FxGraphics if drawRect is called and if an FxRubberPen object is the selected color. The callback methods are used internally and are not intended to be called by applications. They are made public so that derived classes can extend the callback functionality.
Return Value:
Returns true if successful; otherwise, returns false.
Parameter | Description |
g
| The graphics object to use.
|
x1
| The upper-left x coordinate of the rectangle.
|
y1
| The upper-left y coordinate of the rectangle.
|
w
| The width of the rectangle (in pixels).
|
h
| The height of the rectangle (in pixels).
|
Overrides:
drawRectCallback(FxGraphics,int,int,int,int) in FxPen.
See Also: java.awt.Graphics.drawRect, com.ms.fx.FxFill.drawRectCallback
public boolean drawRoundRectCallback(FxGraphics g, int x1, int y1, int w,
int h, int aw, int ah);
Draws a temporary rectangle with rounded edges when called by an FxGraphics object.
Note This method is called by FxGraphics if drawRoundRect is called and if an FxRubberPen object is the selected color. The callback methods are used internally and are not intended to be called by applications. They are made public so that derived classes can extend the callback functionality.
Return Value:
Returns true if successful; otherwise, returns false.
Parameter | Description |
g
| The graphics object to use.
|
x1
| The upper-left x coordinate of the rectangle.
|
y1
| The upper-left y coordinate of the rectangle.
|
w
| The width of the rectangle (in pixels).
|
h
| The height of the rectangle (in pixels).
|
aw
| The arc width of the rectangle rounded edges.
|
ah
| the arc height of the rectangle rounded edges.
|
Overrides:
drawRoundRectCallback(FxGraphics,int,int,int,int,int,int) in FxPen.
See Also: java.awt.Graphics.drawRoundRect, com.ms.fx.FxFill.drawRoundRectCallback