org.knime.base.node.viz.plotter
Class LabelPaintUtil

java.lang.Object
  extended by org.knime.base.node.viz.plotter.LabelPaintUtil

public final class LabelPaintUtil
extends Object

Util class providing methods for drawing labels, which can be rotated if the available space is to small. Since the rotation depends on the position, where the labels is drawn, a value of the LabelPaintUtil.Position must be passed to the drawLabel(String, Graphics2D, Rectangle, org.knime.base.node.viz.plotter.LabelPaintUtil.Position, boolean) method. If the labels must be rotated due to the lack of space can also be determined with the rotateLabels(CoordinateMapping[], int, FontMetrics) method.

Author:
Fabian Dill, University of Konstanz

Nested Class Summary
static class LabelPaintUtil.Position
          Possible positions of the label.
 
Method Summary
static String cutLabel(String label, int desiredLength, FontMetrics fm)
          Cuts the passed label until it fits into the desired length by cutting out the middle of the label.
static void drawLabel(String label, Graphics2D g, Rectangle availableSpace, LabelPaintUtil.Position position, boolean rotate)
          Draws the label, and if the available space is to small it rotates the label depending on the LabelPaintUtil.Position where to draw it.
static String getDoubleAsString(double value, double roundingFactor)
          Rounds the passed double value by the rounding factor and returns a string representation of it.
static boolean rotateLabels(CoordinateMapping[] mappings, int availableSize, FontMetrics fm)
          Returns true if any label is too long to be displayed in the available space.
static boolean rotateLabels(List<String> labels, int availableSize, FontMetrics fm)
          Returns true if any label is too long to be displayed in the available space.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getDoubleAsString

public static String getDoubleAsString(double value,
                                       double roundingFactor)
Rounds the passed double value by the rounding factor and returns a string representation of it. Typical usage for tooltips.

Parameters:
value - the value to be rounded
roundingFactor - the rounding factor use 100 for two numbers after the comma, 1000 for three numbers after the comma and so on.
Returns:
the string representation of the ronded double

drawLabel

public static void drawLabel(String label,
                             Graphics2D g,
                             Rectangle availableSpace,
                             LabelPaintUtil.Position position,
                             boolean rotate)
Draws the label, and if the available space is to small it rotates the label depending on the LabelPaintUtil.Position where to draw it. If it is still too large it cuts the label with the cutLabel(String, int, FontMetrics) method. The Rectangle available space gives information about the available space, depending on the position the labels is placed inside this rectangle.

Parameters:
label - the label to display
g - the graphics object
availableSpace - the available space
position - the position
rotate - whether labels are rotated or not

cutLabel

public static String cutLabel(String label,
                              int desiredLength,
                              FontMetrics fm)
Cuts the passed label until it fits into the desired length by cutting out the middle of the label. The first three and the most possible part of the length are retained. If some charaters are removed "..." is inserted.

Parameters:
label - the label to cut
desiredLength - the desired length
fm - the font metrics
Returns:
a cutted label which fits into the desired length

rotateLabels

public static boolean rotateLabels(CoordinateMapping[] mappings,
                                   int availableSize,
                                   FontMetrics fm)
Returns true if any label is too long to be displayed in the available space.

Parameters:
mappings - the set of labels to be displayed.
availableSize - the available width
fm - the font metrics
Returns:
true if labels should be rotated, false otherwise

rotateLabels

public static boolean rotateLabels(List<String> labels,
                                   int availableSize,
                                   FontMetrics fm)
Returns true if any label is too long to be displayed in the available space.

Parameters:
labels - the set of labels to be displayed.
availableSize - the available width
fm - the font metrics
Returns:
true if labels should be rotated, false otherwise


Copyright, 2003 - 2010. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.