Class DrawLabel

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 DrawLabel extends DrawItem
DrawItem subclass to render a single-line text label.
  • Constructor Details

    • DrawLabel

      public DrawLabel()
    • DrawLabel

      public DrawLabel(JavaScriptObject jsObj)
  • Method Details

    • getOrCreateRef

      public static DrawLabel 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
    • setAlignment

      public DrawLabel setAlignment(LabelAlignment alignment) throws IllegalStateException
      Sets the text alignment from the x position. Similar to HTML5 context.textAlign with alignment values such as "start", "center", and "end".

      Note that this setting is ignored for DrawItem.titleLabel autochildren, which are always considered to have "start" alignment to make handling of DrawItem.titleRotationMode simpler.

      Parameters:
      alignment - New alignment value. Default value is DrawLabel.START
      Returns:
      DrawLabel instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
    • getAlignment

      public LabelAlignment getAlignment()
      Sets the text alignment from the x position. Similar to HTML5 context.textAlign with alignment values such as "start", "center", and "end".

      Note that this setting is ignored for DrawItem.titleLabel autochildren, which are always considered to have "start" alignment to make handling of DrawItem.titleRotationMode simpler.

      Returns:
      Current alignment value. Default value is DrawLabel.START
    • setContents

      public DrawLabel setContents(String contents)
      This is the content that will exist as the label.

      If this method is called after the component has been drawn/initialized: Sets this DrawLabel's contents.
      Parameters:
      contents - the new contents. Default value is null
      Returns:
      DrawLabel instance, for chaining setter calls
      See Also:
    • getContents

      public String getContents()
      This is the content that will exist as the label.
      Returns:
      Current contents value. Default value is null
      See Also:
    • setEditProxyConstructor

      public DrawLabel setEditProxyConstructor(String editProxyConstructor) throws IllegalStateException
      Default class used to construct the EditProxy for this component when the component is first placed into edit mode.
      Overrides:
      setEditProxyConstructor in class DrawItem
      Parameters:
      editProxyConstructor - New editProxyConstructor value. Default value is "DrawLabelEditProxy"
      Returns:
      DrawLabel instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
      See Also:
    • getEditProxyConstructor

      public String getEditProxyConstructor()
      Default class used to construct the EditProxy for this component when the component is first placed into edit mode.
      Overrides:
      getEditProxyConstructor in class DrawItem
      Returns:
      Current editProxyConstructor value. Default value is "DrawLabelEditProxy"
      See Also:
    • setEscapeContents

      public DrawLabel setEscapeContents(boolean escapeContents)
      For SVG-based DrawPanes, whether to escape the specified contents of this label so that any markup syntax is rendered "as is," without being interpreted as SVG. This setting should not be customized when working with other drawingTypes, as the contents are always escaped in such case.

      In SVG, a DrawLabel's contents are rendered inside a <text> tag, so any SVG that's legal inside that tag can be set as the contents when escapeContents is false. See Mozilla SVG Developer Reference for more information about what exactly is supported.

      Note that the Framework will not be able to determine the width or height of a DrawLabel when this property is false, so the Framework will consider both dimensions to be zero, and centering will not work (e.g. for DrawItem.titleLabel autochildren). For top-level DrawLabels, you may be able to get the DOM to center your content by setting alignment as "center" - the DOM will then interpret the left, top coordinates of the label as its centerpoint even though our Framework doesn't know the label's actual size.

      For a titleLabel, the alignment setting is ignored, as the Framework always positions it using "start" alignment, but SVG code such as the following demonstrates that centering is possible (via the "style" setting):

        <tspan text-decoration='underline' font-size='20px' 
               style='dominant-baseline:central; text-anchor:middle;'>MyLabel
        </tspan>
        


      If this method is called after the component has been drawn/initialized: Sets the escapeContents property for this DrawLabel.
      Parameters:
      escapeContents - whether to escape contents. Default value is true
      Returns:
      DrawLabel instance, for chaining setter calls
      See Also:
    • getEscapeContents

      public boolean getEscapeContents()
      For SVG-based DrawPanes, whether to escape the specified contents of this label so that any markup syntax is rendered "as is," without being interpreted as SVG. This setting should not be customized when working with other drawingTypes, as the contents are always escaped in such case.

      In SVG, a DrawLabel's contents are rendered inside a <text> tag, so any SVG that's legal inside that tag can be set as the contents when escapeContents is false. See Mozilla SVG Developer Reference for more information about what exactly is supported.

      Note that the Framework will not be able to determine the width or height of a DrawLabel when this property is false, so the Framework will consider both dimensions to be zero, and centering will not work (e.g. for DrawItem.titleLabel autochildren). For top-level DrawLabels, you may be able to get the DOM to center your content by setting alignment as "center" - the DOM will then interpret the left, top coordinates of the label as its centerpoint even though our Framework doesn't know the label's actual size.

      For a titleLabel, the alignment setting is ignored, as the Framework always positions it using "start" alignment, but SVG code such as the following demonstrates that centering is possible (via the "style" setting):

        <tspan text-decoration='underline' font-size='20px' 
               style='dominant-baseline:central; text-anchor:middle;'>MyLabel
        </tspan>
        
      Returns:
      Current escapeContents value. Default value is true
      See Also:
    • setFontFamily

      public DrawLabel setFontFamily(String fontFamily) throws IllegalStateException
      Font family name, similar to the CSS font-family attribute.
      Parameters:
      fontFamily - New fontFamily value. Default value is "Tahoma"
      Returns:
      DrawLabel instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
      See Also:
    • getFontFamily

      public String getFontFamily()
      Font family name, similar to the CSS font-family attribute.
      Returns:
      Current fontFamily value. Default value is "Tahoma"
      See Also:
    • setFontSize

      public DrawLabel setFontSize(int fontSize)
      Font size in pixels, similar to the CSS font-size attribute.

      If this method is called after the component has been drawn/initialized: Sets this DrawLabel's fontSize.
      Parameters:
      fontSize - the new font size in pixels. Default value is 18
      Returns:
      DrawLabel instance, for chaining setter calls
      See Also:
    • getFontSize

      public int getFontSize()
      Font size in pixels, similar to the CSS font-size attribute.
      Returns:
      Current fontSize value. Default value is 18
      See Also:
    • setFontStyle

      public DrawLabel setFontStyle(String fontStyle) throws IllegalStateException
      Font style, similar to the CSS font-style attribute, eg "normal", "italic".
      Parameters:
      fontStyle - New fontStyle value. Default value is "normal"
      Returns:
      DrawLabel instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
      See Also:
    • getFontStyle

      public String getFontStyle()
      Font style, similar to the CSS font-style attribute, eg "normal", "italic".
      Returns:
      Current fontStyle value. Default value is "normal"
      See Also:
    • setFontWeight

      public DrawLabel setFontWeight(String fontWeight) throws IllegalStateException
      Font weight, similar to the CSS font-weight attribute, eg "normal", "bold".
      Parameters:
      fontWeight - New fontWeight value. Default value is "bold"
      Returns:
      DrawLabel instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
      See Also:
    • getFontWeight

      public String getFontWeight()
      Font weight, similar to the CSS font-weight attribute, eg "normal", "bold".
      Returns:
      Current fontWeight value. Default value is "bold"
      See Also:
    • setKnobs

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

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

      public DrawLabel setLeft(int left) throws IllegalStateException
      Sets the amount from the left of its positioning that the element should be placed.
      Parameters:
      left - New left value. Default value is 0
      Returns:
      DrawLabel instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
    • getLeft

      public int getLeft()
      Sets the amount from the left of its positioning that the element should be placed.
      Returns:
      Current left value. Default value is 0
    • getLeftAsDouble

      public double getLeftAsDouble()
      Sets the amount from the left of its positioning that the element should be placed.
      Returns:
      Current left value. Default value is 0
    • setLineColor

      public DrawLabel setLineColor(String lineColor)
      The text color of the label.

      If this method is called after the component has been drawn/initialized: Sets the text color of the label.
      Overrides:
      setLineColor in class DrawItem
      Parameters:
      lineColor - new text color. Default value is "#808080"
      Returns:
      DrawLabel instance, for chaining setter calls
      See Also:
    • getLineColor

      public String getLineColor()
      The text color of the label.
      Overrides:
      getLineColor in class DrawItem
      Returns:
      Current lineColor value. Default value is "#808080"
      See Also:
    • setRotation

      public DrawLabel setRotation(float rotation) throws IllegalStateException
      Deprecated.
      Rotation in degrees about the top left corner. The positive direction is clockwise.
      Overrides:
      setRotation in class DrawItem
      Parameters:
      rotation - New rotation value. Default value is 0.0
      Returns:
      DrawLabel instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
    • getRotation

      public float getRotation()
      Deprecated.
      Rotation in degrees about the top left corner. The positive direction is clockwise.
      Overrides:
      getRotation in class DrawItem
      Returns:
      Current rotation value. Default value is 0.0
    • setRotation

      public DrawLabel setRotation(double rotation) throws IllegalStateException
      Rotation in degrees about the top left corner. The positive direction is clockwise.
      Overrides:
      setRotation in class DrawItem
      Parameters:
      rotation - New rotation value. Default value is 0.0
      Returns:
      DrawLabel instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
    • getRotationAsDouble

      public double getRotationAsDouble()
      Rotation in degrees about the top left corner. The positive direction is clockwise.
      Overrides:
      getRotationAsDouble in class DrawItem
      Returns:
      Current rotation value. Default value is 0.0
    • setStyleName

      public void setStyleName(String styleName)
      For drawingType "svg" only, the CSS class applied to this label. Similar to Canvas.styleName. The font properties fontSize, fontWeight, fontStyle, and fontFamily, unless set to null, take priority over any CSS settings. This property can be used in combination with escapeContents if needed. but note that in SVG, the precedence of CSS and inline styling applied to an element works differently that it does in HTML. See Mozilla SVG Developer Reference

      Note that only font sizes defined in pixels are supported through this property.

      If this method is called after the component has been drawn/initialized: Sets this DrawLabel's styleName.

      Overrides:
      setStyleName in class UIObject
      Parameters:
      styleName - the new styleName. Default value is "normal"
      See Also:
    • getStyleName

      public String getStyleName()
      For drawingType "svg" only, the CSS class applied to this label. Similar to Canvas.styleName. The font properties fontSize, fontWeight, fontStyle, and fontFamily, unless set to null, take priority over any CSS settings. This property can be used in combination with escapeContents if needed. but note that in SVG, the precedence of CSS and inline styling applied to an element works differently that it does in HTML. See Mozilla SVG Developer Reference

      Note that only font sizes defined in pixels are supported through this property.

      Overrides:
      getStyleName in class UIObject
      Returns:
      Current styleName value. Default value is "normal"
      See Also:
    • setTop

      public DrawLabel setTop(int top) throws IllegalStateException
      Sets the amount from the top of its positioning that the element should be placed.
      Parameters:
      top - New top value. Default value is 0
      Returns:
      DrawLabel instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
    • getTop

      public int getTop()
      Sets the amount from the top of its positioning that the element should be placed.
      Returns:
      Current top value. Default value is 0
    • getTopAsDouble

      public double getTopAsDouble()
      Sets the amount from the top of its positioning that the element should be placed.
      Returns:
      Current top value. Default value is 0
    • getCenter

      public Point getCenter()
      Get the center point of the label.
      Overrides:
      getCenter in class DrawItem
      Returns:
      the center point
    • setDefaultProperties

      public static void setDefaultProperties(DrawLabel drawLabelProperties)
      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:
      drawLabelProperties - properties that should be used as new defaults when instances of this class are created
      See Also:
    • setAlignment

      public void setAlignment(String alignment) throws IllegalStateException
      Deprecated.
      Use the method which takes a LabelAlignment.
      Parameters:
      alignment - Default value is "start"
      Throws:
      IllegalStateException - Thrown upon attempt to change after component creation.
    • setLogicalStructure

      public LogicalStructureObject setLogicalStructure(DrawLabelLogicalStructure 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