Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.nwoods.jgo
Class JGoBrush

    java.lang.Object
      com.nwoods.jgo.JGoBrush

All Implemented Interfaces:
  JGoXMLSaveRestore, java.io.Serializable

public class JGoBrush
extends java.lang.Object
implements java.io.Serializable, JGoXMLSaveRestore

Implements the concept of a drawing "brush", which determines how a graphical figure is filled in. A brush has a "style" that can be one of the following values:

- SOLID - a solid fill
- CUSTOM - a custom, user-supplied Paint
- NONE - no fill at all

A brush also has a color. Brushes are immutable objects, and thus may be shared freely.

When you create a CUSTOM brush, you must also provide a Paint, used by Graphics2D to actually determine how the figure is filled in. See the example classes for how to define drawables with gradients.

Some commonly used brushes are predefined:

- black - solid black fill
- darkGray - solid dark gray fill
- gray - solid gray fill
- lightGray - solid light gray fill
- white - solid white fill
- red - solid red fill
- magenta - solid magenta fill
- yellow - solid yellow fill
- green - solid green fill
- cyan - solid cyan fill
- blue - solid blue fill
- orange - solid orange fill
- pink - solid pink fill
- Null - don't fill at all

Serialized objects will not be compatible with future JGo releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of JGo.

See Also:
  `JGoDrawable`, `JGoPen`, Serialized Form

Field Summary
`static JGoBrush` | `black` a predefined solid black brush
`static JGoBrush` | `blue` a predefined solid blue brush
`static java.awt.Color` | `ColorBlack`
`static java.awt.Color` | `ColorBlue`
`static java.awt.Color` | `ColorCyan`
`static java.awt.Color` | `ColorDarkGray`
`static java.awt.Color` | `ColorGray`
`static java.awt.Color` | `ColorGreen`
`static java.awt.Color` | `ColorLightGray`
`static java.awt.Color` | `ColorMagenta`
`static java.awt.Color` | `ColorOrange`
`static java.awt.Color` | `ColorPink`
`static java.awt.Color` | `ColorRed`
`static java.awt.Color` | `ColorWhite`
`static java.awt.Color` | `ColorYellow`
`static int` | `CUSTOM` user-specified Paint
`static JGoBrush` | `cyan` a predefined solid cyan brush
`static JGoBrush` | `darkGray` a predefined solid dark gray brush
`static JGoBrush` | `gray` a predefined solid gray brush
`static JGoBrush` | `green` a predefined solid green brush
`static JGoBrush` | `lightGray` a predefined solid light gray brush
`static JGoBrush` | `magenta` a predefined solid magenta brush
`static int` | `NONE` no fill; corresponds to a hollow brush
`static JGoBrush` | `Null` a predefined hollow brush -- doesn't fill the object at all
`static JGoBrush` | `orange` a predefined solid orange brush
`static JGoBrush` | `pink` a predefined solid pink brush
`static JGoBrush` | `red` a predefined solid red brush
`static int` | `SOLID` solid fill
`static JGoBrush` | `white` a predefined solid white brush
`static JGoBrush` | `yellow` a predefined solid yellow brush

Constructor Summary
`JGoBrush()` Construct a hollow brush
`JGoBrush(int style, java.awt.Color color)` Construct a brush with the given style and color.
`JGoBrush(java.awt.Paint paint)` Construct a brush with a custom Paint

Method Summary
`java.awt.Color` | `getColor()` Get the color of the fill, if the style is SOLID.
`java.awt.Paint` | `getPaint()` Return the Paint used to fill an object.
`int` | `getStyle()` Get the style of the brush.
`static JGoBrush` | `make(int style, java.awt.Color color)` Return a JGoBrush with the given characteristics.
`static JGoBrush` | `makeStockBrush(java.awt.Color color)` Create and return a brush which fills solidly with the given color.
`void` | `SVGReadAttributes(DomElement svgElement)` This method will read attributes from standard SVG elements.
`DomNode` | `SVGReadObject(DomDoc svgDoc, JGoDocument jGoDoc, DomElement svgElement, DomElement jGoChildElement)` Read this object in from a DomDoc representing a Scalable Vector Graphics (SVG) XML document.
`void` | `SVGWriteAttributes(DomElement svgElement)` This method will add attributes to standard SVG elements.
`void` | `SVGWriteObject(DomDoc svgDoc, DomElement jGoElementGroup)` Write this object out to a DomDoc representing a Scalable Vector Graphics (SVG) XML document.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### ColorBlack

    public static final java.awt.Color ColorBlack

### ColorDarkGray

    public static final java.awt.Color ColorDarkGray

### ColorGray

    public static final java.awt.Color ColorGray

### ColorLightGray

    public static final java.awt.Color ColorLightGray

### ColorWhite

    public static final java.awt.Color ColorWhite

### ColorRed

    public static final java.awt.Color ColorRed

### ColorMagenta

    public static final java.awt.Color ColorMagenta

### ColorYellow

    public static final java.awt.Color ColorYellow

### ColorGreen

    public static final java.awt.Color ColorGreen

### ColorCyan

    public static final java.awt.Color ColorCyan

### ColorBlue

    public static final java.awt.Color ColorBlue

### ColorOrange

    public static final java.awt.Color ColorOrange

### ColorPink

    public static final java.awt.Color ColorPink

### NONE

    public static final int NONE

  no fill; corresponds to a hollow brush

  See Also:
    Constant Field Values

### SOLID

    public static final int SOLID

  solid fill

  See Also:
    Constant Field Values

### CUSTOM

    public static final int CUSTOM

  user-specified Paint

  See Also:
    Constant Field Values

### black

    public static final JGoBrush black

  a predefined solid black brush

### darkGray

    public static final JGoBrush darkGray

  a predefined solid dark gray brush

### gray

    public static final JGoBrush gray

  a predefined solid gray brush

### lightGray

    public static final JGoBrush lightGray

  a predefined solid light gray brush

### white

    public static final JGoBrush white

  a predefined solid white brush

### red

    public static final JGoBrush red

  a predefined solid red brush

### magenta

    public static final JGoBrush magenta

  a predefined solid magenta brush

### yellow

    public static final JGoBrush yellow

  a predefined solid yellow brush

### green

    public static final JGoBrush green

  a predefined solid green brush

### cyan

    public static final JGoBrush cyan

  a predefined solid cyan brush

### blue

    public static final JGoBrush blue

  a predefined solid blue brush

### orange

    public static final JGoBrush orange

  a predefined solid orange brush

### pink

    public static final JGoBrush pink

  a predefined solid pink brush

### Null

    public static final JGoBrush Null

  a predefined hollow brush -- doesn't fill the object at all

Constructor Detail

### JGoBrush

    public JGoBrush()

  Construct a hollow brush

### JGoBrush

    public JGoBrush(int style,
                    java.awt.Color color)

  Construct a brush with the given style and color.

Parameters:
  `style` - the style of the brush.
  `color` - the color of the fill.

### JGoBrush

    public JGoBrush(java.awt.Paint paint)

  Construct a brush with a custom Paint

Parameters:
  `paint` - the Paint to use

Method Detail

### makeStockBrush

    public static JGoBrush makeStockBrush(java.awt.Color color)

  Create and return a brush which fills solidly with the given color.

  For efficiency it may return an existing instance, rather than allocating a new one.

  Parameters:
    `color` - the color with which to fill
  Returns:
    a solid brush

### make

    public static JGoBrush make(int style,
                                java.awt.Color color)

  Return a JGoBrush with the given characteristics.

  For efficiency it may return an existing instance, rather than allocating a new one.

  Parameters:
    `style` - the style of the brush.
    `color` - the color of the fill.

### SVGWriteObject

    public void SVGWriteObject(DomDoc svgDoc,
                               DomElement jGoElementGroup)

  Description copied from interface: `JGoXMLSaveRestore`
  Write this object out to a DomDoc representing a Scalable Vector Graphics (SVG) XML document.

  This method will be called by com.nwoods.jgo.svg.DefaultDocument.SVGWriteDoc() for every JGoObject contained within a JGoDocument. The following example uses a JGoRectangle to illustrate the format of a generated SVG JGoObject:

  <g>
  <JGoClass class="com.nwoods.jgo.JGoRectangle"\>
  <rect height="75" style="stroke:black;stroke-width:1;fill:rgb(255,0,0);" width="75" x="65" y="71"/>
  <JGoClass class="com.nwoods.jgo.JGoDrawable" drawablebrush="jgoid1" drawablepen="jgoid2" embeddedpenbrush="false"/>
  <JGoClass class="com.nwoods.jgo.JGoObject" obj_flags="1054"/>
  </g>

  Note that the entire JGoObject is enclosed in a group (<g>). Each subclass of the JGoObject is described by a <JGoClass> element, starting with the most specific class and moving to the more general. Each <JGoClass> element has a "class" attribute which defines the class name. Each <JGoClass> element may also have several other attributes which uniquely describe that state of that class. Following the <JGoClass> element, each class may also genereate any other elements that are required, including representations of contained objects and standard SVG elements such as the <rect> element shown in the above example. The generation of SVG elements in the output makes it possible for the output to be read by SVG viewers and other SVG aware applications. The information contained in the <JGoClass> elements allows us to accurately save and restore all the information in a particular JGoObject subclass.

  If this class contains a reference to another object, call DomDoc.registerReferencingNode() to register that reference. This will cause the element representing the referenced object to be identified with a unique id attribute, and cause the element representing the referring object to have a user defined attribute containing a reference to that id. See DomDoc.registerReferencingNode() for more information.

  Typically, an implementation of this method will generate a <JGoClass> element using the DomDoc.createJGoClassElement() method, adding whatever attributes are necessary to describe the class. It will then call its superclass so that the superclass can add its own <JGoClass> element and other information to jGoElementGroup within the DomDoc.

  Refer to com.nwoods.jgo.examples.flower.ActivityNode.SVGWriteObject() and com.nwoods.jgo.examples.SimpleNode.SVGWriteObject() for examples using this method.

  Refer to the file com.nwoods.jgo.svg\xsvg.dtd for a formal description of JGo extensions to the SVG document type.

  Specified by:
    `SVGWriteObject` in interface `JGoXMLSaveRestore`
  Parameters:
    `svgDoc` - the DomDoc in which to construct the SVG representation of this object
    `jGoElementGroup` - the DomElement to which to attach this object
  See Also:
    `JGoObject.SVGReadObject(com.nwoods.jgo.DomDoc, com.nwoods.jgo.JGoDocument, com.nwoods.jgo.DomElement, com.nwoods.jgo.DomElement)`, `JGoObject.SVGWriteAttributes(com.nwoods.jgo.DomElement)`, `JGoObject.SVGReadAttributes(com.nwoods.jgo.DomElement)`, `JGoObject.SVGUpdateReference(java.lang.String, java.lang.Object)`, `DomDoc`, `DomNode`, `DomElement`, `DomText`

### SVGReadObject

    public DomNode SVGReadObject(DomDoc svgDoc,
                                 JGoDocument jGoDoc,
                                 DomElement svgElement,
                                 DomElement jGoChildElement)

  Description copied from interface: `JGoXMLSaveRestore`
  Read this object in from a DomDoc representing a Scalable Vector Graphics (SVG) XML document.

  This method will be called by com.nwoods.jgo.svg.DefaultDocument.SVGReadDoc() for every <JGoClass> element encountered in a DomDoc. First, an object of the type specified by the class attribute will be created and then the SVGReadObject() method will be called on that newly created object. Refer to SVGWriteObject() for a description of the expected format of the SVG document.

  This method may also be called by com.nwoods.jgo.svg.DefaultDocument.SVGReadDoc() when reading any SVG document, including those not generated by JGo and therefore not containing any <JGoClass> elements. In such cases, the DefaultDocument.SVGReadElement() method may be subclassed to examine the SVG element and cause the appropriate JGoObject to be created to represent that element and call SVGReadObject() on that newly created object. By default, standard JGoObjects such as JGoRectangles, JGoStrokes, etc will be created to represent these objects.

  If this class contains a reference to another object, call DomDoc.registerReferencingObject() to register that reference. This will cause the JGoObject.SVGUpdateReference() to be called on the referencing object after all the objects have been created, passing in the object befing referenced. See DomDoc.registerReferencingObject() for more information.

  Typically, an implementation of this method starts by verifying that the element being read is a <JGoClass> element (which will be true if jGoChildElement is not null). This will always be true unless you have subclassed the DefaultDocument.SVGReadElement() method as described above. It will then read the expected attributes of the <JGoClass> element (as written by SVGReadObject()), call SVGReadObject() on its superclass, and finally return the next element by calling svgElement.getNextSibling().

  Refer to com.nwoods.jgo.examples.flower.ActivityNode.SVGReadObject() and com.nwoods.jgo.examples.SimpleNode.SVGReadObject() for examples using this method.

  Specified by:
    `SVGReadObject` in interface `JGoXMLSaveRestore`
  Parameters:
    `svgDoc` - the DomDoc containing the SVG representation of this object
    `jGoDoc` - the JGoDocument in which this object was created
    `svgElement` - the element being read (typically the <g> element containing the JGoObject definition)
    `jGoChildElement` - the current <JGoClass> element being read withing the <g>
  See Also:
    `JGoObject.SVGWriteObject(com.nwoods.jgo.DomDoc, com.nwoods.jgo.DomElement)`, `JGoObject.SVGWriteAttributes(com.nwoods.jgo.DomElement)`, `JGoObject.SVGReadAttributes(com.nwoods.jgo.DomElement)`, `JGoObject.SVGUpdateReference(java.lang.String, java.lang.Object)`, `DomDoc`, `DomNode`, `DomElement`, `DomText`

### SVGWriteAttributes

    public void SVGWriteAttributes(DomElement svgElement)

  This method will add attributes to standard SVG elements.

  Call this method from SVGWriteObject() if standard SVG elements are generated by this class or if this class may be subclassed and it should contribute arguments to SVG elements. For example, the JGoDrawable class implements this method to add standard SVG attributes for stroke, fill, and width. The JGoRectangle class calls this method to add all appropriate attributes to the <rect> element it generates. It is not necessary to implement this method if this class does not contribute any attributes to standard SVG elements. It is not necessary to call this method from SVGWriteObject() if this class does not generate any standard SVG elements.

  Typically, an implementation of this method will first call the superclass and then call DomElement.setAttribute() to add attributes for this class.

  Parameters:
    `svgElement` - the DomElement to which to add attributes
  See Also:
    `JGoObject.SVGWriteObject(com.nwoods.jgo.DomDoc, com.nwoods.jgo.DomElement)`, `JGoObject.SVGReadObject(com.nwoods.jgo.DomDoc, com.nwoods.jgo.JGoDocument, com.nwoods.jgo.DomElement, com.nwoods.jgo.DomElement)`, `JGoObject.SVGWriteAttributes(com.nwoods.jgo.DomElement)`, `JGoObject.SVGReadAttributes(com.nwoods.jgo.DomElement)`, `JGoObject.SVGUpdateReference(java.lang.String, java.lang.Object)`, `DomDoc`, `DomNode`, `DomElement`, `DomText`

### SVGReadAttributes

    public void SVGReadAttributes(DomElement svgElement)

  This method will read attributes from standard SVG elements.

  Call this method from SVGReadObject() if standard SVG elements are being read by this class or if this class may be subclassed and it should read arguments from SVG elements. For example, the JGoDrawable class implements this method to read standard SVG attributes for stroke, fill, and width. The JGoRectangle class calls this method to read all appropriate attributes from the <rect> element it is reading. It is not necessary to implement this method if this class does not read any attributes from standard SVG elements. It is not necessary to call this method from SVGReadObject() if this class does not read any standard SVG elements.

  Typically, an implementation of this method will first call the superclass and then call DomElement.getAttribute() to read the attributes for this class.

  Parameters:
    `svgElement` - the DomElement from which to read attributes
  See Also:
    `JGoObject.SVGWriteObject(com.nwoods.jgo.DomDoc, com.nwoods.jgo.DomElement)`, `JGoObject.SVGReadObject(com.nwoods.jgo.DomDoc, com.nwoods.jgo.JGoDocument, com.nwoods.jgo.DomElement, com.nwoods.jgo.DomElement)`, `JGoObject.SVGWriteAttributes(com.nwoods.jgo.DomElement)`, `JGoObject.SVGReadAttributes(com.nwoods.jgo.DomElement)`, `JGoObject.SVGUpdateReference(java.lang.String, java.lang.Object)`, `DomDoc`, `DomNode`, `DomElement`, `DomText`

### getStyle

    public int getStyle()

  Get the style of the brush.

  Returns:
    the style of the brush.

### getPaint

    public java.awt.Paint getPaint()

  Return the Paint used to fill an object. May return null if the style is NONE.

### getColor

    public java.awt.Color getColor()

  Get the color of the fill, if the style is SOLID.

  Returns:
    the color of the fill.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD