|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.lapetus_ltd.api.common.TLptsGuiUtil
public class TLptsGuiUtil
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 |
---|
public static final java.lang.String LOOK_AND_FEEL_CROSS_PLATFORM
public static final java.lang.String LOOK_AND_FEEL_SYSTEM
public static final java.lang.String LOOK_AND_FEEL_WINDOWS
public static final java.lang.String LOOK_AND_FEEL_WINDOWS_CLASSIC
Method Detail |
---|
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); } }
jDialog
- The dialog window that should close on exit.isAskConfirm
- Whether to ask for confirmation or not before closing.public static void closeWindowOnEscape(javax.swing.JFrame frame, boolean isAskConfirm)
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); } }
frame
- The frame that should close on exit.isAskConfirm
- Whether to ask for confirmation or not before closing.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); } }
jWindow
- The frame that should close on exit.public static java.awt.Font fontAddBold(java.awt.Font 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()));
font
- An existing font which is to be used to create an bold version.
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()));
font
- An existing font which is to be used to create an italic version.
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 :
ListfullScreenSupportList = 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); }
public static java.awt.GraphicsDevice getDefaultScreenDevice()
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");
GraphicsEnvironment
public static int getFontHeight(java.awt.Font font)
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)));
font
- The font to use for calculating the font height on the graphics device.
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());
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();
public static int getFontWidth(java.awt.Font font, java.awt.Graphics graphics, java.lang.String text, int minWidth)
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);
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.
public static int getFontWidth(java.awt.Font font, java.lang.String text)
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);
font
- The font to use for calculating the length.text
- The text to use for calculating the length.
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);
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.
public static java.util.List<java.lang.String> getLookAndFeelNames()
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 :
ListlookAndFeels = getLookAndFeelNames(); Result: Metal, Nimbus, Windows, Systems, etc.
public static void loopToNextLookAndFeel()
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()); } });
public static void setLookAndFeel(java.lang.String lookAndFeelName)
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; }
lookAndFeelName
- A look and feel name, like UIManager.getLookAndFeel().getName();public static void zI()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |