org.crosswire.common.swing
Class GuiUtil

java.lang.Object
  extended by org.crosswire.common.swing.GuiUtil

public class GuiUtil
extends Object

Various Gui Utilities.

Distribution Licence:
JSword is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
The License is available on the internet here, or by writing to: Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
The copyright to this program is held by it's authors.

Version:
$Id: GuiUtil.java,v 1.7 2004/09/08 19:54:24 dmsmith Exp $
Author:
Joe Walker [joe at eireneh dot com]
See Also:
Licence

Field Summary
private static Logger log
          The log stream
 
Constructor Summary
private GuiUtil()
          Prevent Instansiation
 
Method Summary
static void centerWindow(Window win)
          Move the specified window to the centre of the screen.
static void enforceMinimumSize(Component comp, int min_width, int min_height)
          Set the size of a component
static Dialog getDialog(Component com)
          Find the parent Frame
static Frame getFrame(Component parent)
          Find the parent Frame.
static ImageIcon getIcon(String name)
          Returns the Icon associated with the name from the resources.
static String getText(Component comp)
          Attempts to get the text from a generic Component.
static Window getWindow(Component com)
          Find the parent window.
static void maximizeWindow(Window win)
          Maximize the specified window.
static void restrainedPack(Window win, float maxx, float maxy)
          A more restricted version of pack() when the component is being pack()ed for the first time.
static void restrainedRePack(Window win)
          A more restricted version of pack() for component responding to live component tweaks.
static int setSize(Window win, Dimension requestedDim)
          Set the size of the window, but no bigger than the screen.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final Logger log
The log stream

Constructor Detail

GuiUtil

private GuiUtil()
Prevent Instansiation

Method Detail

getIcon

public static ImageIcon getIcon(String name)
Returns the Icon associated with the name from the resources. The resouce should be in the path.

Parameters:
name - Name of the icon file i.e., help16.gif
Returns:
the image or null if the icon is not found.

getWindow

public static Window getWindow(Component com)
Find the parent window.

Parameters:
com - a component to find the frame of.
Returns:
The parent Window

getFrame

public static Frame getFrame(Component parent)
Find the parent Frame. This method can do more than simply walking up the tree to find a parent frame by looking for default frames from JOptionPane and by looking for all visible Frames. We can be sure to return a Frame from this method even if null is passed in.

Parameters:
parent - a component to find the frame of.
Returns:
The parent Frame

getDialog

public static Dialog getDialog(Component com)
Find the parent Frame

Parameters:
com - a component to find the frame of.
Returns:
The parent Frame

centerWindow

public static void centerWindow(Window win)
Move the specified window to the centre of the screen. It is the programmer's responsibility to ensure that the window fits on the screen.

Parameters:
win - The window to be moved

setSize

public static int setSize(Window win,
                          Dimension requestedDim)
Set the size of the window, but no bigger than the screen. If the platform supports it, this may maximize the window.

On platforms that allow docking of other windows, this routine does not take that into account for sizes that are near that of the screen. For example, on Windows XP, the user may have a task bar showing permanently on one side of the screen and another application's toolbar on another side of the screen. If the requested size of the window is less than the screen size in a particular dimension, it will not be able to adjust for it.

For that reason, either have the application significantly smaller than the screen size or maximize the window.

Parameters:
win - the window to resize
requestedDim - how wide and tall to make the window, if possible
Returns:
whether the window has been maximized horizontally (Frame.MAXIMIZED_HORIZ), vertically (Frame.MAXIMIZED_VERT

maximizeWindow

public static void maximizeWindow(Window win)
Maximize the specified window. It would be good if we could detect where the taskbar was and not obscure it ...

Parameters:
win - The window to be moved

restrainedRePack

public static void restrainedRePack(Window win)
A more restricted version of pack() for component responding to live component tweaks. Assuming that the window already has a sensible on screen size, do a pack, but don't let the window grow or shrink by more than 10%.

Parameters:
win - The window to be packed

restrainedPack

public static void restrainedPack(Window win,
                                  float maxx,
                                  float maxy)
A more restricted version of pack() when the component is being pack()ed for the first time. Since this is a 'first time only' pack we are only concerned with screen size, and not any growths/shrinkages like restrainedRePack(Window).

Parameters:
win - The window to be packed
maxx - The maximum fraction (0.0 to 1.0) of the screen to be taken up horizontally (-1 means no restrictions to the horizontal alterations)
maxy - The maximum fraction (0.0 to 1.0) of the screen to be taken up vertically (-1 means no restrictions to the vertical alterations)
See Also:
restrainedRePack(Window)

enforceMinimumSize

public static void enforceMinimumSize(Component comp,
                                      int min_width,
                                      int min_height)
Set the size of a component


getText

public static String getText(Component comp)
Attempts to get the text from a generic Component. The Components that we can get some text from include:
  • JTextComponent
  • JLabel
  • AbstractButton
  • JComboBox
  • JToolTip
  • TextComponent
  • Button
  • Label
  • JScrollPane (recurse using the View) The others are done using toString()

    Parameters:
    comp - The object containing the needed text.

  • Copyright ? 2003-2004