org.basex.gui.layout
Class BaseXLayout

java.lang.Object
  extended by org.basex.gui.layout.BaseXLayout

public final class BaseXLayout
extends java.lang.Object

This class provides static layout and paint helper methods which are used all over the GUI.

Author:
BaseX Team 2005-12, BSD License, Christian Gruen

Nested Class Summary
static interface BaseXLayout.DropHandler
          Drag and drop handler.
 
Method Summary
static void addDrop(javax.swing.JComponent comp, BaseXLayout.DropHandler dnd)
          Adds drag and drop functionality.
static java.lang.String addShortcut(java.lang.String str, java.lang.String sc)
          Adds human readable shortcuts to the specified string.
static void chopString(java.awt.Graphics g, byte[] s, int x, int y, int w, int fs)
          Draws the specified string.
static java.util.ArrayList<java.lang.Object> contents(java.awt.datatransfer.Transferable tr)
          Returns the contents of the specified transferable.
static void drawCell(java.awt.Graphics g, int xs, int xe, int ys, int ye, boolean focus)
          Draws a colored cell.
static void drawCenter(java.awt.Graphics g, java.lang.String text, int w, int y)
          Draws a centered string to the panel.
static void drawTooltip(java.awt.Graphics g, java.lang.String tt, int x, int y, int w, int c)
          Draws a visualization tooltip.
static void fill(java.awt.Graphics gg, java.awt.Color c1, java.awt.Color c2, int xs, int ys, int xe, int ye)
          Fills the specified area with a color gradient.
static javax.swing.ImageIcon icon(java.lang.String name)
          Returns the specified image as icon.
static java.awt.Image image(java.lang.String name)
          Returns the specified image.
static void setHeight(java.awt.Component comp, int h)
          Sets the component height, adopting the original component width.
static void setMnemonic(javax.swing.AbstractButton b, java.lang.StringBuilder mnem)
          Sets a mnemomic for the specified button.
static void setWidth(java.awt.Component comp, int w)
          Sets the component width, adopting the original component height.
static java.lang.String value(double val)
          Returns the value of the specified pre value and attribute.
static int width(java.awt.Graphics g, byte[] s)
          Returns the width of the specified text.
static int width(java.awt.Graphics g, int[] cw, int c)
          Returns the character width of the specified character.
static int width(java.awt.Graphics g, java.lang.String s)
          Returns the width of the specified text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setWidth

public static void setWidth(java.awt.Component comp,
                            int w)
Sets the component width, adopting the original component height.

Parameters:
comp - component
w - width

setHeight

public static void setHeight(java.awt.Component comp,
                             int h)
Sets the component height, adopting the original component width.

Parameters:
comp - component
h - height

addDrop

public static void addDrop(javax.swing.JComponent comp,
                           BaseXLayout.DropHandler dnd)
Adds drag and drop functionality.

Parameters:
comp - component
dnd - drag and drop handler

setMnemonic

public static void setMnemonic(javax.swing.AbstractButton b,
                               java.lang.StringBuilder mnem)
Sets a mnemomic for the specified button.

Parameters:
b - button
mnem - mnemonics that have already been assigned

contents

public static java.util.ArrayList<java.lang.Object> contents(java.awt.datatransfer.Transferable tr)
Returns the contents of the specified transferable.

Parameters:
tr - transferable
Returns:
contents

addShortcut

public static java.lang.String addShortcut(java.lang.String str,
                                           java.lang.String sc)
Adds human readable shortcuts to the specified string.

Parameters:
str - text of tooltip
sc - shortcut
Returns:
tooltip

icon

public static javax.swing.ImageIcon icon(java.lang.String name)
Returns the specified image as icon.

Parameters:
name - name of icon
Returns:
icon

image

public static java.awt.Image image(java.lang.String name)
Returns the specified image.

Parameters:
name - name of image
Returns:
image

value

public static java.lang.String value(double val)
Returns the value of the specified pre value and attribute.

Parameters:
val - value to be evaluated
Returns:
value as string

fill

public static void fill(java.awt.Graphics gg,
                        java.awt.Color c1,
                        java.awt.Color c2,
                        int xs,
                        int ys,
                        int xe,
                        int ye)
Fills the specified area with a color gradient.

Parameters:
gg - graphics reference
c1 - first color
c2 - second color
xs - horizontal start position
ys - vertical start position
xe - horizontal end position
ye - vertical end position

drawCell

public static void drawCell(java.awt.Graphics g,
                            int xs,
                            int xe,
                            int ys,
                            int ye,
                            boolean focus)
Draws a colored cell.

Parameters:
g - graphics reference
xs - horizontal start position
xe - horizontal end position
ys - vertical start position
ye - vertical end position
focus - highlighting flag

drawCenter

public static void drawCenter(java.awt.Graphics g,
                              java.lang.String text,
                              int w,
                              int y)
Draws a centered string to the panel.

Parameters:
g - graphics reference
text - text to be painted
w - panel width
y - vertical position

drawTooltip

public static void drawTooltip(java.awt.Graphics g,
                               java.lang.String tt,
                               int x,
                               int y,
                               int w,
                               int c)
Draws a visualization tooltip.

Parameters:
g - graphics reference
tt - tooltip label
x - horizontal position
y - vertical position
w - width
c - color color depth

width

public static int width(java.awt.Graphics g,
                        java.lang.String s)
Returns the width of the specified text.

Parameters:
g - graphics reference
s - string to be evaluated
Returns:
string width

chopString

public static void chopString(java.awt.Graphics g,
                              byte[] s,
                              int x,
                              int y,
                              int w,
                              int fs)
Draws the specified string.

Parameters:
g - graphics reference
s - text
x - x coordinate
y - y coordinate
w - width
fs - font size

width

public static int width(java.awt.Graphics g,
                        byte[] s)
Returns the width of the specified text. Cached font widths are used to speed up calculation.

Parameters:
g - graphics reference
s - string to be evaluated
Returns:
string width

width

public static int width(java.awt.Graphics g,
                        int[] cw,
                        int c)
Returns the character width of the specified character.

Parameters:
g - graphics reference
cw - array with character widths
c - character
Returns:
character width