00001
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.Font;
00031
import java.awt.GridLayout;
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.JFrame;
00039
import javax.swing.JLabel;
00040
import javax.swing.JMenu;
00041
import javax.swing.JMenuBar;
00042
import javax.swing.JMenuItem;
00043
import javax.swing.JPanel;
00044
import javax.swing.JScrollPane;
00045
import javax.swing.JSplitPane;
00046
import javax.swing.JTabbedPane;
00047
import javax.swing.JTextArea;
00048
import javax.swing.JTextPane;
00049
import javax.swing.ProgressMonitor;
00050
00051
import org.objectweb.cjdbc.common.i18n.GuiTranslate;
00052
import org.objectweb.cjdbc.console.gui.constants.GuiCommands;
00053
import org.objectweb.cjdbc.console.gui.constants.GuiConstants;
00054
import org.objectweb.cjdbc.console.gui.constants.GuiIcons;
00055
import org.objectweb.cjdbc.console.gui.dnd.listeners.BackendTransferListener;
00056
import org.objectweb.cjdbc.console.gui.dnd.listeners.ControllerTransferListener;
00057
import org.objectweb.cjdbc.console.gui.frames.GuiExceptionFrame;
00058
import org.objectweb.cjdbc.console.gui.frames.GuiNewControllerFrame;
00059
import org.objectweb.cjdbc.console.gui.jtools.JTextAreaWriter;
00060
import org.objectweb.cjdbc.console.gui.popups.ControllerListPopUpMenu;
00061
import org.objectweb.cjdbc.console.gui.popups.LoggingPopUpMenu;
00062
import org.objectweb.cjdbc.console.gui.popups.XmlEditPopUpMenu;
00063
import org.objectweb.cjdbc.console.gui.session.GuiSession;
00064
import org.objectweb.cjdbc.console.gui.threads.GuiParsingThread;
00065
00072 public class CjdbcGuiLoader implements Runnable
00073 {
00074 static final int TOTAL_LOAD_METHOD = 9;
00075 private CjdbcGui gui;
00076
00082 public CjdbcGuiLoader(
CjdbcGui gui)
00083 {
00084
this.gui = gui;
00085 }
00086
00090 public void run()
00091 {
00092
00093 ProgressMonitor pm =
new ProgressMonitor(
gui,
GuiTranslate
00094 .get(
"gui.init.loading"),
"", 0, 100);
00095 pm.setMillisToDecideToPopup(0);
00096 pm.setMillisToPopup(0);
00097
00098 pm.setNote(
GuiTranslate.get(
"gui.init.variables"));
00099 pm.setProgress(
getProgress(0));
00100
defineMembers();
00101
00102 pm.setNote(
GuiTranslate.get(
"gui.init.size"));
00103 pm.setProgress(
getProgress(1));
00104
defineSize();
00105
00106 pm.setNote(
GuiTranslate.get(
"gui.init.left.pane"));
00107 pm.setProgress(
getProgress(2));
00108
defineLeftPane();
00109
00110 pm.setNote(
GuiTranslate.get(
"gui.init.center.pane"));
00111 pm.setProgress(
getProgress(3));
00112
defineCenterPane();
00113
00114 pm.setNote(
GuiTranslate.get(
"gui.init.right.pane"));
00115 pm.setProgress(
getProgress(4));
00116
defineRightPane();
00117
00118 pm.setNote(
GuiTranslate.get(
"gui.init.frame.controller"));
00119 pm.setProgress(
getProgress(5));
00120
defineNewControllerFrame();
00121
00122 pm.setNote(
GuiTranslate.get(
"gui.init.frame.menu"));
00123 pm.setProgress(
getProgress(6));
00124
defineMenu();
00125
00126 pm.setNote(
GuiTranslate.get(
"gui.init.session"));
00127 pm.setProgress(
getProgress(7));
00128
defineSession();
00129
00130 pm.setNote(
GuiTranslate.get(
"gui.init.rendering"));
00131 pm.setProgress(
getProgress(8));
00132
defineMainFrame();
00133
00134 }
00135
00136 private int getProgress(
int index)
00137 {
00138
return (index + 1) * 100 /
TOTAL_LOAD_METHOD;
00139 }
00140
00141 private void defineMembers()
00142 {
00143
00144
00145
gui.
guiSession =
new GuiSession();
00146
gui.
backendsState =
new Hashtable();
00147
gui.
backendList =
new Hashtable();
00148
gui.
databaseMBeans =
new Hashtable();
00149
gui.
controllerMBeans =
new Hashtable();
00150
gui.
databaseList =
new Hashtable();
00151
gui.
controllerList =
new Hashtable();
00152
gui.
jmxClients =
new Hashtable();
00153
00154
00155
gui.
backendTransferListener =
new BackendTransferListener(
gui);
00156
gui.
configurationFileTransferListener =
new ControllerTransferListener(
gui);
00157
00158
00159
gui.
controllerListPopUpMenu =
new ControllerListPopUpMenu(
gui);
00160
gui.
guiActionListener =
new CjdbcGuiListener(
gui);
00161
00162
00163
gui.
exceptionFrame =
new GuiExceptionFrame(
gui);
00164 }
00165
00166 private void defineSize()
00167 {
00168
00169
gui.setBackground(Color.lightGray);
00170
gui.getContentPane().setLayout(
new BorderLayout());
00171
00172 Toolkit toolkit = Toolkit.getDefaultToolkit();
00173 Dimension dim = toolkit.getScreenSize();
00174
int screenHeight = dim.height;
00175
int screenWidth = dim.width;
00176
gui.setBounds((screenWidth -
GuiConstants.MAIN_FRAME_WIDTH) / 2,
00177 (screenHeight -
GuiConstants.MAIN_FRAME_HEIGHT) / 2,
00178
GuiConstants.MAIN_FRAME_WIDTH,
GuiConstants.MAIN_FRAME_HEIGHT);
00179
00180 }
00181
00182 private void defineMenu()
00183 {
00185
00187 Color toolBarColor = Color.white;
00188 JMenuBar menuBar =
new JMenuBar();
00189 JMenu menu =
new JMenu(
GuiTranslate.get(
"gui.menu.action"));
00190 JMenuItem item1 =
new JMenuItem(
GuiCommands.COMMAND_QUIT);
00191 item1.setBackground(toolBarColor);
00192 JMenuItem item2 =
new JMenuItem(
GuiCommands.COMMAND_ADD_CONFIG_FILE);
00193 item2.setBackground(toolBarColor);
00194 JMenuItem item3 =
new JMenuItem(
GuiCommands.COMMAND_ADD_CONTROLLER);
00195 item3.setBackground(toolBarColor);
00196 JMenuItem item4 =
new JMenuItem(
GuiCommands.COMMAND_SAVE_CONFIGURATION_FILE);
00197 item4.setBackground(toolBarColor);
00198 JMenuItem item5 =
new JMenuItem(
GuiCommands.COMMAND_CLEAN_DEBUG_BUFFER);
00199 item5.setBackground(toolBarColor);
00200 JMenuItem item6 =
new JMenuItem(
GuiCommands.COMMAND_REFRESH_LOGS);
00201 item6.setBackground(toolBarColor);
00202 JMenuItem item7 =
new JMenuItem(
GuiCommands.COMMAND_CLEAN_LOGGING_PANEL);
00203 item7.setBackground(toolBarColor);
00204 menu.add(item2).addActionListener(
gui.
guiActionListener);
00205 menu.add(item3).addActionListener(
gui.
guiActionListener);
00206 menu.add(item4).addActionListener(
gui.
guiActionListener);
00207 menu.add(item5).addActionListener(
gui.
guiActionListener);
00208 menu.add(item6).addActionListener(
gui.
guiActionListener);
00209 menu.add(item7).addActionListener(
gui.
guiActionListener);
00210 menu.addSeparator();
00211 menu.add(item1).addActionListener(
gui.
guiActionListener);
00212 menu.setVisible(
true);
00213 menu.setBackground(toolBarColor);
00214 menuBar.add(menu);
00215 menuBar.setBackground(toolBarColor);
00216
gui.setJMenuBar(menuBar);
00217 }
00218
00219 private void defineSession()
00220 {
00222
00224
try
00225 {
00226
gui.
guiSession.
loadSessionFromFile(
new File(
00227
GuiConstants.CJDBC_DEFAULT_SESSION_FILE));
00228 }
00229
catch (IOException e)
00230 {
00231
gui.
appendDebugText(e.getMessage());
00232 }
00233
gui.
actionLoadXmlList();
00234
gui.
publicActionLoadControllerList();
00235 }
00236
00237 private void defineMainFrame()
00238 {
00239
00240
gui.
publicActionRefreshCursorShape();
00241
gui.validate();
00242
gui.setVisible(
true);
00243
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
00244 }
00245
00246 private void defineLeftPane()
00247 {
00249
00251
gui.
controllerListPanel =
new JPanel(
new GridLayout(1, 1));
00252
gui.
controllerListPanel.setAlignmentX(JPanel.LEFT_ALIGNMENT);
00253
gui.
controllerListPanel.setName(
GuiConstants.LIST_CONTROLLER);
00254
gui.
controllerListPanel.addMouseListener(
gui.
controllerListPopUpMenu);
00255 JScrollPane controllerScroll =
new JScrollPane();
00256 controllerScroll.getViewport().add(
gui.
controllerListPanel);
00257 JPanel controllerPane =
new JPanel(
new BorderLayout());
00258 controllerPane.add(controllerScroll, BorderLayout.CENTER);
00259 controllerPane.add(
new JLabel(
GuiTranslate.get(
"gui.panel.controllers")), BorderLayout.NORTH);
00260
00262
00264
gui.
vdbListPanel =
new JPanel(
new GridLayout(1, 1));
00265
gui.
vdbListPanel.setAlignmentX(JPanel.LEFT_ALIGNMENT);
00266
gui.
vdbListPanel.setName(
GuiConstants.LIST_DATABASE);
00267 JScrollPane vdbScroll =
new JScrollPane();
00268 vdbScroll.getViewport().add(
gui.
vdbListPanel);
00269 JPanel vdbPane =
new JPanel(
new BorderLayout());
00270 vdbPane.add(vdbScroll, BorderLayout.CENTER);
00271 vdbPane.add(
new JLabel(
GuiTranslate.get(
"gui.panel.virtualdatabases")), BorderLayout.NORTH);
00272
00274
00276
gui.
fileListPanel =
new JPanel(
new GridLayout(1, 1));
00277
00278
00279
00280
gui.
fileListPanel.setName(
GuiConstants.LIST_FILES);
00281
gui.
fileListPanel.setVisible(
true);
00282
00283
gui.
fileScroll =
new JScrollPane();
00284
gui.
fileScroll
00285 .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
00286
gui.
fileScroll
00287 .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
00288
gui.
fileScroll.getViewport().add(
gui.
fileListPanel);
00289 JPanel filePane =
new JPanel(
new BorderLayout());
00290 filePane.add(
gui.
fileScroll, BorderLayout.CENTER);
00291 filePane.add(
new JLabel(
GuiTranslate.get(
"gui.panel.configuration.files")), BorderLayout.NORTH);
00292
00294
00296 JPanel logo =
new JPanel();
00297 logo.setBackground(Color.white);
00298 JLabel logoImg =
new JLabel();
00299 logoImg.setIcon(
GuiIcons.CJDBC_LOGO);
00300 logoImg.setMinimumSize(
new Dimension(
GuiIcons.CJDBC_LOGO.getIconWidth(),
00301
GuiIcons.CJDBC_LOGO.getIconHeight()));
00302 logo.add(logoImg);
00303
00305
00307
00308 JPanel leftPane =
new JPanel(
new GridLayout(4, 1));
00309 leftPane.setMaximumSize(
new Dimension(250,
gui.getHeight()));
00310 leftPane.setPreferredSize(
new Dimension(250,
gui.getHeight()));
00311
00312 leftPane.add(controllerPane);
00313 leftPane.add(vdbPane);
00314 leftPane.add(filePane);
00315 leftPane.add(logo);
00316
00317
gui.getContentPane().add(leftPane, BorderLayout.WEST);
00318 }
00319
00320 private void defineNewControllerFrame()
00321 {
00323
00325
gui.
newControllerFrame =
new GuiNewControllerFrame(
gui.
guiActionListener);
00326 }
00327
00328 private void defineCenterPane()
00329 {
00330
00332
00334
gui.
centerPane =
new JTabbedPane();
00335
gui.
centerPane.setTabPlacement(JTabbedPane.TOP);
00336
00337
00338
00339
00341
00343
gui.
debugScroll =
new JScrollPane();
00344
gui.
debugText =
"";
00345
gui.
debugTextPane =
new JTextArea();
00346
gui.
debugTextPane.setFont(
GuiConstants.CENTER_PANE_FONT);
00347
gui.
debugTextPane.setEditable(
false);
00348
gui.
debugTextPane.setText(
gui.
debugText);
00349
gui.
debugTextPane.setBackground(Color.white);
00350
00351
gui.
debugTraceTextPane =
new JTextArea();
00352
gui.
debugTraceTextPane.setFont(
GuiConstants.CENTER_PANE_FONT);
00353
gui.
debugTraceTextPane.setEditable(
false);
00354
gui.
debugTraceTextPane.setBackground(Color.white);
00355
gui.
traceWriter =
new JTextAreaWriter(
gui.
debugTraceTextPane);
00356
00357 JSplitPane pane =
new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
false,
00358
gui.
debugTextPane,
gui.
debugTraceTextPane);
00359
gui.
debugScroll.getViewport().add(pane);
00360
00362
00364
gui.
actionLoadBackendPane(
true);
00365
00367
00369
gui.
helpScroll =
new JScrollPane();
00370
gui.
xmlTextPane =
new JTextPane();
00371 JTextPane helpPanel =
new JTextPane();
00372 URL localUrl =
this.getClass().getResource(
"/userGuide.html");
00373
if (localUrl != null)
00374 {
00375
try
00376 {
00377 helpPanel.setPage(localUrl);
00378 }
00379
catch (IOException e)
00380 {
00381
gui.
appendDebugText(
"Failed to load local help...", e);
00382 helpPanel.setEnabled(
false);
00383 }
00384 }
00385
else
00386 {
00387
gui.
appendDebugText(
"Failed to load local help...");
00388
try
00389 {
00390 URL url =
new URL(
GuiConstants.CJDBC_URL_DOC);
00391 helpPanel.setPage(url);
00392 }
00393
catch (Exception e)
00394 {
00395 helpPanel.setText(
"Could not load online help...");
00396 helpPanel.setEnabled(
false);
00397 }
00398 }
00399 helpPanel.setEditable(
false);
00400
gui.
helpScroll =
new JScrollPane();
00401
gui.
helpScroll.getViewport().add(helpPanel);
00402
00404
00406
gui.
xmlScroll =
new JScrollPane();
00407
gui.
xmlTextPane =
new JTextPane();
00408
gui.
xmlTextPane.setText(
gui.
actionLoadXmlText(null));
00409
gui.
xmlTextPane.setFont(
GuiConstants.CENTER_PANE_FONT);
00410
gui.
xmlTextPane.setBackground(Color.white);
00411
gui.
xmlTextPane.setEditable(
true);
00412
gui.
xmlTextPane.addMouseListener(
new XmlEditPopUpMenu(
gui));
00413 gui.xmlScroll.getViewport().add(gui.xmlTextPane);
00414
00415 gui.parsingThread =
new GuiParsingThread(gui.xmlTextPane);
00416 gui.parsingThread.start();
00417 gui.xmlTextPane.addKeyListener(gui.parsingThread);
00418
00420
00422 gui.loggingScroll =
new JScrollPane();
00423 gui.loggingTextPane =
new JTextArea();
00424 gui.loggingTextPane.setFont(
GuiConstants.CENTER_PANE_FONT);
00425 gui.loggingTextPane.setEditable(
false);
00426 gui.loggingTextPane.addMouseListener(
new LoggingPopUpMenu(gui));
00427 gui.loggingTextPane.setBackground(Color.white);
00428 gui.loggingScroll.getViewport().add(gui.loggingTextPane);
00429
00431
00433 gui.infoScroll =
new JScrollPane();
00434 gui.infoTextPane =
new JTextPane();
00435 gui.infoTextPane.setFont(
GuiConstants.CENTER_PANE_FONT);
00436 gui.infoTextPane.setEditable(
false);
00437 gui.infoTextPane.setBackground(Color.white);
00438 gui.infoScroll.getViewport().add(gui.infoTextPane);
00439
00441
00443 gui.logConfigScroll =
new JScrollPane();
00444 gui.logConfigTextPane =
new JTextPane();
00445 gui.logConfigTextPane.setFont(
GuiConstants.CENTER_PANE_FONT);
00446 gui.logConfigTextPane.setEditable(
true);
00447 gui.logConfigTextPane.setBackground(Color.white);
00448 gui.logConfigScroll.getViewport().add(gui.logConfigTextPane);
00449
00451
00453 gui.centerPane.addTab(
GuiTranslate.get(
"gui.panel.backends"),
GuiIcons.BACKEND_PANEL_ICON,
00454 gui.backendPanel);
00455 gui.centerPane.addTab(
GuiTranslate.get(
"gui.panel.help"),
GuiIcons.HELP_PANEL_ICON, gui.helpScroll);
00456 gui.centerPane.addTab(
GuiTranslate.get(
"gui.panel.xml"),
GuiIcons.XML_PANEL_ICON, gui.xmlScroll);
00457 gui.centerPane.addTab(
GuiTranslate.get(
"gui.panel.logging"),
GuiIcons.LOGGING_PANEL_ICON,
00458 gui.loggingScroll);
00459 gui.centerPane.addTab(
GuiTranslate.get(
"gui.panel.info"),
GuiIcons.INFO_PANEL_ICON, gui.infoScroll);
00460 gui.centerPane.addTab(
GuiTranslate.get(
"gui.panel.log.config"),
GuiIcons.LOG_CONFIG_PANEL_ICON,
00461 gui.logConfigScroll);
00462 gui.getContentPane().add(gui.centerPane, BorderLayout.CENTER);
00463 gui.centerPane.addTab(
GuiTranslate.get(
"gui.panel.debug"),
GuiIcons.DEBUG_PANEL_ICON, gui.debugScroll);
00464 }
00465
00466 private void defineRightPane()
00467 {
00469
00471 JPanel rightPane =
new JPanel(
new BorderLayout());
00472 rightPane.setSize(150, 480);
00473 JTextPane rightTextPane =
new JTextPane();
00474 Font rightPaneFont =
new Font(
"Verdana", Font.PLAIN, 9);
00475 rightTextPane.setFont(rightPaneFont);
00476 rightTextPane.setForeground(Color.red);
00477 rightPane.add(rightTextPane, BorderLayout.CENTER);
00478
gui.
parsingThread.
setOutputPane(rightTextPane);
00479
gui.getContentPane().add(rightPane, BorderLayout.EAST);
00480 }
00481 }