/* @(#)LookAndFeelTools.java 2.4.0 26 May 2005 * * Copyright 2005 * College of Computer and Information Science * Northeastern University * Boston, MA 02115 * * The Java Power Tools software may be used for educational * purposes as long as this copyright notice is retained intact * at the top of all source files. * * To discuss possible commercial use of this software, * contact Richard Rasala at Northeastern University, * College of Computer and Information Science, * 617-373-2462 or rasala@ccs.neu.edu. * * The Java Power Tools software has been designed and built * in collaboration with Viera Proulx and Jeff Raab. * * Should this software be modified, the words "Modified from * Original" must be included as a comment below this notice. * * All publication rights are retained. This software or its * documentation may not be published in any media either * in whole or in part without explicit permission. * * This software was created with support from Northeastern * University and from NSF grant DUE-9950829. */ package edu.neu.ccs.gui; import edu.neu.ccs.*; import edu.neu.ccs.util.*; import java.awt.*; import javax.swing.*; import javax.swing.plaf.*; import java.util.*; /** *
Class LookAndFeelTools contains several static methods
* that assist in using the Java look and feel facilities.
Class LookAndFeelTools cannot be instantiated.
Displays a dialog that permits the user to select the look and feel * from among the look and feel options that are currently installed.
* *In addition, permits the user to adjust the font size of each default * font by a fixed amount specified by a sequence of constants provided in * the dialog.
* *This method must be called before any GUI objects are displayed on
* screen. Therefore, it is best to make the following code the first
* line of the main method that launches the program:
LookAndFeelTools.showSelectLookAndFeelDialog();
* Adjusts the font size of all default fonts by adding the given delta * to the current font size of each font.
* *The method recognizes a default font by looking for the String "font"
* in each key of a UIDefaults object.
This method prevents the net font size adjustment obtained from one * or more calls to the tools in this package from becoming less than the * lower bound MINIMUM_NET_FONT_SIZE_ADJUSTMENT.
* * @param delta the incremental change in font sizes */ public static void adjustAllDefaultFontSizes(float delta) { if ((netFontSizeAdjustment + delta) < MINIMUM_NET_FONT_SIZE_ADJUSTMENT) delta = MINIMUM_NET_FONT_SIZE_ADJUSTMENT - netFontSizeAdjustment; netFontSizeAdjustment += delta; UIDefaults defaults = UIManager.getLookAndFeelDefaults(); Set set = defaults.keySet(); String[] keys = (String[]) set.toArray(new String[0]); int length = keys.length; String key; Font font; float size; Object object; String fontWord = "font"; for (int i = 0; i < length; i++) { if (keys[i].indexOf(fontWord) >= 0) { key = keys[i]; object = defaults.get(key); if (object instanceof Font) { font = (Font) object; size = font.getSize2D() + delta; font = new FontUIResource(font.deriveFont(size)); defaults.put(key, font); } } } } /** *Sets the net font size adjustment to the look and feel fonts * to the given delta.
* * @param delta the absolute change in font sizes */ public static void setNetFontSizeAdjustment(float delta) { adjustAllDefaultFontSizes(delta - netFontSizeAdjustment); } /** *Returns the net font size adjustment to the look and feel fonts * after one or more calls to the tools in this package.
*/ public static float getNetFontSizeAdjustment() { return netFontSizeAdjustment; } }