1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package inc.che.common.gui;
20
21
22 import inc.che.common.resource.ResourceManager;
23 import inc.che.common.resource.StringResources;
24
25 import java.awt.Component;
26 import java.awt.Cursor;
27 import java.awt.Dimension;
28 import java.awt.Toolkit;
29
30 import org.apache.log4j.Logger;
31
32 /***
33 * <b>Utilitymethoden für die GUI</b>
34 * @version $Id: GuiUtil.java,v 1.1 2005/03/06 12:56:51 stevemcmee Exp $
35 * @author <address> Steve McMee <stevemcmee@users.sourceforge.net></address>
36 */
37
38 public final class GuiUtil {
39
40 /*** CVS ID of this file */
41 public static final String CVS_ID =
42 "$Id: GuiUtil.java,v 1.1 2005/03/06 12:56:51 stevemcmee Exp $";
43
44 /***
45 * logger instance for this class
46 */
47
48 private static Logger log = Logger.getLogger(GuiUtil.class);
49
50 /***
51 * The ResourceManager
52 */
53 private static ResourceManager resourceManager =
54 ResourceManager.getResourceManager(StringResources.TEXT_RESOURCES);
55
56 /***
57 * center a component
58 * @param comp component to center
59 */
60
61 /***
62 * forbidden Constructor
63 */
64 private GuiUtil() {
65 }
66
67 public static void center(Component comp) {
68 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
69 Dimension compSize = comp.getSize();
70 if (compSize.height > screenSize.height) {
71 compSize.height = screenSize.height;
72 }
73 if (compSize.width > screenSize.width) {
74 compSize.width = screenSize.width;
75 }
76 comp.setLocation(
77 (screenSize.width - compSize.width) / 2,
78 (screenSize.height - compSize.height) / 2);
79 }
80
81 /***
82 * center a component
83 * @param compbase base component
84 * @param comp component to center relative to compbase
85 */
86
87 public static void center(Component compbase, Component comp) {
88 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
89 Dimension compSize = comp.getSize();
90 Dimension compBaseSize = compbase.getSize();
91 if (compSize.height > screenSize.height) {
92 compSize.height = screenSize.height;
93 }
94 if (compSize.width > screenSize.width) {
95 compSize.width = screenSize.width;
96 }
97 if (compBaseSize.height > screenSize.height) {
98 compBaseSize.height = screenSize.height;
99 }
100 if (compBaseSize.width > screenSize.width) {
101 compBaseSize.width = screenSize.width;
102 }
103 comp.setLocation(
104 compbase.getX() + (compBaseSize.width - compSize.width) / 2,
105 compbase.getY() + (compBaseSize.height - compSize.height) / 2);
106 }
107 /***
108 * maximize a component
109 * @param comp component to maximize
110 */
111 public static void maximize(Component comp) {
112
113
114
115 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
116 log.info(
117 resourceManager.getText(
118 "screenSize",
119 new String[] {String.valueOf(screenSize)}));
120 comp.setSize(
121 (int) screenSize.getWidth(),
122 (int) screenSize.getHeight() - 50);
123
124 }
125
126 /***
127 * set a wait Cursor for a component
128 * @param comp the component
129 * @param wait true:diplay wait cursor on component
130 */
131 public static void setWaitCursor(Component comp, boolean wait) {
132 comp.setCursor(
133 wait
134 ? Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)
135 : Cursor.getDefaultCursor());
136 }
137 }