Search in sources :

Example 6 with NumberRuler

use of org.apache.pivot.wtk.NumberRuler in project pivot by apache.

the class NumberRulerSkin method getPreferredWidth.

@Override
public int getPreferredWidth(int height) {
    NumberRuler ruler = (NumberRuler) getComponent();
    Orientation orientation = ruler.getOrientation();
    if (orientation == Orientation.VERTICAL) {
        int textSize = ruler.getTextSize();
        FontRenderContext fontRenderContext = Platform.getFontRenderContext();
        char[] digits = new char[textSize];
        Arrays.fill(digits, '0');
        String text = new String(digits);
        Rectangle2D stringBounds = font.getStringBounds(text, fontRenderContext);
        return (int) Math.ceil(stringBounds.getWidth()) + padding;
    }
    return 0;
}
Also used : NumberRuler(org.apache.pivot.wtk.NumberRuler) Rectangle2D(java.awt.geom.Rectangle2D) FontRenderContext(java.awt.font.FontRenderContext) Orientation(org.apache.pivot.wtk.Orientation)

Aggregations

NumberRuler (org.apache.pivot.wtk.NumberRuler)6 Orientation (org.apache.pivot.wtk.Orientation)3 FontRenderContext (java.awt.font.FontRenderContext)2 Rectangle2D (java.awt.geom.Rectangle2D)2 Graphics2D (java.awt.Graphics2D)1 Rectangle (java.awt.Rectangle)1 GlyphVector (java.awt.font.GlyphVector)1 StringCharacterIterator (java.text.StringCharacterIterator)1 Insets (org.apache.pivot.wtk.Insets)1 Theme (org.apache.pivot.wtk.Theme)1