Class DrawGroup

All Implemented Interfaces:
HasAttachHandlers, HasHandlers, EventListener, HasVisibility, IsWidget, LogicalStructure, HasClickHandlers, HasDragMoveHandlers, HasDragResizeMoveHandlers, HasDragResizeStartHandlers, HasDragResizeStopHandlers, HasDragStartHandlers, HasDragStopHandlers, HasDrawEndHandlers, HasDrawStartHandlers, HasMouseDownHandlers, HasMouseMoveHandlers, HasMouseOutHandlers, HasMouseOverHandlers, HasMouseUpHandlers, HasMovedHandlers, HasResizedHandlers, HasShowContextMenuHandlers

public class DrawGroup extends DrawItem
DrawItem subclass to manage a group of other DrawItem instances.

A DrawGroup has no local visual representation other than that of its drawItems. Adding items to a drawGroup allows for central event handling, and allows them to be manipulated (drawn, scaled, etc) together.

DrawItems are added to a DrawGroup by creating the DrawItems with DrawItem.drawGroup set to the DrawGroup, or by creating a DrawGroup with drawItems.

DrawGroups handle events by having an explicitly specified group rectangle (see getGroupRect()). This rectangle has no visual representation within the draw pane (is not visible) but any user-interactions within the specified coordinates will trigger group level events.

DrawGroups may contain other DrawGroups.

  • Constructor Details

    • DrawGroup

      public DrawGroup()
    • DrawGroup

      public DrawGroup(JavaScriptObject jsObj)
  • Method Details

    • getOrCreateRef

      public static DrawGroup getOrCreateRef(JavaScriptObject jsObj)
    • changeAutoChildDefaults

      public static void changeAutoChildDefaults(String autoChildName, Canvas defaults)
      Changes the defaults for Canvas AutoChildren named autoChildName.
      Parameters:
      autoChildName - name of an AutoChild to customize the defaults for.
      defaults - Canvas defaults to apply. These defaults override any existing properties without destroying or wiping out non-overridden properties. For usage tips on this param, see SGWTProperties.
      See Also:
    • changeAutoChildDefaults

      public static void changeAutoChildDefaults(String autoChildName, FormItem defaults)
      Changes the defaults for FormItem AutoChildren named autoChildName.
      Parameters:
      autoChildName - name of an AutoChild to customize the defaults for.
      defaults - FormItem defaults to apply. These defaults override any existing properties without destroying or wiping out non-overridden properties. For usage tips on this param, see SGWTProperties.
      See Also:
    • changeAutoChildDefaults

      public static void changeAutoChildDefaults(String autoChildName, DrawItem defaults)
      Changes the defaults for DrawItem AutoChildren named autoChildName.
      Parameters:
      autoChildName - name of an AutoChild to customize the defaults for.
      defaults - DrawItem defaults to apply. These defaults override any existing properties without destroying or wiping out non-overridden properties. For usage tips on this param, see SGWTProperties.
      See Also:
    • create

      protected JavaScriptObject create()
      Overrides:
      create in class DrawItem
    • getGroupRectOutline

      public DrawRect getGroupRectOutline() throws IllegalStateException
      If this group is showing a KnobType.MOVE control knob, the groupRectOutline is a DrawRect AutoChild that identifies the group's group rect (see useGroupRect).

      useGroupRect must be true and the KnobType.MOVE control knob must be showing for the groupRectOutline AutoChild to be created and shown.

      This component is an AutoChild named "groupRectOutline". For an overview of how to use and configure AutoChildren, see Using AutoChildren.

      Returns:
      Current groupRectOutline value. Default value is null
      Throws:
      IllegalStateException - if this widget has not yet been rendered.
    • setHeight

      public DrawGroup setHeight(int height)
      Height of the group rectangle in pixels relative to the DrawPane (the "drawing coordinate system").

      If this method is called after the component has been drawn/initialized: Sets the height of this DrawGroup's group rectangle. Note that setting the height will not move or resize the items in this DrawGroup.
      Parameters:
      height - new height for the group rectangle. Default value is 1
      Returns:
      DrawGroup instance, for chaining setter calls
    • getHeight

      public int getHeight()
      Height of the group rectangle in pixels relative to the DrawPane (the "drawing coordinate system").
      Returns:
      Current height value. Default value is 1
    • getHeightAsDouble

      public double getHeightAsDouble()
      Height of the group rectangle in pixels relative to the DrawPane (the "drawing coordinate system").
      Returns:
      Current height value. Default value is 1
    • setKnobs

      public DrawGroup setKnobs(KnobType... knobs) throws IllegalStateException
      DrawGroup only supports the KnobType.MOVE knob type.
      Overrides:
      setKnobs in class DrawItem
      Parameters:
      knobs - New knobs value. Default value is null
      Returns:
      DrawGroup instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
      See Also:
    • getKnobs

      public KnobType[] getKnobs()
      DrawGroup only supports the KnobType.MOVE knob type.
      Overrides:
      getKnobs in class DrawItem
      Returns:
      Current knobs value. Default value is null
      See Also:
    • setLeft

      public DrawGroup setLeft(int left)
      Left coordinate of the group rectangle in pixels relative to the DrawPane (the "drawing coordinate system").

      If this method is called after the component has been drawn/initialized: Sets the left coordinate of this DrawGroup's group rectangle. Note that setting the left coordinate will not move the items in this DrawGroup.
      Parameters:
      left - new left coordinate. Default value is 0
      Returns:
      DrawGroup instance, for chaining setter calls
    • getLeft

      public int getLeft()
      Left coordinate of the group rectangle in pixels relative to the DrawPane (the "drawing coordinate system").
      Returns:
      Current left value. Default value is 0
    • getLeftAsDouble

      public double getLeftAsDouble()
      Left coordinate of the group rectangle in pixels relative to the DrawPane (the "drawing coordinate system").
      Returns:
      Current left value. Default value is 0
    • setMoveItemsWithGroup

      public DrawGroup setMoveItemsWithGroup(Boolean moveItemsWithGroup)
      Should dragging the group (when canDrag is true) or dragging the move knob also move the items within this DrawGroup?

      Note : This is an advanced setting

      Parameters:
      moveItemsWithGroup - New moveItemsWithGroup value. Default value is true
      Returns:
      DrawGroup instance, for chaining setter calls
    • getMoveItemsWithGroup

      public Boolean getMoveItemsWithGroup()
      Should dragging the group (when canDrag is true) or dragging the move knob also move the items within this DrawGroup?
      Returns:
      Current moveItemsWithGroup value. Default value is true
    • setShowGroupRectOutline

      public DrawGroup setShowGroupRectOutline(Boolean showGroupRectOutline)
      If the KnobType.MOVE control knob is shown for this group and useGroupRect is true, should the groupRectOutline be shown?

      Set to false to disable showing the groupRectOutline.

      Parameters:
      showGroupRectOutline - New showGroupRectOutline value. Default value is null
      Returns:
      DrawGroup instance, for chaining setter calls
    • getShowGroupRectOutline

      public Boolean getShowGroupRectOutline()
      If the KnobType.MOVE control knob is shown for this group and useGroupRect is true, should the groupRectOutline be shown?

      Set to false to disable showing the groupRectOutline.

      Returns:
      Current showGroupRectOutline value. Default value is null
    • setTop

      public DrawGroup setTop(int top)
      Top coordinate of the group rectangle in pixels relative to the DrawPane (the "drawing coordinate system").

      If this method is called after the component has been drawn/initialized: Sets the top coordinate of this DrawGroup's group rectangle. Note that setting the top coordinate will not move the items in this DrawGroup.
      Parameters:
      top - new top coordinate in pixels. Default value is 0
      Returns:
      DrawGroup instance, for chaining setter calls
    • getTop

      public int getTop()
      Top coordinate of the group rectangle in pixels relative to the DrawPane (the "drawing coordinate system").
      Returns:
      Current top value. Default value is 0
    • getTopAsDouble

      public double getTopAsDouble()
      Top coordinate of the group rectangle in pixels relative to the DrawPane (the "drawing coordinate system").
      Returns:
      Current top value. Default value is 0
    • setUseGroupRect

      public DrawGroup setUseGroupRect(boolean useGroupRect) throws IllegalStateException
      When should this drawGroup receive event notifications? If set to true, the developer can specify an explicit set of coordinates. Whenever the user interacts with this rectangle, the drawGroup will be notified and the appropriate event handlers will be fired. Note that rectangle need not contain all DrawItems within the group, and is manually managed by the developer.
      If set to false, the event rectangle coordinates are unused - instead as a user interacts with specific drawItems within this group, the appropriate event handler would be fired on the item, then the event would "bubble" to the drawGroup, firing the appropriate event handler at the group level as well.
      Parameters:
      useGroupRect - New useGroupRect value. Default value is false
      Returns:
      DrawGroup instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
    • getUseGroupRect

      public boolean getUseGroupRect()
      When should this drawGroup receive event notifications? If set to true, the developer can specify an explicit set of coordinates. Whenever the user interacts with this rectangle, the drawGroup will be notified and the appropriate event handlers will be fired. Note that rectangle need not contain all DrawItems within the group, and is manually managed by the developer.
      If set to false, the event rectangle coordinates are unused - instead as a user interacts with specific drawItems within this group, the appropriate event handler would be fired on the item, then the event would "bubble" to the drawGroup, firing the appropriate event handler at the group level as well.
      Returns:
      Current useGroupRect value. Default value is false
    • setWidth

      public DrawGroup setWidth(int width)
      Width of the group rectangle in pixels relative to the DrawPane (the "drawing coordinate system").

      If this method is called after the component has been drawn/initialized: Sets the width of this DrawGroup's group rectangle. Note that setting the width will not move or resize the items in this DrawGroup.
      Parameters:
      width - new width for the group rectangle. Default value is 1
      Returns:
      DrawGroup instance, for chaining setter calls
    • getWidth

      public int getWidth()
      Width of the group rectangle in pixels relative to the DrawPane (the "drawing coordinate system").
      Returns:
      Current width value. Default value is 1
    • getWidthAsDouble

      public double getWidthAsDouble()
      Width of the group rectangle in pixels relative to the DrawPane (the "drawing coordinate system").
      Returns:
      Current width value. Default value is 1
    • click

      public Boolean click()
      Notification fired when the user clicks on this DrawGroup.

      Note that if useGroupRect is true, this notification will be triggered by the user interacting with the specified group rectangle for the group. If useGroupRect is false, the notification will bubble up from interactions with individual items within the group.

      Returns:
      false to prevent this event from bubbling to this widget's parent, true or undefined to bubble.
      See Also:
    • dragMove

      public boolean dragMove()
      Notification fired for every mouseMove event triggered while the user is dragging this DrawGroup. Will only fire if canDrag is true for this group.

      Note that if useGroupRect is true, this notification will be triggered by the user interacting with the specified group rectangle for the group. If useGroupRect is false, the notification will bubble up from interactions with individual items within the group.

      Default drag behavior will be to reposition all items in the group (and update the group rectangle).

      Returns:
      false to cancel drag interaction.
      See Also:
    • dragStart

      public boolean dragStart()
      Notification fired when the user starts to drag this DrawGroup. Will only fire if canDrag is true for this group.

      Note that if useGroupRect is true, this notification will be triggered by the user interacting with the specified group rectangle for the group. If useGroupRect is false, the notification will bubble up from interactions with individual items within the group.

      Default drag behavior will be to reposition all items in the group (and update the group rectangle).

      Returns:
      false to cancel drag action.
      See Also:
    • dragStop

      public boolean dragStop()
      Notification fired when the user stops dragging this DrawGroup. Will only fire if canDrag is true for this group.

      Note that if useGroupRect is true, this notification will be triggered by the user interacting with the specified group rectangle for the group. If useGroupRect is false, the notification will bubble up from interactions with individual items within the group.

      Returns:
      false to cancel drag interaction.
      See Also:
    • erase

      public void erase()
      Erases all DrawItems in the DrawGroup.
      Overrides:
      erase in class DrawItem
    • getCenter

      public Point getCenter()
      Get the center point of the group rectangle.
      Overrides:
      getCenter in class DrawItem
      Returns:
      the center point
    • mouseDown

      public Boolean mouseDown()
      Notification fired when the user presses the left mouse button on this DrawGroup.

      Note that if useGroupRect is true, this notification will be triggered by the user interacting with the specified group rectangle for the group. If useGroupRect is false, the notification will bubble up from interactions with individual items within the group.

      Returns:
      false to prevent this event from bubbling to this widget's parent, true or undefined to bubble.
      See Also:
    • mouseMove

      public Boolean mouseMove()
      Notification fired when the user moves the mouse over this DrawGroup.

      Note that if useGroupRect is true, this notification will be triggered by the user interacting with the specified group rectangle for the group. If useGroupRect is false, the notification will bubble up from interactions with individual items within the group.

      Returns:
      false to prevent this event from bubbling to this widget's parent, true or undefined to bubble.
      See Also:
    • mouseOut

      public Boolean mouseOut()
      Notification fired when the mouse leaves this DrawGroup.

      Note that if useGroupRect is true, this notification will be triggered by the user interacting with the specified group rectangle for the group. If useGroupRect is false, the notification will bubble up from interactions with individual items within the group.

      Returns:
      false to prevent this event from bubbling to this widget's parent, true or undefined to bubble.
      See Also:
    • mouseOver

      public Boolean mouseOver()
      Notification fired when the mouse enters this DrawGroup.

      Note that if useGroupRect is true, this notification will be triggered by the user interacting with the specified group rectangle for the group. If useGroupRect is false, the notification will bubble up from interactions with individual items within the group.

      Returns:
      false to prevent this event from bubbling to this widget's parent, true or undefined to bubble.
      See Also:
    • mouseUp

      public Boolean mouseUp()
      Notification fired when the user releases the left mouse button on this DrawGroup.

      Note that if useGroupRect is true, this notification will be triggered by the user interacting with the specified group rectangle for the group. If useGroupRect is false, the notification will bubble up from interactions with individual items within the group.

      Returns:
      false to prevent this event from bubbling to this widget's parent, true or undefined to bubble.
      See Also:
    • moveBy

      public void moveBy(int dX, int dY)
      Updates the DrawGroup's left coordinate by dX and the top coordinate by dY. Note that this does not move or resize the items in this DrawGroup.
      Overrides:
      moveBy in class DrawItem
      Parameters:
      dX - change to left coordinate in pixels
      dY - change to top coordinate in pixels
    • moveTo

      public void moveTo(Integer left, Integer top)
      Sets both the left and top coordinates of this DrawGroup's group rectangle. Note that this does not move or resize the items in this DrawGroup.
      Overrides:
      moveTo in class DrawItem
      Parameters:
      left - new left coordinate in pixels
      top - new top coordinate in pixels
    • scaleBy

      public void scaleBy(float x, float y)
      Deprecated.
      Scale all drawItem[] shapes by the x, y multipliers
      Parameters:
      x - scale in the x direction
      y - scale in the y direction
    • scaleBy

      public void scaleBy(double x, double y)
      Scale all drawItem[] shapes by the x, y multipliers
      Overrides:
      scaleBy in class DrawItem
      Parameters:
      x - scale in the x direction
      y - scale in the y direction
    • scaleTo

      public void scaleTo(float x, float y)
      Deprecated.
      Scale the each item in the drawGroup by the x, y multipliers
      Parameters:
      x - scale in the x direction
      y - scale in the y direction
    • scaleTo

      public void scaleTo(double x, double y)
      Scale the each item in the drawGroup by the x, y multipliers
      Overrides:
      scaleTo in class DrawItem
      Parameters:
      x - scale in the x direction
      y - scale in the y direction
    • setDefaultProperties

      public static void setDefaultProperties(DrawGroup drawGroupProperties)
      Class level method to set the default properties of this class. If set, then all existing and subsequently created instances of this class will automatically have default properties corresponding to the properties set on the SmartGWT class instance passed to this function before its underlying SmartClient JS object was created. This is a powerful feature that eliminates the need for users to create a separate hierarchy of subclasses that only alter the default properties of this class. Can also be used for skinning / styling purposes.

      Note: This method is intended for setting default attributes only and will affect all instances of the underlying class (including those automatically generated in JavaScript). This method should not be used to apply standard EventHandlers or override methods for a class - use a custom subclass instead. Calling this method after instances have been created can result in undefined behavior, since it bypasses any setters and a class instance may have already examined a particular property and not be expecting any changes through this route.

      Parameters:
      drawGroupProperties - properties that should be used as new defaults when instances of this class are created
      See Also:
    • rotateBy

      public void rotateBy(String degrees)
      Rotate the group by degrees. This is a relative rotation based on any current rotation
      Parameters:
      degrees -
    • rotateTo

      public void rotateTo(String degrees)
      Rotate the group to degrees. This is an absolute rotation and does not consider any existing rotation
      Parameters:
      degrees -
    • setDrawItems

      public void setDrawItems(DrawItem... drawItems) throws IllegalStateException
      Initial list of DrawItems for this DrawGroup.

      DrawItems can be added to a DrawGroup after initialization by setting drawGroup.

      Parameters:
      drawItems - drawItems Default value is null
      Throws:
      IllegalStateException - this property cannot be changed after the underlying component has been created
    • getDrawItems

      public DrawItem[] getDrawItems()
      Initial list of DrawItems for this DrawGroup.

      DrawItems can be added to a DrawGroup after initialization by setting drawGroup.

      Returns:
      DrawItem
    • getGroupRect

      public Rectangle getGroupRect()
      This method will return an array of integers mapping out the coordinates (left, top, width, height) of the "group rectangle" for the group. This is the area of the drawPane where user interactions will fire event notifications on this drawGroup.

      Developers may also use left, top, width and height to manage each coordinate directly.

      Returns:
      4 element array containing left, top, width, height of the group rectangle.
    • setLogicalStructure

      public LogicalStructureObject setLogicalStructure(DrawGroupLogicalStructure s)
      Setter implementing the LogicalStructure interface, which supports Eclipse's logical structure debugging facility.
    • getLogicalStructure

      public LogicalStructureObject getLogicalStructure()
      Getter implementing the LogicalStructure interface, which supports Eclipse's logical structure debugging facility.
      Specified by:
      getLogicalStructure in interface LogicalStructure
      Overrides:
      getLogicalStructure in class DrawItem