Package kiyut.sketsa.canvas
Class CanvasSelection
- java.lang.Object
-
- kiyut.sketsa.canvas.CanvasSelection
-
public class CanvasSelection extends Object
This class represents the current state of the canvas selection. The default insets and handles are 6px. The default stroke is dashed- Author:
- KIYUT
-
-
Constructor Summary
Constructors Constructor Description CanvasSelection()Creates a new instance of SelectionModel
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddSelectionListener(CanvasSelectionListener listener)Add CanvasSelectionListener for notification of any changes to the CanvasSelection.voidclearSelection()clear the selection only, it doesn't change the DOM / documentMap<String,Rectangle2D>getBorder()Return selection border in the form of phone keypad format.Rectangle2DgetSelectionBounds2D()Return Rectangle2D of selection bounds.Rectangle2DgetSelectionBounds2D(boolean includeInsets)Deprecated.not to be used anymore, use #getSelectionBounds2D() instead.List<org.w3c.dom.svg.SVGElement>getSelectionList()Return selection listSelectionToolgetSelectionTool()StrokegetStroke()Return stroke.PaintgetStrokePaint()Return stroke paint used.VectorCanvasgetVectorCanvas()Return theVectorCanvasthat this associated with.booleanisBoundsVisible()Determines if the selection bounds is currently visible.booleanisEnabled()Return true if enabled otherwise falsebooleanisHandlessVisible()Determines if the selection handles is currently visible.voidkeyPressed(KeyEvent evt)Invoked when a key has been pressed.voidkeyReleased(KeyEvent evt)Invoked when a key has been released.voidkeyTyped(KeyEvent evt)Invoked when a key has been typed.voidmouseClicked(MouseEvent evt)Invoked when the mouse button has been clicked (pressed and released) on a component.voidmouseDragged(MouseEvent evt)Invoked when a mouse button is pressed on a component and then dragged.voidmouseEntered(MouseEvent evt)Invoked when the mouse enters a component.voidmouseExited(MouseEvent evt)Invoked when the mouse exits a component.voidmouseMoved(MouseEvent evt)Invoked when the mouse cursor has been moved onto a component but no buttons have been pushed.voidmousePressed(MouseEvent evt)Invoked when a mouse button has been pressed on a component.voidmouseReleased(MouseEvent evt)Invoked when a mouse button has been released on a component.voidpaint(Graphics2D g2d)Paint this CanvasSelectionvoidremoveSelectionListener(CanvasSelectionListener listener)Remove CanvasSelectionListener for notification of any changes to the CanvasSelection.protected voidresetBorder()Reset the Border and Handle to default or initial locationvoidsetBoundsVisible(boolean boundsVisible)Set the visibility of selection boundsvoidsetEnabled(boolean enabled)Sets whether or not this CanvasSelection is enabled.voidsetEnabledVisible(boolean enabled, boolean visible)Deprecated.replaced bysetEnabledVisible(boolean,boolean,boolean)voidsetEnabledVisible(boolean enabled, boolean boundsVisible, boolean handleVisible)Convenience method to set enabled, boundsVisible, handleVisible in one method callvoidsetHandlesVisible(boolean handlesVisible)set the visibility of selection handlesvoidsetSelectionList(List<org.w3c.dom.svg.SVGElement> selectionList)Set the selectionList.voidsetSelectionTool(SelectionTool tool)Set theSelectionToolto be used asSelectionToolvoidsetVectorCanvas(VectorCanvas canvas)Sets the canvas associated with this CanvasSelection.voidsetVisible(boolean boundsVisible, boolean handleVisible)Convenience method to set boundsVisible, handleVisible in one method callvoidupdateBorder()Update the selection borderprotected voidupdateCanvasTool(Tool tool)
-
-
-
Method Detail
-
paint
public void paint(Graphics2D g2d)
Paint this CanvasSelection- Parameters:
g2d- Graphics2D
-
setVectorCanvas
public void setVectorCanvas(VectorCanvas canvas)
Sets the canvas associated with this CanvasSelection.- Parameters:
canvas- theVectorCanvas
-
getVectorCanvas
public VectorCanvas getVectorCanvas()
Return theVectorCanvasthat this associated with.- Returns:
VectorCanvas- See Also:
setVectorCanvas(VectorCanvas)
-
setSelectionTool
public void setSelectionTool(SelectionTool tool)
Set theSelectionToolto be used asSelectionTool- Parameters:
tool-SelectionTool
-
getSelectionTool
public SelectionTool getSelectionTool()
-
getStrokePaint
public Paint getStrokePaint()
Return stroke paint used. The value returned is same with the preferences- Returns:
- stroke Paint
- See Also:
getStroke()
-
getStroke
public Stroke getStroke()
Return stroke. The value returned is same with the preferences- Returns:
Stroke- See Also:
getStrokePaint()
-
addSelectionListener
public void addSelectionListener(CanvasSelectionListener listener)
Add CanvasSelectionListener for notification of any changes to the CanvasSelection.- Parameters:
listener- Listener to be added
-
removeSelectionListener
public void removeSelectionListener(CanvasSelectionListener listener)
Remove CanvasSelectionListener for notification of any changes to the CanvasSelection.- Parameters:
listener- Listener to be removed
-
clearSelection
public void clearSelection()
clear the selection only, it doesn't change the DOM / document
-
resetBorder
protected void resetBorder()
Reset the Border and Handle to default or initial location
-
setBoundsVisible
public void setBoundsVisible(boolean boundsVisible)
Set the visibility of selection bounds- Parameters:
boundsVisible- true or false
-
isBoundsVisible
public boolean isBoundsVisible()
Determines if the selection bounds is currently visible.- Returns:
- true or false
-
setHandlesVisible
public void setHandlesVisible(boolean handlesVisible)
set the visibility of selection handles- Parameters:
handlesVisible- true or false
-
isHandlessVisible
public boolean isHandlessVisible()
Determines if the selection handles is currently visible.- Returns:
- true or false
-
setEnabled
public void setEnabled(boolean enabled)
Sets whether or not this CanvasSelection is enabled. If enabled is false, it does not respond to user input eg: mouse and keyboard event- Parameters:
enabled- true or false
-
isEnabled
public boolean isEnabled()
Return true if enabled otherwise false- Returns:
- true if enabled otherwise false
-
setEnabledVisible
@Deprecated public void setEnabledVisible(boolean enabled, boolean visible)
Deprecated.replaced bysetEnabledVisible(boolean,boolean,boolean)- Parameters:
enabled- true or falsevisible- true or false- See Also:
setEnabledVisible(boolean,boolean,boolean)
-
setEnabledVisible
public void setEnabledVisible(boolean enabled, boolean boundsVisible, boolean handleVisible)Convenience method to set enabled, boundsVisible, handleVisible in one method call- Parameters:
enabled- true or falseboundsVisible- true or falsehandleVisible- true or false
-
setVisible
public void setVisible(boolean boundsVisible, boolean handleVisible)Convenience method to set boundsVisible, handleVisible in one method call- Parameters:
boundsVisible- true or falsehandleVisible- true or false
-
getSelectionList
public List<org.w3c.dom.svg.SVGElement> getSelectionList()
Return selection list- Returns:
- selection list
-
setSelectionList
public void setSelectionList(List<org.w3c.dom.svg.SVGElement> selectionList)
Set the selectionList. If selectionList is null, this has the same effect as invoking clearSelection.- Parameters:
selectionList- List of SVGElement- See Also:
clearSelection()
-
getBorder
public Map<String,Rectangle2D> getBorder()
Return selection border in the form of phone keypad format.
[1 2 3]
[4 5 6]
[7 8 9]
- key 0 as the bounds
- 1 as top left handle or North West
- 9 as bottom right handle or South East- Returns:
- border
-
getSelectionBounds2D
public Rectangle2D getSelectionBounds2D()
Return Rectangle2D of selection bounds.- Returns:
- Rectangle2D of selection bounds
-
getSelectionBounds2D
@Deprecated public Rectangle2D getSelectionBounds2D(boolean includeInsets)
Deprecated.not to be used anymore, use #getSelectionBounds2D() instead. no more insetsReturn Rectangle2D of selection bounds include inset or not- Parameters:
includeInsets- true or false- Returns:
- Rectangle2D of selection bounds
-
updateBorder
public void updateBorder()
Update the selection border
-
updateCanvasTool
protected void updateCanvasTool(Tool tool)
-
keyPressed
public void keyPressed(KeyEvent evt)
Invoked when a key has been pressed. See the class description forKeyEventfor a definition of a key pressed event.- Parameters:
evt- the KeyEvent- See Also:
KeyListener.keyPressed(java.awt.event.KeyEvent)
-
keyReleased
public void keyReleased(KeyEvent evt)
Invoked when a key has been released. See the class description forKeyEventfor a definition of a key released event.- Parameters:
evt- the KeyEvent- See Also:
KeyListener.keyReleased(java.awt.event.KeyEvent)
-
keyTyped
public void keyTyped(KeyEvent evt)
Invoked when a key has been typed. See the class description forKeyEventfor a definition of a key typed event.- Parameters:
evt- the KeyEvent- See Also:
KeyListener.keyTyped(java.awt.event.KeyEvent)
-
mouseClicked
public void mouseClicked(MouseEvent evt)
Invoked when the mouse button has been clicked (pressed and released) on a component.- Parameters:
evt- the MouseEvent- See Also:
MouseListener.mouseClicked(java.awt.event.MouseEvent)
-
mouseDragged
public void mouseDragged(MouseEvent evt)
Invoked when a mouse button is pressed on a component and then dragged.- Parameters:
evt- the MouseEvent- See Also:
MouseMotionListener.mouseDragged(java.awt.event.MouseEvent)
-
mouseEntered
public void mouseEntered(MouseEvent evt)
Invoked when the mouse enters a component.- Parameters:
evt- the MouseEvent- See Also:
MouseListener.mouseEntered(java.awt.event.MouseEvent)
-
mouseExited
public void mouseExited(MouseEvent evt)
Invoked when the mouse exits a component.- Parameters:
evt- the MouseEvent- See Also:
MouseListener.mouseExited(java.awt.event.MouseEvent)
-
mouseMoved
public void mouseMoved(MouseEvent evt)
Invoked when the mouse cursor has been moved onto a component but no buttons have been pushed.- Parameters:
evt- the MouseEvent- See Also:
MouseMotionListener.mouseMoved(java.awt.event.MouseEvent)
-
mousePressed
public void mousePressed(MouseEvent evt)
Invoked when a mouse button has been pressed on a component.- Parameters:
evt- the MouseEvent- See Also:
MouseListener.mousePressed(java.awt.event.MouseEvent)
-
mouseReleased
public void mouseReleased(MouseEvent evt)
Invoked when a mouse button has been released on a component.- Parameters:
evt- the MouseEvent- See Also:
MouseListener.mouseReleased(java.awt.event.MouseEvent)
-
-