View Javadoc

1   /*
2    * JarInspector - Copyright (C) 2004 Che Inc., Rosario Argentina
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Library General Public
6    * License as published by the Free Software Foundation; either
7    * version 2 of the License, or (at your option) any later version.
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12   * Library General Public License for more details.
13   *
14   * You should have received a copy of the GNU Library General Public
15   * License along with this library; if not, write to the Free
16   * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17   */
18  
19  package inc.che.common.gui;
20  
21  // Imports
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 &lt;stevemcmee@users.sourceforge.net&gt;</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         //        GraphicsDevice device;
113         //        device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
114         //        device.setFullScreenWindow(comp);
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 }