com.norbl.util.gui
Class GuiMetrics

java.lang.Object
  extended by com.norbl.util.gui.GuiMetrics

public class GuiMetrics
extends java.lang.Object

Static methods for finding and manipulating the sizes of gui components.


Field Summary
static java.awt.FontMetrics fontMetrics
           
static javax.swing.JLabel LABEL_SAMPLE
          Used as sample JComponent for finding the size of things.
static int lineHeight
          The height of a line in the the default font of a JLabel.
static boolean permitInit
          Flag to prevent init from being called in non-gui applications.
static int screenHeight
           
static int screenWidth
           
static int STANDARD_SPACE
           
static int widthX
          The width in pixels of 'X', in the default font of a JLabel.
 
Constructor Summary
GuiMetrics()
           
 
Method Summary
static int getScreenHeight()
           
static int getScreenHeight(javax.swing.JComponent c)
           
static java.awt.Dimension getScreenSize()
           
static java.awt.Dimension getScreenSize(javax.swing.JComponent c)
           
static int getScreenWidth()
           
static int getScreenWidth(javax.swing.JComponent c)
           
static int getWidth(java.lang.String s)
           
static void init()
           
static java.awt.Dimension noBiggerThanScreen(java.awt.Dimension d)
           
static java.awt.Dimension noBiggerThanScreenFraction(java.awt.Dimension d, float fraction)
           
static int roundDiv(int numer, int denom)
           
static int roundMult(int v, float factor)
           
static java.awt.Dimension screenFraction(float fraction)
          Calculates a fraction of the screen size.
static int toPixelHeight(float fraction)
          The height, in pixels, of a fraction of the screeen height.
static int toPixelWidth(float fraction)
          The width, in pixels, of a fraction of the screeen width.
static int upToMultiple(int h, int lineH)
          Converts a number of pixels to an exact multiple of a another integer, rounding up.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STANDARD_SPACE

public static int STANDARD_SPACE

screenWidth

public static int screenWidth

screenHeight

public static int screenHeight

fontMetrics

public static java.awt.FontMetrics fontMetrics

widthX

public static int widthX
The width in pixels of 'X', in the default font of a JLabel.


lineHeight

public static int lineHeight
The height of a line in the the default font of a JLabel.


LABEL_SAMPLE

public static javax.swing.JLabel LABEL_SAMPLE
Used as sample JComponent for finding the size of things.


permitInit

public static boolean permitInit
Flag to prevent init from being called in non-gui applications. TEMPORARY KLUDGE.

Constructor Detail

GuiMetrics

public GuiMetrics()
Method Detail

init

public static void init()

getScreenWidth

public static int getScreenWidth(javax.swing.JComponent c)

getScreenWidth

public static int getScreenWidth()

getScreenHeight

public static int getScreenHeight(javax.swing.JComponent c)

getScreenHeight

public static int getScreenHeight()

getScreenSize

public static java.awt.Dimension getScreenSize(javax.swing.JComponent c)

getScreenSize

public static java.awt.Dimension getScreenSize()

noBiggerThanScreen

public static java.awt.Dimension noBiggerThanScreen(java.awt.Dimension d)

noBiggerThanScreenFraction

public static java.awt.Dimension noBiggerThanScreenFraction(java.awt.Dimension d,
                                                            float fraction)

roundMult

public static int roundMult(int v,
                            float factor)

screenFraction

public static java.awt.Dimension screenFraction(float fraction)
Calculates a fraction of the screen size. It never returns zero values; if a zero is calculated, it is promoted to unity.


toPixelWidth

public static int toPixelWidth(float fraction)
The width, in pixels, of a fraction of the screeen width.


toPixelHeight

public static int toPixelHeight(float fraction)
The height, in pixels, of a fraction of the screeen height.


roundDiv

public static int roundDiv(int numer,
                           int denom)

getWidth

public static int getWidth(java.lang.String s)

upToMultiple

public static int upToMultiple(int h,
                               int lineH)
Converts a number of pixels to an exact multiple of a another integer, rounding up.

Parameters:
h - the number to modified.
lineH - the 'base', which the return will be a multiple of.