KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > console > gui > constants > GuiConstants


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.console.gui.constants;
26
27 import java.awt.Color JavaDoc;
28 import java.awt.Cursor JavaDoc;
29 import java.awt.Dimension JavaDoc;
30 import java.awt.Font JavaDoc;
31 import java.awt.Point JavaDoc;
32 import java.awt.Toolkit JavaDoc;
33 import java.awt.Window JavaDoc;
34
35 import javax.swing.BorderFactory JavaDoc;
36 import javax.swing.border.Border JavaDoc;
37
38 import org.objectweb.cjdbc.common.i18n.GuiTranslate;
39
40 /**
41  * This class defines all the GuiConstants
42  *
43  * @author <a HREF="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
44  * @version 1.0
45  */

46 public final class GuiConstants
47 {
48   /** Backend state enabled */
49   public static final String JavaDoc BACKEND_STATE_ENABLED = GuiTranslate
50                                                               .get("gui.backend.enabled");
51   /** Backend state disabled */
52   public static final String JavaDoc BACKEND_STATE_DISABLED = GuiTranslate
53                                                               .get("gui.backend.disabled");
54   /** Backend state disabling */
55   public static final String JavaDoc BACKEND_STATE_DISABLING = GuiTranslate
56                                                               .get("gui.backend.disabling");
57   /** Backend state restore */
58   public static final String JavaDoc BACKEND_STATE_RESTORE = GuiTranslate
59                                                               .get("gui.backend.restore");
60   /** Backend state backup */
61   public static final String JavaDoc BACKEND_STATE_BACKUP = GuiTranslate
62                                                               .get("gui.backend.backup");
63   /** Backend state recovery */
64   public static final String JavaDoc BACKEND_STATE_RECOVERY = GuiTranslate
65                                                               .get("gui.backend.recovery");
66   /** Backend state new */
67   public static final String JavaDoc BACKEND_STATE_NEW = GuiTranslate
68                                                               .get("gui.backend.new");
69
70   /** Debug Level All */
71   public static final int DEBUG_ALL = 0;
72   /** Debug level all but do not show exception window */
73   public static final int DEBUG_NO_EXCEPTION_WINDOW = 1;
74   /** Debug level info */
75   public static final int DEBUG_INFO = 2;
76   /** No Debug */
77   public static final int DEBUG_NONE = 3;
78   /** Level of output of the debug */
79   public static final int DEBUG_LEVEL = DEBUG_ALL;
80
81   /** Main frame width */
82   public static final int MAIN_FRAME_WIDTH = 1024;
83   /** Main gui frame height */
84   public static final int MAIN_FRAME_HEIGHT = 600;
85
86   /** Component Name for the list of controllers */
87   public static final String JavaDoc LIST_CONTROLLER = "ListController";
88
89   /** Component Name for the list of databases */
90   public static final String JavaDoc LIST_DATABASE = "ListDatabase";
91   /** Component Name for the files list */
92   public static final String JavaDoc LIST_FILES = "ListFiles";
93
94   /** Controller state up */
95   public static final String JavaDoc CONTROLLER_STATE_UP = "Controller_UP";
96   /** Controller state down */
97   public static final String JavaDoc CONTROLLER_STATE_DOWN = "Controller_DOWN";
98   /** URL to the help of CJDBC */
99   public static final String JavaDoc CJDBC_URL_DOC = "http://c-jdbc.objectweb.org/current/doc/userGuide/html/userGuide.html";
100   /** Default save session file */
101   public static final String JavaDoc CJDBC_DEFAULT_SESSION_NAME = "session";
102   /** Default save session file */
103   public static final String JavaDoc CJDBC_DEFAULT_SESSION_FILE = CJDBC_DEFAULT_SESSION_NAME
104                                                               + ".properties";
105
106   /** Font used for the center panel */
107   public static final Font JavaDoc CENTER_PANE_FONT = new Font JavaDoc("Verdana",
108                                                               Font.PLAIN, 9);
109
110   /**
111    * Default Font
112    */

113   public static final Font JavaDoc DEFAULT_FONT = new Font JavaDoc("Verdana",
114                                                               Font.PLAIN, 9);
115
116   /**
117    * Final Color for backend state enabled
118    */

119   public static final Color JavaDoc BACKEND_STATE_ENABLED_COLOR = new Color JavaDoc(180, 238,
120                                                               180);
121   /**
122    * Final Color for backend state recovery
123    */

124   public static final Color JavaDoc BACKEND_STATE_RECOVERY_COLOR = new Color JavaDoc(255, 211,
125                                                               155);
126
127   /**
128    * Final Color for backend state disabled
129    */

130   public static final Color JavaDoc BACKEND_STATE_DISABLED_COLOR = new Color JavaDoc(238, 180,
131                                                               180);
132
133   /**
134    * Nice color
135    */

136   public static final Color JavaDoc NICE_COLOR = new Color JavaDoc(99, 184,
137                                                               255);
138
139   /**
140    * Lowered border
141    */

142   public static final Border JavaDoc LOWERED_BORDER = BorderFactory
143                                                               .createLoweredBevelBorder();
144
145   /**
146    * Line border
147    */

148   public static final Border JavaDoc LINE_BORDER = BorderFactory
149                                                               .createLineBorder(Color.BLACK);
150
151   /**
152    * Titled border
153    */

154   public static final Border JavaDoc TITLED_BORDER = BorderFactory
155                                                               .createTitledBorder(
156                                                                   LOWERED_BORDER,
157                                                                   GuiTranslate
158                                                                       .get("gui.border.selected"));
159
160   /**
161    * Default Custom Cursor for drags
162    */

163   public static Cursor JavaDoc customCursor;
164
165   private static final Color JavaDoc BACKEND_STATE_NEW_COLOR = new Color JavaDoc(185, 211,
166                                                               238);
167   private static final Color JavaDoc BACKEND_STATE_BACKUP_COLOR = new Color JavaDoc(255, 193,
168                                                               193);
169   private static final Color JavaDoc BACKEND_STATE_RESTORE_COLOR = new Color JavaDoc(255, 174,
170                                                               185);
171   /**
172    * Do not use any checkpoint for enable or disable of a backend
173    */

174   public static final String JavaDoc BACKEND_NO_CHECKPOINT = GuiTranslate
175                                                               .get("gui.backend.no.checkpoint");
176
177   /** JMX attributes table */
178   public static final String JavaDoc TABLE_JMX_ATTRIBUTES = GuiTranslate
179                                                               .get("table.jmx.attributes");
180   /** JMX operations table */
181   public static final String JavaDoc TABLE_JMX_OPERATIONS = GuiTranslate
182                                                               .get("table.jmx.operations");
183
184   static
185   {
186     Toolkit JavaDoc tk = Toolkit.getDefaultToolkit();
187     Point JavaDoc p = new Point JavaDoc(0, 0);
188     try
189     {
190       customCursor = tk.createCustomCursor(GuiIcons.CUSTOM_CURSOR_ICON
191           .getImage(), p, "CustomCursor");
192     }
193     catch (Exception JavaDoc e)
194     {
195       // Ignore
196
}
197   }
198
199   /**
200    * Get colors for backend panels
201    *
202    * @param paneName name of the panel
203    * @return <code>Color</code> NEVER <code>null</code>
204    */

205   public static Color JavaDoc getBackendBgColor(String JavaDoc paneName)
206   {
207     if (paneName.equals(BACKEND_STATE_ENABLED))
208       return BACKEND_STATE_ENABLED_COLOR;
209     else if (paneName.equals(BACKEND_STATE_DISABLED))
210       return BACKEND_STATE_DISABLED_COLOR;
211     else if (paneName.equals(BACKEND_STATE_RECOVERY))
212       return BACKEND_STATE_RECOVERY_COLOR;
213     else if (paneName.equals(BACKEND_STATE_NEW))
214       return BACKEND_STATE_NEW_COLOR;
215     else if (paneName.equals(BACKEND_STATE_RESTORE))
216       return BACKEND_STATE_RESTORE_COLOR;
217     else if (paneName.equals(BACKEND_STATE_BACKUP))
218       return BACKEND_STATE_BACKUP_COLOR;
219     else
220       return Color.white;
221   }
222
223   /**
224    * Test whether the given backend state is a valid state Since all the backend
225    * states are defined here, this test method should also be defined here.
226    *
227    * @param state the test to validate
228    * @return true if valid state, false otherwise.
229    */

230   public static boolean isValidBackendState(String JavaDoc state)
231   {
232     if (state.equals(BACKEND_STATE_ENABLED))
233       return true;
234     else if (state.equals(BACKEND_STATE_DISABLED))
235       return true;
236     else if (state.equals(BACKEND_STATE_RESTORE))
237       return true;
238     else if (state.equals(BACKEND_STATE_RECOVERY))
239       return true;
240     else if (state.equals(BACKEND_STATE_BACKUP))
241       return true;
242     else if (state.equals(BACKEND_STATE_NEW))
243       return true;
244     else
245       return false;
246   }
247
248   /**
249    * Centers a new component on the screen
250    *
251    * @param comp the window to center
252    * @param width the width of the window
253    * @param height the height of the window
254    */

255   public static void centerComponent(Window JavaDoc comp, int width, int height)
256   {
257     Toolkit JavaDoc toolkit = Toolkit.getDefaultToolkit();
258     Dimension JavaDoc dim = toolkit.getScreenSize();
259     int screenHeight = dim.height;
260     int screenWidth = dim.width;
261     int frameWidth = width;
262     int frameHeight = height;
263     comp.setSize(width, height);
264     comp.setBounds((screenWidth - frameWidth) / 2,
265         (screenHeight - frameHeight) / 2, frameWidth, frameHeight);
266     comp.validate();
267   }
268
269   /**
270    * Convert a parameter value depending on its type. Supported types are int
271    * and boolean.
272    *
273    * @param value value to convert
274    * @param type "int" or "boolean"
275    * @return value converted to an Integer or a Boolean object, or value as is
276    * for any other type
277    */

278   public static Object JavaDoc convertType(String JavaDoc value, String JavaDoc type)
279   {
280     if (type.equals("int"))
281       return new Integer JavaDoc(value);
282     if (type.equals("boolean"))
283       return new Boolean JavaDoc(value);
284     else
285       return value;
286   }
287
288   /**
289    * Get the parameter type.
290    *
291    * @param tmp paramter to extract type from
292    * @return the parameter type
293    */

294   public static String JavaDoc getParameterType(String JavaDoc tmp)
295   {
296     int indexOf = tmp.indexOf(";");
297     if (indexOf != -1)
298       tmp = tmp.substring(0, indexOf);
299     while (tmp.charAt(0) == '[')
300       tmp = tmp.substring(1) + "[]";
301     if (tmp.charAt(0) == 'L')
302       tmp = tmp.substring(1);
303     if (tmp.indexOf(".") != -1)
304       tmp = tmp.substring(tmp.lastIndexOf(".") + 1);
305     return tmp;
306   }
307
308 }
Popular Tags