1 24 25 package org.objectweb.cjdbc.console.gui; 26 27 import java.awt.BorderLayout ; 28 import java.awt.Color ; 29 import java.awt.Dimension ; 30 import java.awt.GridLayout ; 31 import java.awt.Point ; 32 import java.awt.Toolkit ; 33 import java.io.File ; 34 import java.io.IOException ; 35 import java.net.URL ; 36 import java.util.Hashtable ; 37 38 import javax.swing.JDesktopPane ; 39 import javax.swing.JFrame ; 40 import javax.swing.JInternalFrame ; 41 import javax.swing.JLabel ; 42 import javax.swing.JMenu ; 43 import javax.swing.JMenuBar ; 44 import javax.swing.JMenuItem ; 45 import javax.swing.JPanel ; 46 import javax.swing.JScrollPane ; 47 import javax.swing.JSplitPane ; 48 import javax.swing.JTabbedPane ; 49 import javax.swing.JTable ; 50 import javax.swing.JTextArea ; 51 import javax.swing.JTextPane ; 52 import javax.swing.ProgressMonitor ; 53 54 import org.objectweb.cjdbc.common.i18n.GuiTranslate; 55 import org.objectweb.cjdbc.console.gui.constants.GuiCommands; 56 import org.objectweb.cjdbc.console.gui.constants.GuiConstants; 57 import org.objectweb.cjdbc.console.gui.constants.GuiIcons; 58 import org.objectweb.cjdbc.console.gui.dnd.listeners.BackendTransferListener; 59 import org.objectweb.cjdbc.console.gui.dnd.listeners.ControllerTransferListener; 60 import org.objectweb.cjdbc.console.gui.frames.GuiExceptionFrame; 61 import org.objectweb.cjdbc.console.gui.frames.GuiNewControllerFrame; 62 import org.objectweb.cjdbc.console.gui.jtools.JTextAreaWriter; 63 import org.objectweb.cjdbc.console.gui.model.JNewList; 64 import org.objectweb.cjdbc.console.gui.popups.ControllerListPopUpMenu; 65 import org.objectweb.cjdbc.console.gui.popups.LoggingPopUpMenu; 66 import org.objectweb.cjdbc.console.gui.popups.XmlEditPopUpMenu; 67 import org.objectweb.cjdbc.console.gui.session.GuiSession; 68 import org.objectweb.cjdbc.console.gui.threads.GuiParsingThread; 69 70 76 public class CjdbcGuiLoader implements Runnable 77 { 78 static final int TOTAL_LOAD_METHOD = 9; 79 private CjdbcGui gui; 80 81 86 public CjdbcGuiLoader(CjdbcGui gui) 87 { 88 this.gui = gui; 89 } 90 91 94 public void run() 95 { 96 ProgressMonitor pm = new ProgressMonitor (gui, GuiTranslate 98 .get("gui.init.loading"), "", 0, 100); 99 pm.setMillisToDecideToPopup(0); 100 pm.setMillisToPopup(0); 101 102 pm.setNote(GuiTranslate.get("gui.init.variables")); 103 pm.setProgress(getProgress(0)); 104 defineMembers(); 105 106 pm.setNote(GuiTranslate.get("gui.init.size")); 107 pm.setProgress(getProgress(1)); 108 defineSize(); 109 110 pm.setNote(GuiTranslate.get("gui.init.left.pane")); 111 pm.setProgress(getProgress(2)); 112 defineLeftPane(); 113 114 pm.setNote(GuiTranslate.get("gui.init.center.pane")); 115 pm.setProgress(getProgress(3)); 116 defineCenterPane(); 117 118 pm.setNote(GuiTranslate.get("gui.init.right.pane")); 119 pm.setProgress(getProgress(4)); 120 122 pm.setNote(GuiTranslate.get("gui.init.frame.controller")); 123 pm.setProgress(getProgress(5)); 124 defineNewControllerFrame(); 125 126 pm.setNote(GuiTranslate.get("gui.init.frame.menu")); 127 pm.setProgress(getProgress(6)); 128 defineMenu(); 129 130 pm.setNote(GuiTranslate.get("gui.init.session")); 131 pm.setProgress(getProgress(7)); 132 defineSession(); 133 134 pm.setNote(GuiTranslate.get("gui.init.rendering")); 135 pm.setProgress(getProgress(8)); 136 defineMainFrame(); 137 138 } 139 140 private int getProgress(int index) 141 { 142 return (index + 1) * 100 / TOTAL_LOAD_METHOD; 143 } 144 145 private void defineMembers() 146 { 147 148 gui.guiSession = new GuiSession(); 150 gui.backendsState = new Hashtable (); 151 gui.backendList = new Hashtable (); 152 gui.databaseMBeans = new Hashtable (); 153 gui.controllerMBeans = new Hashtable (); 154 gui.databaseList = new Hashtable (); 155 gui.controllerList = new Hashtable (); 156 gui.jmxClients = new Hashtable (); 157 158 gui.backendTransferListener = new BackendTransferListener(gui); 160 gui.configurationFileTransferListener = new ControllerTransferListener(gui); 161 162 gui.controllerListPopUpMenu = new ControllerListPopUpMenu(gui); 164 gui.guiActionListener = new CjdbcGuiListener(gui); 165 166 gui.exceptionFrame = new GuiExceptionFrame(gui); 168 } 169 170 private void defineSize() 171 { 172 gui.setBackground(Color.lightGray); 174 gui.getContentPane().setLayout(new BorderLayout ()); 175 Toolkit toolkit = Toolkit.getDefaultToolkit(); 177 Dimension dim = toolkit.getScreenSize(); 178 int screenHeight = dim.height; 179 int screenWidth = dim.width; 180 gui.setBounds((screenWidth - GuiConstants.MAIN_FRAME_WIDTH) / 2, 181 (screenHeight - GuiConstants.MAIN_FRAME_HEIGHT) / 2, 182 GuiConstants.MAIN_FRAME_WIDTH, GuiConstants.MAIN_FRAME_HEIGHT); 183 184 } 185 186 private void defineMenu() 187 { 188 Color toolBarColor = Color.white; 192 JMenuBar menuBar = new JMenuBar (); 193 JMenu menu = new JMenu (GuiTranslate.get("gui.menu.action")); 194 JMenuItem item1 = new JMenuItem (GuiCommands.COMMAND_QUIT); 195 item1.setBackground(toolBarColor); 196 JMenuItem item2 = new JMenuItem (GuiCommands.COMMAND_ADD_CONFIG_FILE); 197 item2.setBackground(toolBarColor); 198 JMenuItem item3 = new JMenuItem (GuiCommands.COMMAND_ADD_CONTROLLER); 199 item3.setBackground(toolBarColor); 200 JMenuItem item4 = new JMenuItem (GuiCommands.COMMAND_SAVE_CONFIGURATION_FILE); 201 item4.setBackground(toolBarColor); 202 JMenuItem item5 = new JMenuItem (GuiCommands.COMMAND_CLEAN_DEBUG_BUFFER); 203 item5.setBackground(toolBarColor); 204 JMenuItem item6 = new JMenuItem (GuiCommands.COMMAND_REFRESH_LOGS); 205 item6.setBackground(toolBarColor); 206 JMenuItem item7 = new JMenuItem (GuiCommands.COMMAND_CLEAN_LOGGING_PANEL); 207 item7.setBackground(toolBarColor); 208 JMenuItem item8 = new JMenuItem ( 209 GuiCommands.COMMAND_MONITOR_CURRENT_CONTROLLER); 210 item8.setBackground(toolBarColor); 211 menu.add(item2).addActionListener(gui.guiActionListener); 212 menu.add(item3).addActionListener(gui.guiActionListener); 213 menu.add(item4).addActionListener(gui.guiActionListener); 214 menu.add(item5).addActionListener(gui.guiActionListener); 215 menu.add(item6).addActionListener(gui.guiActionListener); 216 menu.add(item7).addActionListener(gui.guiActionListener); 217 menu.add(item8).addActionListener(gui.guiActionListener); 218 menu.addSeparator(); 219 menu.add(item1).addActionListener(gui.guiActionListener); 220 menu.setVisible(true); 221 menu.setBackground(toolBarColor); 222 menuBar.add(menu); 223 menuBar.setBackground(toolBarColor); 224 gui.setJMenuBar(menuBar); 225 } 226 227 private void defineSession() 228 { 229 try 233 { 234 gui.guiSession.loadSessionFromFile(new File ( 235 GuiConstants.CJDBC_DEFAULT_SESSION_FILE)); 236 } 237 catch (IOException e) 238 { 239 gui.appendDebugText(e.getMessage()); 240 } 241 gui.actionLoadXmlList(); 242 gui.publicActionLoadControllerList(); 243 } 244 245 private void defineMainFrame() 246 { 247 gui.publicActionRefreshCursorShape(); 249 gui.validate(); 250 gui.setVisible(true); 251 gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 252 } 253 254 private void defineLeftPane() 255 { 256 gui.controllerListPanel = new JPanel (new GridLayout (1, 1)); 260 gui.controllerListPanel.setAlignmentX(JPanel.LEFT_ALIGNMENT); 261 gui.controllerListPanel.setName(GuiConstants.LIST_CONTROLLER); 262 gui.controllerListPanel.addMouseListener(gui.controllerListPopUpMenu); 263 JScrollPane controllerScroll = new JScrollPane (); 264 controllerScroll.getViewport().add(gui.controllerListPanel); 265 JPanel controllerPane = new JPanel (new BorderLayout ()); 266 controllerPane.add(controllerScroll, BorderLayout.CENTER); 267 controllerPane.add(new JLabel (GuiTranslate.get("gui.panel.controllers")), 268 BorderLayout.NORTH); 269 270 gui.vdbListPanel = new JPanel (new GridLayout (1, 1)); 274 gui.vdbListPanel.setAlignmentX(JPanel.LEFT_ALIGNMENT); 275 gui.vdbListPanel.setName(GuiConstants.LIST_DATABASE); 276 JScrollPane vdbScroll = new JScrollPane (); 277 vdbScroll.getViewport().add(gui.vdbListPanel); 278 JPanel vdbPane = new JPanel (new BorderLayout ()); 279 vdbPane.add(vdbScroll, BorderLayout.CENTER); 280 vdbPane.add(new JLabel (GuiTranslate.get("gui.panel.virtualdatabases")), 281 BorderLayout.NORTH); 282 283 gui.fileListPanel = new JPanel (new GridLayout (1, 1)); 287 gui.fileListPanel.setName(GuiConstants.LIST_FILES); 291 gui.fileListPanel.setVisible(true); 292 293 gui.fileScroll = new JScrollPane (); 294 gui.fileScroll 295 .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 296 gui.fileScroll 297 .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); 298 gui.fileScroll.getViewport().add(gui.fileListPanel); 299 JPanel filePane = new JPanel (new BorderLayout ()); 300 filePane.add(gui.fileScroll, BorderLayout.CENTER); 301 filePane.add(new JLabel (GuiTranslate.get("gui.panel.configuration.files")), 302 BorderLayout.NORTH); 303 304 JPanel logo = new JPanel (); 308 logo.setBackground(Color.white); 309 JLabel logoImg = new JLabel (); 310 logoImg.setIcon(GuiIcons.CJDBC_LOGO); 311 logoImg.setMinimumSize(new Dimension (GuiIcons.CJDBC_LOGO.getIconWidth(), 312 GuiIcons.CJDBC_LOGO.getIconHeight())); 313 logo.add(logoImg); 314 315 JPanel leftPane = new JPanel (new GridLayout (4, 1)); 320 leftPane.setMaximumSize(new Dimension (250, gui.getHeight())); 321 leftPane.setPreferredSize(new Dimension (250, gui.getHeight())); 322 323 leftPane.add(controllerPane); 324 leftPane.add(vdbPane); 325 leftPane.add(filePane); 326 leftPane.add(logo); 327 gui.getContentPane().add(leftPane, BorderLayout.WEST); 329 } 330 331 private void defineNewControllerFrame() 332 { 333 gui.newControllerFrame = new GuiNewControllerFrame(gui.guiActionListener); 337 } 338 339 private void defineCenterPane() 340 { 341 342 gui.centerPane = new JTabbedPane (); 346 gui.centerPane.setTabPlacement(JTabbedPane.TOP); 351 gui.jmxPanel = new JDesktopPane (); 355 gui.jmxPanel.addFocusListener(gui.guiActionListener); 356 gui.mbeanList = new JNewList(); 357 gui.mbeanList.addListSelectionListener(gui.guiActionListener); 358 gui.jmxScroll = new JScrollPane (gui.mbeanList); 359 360 gui.mbeanFrame = new JInternalFrame ("Jmx MBeans List", true); 362 gui.mbeanFrame.setBackground(Color.WHITE); 363 gui.mbeanFrame.getContentPane().add(gui.jmxScroll); 364 gui.mbeanFrame.setSize(300, 400); 365 gui.mbeanFrame.setVisible(true); 366 367 gui.jmxPanel.add(gui.mbeanFrame); 368 369 gui.attributeFrame = new JInternalFrame ("Jmx MBean Attributes", true); 371 gui.attributeFrame.setBackground(Color.WHITE); 372 gui.attributeTable = new JTable (); 373 gui.attributeTable.setName(GuiConstants.TABLE_JMX_ATTRIBUTES); 374 gui.attributeTable.addMouseListener(gui.guiActionListener); 375 gui.attributePane = new JScrollPane (gui.attributeTable); 376 gui.attributeFrame.getContentPane().add(gui.attributePane); 377 gui.attributeFrame.setSize(300, 400); 378 Point point = ((Point ) gui.jmxPanel.getLocation().clone()); 379 point.move(300, 0); 380 gui.attributeFrame.setLocation(point); 381 gui.attributeFrame.setVisible(true); 382 gui.attributeFrame.validate(); 383 gui.jmxPanel.add(gui.attributeFrame); 384 385 gui.operationFrame = new JInternalFrame ("Jmx MBean Operations", true); 387 gui.operationFrame.setBackground(Color.WHITE); 388 gui.operationTable = new JTable (); 389 gui.operationTable.setName(GuiConstants.TABLE_JMX_OPERATIONS); 390 gui.operationTable.addMouseListener(gui.guiActionListener); 391 gui.operationPane = new JScrollPane (gui.operationTable); 392 gui.operationFrame.getContentPane().add(gui.operationPane); 393 gui.operationFrame.setSize(300, 400); 394 Point point2 = ((Point ) gui.jmxPanel.getLocation().clone()); 395 point2.move(600, 0); 396 gui.operationFrame.setLocation(point2); 397 gui.operationFrame.setVisible(true); 398 gui.operationFrame.validate(); 399 gui.jmxPanel.add(gui.operationFrame); 400 401 gui.debugScroll = new JScrollPane (); 405 gui.debugText = ""; 406 gui.debugTextPane = new JTextArea (); 407 gui.debugTextPane.setFont(GuiConstants.CENTER_PANE_FONT); 408 gui.debugTextPane.setEditable(false); 409 gui.debugTextPane.setText(gui.debugText); 410 gui.debugTextPane.setBackground(Color.white); 411 412 gui.debugTraceTextPane = new JTextArea (); 413 gui.debugTraceTextPane.setFont(GuiConstants.CENTER_PANE_FONT); 414 gui.debugTraceTextPane.setEditable(false); 415 gui.debugTraceTextPane.setBackground(Color.white); 416 gui.traceWriter = new JTextAreaWriter(gui.debugTraceTextPane); 417 418 JSplitPane pane = new JSplitPane (JSplitPane.HORIZONTAL_SPLIT, false, 419 gui.debugTextPane, gui.debugTraceTextPane); 420 gui.debugScroll.getViewport().add(pane); 421 422 gui.actionLoadBackendPane(true); 426 427 gui.helpScroll = new JScrollPane (); 431 gui.xmlTextPane = new JTextPane (); 432 JTextPane helpPanel = new JTextPane (); 433 URL localUrl = this.getClass().getResource("/userGuide.html"); 434 if (localUrl != null) 435 { 436 try 437 { 438 helpPanel.setPage(localUrl); 439 } 440 catch (IOException e) 441 { 442 gui.appendDebugText("Failed to load local help...", e); 443 helpPanel.setEnabled(false); 444 } 445 } 446 else 447 { 448 gui.appendDebugText("Failed to load local help..."); 449 try 450 { 451 URL url = new URL (GuiConstants.CJDBC_URL_DOC); 452 helpPanel.setPage(url); 453 } 454 catch (Exception e) 455 { 456 helpPanel.setText("Could not load online help..."); 457 helpPanel.setEnabled(false); 458 } 459 } 460 helpPanel.setEditable(false); 461 gui.helpScroll = new JScrollPane (); 462 gui.helpScroll.getViewport().add(helpPanel); 463 464 gui.xmlScroll = new JScrollPane (); 468 gui.xmlTextPane = new JTextPane (); 469 gui.xmlTextPane.setText(gui.actionLoadXmlText(null)); 470 gui.xmlTextPane.setFont(GuiConstants.CENTER_PANE_FONT); 471 gui.xmlTextPane.setBackground(Color.white); 472 gui.xmlTextPane.setEditable(true); 473 gui.xmlTextPane.addMouseListener(new XmlEditPopUpMenu(gui)); 474 gui.xmlScroll.getViewport().add(gui.xmlTextPane); 475 gui.parsingThread = new GuiParsingThread(gui.xmlTextPane); 477 gui.parsingThread.start(); 478 gui.xmlTextPane.addKeyListener(gui.parsingThread); 479 480 gui.loggingScroll = new JScrollPane (); 484 gui.loggingTextPane = new JTextArea (); 485 gui.loggingTextPane.setFont(GuiConstants.CENTER_PANE_FONT); 486 gui.loggingTextPane.setEditable(false); 487 gui.loggingTextPane.addMouseListener(new LoggingPopUpMenu(gui)); 488 gui.loggingTextPane.setBackground(Color.white); 489 gui.loggingScroll.getViewport().add(gui.loggingTextPane); 490 491 gui.infoScroll = new JScrollPane (); 495 gui.infoTextPane = new JTextPane (); 496 gui.infoTextPane.setFont(GuiConstants.CENTER_PANE_FONT); 497 gui.infoTextPane.setEditable(false); 498 gui.infoTextPane.setBackground(Color.white); 499 gui.infoScroll.getViewport().add(gui.infoTextPane); 500 501 gui.logConfigScroll = new JScrollPane (); 505 gui.logConfigTextPane = new JTextPane (); 506 gui.logConfigTextPane.setFont(GuiConstants.CENTER_PANE_FONT); 507 gui.logConfigTextPane.setEditable(true); 508 gui.logConfigTextPane.setBackground(Color.white); 509 gui.logConfigScroll.getViewport().add(gui.logConfigTextPane); 510 511 gui.centerPane.addTab(GuiTranslate.get("gui.panel.backends"), 515 GuiIcons.BACKEND_PANEL_ICON, gui.backendPanel); 516 517 gui.centerPane.addFocusListener(gui.guiActionListener); 518 519 gui.centerPane.addTab(GuiTranslate.get("gui.panel.jmx"), 520 GuiIcons.JMX_PANEL_ICON, gui.jmxPanel); 521 522 gui.centerPane.addTab(GuiTranslate.get("gui.panel.xml"), 523 GuiIcons.XML_PANEL_ICON, gui.xmlScroll); 524 gui.centerPane.addTab(GuiTranslate.get("gui.panel.info"), 525 GuiIcons.INFO_PANEL_ICON, gui.infoScroll); 526 gui.centerPane.addTab(GuiTranslate.get("gui.panel.logging"), 527 GuiIcons.LOGGING_PANEL_ICON, gui.loggingScroll); 528 gui.centerPane.addTab(GuiTranslate.get("gui.panel.log.config"), 529 GuiIcons.LOG_CONFIG_PANEL_ICON, gui.logConfigScroll); 530 gui.getContentPane().add(gui.centerPane, BorderLayout.CENTER); 531 gui.centerPane.addTab(GuiTranslate.get("gui.panel.debug"), 532 GuiIcons.DEBUG_PANEL_ICON, gui.debugScroll); 533 gui.centerPane.addTab(GuiTranslate.get("gui.panel.help"), 534 GuiIcons.HELP_PANEL_ICON, gui.helpScroll); 535 } 536 537 } | Popular Tags |