Class ArtEditor

All Implemented Interfaces:
ArtListener, Animation, Editable, StyleListener, Iterable<Component>

public class ArtEditor extends Container implements ArtListener

A simple vector and raster editor: an ArtView with a tool bar, a layers panel and an inspector.

The tools select, move and resize; pan; draw rectangles, ellipses and lines; draw Bezier paths with the pen and freehand strokes; paint and erase pixels; place text; pick a color; and fill a shape or a region of pixels. Every change goes through the ArtModel, so it can be undone. The layers panel and the inspector are ordinary components, available separately through getLayersPanel and getInspector.

byte[] svg = "<svg xmlns='http://www.w3.org/2000/svg' width='200' height='120'><circle cx='60' cy='60' r='40' fill='#1e88e5'/></svg>".getBytes("UTF-8");
ArtEditor editor = new ArtEditor(new ArtModel(ArtFormats.read(svg)));
Form form = new Form("Draw", new BorderLayout());
form.add(BorderLayout.CENTER, editor);
form.show();
  • Field Details

    • TOOL_SELECT

      public static final int TOOL_SELECT
      Selects, moves and resizes nodes.
      See Also:
    • TOOL_PAN

      public static final int TOOL_PAN
      Drags the view.
      See Also:
    • TOOL_RECTANGLE

      public static final int TOOL_RECTANGLE
      Draws rectangles.
      See Also:
    • TOOL_ELLIPSE

      public static final int TOOL_ELLIPSE
      Draws ellipses.
      See Also:
    • TOOL_LINE

      public static final int TOOL_LINE
      Draws straight lines.
      See Also:
    • TOOL_PEN

      public static final int TOOL_PEN
      Draws Bezier paths: tap to add a corner, drag to add a smooth point, tap the first point to close.
      See Also:
    • TOOL_FREEHAND

      public static final int TOOL_FREEHAND
      Draws smoothed freehand strokes.
      See Also:
    • TOOL_BRUSH

      public static final int TOOL_BRUSH
      Paints pixels onto the selected pixel layer, or a new one.
      See Also:
    • TOOL_ERASER

      public static final int TOOL_ERASER
      Erases pixels from the selected pixel layer.
      See Also:
    • TOOL_TEXT

      public static final int TOOL_TEXT
      Places text.
      See Also:
    • TOOL_EYEDROPPER

      public static final int TOOL_EYEDROPPER
      Picks the color under the pointer as the fill color.
      See Also:
    • TOOL_FILL

      public static final int TOOL_FILL
      Fills a shape, or a region of similar pixels, with the fill color.
      See Also:
  • Constructor Details

    • ArtEditor

      public ArtEditor()
      Creates an editor of an empty document.
    • ArtEditor

      public ArtEditor(ArtModel model)

      Creates an editor.

      Parameters
      • model: the model to edit
  • Method Details

    • initComponent

      protected void initComponent()
      Description copied from class: Component
      Allows subclasses to bind functionality that relies on fully initialized and "ready for action" component state
      Overrides:
      initComponent in class Component
    • deinitialize

      protected void deinitialize()
      Description copied from class: Component
      Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy. This allows the component to deregister animators and cleanup after itself. This method is the opposite of the initComponent() method.
      Overrides:
      deinitialize in class Component
    • getModel

      public ArtModel getModel()
      The model.
    • getView

      public ArtView getView()
      The view.
    • getLayersPanel

      public Container getLayersPanel()
      The layers panel: the node tree, with visibility, order and selection.
    • getInspector

      public Container getInspector()
      The inspector: the selected node's properties and effects.
    • setPanelsVisible

      public void setPanelsVisible(boolean show)

      Shows or hides the side panel holding the layers and the inspector.

      Parameters
      • show: true to show it
    • getTool

      public int getTool()
      The current tool, one of the TOOL_ constants.
    • setTool

      public void setTool(int t)

      Picks a tool.

      Parameters
      • t: one of the TOOL_ constants
    • getFillColor

      public int getFillColor()
      The color new shapes, text and the brush use.
    • setFillColor

      public void setFillColor(int argb)

      Sets the fill color.

      Parameters
      • argb: the color
    • getStrokeColor

      public int getStrokeColor()
      The outline color for lines, paths and freehand strokes.
    • setStrokeColor

      public void setStrokeColor(int argb)

      Sets the outline color.

      Parameters
      • argb: the color
    • setStrokeWidth

      public void setStrokeWidth(float w)

      Sets the outline width in document units.

      Parameters
      • w: the width
    • setBrushSize

      public void setBrushSize(float size)

      Sets the brush and eraser diameter in document units.

      Parameters
      • size: the diameter
    • exportSvg

      public void exportSvg(OutputStream out) throws IOException

      Writes the document as SVG.

      Parameters
      • out: the destination; not closed
      Throws:
      IOException
    • exportPsd

      public void exportPsd(OutputStream out) throws IOException

      Writes the document as a layered PSD.

      Parameters
      • out: the destination; not closed
      Throws:
      IOException
    • exportPng

      public void exportPng(OutputStream out, double scale) throws IOException

      Writes the document as a PNG.

      Parameters
      • out: the destination; not closed
      • scale: pixels per document unit
      Throws:
      IOException
    • exportNative

      public void exportNative(OutputStream out) throws IOException

      Writes the document losslessly as .cn1gfx.

      Parameters
      • out: the destination; not closed
      Throws:
      IOException
    • artChanged

      public void artChanged(ArtModel m, boolean contentChanged)
      Description copied from interface: ArtListener

      Called after the change, on the thread that made it.

      Parameters
      • model: the model
      • contentChanged: false when only the selection changed
      Specified by:
      artChanged in interface ArtListener