00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 package org.objectweb.cjdbc.console.gui;
00026
00027 import java.awt.BorderLayout;
00028 import java.awt.Color;
00029 import java.awt.Dimension;
00030 import java.awt.GridLayout;
00031 import java.awt.Point;
00032 import java.awt.Toolkit;
00033 import java.io.File;
00034 import java.io.IOException;
00035 import java.net.URL;
00036 import java.util.Hashtable;
00037
00038 import javax.swing.JDesktopPane;
00039 import javax.swing.JFrame;
00040 import javax.swing.JInternalFrame;
00041 import javax.swing.JLabel;
00042 import javax.swing.JMenu;
00043 import javax.swing.JMenuBar;
00044 import javax.swing.JMenuItem;
00045 import javax.swing.JPanel;
00046 import javax.swing.JScrollPane;
00047 import javax.swing.JSplitPane;
00048 import javax.swing.JTabbedPane;
00049 import javax.swing.JTable;
00050 import javax.swing.JTextArea;
00051 import javax.swing.JTextPane;
00052 import javax.swing.ProgressMonitor;
00053
00054 import org.objectweb.cjdbc.common.i18n.GuiTranslate;
00055 import org.objectweb.cjdbc.console.gui.constants.GuiCommands;
00056 import org.objectweb.cjdbc.console.gui.constants.GuiConstants;
00057 import org.objectweb.cjdbc.console.gui.constants.GuiIcons;
00058 import org.objectweb.cjdbc.console.gui.dnd.listeners.BackendTransferListener;
00059 import org.objectweb.cjdbc.console.gui.dnd.listeners.ControllerTransferListener;
00060 import org.objectweb.cjdbc.console.gui.frames.GuiExceptionFrame;
00061 import org.objectweb.cjdbc.console.gui.frames.GuiNewControllerFrame;
00062 import org.objectweb.cjdbc.console.gui.jtools.JTextAreaWriter;
00063 import org.objectweb.cjdbc.console.gui.model.JNewList;
00064 import org.objectweb.cjdbc.console.gui.popups.ControllerListPopUpMenu;
00065 import org.objectweb.cjdbc.console.gui.popups.LoggingPopUpMenu;
00066 import org.objectweb.cjdbc.console.gui.popups.XmlEditPopUpMenu;
00067 import org.objectweb.cjdbc.console.gui.session.GuiSession;
00068 import org.objectweb.cjdbc.console.gui.threads.GuiParsingThread;
00069
00070
00071
00072
00073
00074
00075
00076 public class CjdbcGuiLoader implements Runnable
00077 {
00078 static final int TOTAL_LOAD_METHOD = 9;
00079 private CjdbcGui gui;
00080
00081
00082
00083
00084
00085
00086 public CjdbcGuiLoader(CjdbcGui gui)
00087 {
00088 this.gui = gui;
00089 }
00090
00091
00092
00093
00094 public void run()
00095 {
00096
00097 ProgressMonitor pm = new ProgressMonitor(gui, GuiTranslate
00098 .get("gui.init.loading"), "", 0, 100);
00099 pm.setMillisToDecideToPopup(0);
00100 pm.setMillisToPopup(0);
00101
00102 pm.setNote(GuiTranslate.get("gui.init.variables"));
00103 pm.setProgress(getProgress(0));
00104 defineMembers();
00105
00106 pm.setNote(GuiTranslate.get("gui.init.size"));
00107 pm.setProgress(getProgress(1));
00108 defineSize();
00109
00110 pm.setNote(GuiTranslate.get("gui.init.left.pane"));
00111 pm.setProgress(getProgress(2));
00112 defineLeftPane();
00113
00114 pm.setNote(GuiTranslate.get("gui.init.center.pane"));
00115 pm.setProgress(getProgress(3));
00116 defineCenterPane();
00117
00118 pm.setNote(GuiTranslate.get("gui.init.right.pane"));
00119 pm.setProgress(getProgress(4));
00120
00121
00122 pm.setNote(GuiTranslate.get("gui.init.frame.controller"));
00123 pm.setProgress(getProgress(5));
00124 defineNewControllerFrame();
00125
00126 pm.setNote(GuiTranslate.get("gui.init.frame.menu"));
00127 pm.setProgress(getProgress(6));
00128 defineMenu();
00129
00130 pm.setNote(GuiTranslate.get("gui.init.session"));
00131 pm.setProgress(getProgress(7));
00132 defineSession();
00133
00134 pm.setNote(GuiTranslate.get("gui.init.rendering"));
00135 pm.setProgress(getProgress(8));
00136 defineMainFrame();
00137
00138 }
00139
00140 private int getProgress(int index)
00141 {
00142 return (index + 1) * 100 / TOTAL_LOAD_METHOD;
00143 }
00144
00145 private void defineMembers()
00146 {
00147
00148
00149 gui.guiSession = new GuiSession();
00150 gui.backendsState = new Hashtable();
00151 gui.backendList = new Hashtable();
00152 gui.databaseMBeans = new Hashtable();
00153 gui.controllerMBeans = new Hashtable();
00154 gui.databaseList = new Hashtable();
00155 gui.controllerList = new Hashtable();
00156 gui.jmxClients = new Hashtable();
00157
00158
00159 gui.backendTransferListener = new BackendTransferListener(gui);
00160 gui.configurationFileTransferListener = new ControllerTransferListener(gui);
00161
00162
00163 gui.controllerListPopUpMenu = new ControllerListPopUpMenu(gui);
00164 gui.guiActionListener = new CjdbcGuiListener(gui);
00165
00166
00167 gui.exceptionFrame = new GuiExceptionFrame(gui);
00168 }
00169
00170 private void defineSize()
00171 {
00172
00173 gui.setBackground(Color.lightGray);
00174 gui.getContentPane().setLayout(new BorderLayout());
00175
00176 Toolkit toolkit = Toolkit.getDefaultToolkit();
00177 Dimension dim = toolkit.getScreenSize();
00178 int screenHeight = dim.height;
00179 int screenWidth = dim.width;
00180 gui.setBounds((screenWidth - GuiConstants.MAIN_FRAME_WIDTH) / 2,
00181 (screenHeight - GuiConstants.MAIN_FRAME_HEIGHT) / 2,
00182 GuiConstants.MAIN_FRAME_WIDTH, GuiConstants.MAIN_FRAME_HEIGHT);
00183
00184 }
00185
00186 private void defineMenu()
00187 {
00188
00189
00190
00191 Color toolBarColor = Color.white;
00192 JMenuBar menuBar = new JMenuBar();
00193 JMenu menu = new JMenu(GuiTranslate.get("gui.menu.action"));
00194 JMenuItem item1 = new JMenuItem(GuiCommands.COMMAND_QUIT);
00195 item1.setBackground(toolBarColor);
00196 JMenuItem item2 = new JMenuItem(GuiCommands.COMMAND_ADD_CONFIG_FILE);
00197 item2.setBackground(toolBarColor);
00198 JMenuItem item3 = new JMenuItem(GuiCommands.COMMAND_ADD_CONTROLLER);
00199 item3.setBackground(toolBarColor);
00200 JMenuItem item4 = new JMenuItem(GuiCommands.COMMAND_SAVE_CONFIGURATION_FILE);
00201 item4.setBackground(toolBarColor);
00202 JMenuItem item5 = new JMenuItem(GuiCommands.COMMAND_CLEAN_DEBUG_BUFFER);
00203 item5.setBackground(toolBarColor);
00204 JMenuItem item6 = new JMenuItem(GuiCommands.COMMAND_REFRESH_LOGS);
00205 item6.setBackground(toolBarColor);
00206 JMenuItem item7 = new JMenuItem(GuiCommands.COMMAND_CLEAN_LOGGING_PANEL);
00207 item7.setBackground(toolBarColor);
00208 JMenuItem item8 = new JMenuItem(
00209 GuiCommands.COMMAND_MONITOR_CURRENT_CONTROLLER);
00210 item8.setBackground(toolBarColor);
00211 menu.add(item2).addActionListener(gui.guiActionListener);
00212 menu.add(item3).addActionListener(gui.guiActionListener);
00213 menu.add(item4).addActionListener(gui.guiActionListener);
00214 menu.add(item5).addActionListener(gui.guiActionListener);
00215 menu.add(item6).addActionListener(gui.guiActionListener);
00216 menu.add(item7).addActionListener(gui.guiActionListener);
00217 menu.add(item8).addActionListener(gui.guiActionListener);
00218 menu.addSeparator();
00219 menu.add(item1).addActionListener(gui.guiActionListener);
00220 menu.setVisible(true);
00221 menu.setBackground(toolBarColor);
00222 menuBar.add(menu);
00223 menuBar.setBackground(toolBarColor);
00224 gui.setJMenuBar(menuBar);
00225 }
00226
00227 private void defineSession()
00228 {
00229
00230
00231
00232 try
00233 {
00234 gui.guiSession.loadSessionFromFile(new File(
00235 GuiConstants.CJDBC_DEFAULT_SESSION_FILE));
00236 }
00237 catch (IOException e)
00238 {
00239 gui.appendDebugText(e.getMessage());
00240 }
00241 gui.actionLoadXmlList();
00242 gui.publicActionLoadControllerList();
00243 }
00244
00245 private void defineMainFrame()
00246 {
00247
00248 gui.publicActionRefreshCursorShape();
00249 gui.validate();
00250 gui.setVisible(true);
00251 gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
00252 }
00253
00254 private void defineLeftPane()
00255 {
00256
00257
00258
00259 gui.controllerListPanel = new JPanel(new GridLayout(1, 1));
00260 gui.controllerListPanel.setAlignmentX(JPanel.LEFT_ALIGNMENT);
00261 gui.controllerListPanel.setName(GuiConstants.LIST_CONTROLLER);
00262 gui.controllerListPanel.addMouseListener(gui.controllerListPopUpMenu);
00263 JScrollPane controllerScroll = new JScrollPane();
00264 controllerScroll.getViewport().add(gui.controllerListPanel);
00265 JPanel controllerPane = new JPanel(new BorderLayout());
00266 controllerPane.add(controllerScroll, BorderLayout.CENTER);
00267 controllerPane.add(new JLabel(GuiTranslate.get("gui.panel.controllers")),
00268 BorderLayout.NORTH);
00269
00270
00271
00272
00273 gui.vdbListPanel = new JPanel(new GridLayout(1, 1));
00274 gui.vdbListPanel.setAlignmentX(JPanel.LEFT_ALIGNMENT);
00275 gui.vdbListPanel.setName(GuiConstants.LIST_DATABASE);
00276 JScrollPane vdbScroll = new JScrollPane();
00277 vdbScroll.getViewport().add(gui.vdbListPanel);
00278 JPanel vdbPane = new JPanel(new BorderLayout());
00279 vdbPane.add(vdbScroll, BorderLayout.CENTER);
00280 vdbPane.add(new JLabel(GuiTranslate.get("gui.panel.virtualdatabases")),
00281 BorderLayout.NORTH);
00282
00283
00284
00285
00286 gui.fileListPanel = new JPanel(new GridLayout(1, 1));
00287
00288
00289
00290 gui.fileListPanel.setName(GuiConstants.LIST_FILES);
00291 gui.fileListPanel.setVisible(true);
00292
00293 gui.fileScroll = new JScrollPane();
00294 gui.fileScroll
00295 .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
00296 gui.fileScroll
00297 .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
00298 gui.fileScroll.getViewport().add(gui.fileListPanel);
00299 JPanel filePane = new JPanel(new BorderLayout());
00300 filePane.add(gui.fileScroll, BorderLayout.CENTER);
00301 filePane.add(new JLabel(GuiTranslate.get("gui.panel.configuration.files")),
00302 BorderLayout.NORTH);
00303
00304
00305
00306
00307 JPanel logo = new JPanel();
00308 logo.setBackground(Color.white);
00309 JLabel logoImg = new JLabel();
00310 logoImg.setIcon(GuiIcons.CJDBC_LOGO);
00311 logoImg.setMinimumSize(new Dimension(GuiIcons.CJDBC_LOGO.getIconWidth(),
00312 GuiIcons.CJDBC_LOGO.getIconHeight()));
00313 logo.add(logoImg);
00314
00315
00316
00317
00318
00319 JPanel leftPane = new JPanel(new GridLayout(4, 1));
00320 leftPane.setMaximumSize(new Dimension(250, gui.getHeight()));
00321 leftPane.setPreferredSize(new Dimension(250, gui.getHeight()));
00322
00323 leftPane.add(controllerPane);
00324 leftPane.add(vdbPane);
00325 leftPane.add(filePane);
00326 leftPane.add(logo);
00327
00328 gui.getContentPane().add(leftPane, BorderLayout.WEST);
00329 }
00330
00331 private void defineNewControllerFrame()
00332 {
00333
00334
00335
00336 gui.newControllerFrame = new GuiNewControllerFrame(gui.guiActionListener);
00337 }
00338
00339 private void defineCenterPane()
00340 {
00341
00342
00343
00344
00345 gui.centerPane = new JTabbedPane();
00346 gui.centerPane.setTabPlacement(JTabbedPane.TOP);
00347
00348
00349
00350
00351
00352
00353
00354 gui.jmxPanel = new JDesktopPane();
00355 gui.jmxPanel.addFocusListener(gui.guiActionListener);
00356 gui.mbeanList = new JNewList();
00357 gui.mbeanList.addListSelectionListener(gui.guiActionListener);
00358 gui.jmxScroll = new JScrollPane(gui.mbeanList);
00359
00360
00361 gui.mbeanFrame = new JInternalFrame("Jmx MBeans List", true);
00362 gui.mbeanFrame.setBackground(Color.WHITE);
00363 gui.mbeanFrame.getContentPane().add(gui.jmxScroll);
00364 gui.mbeanFrame.setSize(300, 400);
00365 gui.mbeanFrame.setVisible(true);
00366
00367 gui.jmxPanel.add(gui.mbeanFrame);
00368
00369
00370 gui.attributeFrame = new JInternalFrame("Jmx MBean Attributes", true);
00371 gui.attributeFrame.setBackground(Color.WHITE);
00372 gui.attributeTable = new JTable();
00373 gui.attributeTable.setName(GuiConstants.TABLE_JMX_ATTRIBUTES);
00374 gui.attributeTable.addMouseListener(gui.guiActionListener);
00375 gui.attributePane = new JScrollPane(gui.attributeTable);
00376 gui.attributeFrame.getContentPane().add(gui.attributePane);
00377 gui.attributeFrame.setSize(300, 400);
00378 Point point = ((Point) gui.jmxPanel.getLocation().clone());
00379 point.move(300, 0);
00380 gui.attributeFrame.setLocation(point);
00381 gui.attributeFrame.setVisible(true);
00382 gui.attributeFrame.validate();
00383 gui.jmxPanel.add(gui.attributeFrame);
00384
00385
00386 gui.operationFrame = new JInternalFrame("Jmx MBean Operations", true);
00387 gui.operationFrame.setBackground(Color.WHITE);
00388 gui.operationTable = new JTable();
00389 gui.operationTable.setName(GuiConstants.TABLE_JMX_OPERATIONS);
00390 gui.operationTable.addMouseListener(gui.guiActionListener);
00391 gui.operationPane = new JScrollPane(gui.operationTable);
00392 gui.operationFrame.getContentPane().add(gui.operationPane);
00393 gui.operationFrame.setSize(300, 400);
00394 Point point2 = ((Point) gui.jmxPanel.getLocation().clone());
00395 point2.move(600, 0);
00396 gui.operationFrame.setLocation(point2);
00397 gui.operationFrame.setVisible(true);
00398 gui.operationFrame.validate();
00399 gui.jmxPanel.add(gui.operationFrame);
00400
00401
00402
00403
00404 gui.debugScroll = new JScrollPane();
00405 gui.debugText = "";
00406 gui.debugTextPane = new JTextArea();
00407 gui.debugTextPane.setFont(GuiConstants.CENTER_PANE_FONT);
00408 gui.debugTextPane.setEditable(false);
00409 gui.debugTextPane.setText(gui.debugText);
00410 gui.debugTextPane.setBackground(Color.white);
00411
00412 gui.debugTraceTextPane = new JTextArea();
00413 gui.debugTraceTextPane.setFont(GuiConstants.CENTER_PANE_FONT);
00414 gui.debugTraceTextPane.setEditable(false);
00415 gui.debugTraceTextPane.setBackground(Color.white);
00416 gui.traceWriter = new JTextAreaWriter(gui.debugTraceTextPane);
00417
00418 JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false,
00419 gui.debugTextPane, gui.debugTraceTextPane);
00420 gui.debugScroll.getViewport().add(pane);
00421
00422
00423
00424
00425 gui.actionLoadBackendPane(true);
00426
00427
00428
00429
00430 gui.helpScroll = new JScrollPane();
00431 gui.xmlTextPane = new JTextPane();
00432 JTextPane helpPanel = new JTextPane();
00433 URL localUrl = this.getClass().getResource("/userGuide.html");
00434 if (localUrl != null)
00435 {
00436 try
00437 {
00438 helpPanel.setPage(localUrl);
00439 }
00440 catch (IOException e)
00441 {
00442 gui.appendDebugText("Failed to load local help...", e);
00443 helpPanel.setEnabled(false);
00444 }
00445 }
00446 else
00447 {
00448 gui.appendDebugText("Failed to load local help...");
00449 try
00450 {
00451 URL url = new URL(GuiConstants.CJDBC_URL_DOC);
00452 helpPanel.setPage(url);
00453 }
00454 catch (Exception e)
00455 {
00456 helpPanel.setText("Could not load online help...");
00457 helpPanel.setEnabled(false);
00458 }
00459 }
00460 helpPanel.setEditable(false);
00461 gui.helpScroll = new JScrollPane();
00462 gui.helpScroll.getViewport().add(helpPanel);
00463
00464
00465
00466
00467 gui.xmlScroll = new JScrollPane();
00468 gui.xmlTextPane = new JTextPane();
00469 gui.xmlTextPane.setText(gui.actionLoadXmlText(null));
00470 gui.xmlTextPane.setFont(GuiConstants.CENTER_PANE_FONT);
00471 gui.xmlTextPane.setBackground(Color.white);
00472 gui.xmlTextPane.setEditable(true);
00473 gui.xmlTextPane.addMouseListener(new XmlEditPopUpMenu(gui));
00474 gui.xmlScroll.getViewport().add(gui.xmlTextPane);
00475
00476 gui.parsingThread = new GuiParsingThread(gui.xmlTextPane);
00477 gui.parsingThread.start();
00478 gui.xmlTextPane.addKeyListener(gui.parsingThread);
00479
00480
00481
00482
00483 gui.loggingScroll = new JScrollPane();
00484 gui.loggingTextPane = new JTextArea();
00485 gui.loggingTextPane.setFont(GuiConstants.CENTER_PANE_FONT);
00486 gui.loggingTextPane.setEditable(false);
00487 gui.loggingTextPane.addMouseListener(new LoggingPopUpMenu(gui));
00488 gui.loggingTextPane.setBackground(Color.white);
00489 gui.loggingScroll.getViewport().add(gui.loggingTextPane);
00490
00491
00492
00493
00494 gui.infoScroll = new JScrollPane();
00495 gui.infoTextPane = new JTextPane();
00496 gui.infoTextPane.setFont(GuiConstants.CENTER_PANE_FONT);
00497 gui.infoTextPane.setEditable(false);
00498 gui.infoTextPane.setBackground(Color.white);
00499 gui.infoScroll.getViewport().add(gui.infoTextPane);
00500
00501
00502
00503
00504 gui.logConfigScroll = new JScrollPane();
00505 gui.logConfigTextPane = new JTextPane();
00506 gui.logConfigTextPane.setFont(GuiConstants.CENTER_PANE_FONT);
00507 gui.logConfigTextPane.setEditable(true);
00508 gui.logConfigTextPane.setBackground(Color.white);
00509 gui.logConfigScroll.getViewport().add(gui.logConfigTextPane);
00510
00511
00512
00513
00514 gui.centerPane.addTab(GuiTranslate.get("gui.panel.backends"),
00515 GuiIcons.BACKEND_PANEL_ICON, gui.backendPanel);
00516
00517 gui.centerPane.addFocusListener(gui.guiActionListener);
00518
00519 gui.centerPane.addTab(GuiTranslate.get("gui.panel.jmx"),
00520 GuiIcons.JMX_PANEL_ICON, gui.jmxPanel);
00521
00522 gui.centerPane.addTab(GuiTranslate.get("gui.panel.xml"),
00523 GuiIcons.XML_PANEL_ICON, gui.xmlScroll);
00524 gui.centerPane.addTab(GuiTranslate.get("gui.panel.info"),
00525 GuiIcons.INFO_PANEL_ICON, gui.infoScroll);
00526 gui.centerPane.addTab(GuiTranslate.get("gui.panel.logging"),
00527 GuiIcons.LOGGING_PANEL_ICON, gui.loggingScroll);
00528 gui.centerPane.addTab(GuiTranslate.get("gui.panel.log.config"),
00529 GuiIcons.LOG_CONFIG_PANEL_ICON, gui.logConfigScroll);
00530 gui.getContentPane().add(gui.centerPane, BorderLayout.CENTER);
00531 gui.centerPane.addTab(GuiTranslate.get("gui.panel.debug"),
00532 GuiIcons.DEBUG_PANEL_ICON, gui.debugScroll);
00533 gui.centerPane.addTab(GuiTranslate.get("gui.panel.help"),
00534 GuiIcons.HELP_PANEL_ICON, gui.helpScroll);
00535 }
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552 }