01: /*
02: This library is free software; you can redistribute it and/or
03: modify it under the terms of the GNU General Public
04: License as published by the Free Software Foundation; either
05: version 2 of the license, or (at your option) any later version.
06: */
07:
08: package org.gjt.jclasslib.util;
09:
10: import javax.swing.*;
11: import java.awt.*;
12:
13: /**
14: Collection of GUI utility methods.
15:
16: @author <a href="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>
17: @version $Revision: 1.1 $ $Date: 2003/08/18 07:46:43 $
18: */
19: public class GUIHelper {
20:
21: /** The title for message boxes. */
22: public static final String MESSAGE_TITLE = "jclasslib";
23:
24: /** "Yes" and "No" Options for showOptionDialog. */
25: public static final String[] YES_NO_OPTIONS = new String[] { "Yes",
26: "No" };
27: /** Empty icon 16x16. */
28: public static final Icon ICON_EMPTY = new EmptyIcon(16, 16);
29:
30: /**
31: Show a <tt>JOptionPane</tt> option dialog.
32: @param parent parent component
33: @param message the message string
34: @param options the array of option strings
35: @param messageType the message type as defined in <tt>JOptionPane</tt>
36: @return the result code of the dialog
37: */
38: public static int showOptionDialog(Component parent,
39: String message, String[] options, int messageType) {
40: return JOptionPane.showOptionDialog(parent, message,
41: MESSAGE_TITLE, 0, messageType, null, options,
42: options[0]);
43: }
44:
45: /**
46: Show a <tt>JOptionPane</tt> message dialog.
47: @param parent parent component
48: @param message the message string
49: @param messageType the message type as defined in <tt>JOptionPane</tt>
50: */
51: public static void showMessage(Component parent, String message,
52: int messageType) {
53: JOptionPane.showMessageDialog(parent, message, MESSAGE_TITLE,
54: messageType, null);
55: }
56:
57: /**
58: Center a window on another window.
59: @param window the window to be centered.
60: @param parentWindow the parent window on which the window is to be centered.
61: */
62: public static void centerOnParentWindow(Window window,
63: Window parentWindow) {
64: window.setLocation(parentWindow.getX()
65: + (parentWindow.getWidth() - window.getWidth()) / 2,
66: parentWindow.getY()
67: + (parentWindow.getHeight() - window
68: .getHeight()) / 2);
69: }
70:
71: /**
72: Set reasonable unit increments for a scroll pane that does not contain a
73: <tt>Scrollable</tt>.
74: @param scrollPane
75: */
76: public static void setDefaultScrollbarUnits(JScrollPane scrollPane) {
77:
78: int unit = new JLabel().getFont().getSize() * 2;
79: scrollPane.getHorizontalScrollBar().setUnitIncrement(unit);
80: scrollPane.getVerticalScrollBar().setUnitIncrement(unit);
81: }
82:
83: }
|