Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public class ArtEditor

  1. Object
  2. Component
  3. Container
  4. ArtEditor

ImplementsAnimation, ArtListener, Editable, Iterable<Component>, StyleListener

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();

Fields

public static final int TOOL_SELECT = 0Selects, moves and resizes nodes.
public static final int TOOL_PAN = 1Drags the view.
public static final int TOOL_RECTANGLE = 2Draws rectangles.
public static final int TOOL_ELLIPSE = 3Draws ellipses.
public static final int TOOL_LINE = 4Draws straight lines.
public static final int TOOL_PEN = 5Draws Bezier paths: tap to add a corner, drag to add a smooth point, tap the first point to close.
public static final int TOOL_FREEHAND = 6Draws smoothed freehand strokes.
public static final int TOOL_BRUSH = 7Paints pixels onto the selected pixel layer, or a new one.
public static final int TOOL_ERASER = 8Erases pixels from the selected pixel layer.
public static final int TOOL_TEXT = 9Places text.
public static final int TOOL_EYEDROPPER = 10Picks the color under the pointer as the fill color.
public static final int TOOL_FILL = 11Fills a shape, or a region of similar pixels, with the fill color.

Constructors

public ArtEditor()Creates an editor of an empty document.
public ArtEditor(ArtModel model)Creates an editor.

Methods

protected void initComponent()Allows subclasses to bind functionality that relies on fully initialized and “ready for action” component state
protected void deinitialize()Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy.
public ArtModel getModel()The model.
public ArtView getView()The view.
public Container getLayersPanel()The layers panel: the node tree, with visibility, order and selection.
public Container getInspector()The inspector: the selected node’s properties and effects.
public void setPanelsVisible(boolean show)Shows or hides the side panel holding the layers and the inspector.
public int getTool()The current tool, one of the TOOL_ constants.
public void setTool(int t)Picks a tool.
public int getFillColor()The color new shapes, text and the brush use.
public void setFillColor(int argb)Sets the fill color.
public int getStrokeColor()The outline color for lines, paths and freehand strokes.
public void setStrokeColor(int argb)Sets the outline color.
public void setStrokeWidth(float w)Sets the outline width in document units.
public void setBrushSize(float size)Sets the brush and eraser diameter in document units.
public void exportSvg(OutputStream out) throws IOExceptionWrites the document as SVG.
public void exportPsd(OutputStream out) throws IOExceptionWrites the document as a layered PSD.
public void exportPng(OutputStream out, double scale) throws IOExceptionWrites the document as a PNG.
public void exportNative(OutputStream out) throws IOExceptionWrites the document losslessly as .cn1gfx.
public void artChanged(ArtModel m, boolean contentChanged)Called after the change, on the thread that made it.

Inherited fields

Inherited methods

From Container

encloseIn, encloseIn, initLaf, getUIManager, setUIManager, isSurface, add, addAll, add, add, add, add, add, getLeadComponent, setLeadComponent, getLeadParent, keyPressed, keyReleased, getLayout, setLayout, invalidate, setShouldLayout, setShouldCalcPreferredSize, getLayoutWidth, getLayoutHeight, applyRTL, constrainWidthWhenScrollable, constrainHeightWhenScrollable, addComponent, addComponent, addComponent, addComponent, replaceAndWait, replaceAndWait, replace, replaceAndWait, replace, createReplaceTransition, isEnabled, setEnabled, removeComponent, cancelRepaints, flushReplace, removeAll, revalidateWithAnimationSafety, revalidate, revalidateLater, forceRevalidate, clearClientProperties, paint, paintGlass, layoutContainer, isSafeArea, setSafeArea, isSafeAreaRoot, getSafeAreaRoot, setSafeAreaRoot, getComponentCount, getComponentAt, getComponentIndex, contains, scrollComponentToVisible, getClosestComponentTo, getResponderAt, getComponentAt, findDropTargetAt, pointerPressed, calcPreferredSize, paramString, refreshTheme, isScrollableX, setScrollableX, isScrollableY, setScrollableY, getSideGap, getBottomGap, setScrollable, setCellRenderer, getScrollIncrement, setScrollIncrement, findFirstFocusable, dragInitiated, fireClicked, isSelectableInteraction, getGridPosY, paintComponentBackground, getGridPosX, animateHierarchyAndWait, createAnimateHierarchy, animateHierarchy, animateHierarchyFadeAndWait, createAnimateHierarchyFade, animateHierarchyFade, animateLayoutFadeAndWait, createAnimateLayoutFadeAndWait, animateLayoutFade, createAnimateLayoutFade, animateLayoutAndWait, animateLayout, updateTabIndices, createAnimateLayout, drop, createAnimateMotion, morph, morphAndWait, animateUnlayout, animateUnlayoutAndWait, createAnimateUnlayout, getChildrenAsList, iterator, iterator

From Component

setSameSize, isSetCursorSupported, parsePreferredSize, getDefaultDragTransparency, setDefaultDragTransparency, getEditingDelegate, setEditingDelegate, getCursor, setCursor, showNativeOverlay, hideNativeOverlay, updateNativeOverlay, getNativeOverlay, getAllStyles, getSameWidth, setSameWidth, getSameHeight, setSameHeight, getX, setX, getOuterX, getInnerX, getY, setY, getOuterY, getInnerY, isVisible, setVisible, getClientProperty, stripMarginAndPadding, putClientProperty, getDirtyRegion, setDirtyRegion, isOpaque, setOpaque, getWidth, setWidth, getOuterWidth, getInnerWidth, getHeight, setHeight, getOuterHeight, getInnerHeight, isDragRegion, getDragRegionStatus, getBaseline, getBaselineResizeBehavior, getPreferredSizeStr, setPreferredSizeStr, getPreferredSize, setPreferredSize, getScrollDimension, calcScrollSize, setScrollSize, getPreferredW, setPreferredW, getPreferredH, setPreferredH, getOuterPreferredH, getInnerPreferredH, getOuterPreferredW, getInnerPreferredW, setSize, getUIID, setUIID, setUIIDFinal, setUIID, getInlineAllStyles, setInlineAllStyles, getInlineSelectedStyles, setInlineSelectedStyles, getInlineUnselectedStyles, setInlineUnselectedStyles, getInlineDisabledStyles, setInlineDisabledStyles, getInlinePressedStyles, setInlinePressedStyles, remove, getParent, getOwner, setOwner, isOwnedBy, containsOrOwns, addFocusListener, removeFocusListener, addScrollListener, removeScrollListener, getSelectCommandText, setSelectCommandText, getLabelForComponent, setLabelForComponent, focusGained, focusLost, paintBackgrounds, paintShadows, getAbsoluteX, getAbsoluteY, isInClippingRegion, paintIntersectingComponentsAbove, paintScrollbars, paintScrollbarX, getScrollOpacity, getSelectedRect, paintScrollbarY, paintComponent, paintComponent, getBorder, getScrollable, paintBackground, isScrollable, getScrollX, setScrollX, getScrollY, setScrollY, onScrollX, onScrollY, getDraggedx, getDraggedy, contains, visibleBoundsContains, hasFixedPreferredSize, getBounds, getBounds, getVisibleBounds, getVisibleBounds, isFocusable, setFocusable, onSetFocusable, resetFocusable, getTabIndex, setTabIndex, getPreferredTabIndex, setPreferredTabIndex, isTraversable, setTraversable, handlesInput, setHandlesInput, consumesRawTextInput, hasFocus, setFocus, getComponentForm, getTopLevelContainer, repaint, repaint, longKeyPress, keyRepeated, registerForAnimation, deregisterFromAnimation, getAnimationManager, getScrollAnimationSpeed, setScrollAnimationSpeed, isBlockLead, setBlockLead, isIgnorePointerEvents, setIgnorePointerEvents, isRippleEffect, setRippleEffect, getInlineStylesTheme, setInlineStylesTheme, shouldRenderComponentSelection, isHideInLandscape, setHideInLandscape, createStyleAnimation, isSmoothScrolling, setSmoothScrolling, pointerHover, stopScrollMomentum, pointerHoverReleased, pointerHoverPressed, pinch, pinchReleased, pinch, rotation, isPinchBlocksDragAndDrop, setPinchBlocksDragAndDrop, pointerDragged, getDragImage, getDragTransparency, setDragTransparency, toImage, drawDraggedImage, draggingOver, dragEnter, dragExit, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, pointerDragged, isStickyDrag, pointerPressed, isDragAndDropOperation, pointerReleased, longPointerPress, pointerReleased, setVerticalScrollBounds, setHorizontalScrollBounds, isVScrollThumbGrabbed, isHScrollThumbGrabbed, isVScrollThumbHover, isHScrollThumbHover, isTensileDragEnabled, setTensileDragEnabled, getTextSelectionSupport, addDropListener, removeDropListener, addDragOverListener, removeDragOverListener, isNativeDragSource, setNativeDragSource, getNativeDragOperation, setNativeDragOperation, createNativeDragOperation, isNativeDropTarget, setNativeDropTarget, getAcceptedDropMimeTypes, setAcceptedDropMimeTypes, getAcceptedDropActions, setAcceptedDropActions, canAcceptNativeDrop, nativeDragEnter, nativeDragOver, nativeDragExit, nativeDrop, addNativeDropListener, removeNativeDropListener, addNativeDragOverListener, removeNativeDragOverListener, dragFinished, addDragFinishedListener, addStateChangeListener, removeStateChangeListener, addPointerPressedListener, addLongPressListener, addContextMenuListener, removeContextMenuListener, addMouseWheelListener, removeMouseWheelListener, addStylusListener, removeStylusListener, getContextMenuCommands, setContextMenuCommands, mouseWheel, paintRippleOverlay, removePointerPressedListener, removeLongPressListener, removeDragFinishedListener, addPointerReleasedListener, removePointerReleasedListener, addPointerDraggedListener, removePointerDraggedListener, getDragSpeed, getStyle, getPressedStyle, getHoverStyle, setHoverStyle, isHovered, setHovered, setPressedStyle, initUnselectedStyle, initPressedStyle, initDisabledStyle, initSelectedStyle, getUnselectedStyle, setUnselectedStyle, getSelectedStyle, setSelectedStyle, getDisabledStyle, setDisabledStyle, installDefaultPainter, requestFocus, toString, refreshTheme, refreshTheme, isDragActivated, animate, scrollRectToVisible, scrollRectToVisible, paintBorder, paintBorderBackground, isCellRenderer, isScrollVisible, setScrollVisible, setIsScrollVisible, startEditingAsync, stopEditing, isEditing, isEditable, laidOut, isInitialized, setInitialized, styleChanged, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, getName, setName, initCustomStyle, deinitializeCustomStyle, isRTL, setRTL, isTactileTouch, isTactileTouch, setTactileTouch, getPropertyNames, getPropertyTypes, getPropertyTypeNames, getPropertyValue, setPropertyValue, paintLockRelease, paintLock, isSnapToGrid, setSnapToGrid, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, blocksSideSwipe, isFlatten, setFlatten, getTensileLength, setTensileLength, isGrabsPointerEvents, setGrabsPointerEvents, getScrollOpacityChangeSpeed, setScrollOpacityChangeSpeed, growShrink, isAlwaysTensile, setAlwaysTensile, isDraggable, setDraggable, isDropTarget, setDropTarget, isChildOf, isHideInPortrait, setHideInPortrait, getBindablePropertyNames, getBindablePropertyTypes, bindProperty, unbindProperty, getBoundPropertyValue, setBoundPropertyValue, getCloudBoundProperty, setCloudBoundProperty, getCloudDestinationProperty, setCloudDestinationProperty, getComponentState, setComponentState, setHidden, isHidden, setHidden, isHidden, announceForAccessibility, getAccessibilityText, setAccessibilityText, getSemantics, getAccessibilityNode, accessibilityChanged, accessibilityChanged, getTooltip, setTooltip

Field details

TOOL_SELECT

public static final int TOOL_SELECT = 0
Selects, moves and resizes nodes.

TOOL_PAN

public static final int TOOL_PAN = 1
Drags the view.

TOOL_RECTANGLE

public static final int TOOL_RECTANGLE = 2
Draws rectangles.

TOOL_ELLIPSE

public static final int TOOL_ELLIPSE = 3
Draws ellipses.

TOOL_LINE

public static final int TOOL_LINE = 4
Draws straight lines.

TOOL_PEN

public static final int TOOL_PEN = 5
Draws Bezier paths: tap to add a corner, drag to add a smooth point, tap the first point to close.

TOOL_FREEHAND

public static final int TOOL_FREEHAND = 6
Draws smoothed freehand strokes.

TOOL_BRUSH

public static final int TOOL_BRUSH = 7
Paints pixels onto the selected pixel layer, or a new one.

TOOL_ERASER

public static final int TOOL_ERASER = 8
Erases pixels from the selected pixel layer.

TOOL_TEXT

public static final int TOOL_TEXT = 9
Places text.

TOOL_EYEDROPPER

public static final int TOOL_EYEDROPPER = 10
Picks the color under the pointer as the fill color.

TOOL_FILL

public static final int TOOL_FILL = 11
Fills a shape, or a region of similar pixels, with the fill color.

Constructor details

ArtEditor

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

ArtEditor

public ArtEditor(ArtModel model)
Creates an editor.

Parameters

model ArtModel
the model to edit

Method details

initComponent

protected void initComponent()
Allows subclasses to bind functionality that relies on fully initialized and “ready for action” component state

deinitialize

protected void deinitialize()
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.

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 boolean
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 int
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 int
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 int
the color

setStrokeWidth

public void setStrokeWidth(float w)
Sets the outline width in document units.

Parameters

w float
the width

setBrushSize

public void setBrushSize(float size)
Sets the brush and eraser diameter in document units.

Parameters

size float
the diameter

exportSvg

public void exportSvg(OutputStream out) throws IOException
Writes the document as SVG.

Parameters

out OutputStream
the destination; not closed

exportPsd

public void exportPsd(OutputStream out) throws IOException
Writes the document as a layered PSD.

Parameters

out OutputStream
the destination; not closed

exportPng

public void exportPng(OutputStream out, double scale) throws IOException
Writes the document as a PNG.

Parameters

out OutputStream
the destination; not closed
scale double
pixels per document unit

exportNative

public void exportNative(OutputStream out) throws IOException
Writes the document losslessly as .cn1gfx.

Parameters

out OutputStream
the destination; not closed

artChanged

public void artChanged(ArtModel m, boolean contentChanged)
Called after the change, on the thread that made it.

Parameters

m ArtModel
the model
contentChanged boolean
false when only the selection changed