PageRenderTime 55ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/projects/c_jdbc-2.0.2/src/org/objectweb/cjdbc/console/gui/constants/GuiConstants.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 308 lines | 160 code | 28 blank | 120 comment | 32 complexity | a797fe29bda954e940d518a1d2c98176 MD5 | raw file
  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. package org.objectweb.cjdbc.console.gui.constants;
  25. import java.awt.Color;
  26. import java.awt.Cursor;
  27. import java.awt.Dimension;
  28. import java.awt.Font;
  29. import java.awt.Point;
  30. import java.awt.Toolkit;
  31. import java.awt.Window;
  32. import javax.swing.BorderFactory;
  33. import javax.swing.border.Border;
  34. import org.objectweb.cjdbc.common.i18n.GuiTranslate;
  35. /**
  36. * This class defines all the GuiConstants
  37. *
  38. * @author <a href="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
  39. * @version 1.0
  40. */
  41. public final class GuiConstants
  42. {
  43. /** Backend state enabled */
  44. public static final String BACKEND_STATE_ENABLED = GuiTranslate
  45. .get("gui.backend.enabled");
  46. /** Backend state disabled */
  47. public static final String BACKEND_STATE_DISABLED = GuiTranslate
  48. .get("gui.backend.disabled");
  49. /** Backend state disabling */
  50. public static final String BACKEND_STATE_DISABLING = GuiTranslate
  51. .get("gui.backend.disabling");
  52. /** Backend state restore */
  53. public static final String BACKEND_STATE_RESTORE = GuiTranslate
  54. .get("gui.backend.restore");
  55. /** Backend state backup */
  56. public static final String BACKEND_STATE_BACKUP = GuiTranslate
  57. .get("gui.backend.backup");
  58. /** Backend state recovery */
  59. public static final String BACKEND_STATE_RECOVERY = GuiTranslate
  60. .get("gui.backend.recovery");
  61. /** Backend state new */
  62. public static final String BACKEND_STATE_NEW = GuiTranslate
  63. .get("gui.backend.new");
  64. /** Debug Level All */
  65. public static final int DEBUG_ALL = 0;
  66. /** Debug level all but do not show exception window */
  67. public static final int DEBUG_NO_EXCEPTION_WINDOW = 1;
  68. /** Debug level info */
  69. public static final int DEBUG_INFO = 2;
  70. /** No Debug */
  71. public static final int DEBUG_NONE = 3;
  72. /** Level of output of the debug */
  73. public static final int DEBUG_LEVEL = DEBUG_ALL;
  74. /** Main frame width */
  75. public static final int MAIN_FRAME_WIDTH = 1024;
  76. /** Main gui frame height */
  77. public static final int MAIN_FRAME_HEIGHT = 600;
  78. /** Component Name for the list of controllers */
  79. public static final String LIST_CONTROLLER = "ListController";
  80. /** Component Name for the list of databases */
  81. public static final String LIST_DATABASE = "ListDatabase";
  82. /** Component Name for the files list */
  83. public static final String LIST_FILES = "ListFiles";
  84. /** Controller state up */
  85. public static final String CONTROLLER_STATE_UP = "Controller_UP";
  86. /** Controller state down */
  87. public static final String CONTROLLER_STATE_DOWN = "Controller_DOWN";
  88. /** URL to the help of CJDBC */
  89. public static final String CJDBC_URL_DOC = "http://c-jdbc.objectweb.org/current/doc/userGuide/html/userGuide.html";
  90. /** Default save session file */
  91. public static final String CJDBC_DEFAULT_SESSION_NAME = "session";
  92. /** Default save session file */
  93. public static final String CJDBC_DEFAULT_SESSION_FILE = CJDBC_DEFAULT_SESSION_NAME
  94. + ".properties";
  95. /** Font used for the center panel */
  96. public static final Font CENTER_PANE_FONT = new Font("Verdana",
  97. Font.PLAIN, 9);
  98. /**
  99. * Default Font
  100. */
  101. public static final Font DEFAULT_FONT = new Font("Verdana",
  102. Font.PLAIN, 9);
  103. /**
  104. * Final Color for backend state enabled
  105. */
  106. public static final Color BACKEND_STATE_ENABLED_COLOR = new Color(180, 238,
  107. 180);
  108. /**
  109. * Final Color for backend state recovery
  110. */
  111. public static final Color BACKEND_STATE_RECOVERY_COLOR = new Color(255, 211,
  112. 155);
  113. /**
  114. * Final Color for backend state disabled
  115. */
  116. public static final Color BACKEND_STATE_DISABLED_COLOR = new Color(238, 180,
  117. 180);
  118. /**
  119. * Nice color
  120. */
  121. public static final Color NICE_COLOR = new Color(99, 184,
  122. 255);
  123. /**
  124. * Lowered border
  125. */
  126. public static final Border LOWERED_BORDER = BorderFactory
  127. .createLoweredBevelBorder();
  128. /**
  129. * Line border
  130. */
  131. public static final Border LINE_BORDER = BorderFactory
  132. .createLineBorder(Color.BLACK);
  133. /**
  134. * Titled border
  135. */
  136. public static final Border TITLED_BORDER = BorderFactory
  137. .createTitledBorder(
  138. LOWERED_BORDER,
  139. GuiTranslate
  140. .get("gui.border.selected"));
  141. /**
  142. * Default Custom Cursor for drags
  143. */
  144. public static Cursor customCursor;
  145. private static final Color BACKEND_STATE_NEW_COLOR = new Color(185, 211,
  146. 238);
  147. private static final Color BACKEND_STATE_BACKUP_COLOR = new Color(255, 193,
  148. 193);
  149. private static final Color BACKEND_STATE_RESTORE_COLOR = new Color(255, 174,
  150. 185);
  151. /**
  152. * Do not use any checkpoint for enable or disable of a backend
  153. */
  154. public static final String BACKEND_NO_CHECKPOINT = GuiTranslate
  155. .get("gui.backend.no.checkpoint");
  156. /** JMX attributes table */
  157. public static final String TABLE_JMX_ATTRIBUTES = GuiTranslate
  158. .get("table.jmx.attributes");
  159. /** JMX operations table */
  160. public static final String TABLE_JMX_OPERATIONS = GuiTranslate
  161. .get("table.jmx.operations");
  162. static
  163. {
  164. Toolkit tk = Toolkit.getDefaultToolkit();
  165. Point p = new Point(0, 0);
  166. try
  167. {
  168. customCursor = tk.createCustomCursor(GuiIcons.CUSTOM_CURSOR_ICON
  169. .getImage(), p, "CustomCursor");
  170. }
  171. catch (Exception e)
  172. {
  173. // Ignore
  174. }
  175. }
  176. /**
  177. * Get colors for backend panels
  178. *
  179. * @param paneName name of the panel
  180. * @return <code>Color</code> NEVER <code>null</code>
  181. */
  182. public static Color getBackendBgColor(String paneName)
  183. {
  184. if (paneName.equals(BACKEND_STATE_ENABLED))
  185. return BACKEND_STATE_ENABLED_COLOR;
  186. else if (paneName.equals(BACKEND_STATE_DISABLED))
  187. return BACKEND_STATE_DISABLED_COLOR;
  188. else if (paneName.equals(BACKEND_STATE_RECOVERY))
  189. return BACKEND_STATE_RECOVERY_COLOR;
  190. else if (paneName.equals(BACKEND_STATE_NEW))
  191. return BACKEND_STATE_NEW_COLOR;
  192. else if (paneName.equals(BACKEND_STATE_RESTORE))
  193. return BACKEND_STATE_RESTORE_COLOR;
  194. else if (paneName.equals(BACKEND_STATE_BACKUP))
  195. return BACKEND_STATE_BACKUP_COLOR;
  196. else
  197. return Color.white;
  198. }
  199. /**
  200. * Test whether the given backend state is a valid state Since all the backend
  201. * states are defined here, this test method should also be defined here.
  202. *
  203. * @param state the test to validate
  204. * @return true if valid state, false otherwise.
  205. */
  206. public static boolean isValidBackendState(String state)
  207. {
  208. if (state.equals(BACKEND_STATE_ENABLED))
  209. return true;
  210. else if (state.equals(BACKEND_STATE_DISABLED))
  211. return true;
  212. else if (state.equals(BACKEND_STATE_RESTORE))
  213. return true;
  214. else if (state.equals(BACKEND_STATE_RECOVERY))
  215. return true;
  216. else if (state.equals(BACKEND_STATE_BACKUP))
  217. return true;
  218. else if (state.equals(BACKEND_STATE_NEW))
  219. return true;
  220. else
  221. return false;
  222. }
  223. /**
  224. * Centers a new component on the screen
  225. *
  226. * @param comp the window to center
  227. * @param width the width of the window
  228. * @param height the height of the window
  229. */
  230. public static void centerComponent(Window comp, int width, int height)
  231. {
  232. Toolkit toolkit = Toolkit.getDefaultToolkit();
  233. Dimension dim = toolkit.getScreenSize();
  234. int screenHeight = dim.height;
  235. int screenWidth = dim.width;
  236. int frameWidth = width;
  237. int frameHeight = height;
  238. comp.setSize(width, height);
  239. comp.setBounds((screenWidth - frameWidth) / 2,
  240. (screenHeight - frameHeight) / 2, frameWidth, frameHeight);
  241. comp.validate();
  242. }
  243. /**
  244. * Convert a parameter value depending on its type. Supported types are int
  245. * and boolean.
  246. *
  247. * @param value value to convert
  248. * @param type "int" or "boolean"
  249. * @return value converted to an Integer or a Boolean object, or value as is
  250. * for any other type
  251. */
  252. public static Object convertType(String value, String type)
  253. {
  254. if (type.equals("int"))
  255. return new Integer(value);
  256. if (type.equals("boolean"))
  257. return new Boolean(value);
  258. else
  259. return value;
  260. }
  261. /**
  262. * Get the parameter type.
  263. *
  264. * @param tmp paramter to extract type from
  265. * @return the parameter type
  266. */
  267. public static String getParameterType(String tmp)
  268. {
  269. int indexOf = tmp.indexOf(";");
  270. if (indexOf != -1)
  271. tmp = tmp.substring(0, indexOf);
  272. while (tmp.charAt(0) == '[')
  273. tmp = tmp.substring(1) + "[]";
  274. if (tmp.charAt(0) == 'L')
  275. tmp = tmp.substring(1);
  276. if (tmp.indexOf(".") != -1)
  277. tmp = tmp.substring(tmp.lastIndexOf(".") + 1);
  278. return tmp;
  279. }
  280. }