Search this API

y.view
Class HtmlLabelConfiguration

java.lang.Object
  extended by y.view.AbstractCustomLabelPainter
      extended by y.view.HtmlLabelConfiguration
All Implemented Interfaces:
YLabel.BoundsProvider, YLabel.Layout, YLabel.Painter

public class HtmlLabelConfiguration
extends AbstractCustomLabelPainter
implements YLabel.Painter, YLabel.Layout, YLabel.BoundsProvider

Label configuration for displaying HTML formatted label text.

The configuration uses Swing components to measure and render HTML formatted text. By default, the Swing component used is a shared JLabel instance but may be changed to (possibly shared) JEditorPane instance using the configuration's single argument constructor.

The configuration provides support for hyperlink events, too.

If label text is not recognized as being HTML formatted (i.e. BasicHTML.isHTMLString(String) returns false), the default plain text label handling will be used.

See Also:
handleLabelEvent(YLabel, Mouse2DEvent, javax.swing.event.HyperlinkListener), HtmlLabelConfiguration.LabelHyperlinkEvent
 

Nested Class Summary
static class HtmlLabelConfiguration.LabelHyperlinkEvent
          Used to notify interested parties of label hyper link events.
 
Constructor Summary
HtmlLabelConfiguration()
          Initialize a new HtmlLabelConfiguration instance.
HtmlLabelConfiguration(javax.swing.JEditorPane editorPane)
          Initialize a new HtmlLabelConfiguration instance.
 
Method Summary
 void calculateContentSize(YLabel label, java.awt.font.FontRenderContext frc)
          Delegating method of YLabel.calculateSize(java.awt.font.FontRenderContext)
 void calcUnionRect(YLabel label, java.awt.geom.Rectangle2D r)
          Delegating method of YLabel.calcUnionRect(java.awt.geom.Rectangle2D)
 boolean contains(YLabel label, double x, double y)
          Delegating method of YLabel.contains(double, double)
protected  javax.swing.JComponent getConfiguredHtmlComponent(YLabel label)
          Return the JComponent that is used to measure and render HTML formatted text.
 OrientedRectangle getIconBox(YLabel label)
          Delegating method of YLabel.getIconBox().
 OrientedRectangle getTextBox(YLabel label)
          Delegating method of YLabel.getTextBox().
 void handleLabelEvent(YLabel label, Mouse2DEvent event, javax.swing.event.HyperlinkListener callback)
          Determines whether or not the specified mouse event will raise a hyperlink event for the specified label.
 void paintContent(YLabel label, java.awt.Graphics2D gfx, double x, double y, double width, double height)
          Delegating method of YLabel.paintContent(java.awt.Graphics2D, double, double, double, double)
protected  void paintIcon(java.awt.Graphics2D gfx, javax.swing.Icon icon, double x, double y)
           
 
Methods inherited from class y.view.AbstractCustomLabelPainter
asAutoFlippingPainter, getBackgroundColor, getBackgroundPaint, getLineColor, getLinePaint, getLineStroke, initializeBackground, initializeLine, isAutoFlippingEnabled, paint, paintBox, paintSelectionBox, setAutoFlippingEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface y.view.YLabel.Painter
getIconBox, getTextBox, paint, paintBox, paintContent
 
Methods inherited from interface y.view.YLabel.Layout
calculateContentSize, contains
 
Methods inherited from interface y.view.YLabel.BoundsProvider
calcUnionRect
 

Constructor Detail

HtmlLabelConfiguration

public HtmlLabelConfiguration()
Initialize a new HtmlLabelConfiguration instance. This instance will use JLabel to render HTML formatted text.


HtmlLabelConfiguration

public HtmlLabelConfiguration(javax.swing.JEditorPane editorPane)
Initialize a new HtmlLabelConfiguration instance. This instance will use JEditorPane to render HTML formatted text.

Parameters:
editorPane - the JEditorPane instance to render HTML formatted text. If null, a shared default instance of JEditorPane will be used.
Method Detail

getConfiguredHtmlComponent

protected javax.swing.JComponent getConfiguredHtmlComponent(YLabel label)
Return the JComponent that is used to measure and render HTML formatted text.

Parameters:
label - the YLabel that is measured or rendered by this configuration.
Returns:
either a JLabel or a JEditorPane instance.

handleLabelEvent

public void handleLabelEvent(YLabel label,
                             Mouse2DEvent event,
                             javax.swing.event.HyperlinkListener callback)
Determines whether or not the specified mouse event will raise a hyperlink event for the specified label. The specified label has to use this configuration for measuring and rendering its content in order for this method to work reliably.

Hyperlink events raised by this method will be of type HtmlLabelConfiguration.LabelHyperlinkEvent. The source of the specified mouse event will be the source of the raised hyperlink event.

Parameters:
label - the YLabel to check.
event - the triggering mouse event.
callback - the listener to process the raised hyperlink event.

calcUnionRect

public void calcUnionRect(YLabel label,
                          java.awt.geom.Rectangle2D r)
Description copied from interface: YLabel.BoundsProvider
Delegating method of YLabel.calcUnionRect(java.awt.geom.Rectangle2D)

Specified by:
calcUnionRect in interface YLabel.BoundsProvider
Parameters:
label - the label context
r - the bounds to update

paintContent

public void paintContent(YLabel label,
                         java.awt.Graphics2D gfx,
                         double x,
                         double y,
                         double width,
                         double height)
Description copied from interface: YLabel.Painter
Delegating method of YLabel.paintContent(java.awt.Graphics2D, double, double, double, double)

Specified by:
paintContent in interface YLabel.Painter
Parameters:
label - the label context

paintIcon

protected void paintIcon(java.awt.Graphics2D gfx,
                         javax.swing.Icon icon,
                         double x,
                         double y)

getTextBox

public OrientedRectangle getTextBox(YLabel label)
Description copied from interface: YLabel.Painter
Delegating method of YLabel.getTextBox().

Note: This method is not used to calculate the text placement in the painter, but rather provides a means to query the painter for text position and orientation.

Specified by:
getTextBox in interface YLabel.Painter
Parameters:
label - the label context

getIconBox

public OrientedRectangle getIconBox(YLabel label)
Description copied from interface: YLabel.Painter
Delegating method of YLabel.getIconBox().

Note: This method is not used to calculate the icon placement in the painter, but rather provides a means to query the painter for icon position and orientation.

Specified by:
getIconBox in interface YLabel.Painter
Parameters:
label - the label context

calculateContentSize

public void calculateContentSize(YLabel label,
                                 java.awt.font.FontRenderContext frc)
Description copied from interface: YLabel.Layout
Delegating method of YLabel.calculateSize(java.awt.font.FontRenderContext)

Specified by:
calculateContentSize in interface YLabel.Layout
Parameters:
label - the label context
frc - the font render context.

contains

public boolean contains(YLabel label,
                        double x,
                        double y)
Description copied from interface: YLabel.Layout
Delegating method of YLabel.contains(double, double)

Specified by:
contains in interface YLabel.Layout
Parameters:
label - the label context.

© Copyright 2000-2022,
yWorks GmbH.
All rights reserved.