Copyright 2009,2010, Lapetus Systems Ltd. (All rights reserved)

com.lapetus_ltd.api.common
Class TLptsGuiUtil

java.lang.Object
  extended by com.lapetus_ltd.api.common.TLptsGuiUtil

public class TLptsGuiUtil
extends java.lang.Object

Class Description : Util that deals with the Fonts and GUI Settings.

This class contains GUI functions for fonts and look&feel. There are also functions for closing windows on escape.

$LastChangedRevision: 1179 $
$LastChangedDate:: 2010-11-12 10:13:56#$


Field Summary
static java.lang.String LOOK_AND_FEEL_CROSS_PLATFORM
          Look and feel that works on most systems
static java.lang.String LOOK_AND_FEEL_SYSTEM
          The default look and feel
static java.lang.String LOOK_AND_FEEL_WINDOWS
          Windows only look and feel
static java.lang.String LOOK_AND_FEEL_WINDOWS_CLASSIC
          Windows only look and feel
 
Method Summary
static void closeWindowOnEscape(javax.swing.JDialog jDialog, boolean isAskConfirm)
           This sets the Dialog listener so that it closes when the exit key is pressed.
static void closeWindowOnEscape(javax.swing.JFrame frame, boolean isAskConfirm)
          This sets the Frame listener so that it closes when the exit key is pressed.
static void closeWindowOnEscape(javax.swing.JWindow jWindow)
           This sets the JWindow listener so that it closes when the exit key is pressed.
static java.awt.Font fontAddBold(java.awt.Font font)
          Creates a bold version of the supplied font.
static java.awt.Font fontAddItalic(java.awt.Font font)
           Creates an italic version of the supplied font.
static java.util.List<java.awt.GraphicsDevice> getAllGraphicsDevices()
           Get all Graphics devices on the local system.
static java.awt.GraphicsDevice getDefaultScreenDevice()
          Get the default device from the Java Graphics environment.
static int getFontHeight(java.awt.Font font)
          Get the height of a font, in pixels, on the default graphics device.
static int getFontHeight(java.awt.Font font, java.awt.Graphics graphics)
           Gets the height of a font, in pixels, on the graphics device supplied.
static int getFontWidth(java.awt.Font font, java.awt.Graphics graphics, java.lang.String text, int minWidth)
          The width of a text string, in pixels, on the supplied graphics device.
static int getFontWidth(java.awt.Font font, java.lang.String text)
          The width of a text string, in pixels, on the default graphics device.
static int getFontWidth(java.awt.Font font, java.lang.String text, int minWidth)
           The width of a text string, in pixels, on the default graphics device.
static java.util.List<java.lang.String> getLookAndFeelNames()
          Gets all the look and feels on the current system.
static void loopToNextLookAndFeel()
          Loops to the next look and feel and implements it.
static void setLookAndFeel(java.lang.String lookAndFeelName)
          Sets a look and feel that was retrieved from getLookAndFeelNames().
static void zI()
          Obfuscated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOOK_AND_FEEL_CROSS_PLATFORM

public static final java.lang.String LOOK_AND_FEEL_CROSS_PLATFORM
Look and feel that works on most systems

See Also:
Constant Field Values

LOOK_AND_FEEL_SYSTEM

public static final java.lang.String LOOK_AND_FEEL_SYSTEM
The default look and feel

See Also:
Constant Field Values

LOOK_AND_FEEL_WINDOWS

public static final java.lang.String LOOK_AND_FEEL_WINDOWS
Windows only look and feel

See Also:
Constant Field Values

LOOK_AND_FEEL_WINDOWS_CLASSIC

public static final java.lang.String LOOK_AND_FEEL_WINDOWS_CLASSIC
Windows only look and feel

See Also:
Constant Field Values
Method Detail

closeWindowOnEscape

public static void closeWindowOnEscape(javax.swing.JDialog jDialog,
                                       boolean isAskConfirm)

This sets the Dialog listener so that it closes when the exit key is pressed.

Notes : A dialog pops up to ask for confirmation if the isAskConfirn parameter is set.

Thread Safe : No

Spawns its own Thread : No

May Return NULL : No

Example :


 public class MyDialog extends JDialog
 {
    public MyDialog()
    {
      ...
      //if dialog is very important, probably we want to confirm for exit. So we set second arg as true
      TLptsGuiUtil.closeWindowOnEscape(this,true);
    }
 }

 

Parameters:
jDialog - The dialog window that should close on exit.
isAskConfirm - Whether to ask for confirmation or not before closing.

closeWindowOnEscape

public static void closeWindowOnEscape(javax.swing.JFrame frame,
                                       boolean isAskConfirm)
This sets the Frame listener so that it closes when the exit key is pressed.

Notes : A dialog pops up to ask for confirmation if the isAskConfirn parameter is set.

Thread Safe : No

Spawns its own Thread : No

May Return NULL : No

Example :


 public class MyFrame extends JFrame
 {
    public MyFrame()
    {
      ...
      //if frame is the Main Application frame, probably we want to confirm for exit. So we set second arg as true
      TLptsGuiUtil.closeWindowOnEscape(this,true);
    }
 }

 

Parameters:
frame - The frame that should close on exit.
isAskConfirm - Whether to ask for confirmation or not before closing.

closeWindowOnEscape

public static void closeWindowOnEscape(javax.swing.JWindow jWindow)

This sets the JWindow listener so that it closes when the exit key is pressed.

Notes :

Thread Safe : No

Spawns its own Thread : No

May Return NULL : No

Example :


 public class MyWindow extends JWindow
 {
    public MyWindow()
    {
      ...
      TLptsGuiUtil.closeWindowOnEscape(this);
    }
 }

 

Parameters:
jWindow - The frame that should close on exit.

fontAddBold

public static java.awt.Font fontAddBold(java.awt.Font font)
Creates a bold version of the supplied font.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : No

Notes :

Example :


 //Get the current font of the table, convert to bold and set it back to the table.
 JTable table = new JTable();
 table.setFont(TLptsGuiUtil.fontAddBold(table.getFont()));

 

Parameters:
font - An existing font which is to be used to create an bold version.
Returns:
A new font with the characteristics of the supplied font, and emboldening.

fontAddItalic

public static java.awt.Font fontAddItalic(java.awt.Font font)

Creates an italic version of the supplied font.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : No

Notes :

Example :


 //Get the current font of the table, convert to bold and set it back to the table.
 JTable table = new JTable();
 table.setFont(TLptsGuiUtil.fontAddItalic(table.getFont()));

 

Parameters:
font - An existing font which is to be used to create an italic version.
Returns:
A new font with the characteristics of the supplied font, and italics.

getAllGraphicsDevices

public static java.util.List<java.awt.GraphicsDevice> getAllGraphicsDevices()

Get all Graphics devices on the local system.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : No, in worst case an empty list.

Notes : Calls GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices() and puts all the devices in a list.
Be aware that not only screen devices are returned, as suggested by the method name.

Example :


 List fullScreenSupportList = new LinkedList();
 for (GraphicsDevice device : TLptsGuiUtil.getAllGraphicsDevices())
   if (device.isFullScreenSupported())
   {
     System.out.println("Added a device to the full screen support list");
     fullScreenSupportList.add(device);
   }
 

Returns:
A list of all the graphics devices on the host system.

getDefaultScreenDevice

public static java.awt.GraphicsDevice getDefaultScreenDevice()
Get the default device from the Java Graphics environment.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : No

Notes : This is a wrapped call to GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().

Example :


 GraphicsDevice defaultDev = TLptsGuiUtil.getDefaultScreenDevice() ;
 if (defaultDev.getType()==GraphicsDevice.TYPE_RASTER_SCREEN)
   System.out.println("The default Graphics device is a Screen");
 

Returns:
The default device for graphics output. Normally a screen, but can be a printer or other device.
GraphicsEnvironment

getFontHeight

public static int getFontHeight(java.awt.Font font)
Get the height of a font, in pixels, on the default graphics device.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : No

Notes :

Example :


 JTable table = new JTable();
 table.setRowHeight(TLptsGuiUtil.getFontHeight(new Font("Arial",Font.BOLD,10)));
 

Parameters:
font - The font to use for calculating the font height on the graphics device.
Returns:
The number of pixels that represent the height of text using the given font on the default graphics device.

getFontHeight

public static int getFontHeight(java.awt.Font font,
                                java.awt.Graphics graphics)

Gets the height of a font, in pixels, on the graphics device supplied.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : No

Notes :

Example :


 JTable table = new JTable();
 table.setRowHeight(TLptsGuiUtil.getFontHeight(new Font("Arial",Font.BOLD,10)),table.getGraphics());
 

Parameters:
font - The font to use for calculating the font height on the graphics device.
graphics - The graphics to use for the calculations. ie JComponent.getGraphics();
Returns:
The number of pixels that represent the height of text using the given font on the supplied graphics device.

getFontWidth

public static int getFontWidth(java.awt.Font font,
                               java.awt.Graphics graphics,
                               java.lang.String text,
                               int minWidth)
The width of a text string, in pixels, on the supplied graphics device.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : No

Notes :

Example :


 JTable table = new JTable();
 int width = TLptsGuiUtil.getFontWidth(new Font("Arial",table.getGraphics(),Font.PLAIN,10),"Column Text");
 table.getColumnModel().getColumn(1).setPreferredWidth(width);
 

Parameters:
font - The font to use for calculating the length.
graphics - The graphics to use for this calculation.
text - The text to use for calculating the length.
minWidth - The minimum width that will be returned by this function. Useful with columns that have the current column header as the minimum.
Returns:
The width of the text with the font and string and supplied grahics environment.

getFontWidth

public static int getFontWidth(java.awt.Font font,
                               java.lang.String text)
The width of a text string, in pixels, on the default graphics device.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : No

Notes :

Example :


 JTable table = new JTable();
 int width = TLptsGuiUtil.getFontWidth(new Font("Arial",Font.PLAIN,10),"Column Text");
 table.getColumnModel().getColumn(1).setPreferredWidth(width);
 

Parameters:
font - The font to use for calculating the length.
text - The text to use for calculating the length.
Returns:
The width of the text with the font and string and default graphics environment.

getFontWidth

public static int getFontWidth(java.awt.Font font,
                               java.lang.String text,
                               int minWidth)

The width of a text string, in pixels, on the default graphics device.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : No

Notes :

Example :


 JTable table = new JTable();
 int width = TLptsGuiUtil.getFontWidth(new Font("Arial",Font.PLAIN,10),"Column Text");
 table.getColumnModel().getColumn(1).setPreferredWidth(width);
 

Parameters:
font - The font to use for calculating the length.
text - The text to use for calculating the length.
minWidth - The minimum width that will be returned by this function. Useful with columns that have the current column header as the minimum.
Returns:
The width of the text with the font and string and default graphics environment.

getLookAndFeelNames

public static java.util.List<java.lang.String> getLookAndFeelNames()
Gets all the look and feels on the current system.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : No, empty list in worst case.

Notes : Use the names returned from here in the function TLptsGuiUtil.setLookAndFeel(name);
Not all look and feels are implemented well on every host OS.
This means that some l&Fs will look odd on certain host systems.

Example :


 List lookAndFeels = getLookAndFeelNames();
 Result:  Metal, Nimbus, Windows, Systems, etc.
 

Returns:
Returns the names of the look and feels on the current system. A list is always returned, but may be empty. It will never be null.

loopToNextLookAndFeel

public static void loopToNextLookAndFeel()
Loops to the next look and feel and implements it.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : No

Notes : An easy way to go through all the L&Fs on your system.

Example :


 JButton button = new JButton("L&F loop");
 button.addActionListener(new ActionListener()
 {
   public void actionPerformed(ActionEvent e)
   {
     TLptsGuiUtil.loopToNextLookAndFeel();
     System.out.println("The current look and feel is " + UIManager.getLookAndFeel().getName());
   }
 });
 


setLookAndFeel

public static void setLookAndFeel(java.lang.String lookAndFeelName)
Sets a look and feel that was retrieved from getLookAndFeelNames().

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : No

Notes :

Example :


 for (String name : TLptsGuiUtil.getLookAndFeelNames())
 {
   TLptsGuiUtil.setLookAndFeel(name);
   System.out.println("Setting L&F " + name);
   if (JOptionPane.showConfirmDialog(null,"Is this L&F ok?",
                                 "Look and Feel",
                                 JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION)
     break;
 }
 

Parameters:
lookAndFeelName - A look and feel name, like UIManager.getLookAndFeel().getName();

zI

public static void zI()
Obfuscated.



Copyright 2009,2010, Lapetus Systems Ltd. (All rights reserved)