KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > util > GUIHelper


1 /*
2     This library is free software; you can redistribute it and/or
3     modify it under the terms of the GNU General Public
4     License as published by the Free Software Foundation; either
5     version 2 of the license, or (at your option) any later version.
6 */

7
8 package org.gjt.jclasslib.util;
9
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 JavaDoc MESSAGE_TITLE = "jclasslib";
23
24     /** "Yes" and "No" Options for showOptionDialog. */
25     public static final String JavaDoc[] YES_NO_OPTIONS = new String JavaDoc[] {"Yes", "No"};
26     /** Empty icon 16x16. */
27     public static final Icon ICON_EMPTY = new EmptyIcon(16, 16);
28
29     /**
30         Show a <tt>JOptionPane</tt> option dialog.
31         @param parent parent component
32         @param message the message string
33         @param options the array of option strings
34         @param messageType the message type as defined in <tt>JOptionPane</tt>
35         @return the result code of the dialog
36      */

37     public static int showOptionDialog(Component parent, String JavaDoc message, String JavaDoc[] options, int messageType) {
38         return JOptionPane.showOptionDialog(parent,
39                                             message,
40                                             MESSAGE_TITLE,
41                                             0,
42                                             messageType,
43                                             null,
44                                             options,
45                                             options[0]);
46     }
47
48     /**
49         Show a <tt>JOptionPane</tt> message dialog.
50         @param parent parent component
51         @param message the message string
52         @param messageType the message type as defined in <tt>JOptionPane</tt>
53      */

54     public static void showMessage(Component parent, String JavaDoc message, int messageType) {
55         JOptionPane.showMessageDialog(parent,
56                                       message,
57                                       MESSAGE_TITLE,
58                                       messageType,
59                                       null);
60     }
61
62     /**
63         Center a window on another window.
64         @param window the window to be centered.
65         @param parentWindow the parent window on which the window is to be centered.
66      */

67     public static void centerOnParentWindow(Window window, Window parentWindow) {
68         window.setLocation(
69                 parentWindow.getX() + (parentWindow.getWidth() - window.getWidth()) / 2,
70                 parentWindow.getY() + (parentWindow.getHeight() - window.getHeight()) / 2
71         );
72     }
73
74     /**
75         Set reasonable unit increments for a scroll pane that does not contain a
76         <tt>Scrollable</tt>.
77         @param scrollPane
78      */

79     public static void setDefaultScrollbarUnits(JScrollPane scrollPane) {
80
81         int unit = new JLabel().getFont().getSize() * 2;
82         scrollPane.getHorizontalScrollBar().setUnitIncrement(unit);
83         scrollPane.getVerticalScrollBar().setUnitIncrement(unit);
84     }
85
86 }
87
Popular Tags