Class ArtEditor
- All Implemented Interfaces:
ArtListener, Animation, Editable, StyleListener, Iterable<Component>
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intPaints pixels onto the selected pixel layer, or a new one.static final intDraws ellipses.static final intErases pixels from the selected pixel layer.static final intPicks the color under the pointer as the fill color.static final intFills a shape, or a region of similar pixels, with the fill color.static final intDraws smoothed freehand strokes.static final intDraws straight lines.static final intDrags the view.static final intDraws Bezier paths: tap to add a corner, drag to add a smooth point, tap the first point to close.static final intDraws rectangles.static final intSelects, moves and resizes nodes.static final intPlaces text.Fields inherited from class Component
BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidartChanged(ArtModel m, boolean contentChanged) Called after the change, on the thread that made it.protected voidInvoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy.voidexportNative(OutputStream out) Writes the document losslessly as.cn1gfx.voidexportPng(OutputStream out, double scale) Writes the document as a PNG.voidexportPsd(OutputStream out) Writes the document as a layered PSD.voidexportSvg(OutputStream out) Writes the document as SVG.intThe color new shapes, text and the brush use.The inspector: the selected node's properties and effects.The layers panel: the node tree, with visibility, order and selection.getModel()The model.intThe outline color for lines, paths and freehand strokes.intgetTool()The current tool, one of theTOOL_constants.getView()The view.protected voidAllows subclasses to bind functionality that relies on fully initialized and "ready for action" component statevoidsetBrushSize(float size) Sets the brush and eraser diameter in document units.voidsetFillColor(int argb) Sets the fill color.voidsetPanelsVisible(boolean show) Shows or hides the side panel holding the layers and the inspector.voidsetStrokeColor(int argb) Sets the outline color.voidsetStrokeWidth(float w) Sets the outline width in document units.voidsetTool(int t) Picks a tool.Methods inherited from class Container
add, add, add, add, add, add, addAll, addComponent, addComponent, addComponent, addComponent, animateHierarchy, animateHierarchyAndWait, animateHierarchyFade, animateHierarchyFadeAndWait, animateLayout, animateLayoutAndWait, animateLayoutFade, animateLayoutFadeAndWait, animateUnlayout, animateUnlayoutAndWait, applyRTL, calcPreferredSize, cancelRepaints, clearClientProperties, constrainHeightWhenScrollable, constrainWidthWhenScrollable, contains, createAnimateHierarchy, createAnimateHierarchyFade, createAnimateLayout, createAnimateLayoutFade, createAnimateLayoutFadeAndWait, createAnimateMotion, createAnimateUnlayout, createReplaceTransition, dragInitiated, drop, encloseIn, encloseIn, findDropTargetAt, findFirstFocusable, fireClicked, flushReplace, forceRevalidate, getBottomGap, getChildrenAsList, getClosestComponentTo, getComponentAt, getComponentAt, getComponentCount, getComponentIndex, getGridPosX, getGridPosY, getLayout, getLayoutHeight, getLayoutWidth, getLeadComponent, getLeadParent, getResponderAt, getSafeAreaRoot, getScrollIncrement, getSideGap, getUIManager, initLaf, invalidate, isEnabled, isSafeArea, isSafeAreaRoot, isScrollableX, isScrollableY, isSelectableInteraction, isSurface, iterator, iterator, keyPressed, keyReleased, layoutContainer, morph, morphAndWait, paint, paintComponentBackground, paintGlass, paramString, pointerPressed, refreshTheme, removeAll, removeComponent, replace, replace, replaceAndWait, replaceAndWait, replaceAndWait, revalidate, revalidateLater, revalidateWithAnimationSafety, scrollComponentToVisible, setCellRenderer, setEnabled, setLayout, setLeadComponent, setSafeArea, setSafeAreaRoot, setScrollable, setScrollableX, setScrollableY, setScrollIncrement, setShouldCalcPreferredSize, setShouldLayout, setUIManager, updateTabIndicesMethods inherited from class Component
accessibilityChanged, accessibilityChanged, addContextMenuListener, addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addMouseWheelListener, addNativeDragOverListener, addNativeDropListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, addStylusListener, animate, announceForAccessibility, bindProperty, blocksSideSwipe, calcScrollSize, canAcceptNativeDrop, consumesRawTextInput, contains, containsOrOwns, createNativeDragOperation, createStyleAnimation, deinitializeCustomStyle, deregisterFromAnimation, dragEnter, dragExit, dragFinished, draggingOver, drawDraggedImage, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAcceptedDropActions, getAcceptedDropMimeTypes, getAccessibilityNode, getAccessibilityText, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getContextMenuCommands, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getHeight, getHoverStyle, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeDragOperation, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getSemantics, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getTopLevelContainer, getUIID, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initCustomStyle, initDisabledStyle, initPressedStyle, initSelectedStyle, initUnselectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditable, isEditing, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isHovered, isHScrollThumbGrabbed, isHScrollThumbHover, isIgnorePointerEvents, isInClippingRegion, isInitialized, isNativeDragSource, isNativeDropTarget, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollVisible, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, isVScrollThumbGrabbed, isVScrollThumbHover, keyRepeated, laidOut, longKeyPress, longPointerPress, mouseWheel, nativeDragEnter, nativeDragExit, nativeDragOver, nativeDrop, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerDragged, pointerHover, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, pointerReleased, putClientProperty, refreshTheme, refreshTheme, registerForAnimation, remove, removeContextMenuListener, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removeMouseWheelListener, removeNativeDragOverListener, removeNativeDropListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, removeStylusListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, rotation, scrollRectToVisible, scrollRectToVisible, setAcceptedDropActions, setAcceptedDropMimeTypes, setAccessibilityText, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setContextMenuCommands, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setHorizontalScrollBounds, setHovered, setHoverStyle, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNativeDragOperation, setNativeDragSource, setNativeDropTarget, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setPropertyValue, setPullToRefresh, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIID, setUIIDFinal, setUnselectedStyle, setVerticalScrollBounds, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stopScrollMomentum, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContainsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
TOOL_SELECT
public static final int TOOL_SELECTSelects, moves and resizes nodes.- See Also:
-
TOOL_PAN
public static final int TOOL_PANDrags the view.- See Also:
-
TOOL_RECTANGLE
public static final int TOOL_RECTANGLEDraws rectangles.- See Also:
-
TOOL_ELLIPSE
public static final int TOOL_ELLIPSEDraws ellipses.- See Also:
-
TOOL_LINE
public static final int TOOL_LINEDraws straight lines.- See Also:
-
TOOL_PEN
public static final int TOOL_PENDraws 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_FREEHANDDraws smoothed freehand strokes.- See Also:
-
TOOL_BRUSH
public static final int TOOL_BRUSHPaints pixels onto the selected pixel layer, or a new one.- See Also:
-
TOOL_ERASER
public static final int TOOL_ERASERErases pixels from the selected pixel layer.- See Also:
-
TOOL_TEXT
public static final int TOOL_TEXTPlaces text.- See Also:
-
TOOL_EYEDROPPER
public static final int TOOL_EYEDROPPERPicks the color under the pointer as the fill color.- See Also:
-
TOOL_FILL
public static final int TOOL_FILLFills 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
Creates an editor.
Parameters
model: the model to edit
-
-
Method Details
-
initComponent
protected void initComponent()Description copied from class:ComponentAllows subclasses to bind functionality that relies on fully initialized and "ready for action" component state- Overrides:
initComponentin classComponent
-
deinitialize
protected void deinitialize()Description copied from class:ComponentInvoked 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:
deinitializein classComponent
-
getModel
The model. -
getView
The view. -
getLayersPanel
The layers panel: the node tree, with visibility, order and selection. -
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 theTOOL_constants. -
setTool
public void setTool(int t) Picks a tool.
Parameters
t: one of theTOOL_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
Writes the document as SVG.
Parameters
out: the destination; not closed
- Throws:
IOException
-
exportPsd
Writes the document as a layered PSD.
Parameters
out: the destination; not closed
- Throws:
IOException
-
exportPng
Writes the document as a PNG.
Parameters
out: the destination; not closedscale: pixels per document unit
- Throws:
IOException
-
exportNative
Writes the document losslessly as
.cn1gfx.Parameters
out: the destination; not closed
- Throws:
IOException
-
artChanged
Description copied from interface:ArtListenerCalled after the change, on the thread that made it.
Parameters
model: the modelcontentChanged: false when only the selection changed
- Specified by:
artChangedin interfaceArtListener
-