Class PHtmlView

java.lang.Object
edu.umd.cs.piccolo.PNode
edu.umd.cs.piccolo.nodes.PHtmlView
All Implemented Interfaces:
Printable, Serializable, Cloneable

public class PHtmlView extends PNode
PHtmlView is a Piccolo node for rendering HTML text. It uses a JLabel under the hood so you have the same restrictions regarding HTML as you have when using standard Swing components (HTML 3.2 + subset of CSS 1.0).
Since:
1.3
Author:
Chris Malley (cmal...@pixelzoom.com), Sam Reid, Allain Lalonde
See Also:
  • Field Details

    • DEFAULT_FONT

      public static final Font DEFAULT_FONT
      Default font if not otherwise specified in the HTML text, 12 point "SansSerif".
    • DEFAULT_TEXT_COLOR

      public static final Color DEFAULT_TEXT_COLOR
      Default text color if not otherwise specified in the HTML text, Color.BLACK.
    • PROPERTY_FONT

      public static final String PROPERTY_FONT
      The property name that identifies a change of this node's font (see getFont). Both old and new value will be set in any property change event.
      See Also:
    • PROPERTY_CODE_FONT

      public static final int PROPERTY_CODE_FONT
      The property code that identifies a change of this node's font (see getFont). Both old and new value will be set in any property change event.
      See Also:
    • PROPERTY_TEXT

      public static final String PROPERTY_TEXT
      The property name that identifies a change of this node's HTML text (see getText). Both old and new value will be set in any property change event.
      See Also:
    • PROPERTY_CODE_TEXT

      public static final int PROPERTY_CODE_TEXT
      The property code that identifies a change of this node's HTML text (see getText). Both old and new value will be set in any property change event.
      See Also:
    • PROPERTY_TEXT_COLOR

      public static final String PROPERTY_TEXT_COLOR
      The property name that identifies a change of this node's HTML text color (see getTextColor). Both old and new value will be set in any property change event.
      See Also:
    • PROPERTY_CODE_TEXT_COLOR

      public static final int PROPERTY_CODE_TEXT_COLOR
      The property code that identifies a change of this node's HTML text color (see getTextColor). Both old and new value will be set in any property change event.
      See Also:
  • Constructor Details

    • PHtmlView

      public PHtmlView()
      Create an empty HTML text node with the default font and text color.
    • PHtmlView

      public PHtmlView(String text)
      Create a HTML text node with the specified HTML text and the default font and text color.
      Parameters:
      text - HTML text for this HTML text node
    • PHtmlView

      public PHtmlView(String text, Font font, Color textColor)
      Create a HTML text node with the specified HTML text, font, and text color. The font and text color are used to render the HTML text if not otherwise specified via CSS.
      Parameters:
      text - HTML text for this HTML text node
      font - font for this HTML text node
      textColor - text color for this HTML text node
  • Method Details

    • getText

      public String getText()
      Return the HTML text for this HTML text node.
      Returns:
      the HTML text for this HTML text node
    • setText

      public void setText(String text)
      Set the HTML text for this HTML text node to text.

      This is a bound property.

      Parameters:
      text - HTML text for this HTML text node
    • getFont

      public Font getFont()
      Return the font for this HTML text node. This font is used to render the HTML text if not otherwise specified via CSS. Defaults to DEFAULT_FONT.
      Returns:
      the font for this HTML text node
    • setFont

      public void setFont(Font font)
      Set the font for this HTML text node to font. This font is used to render the HTML text if not otherwise specified via CSS.

      This is a bound property.

      Parameters:
      font - font for this HTML text node
    • getTextColor

      public Color getTextColor()
      Return the text color for this HTML text node. This text color is used to render the HTML text if not otherwise specified via CSS. Defaults to DEFAULT_TEXT_COLOR.
      Returns:
      the text color for this HTML text node
    • setTextColor

      public void setTextColor(Color textColor)
      Set the text color for this HTML text node to textColor. This text color is used to render the HTML text if not otherwise specified via CSS. This is a bound property.
      Parameters:
      textColor - text color for this HTML text node
    • setBounds

      public boolean setBounds(double x, double y, double width, double height)
      Set the bounds of this node to the given position and size. These bounds are stored in the local coordinate system of this node. If the width or height is less then or equal to zero then the bound's empty bit will be set to true. Subclasses must call the super.setBounds() method.
      Overrides:
      setBounds in class PNode
      Parameters:
      x - x position of bounds
      y - y position of bounds
      width - width to apply to the bounds
      height - height to apply to the bounds
      Returns:
      true if the bounds changed.
    • setBounds

      public boolean setBounds(Rectangle2D newBounds)
      Set the bounds of this node to the given value. These bounds are stored in the local coordinate system of this node.
      Overrides:
      setBounds in class PNode
      Parameters:
      newBounds - bounds to apply to this node
      Returns:
      true if the bounds changed.
    • paint

      protected void paint(PPaintContext paintContext)
      Paint this node behind any of its children nodes. Subclasses that define a different appearance should override this method and paint themselves there.

      The HTML text is painted last, so it will appear on top of any child nodes.

      Overrides:
      paint in class PNode
      Parameters:
      paintContext - the paint context to use for painting the node
    • getLinkAddressAt

      public String getLinkAddressAt(Point2D point)
      Return the address specified in the HTML link at the specified point in this node's local coordinate system, if any.
      Parameters:
      point - point in this node's local coordinate system
      Returns:
      the address specified in the HTML link at the specified point in this node's local coordinate system, or null if no such HTML link exists
    • getLinkAddressAt

      public String getLinkAddressAt(double x, double y)
      Return the address specified in the HTML link at the specified x and y coordinates in this node's local coordinate system, if any.
      Parameters:
      x - x coordinate in this node's local coordinate system
      y - y coordinate in this node's local coordinate system
      Returns:
      the address specified in the HTML link at the specified x and y coordinates in this node's local coordinate system, or null if no such HTML link exists