001: package org.dbbrowser.ui;
002:
003: import infrastructure.propertymanager.PropertyManager;
004: import infrastructure.internationalization.InternationalizationManager;
005: import javax.swing.*;
006: import java.util.Observable;
007: import java.util.Observer;
008: import java.util.List;
009: import java.util.ArrayList;
010: import java.awt.event.ActionListener;
011: import java.awt.event.ActionEvent;
012: import org.dbbrowser.db.engine.SQLLog;
013: import org.dbbrowser.ui.widget.Button;
014: import org.dbbrowser.ui.panel.ButtonsPanel;
015:
016: /**
017: * Displays a log of all SQL statements
018: */
019: public class SQLLogUI implements Observer, ActionListener {
020: private static final String SQL_LOG_ICON_FILENAME = PropertyManager
021: .getInstance().getProperty(
022: "dbbrowser-ui-sql-log-window-icon");
023: private static final String CLEAR_SQL_LOG_ICON_FILENAME = PropertyManager
024: .getInstance()
025: .getProperty(
026: "dbbrowser-ui-sql-log-window-clear-log-button-icon");
027:
028: private static final String SQL_LOG_WINDOW_TITLE = InternationalizationManager
029: .getInstance().getMessage("dbbrowser-ui",
030: "dbbrowser-ui-sql-log-window-title", null);
031: private static final String SQL_LOG_CLEAR_BUTTON_LABEL = InternationalizationManager
032: .getInstance()
033: .getMessage(
034: "dbbrowser-ui",
035: "dbbrowser-ui-sql-log-window-clear-log-button-label",
036: null);
037:
038: private JFrame frame = new JFrame();
039: private JTextArea sqlLog = new JTextArea();
040: private JScrollPane paneForSQL = null;
041:
042: /**
043: * Constructer
044: */
045: public SQLLogUI() {
046: initialize();
047: }
048:
049: /**
050: * Show the UI
051: */
052: public void show() {
053: this .frame.show();
054: }
055:
056: //Hide the SQL Logger UI
057: public void hide() {
058: this .frame.hide();
059: }
060:
061: /**
062: * Called by the observable to inform the observer when a change occurs
063: * @param observable
064: * @param args
065: */
066: public void update(Observable observable, Object args) {
067: sqlLog.append(args.toString() + "\n\n");
068: this .paneForSQL.getVerticalScrollBar()
069: .setValue(
070: this .paneForSQL.getVerticalScrollBar()
071: .getMaximum() + 1000);
072: }
073:
074: public void actionPerformed(ActionEvent e) {
075: this .sqlLog.setText("");
076: }
077:
078: private void initialize() {
079: //Setup the frame
080: this .frame.setTitle(SQL_LOG_WINDOW_TITLE);
081: this .frame.setSize(700, 300);
082: this .frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
083: this .frame.setIconImage((new ImageIcon(SQL_LOG_ICON_FILENAME))
084: .getImage());
085: this .frame.toBack();
086:
087: //Setup the widgets
088: this .frame.getContentPane().setLayout(
089: new BoxLayout(this .frame.getContentPane(),
090: BoxLayout.PAGE_AXIS));
091: this .sqlLog.setEditable(false);
092: this .sqlLog.setLineWrap(true);
093: this .paneForSQL = new JScrollPane(this .sqlLog);
094: paneForSQL
095: .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
096: this .frame.getContentPane().add(paneForSQL);
097:
098: //Add the button to clear the log
099: Button buttonToClearSQLLog = new Button(
100: SQL_LOG_CLEAR_BUTTON_LABEL, this ,
101: SQL_LOG_CLEAR_BUTTON_LABEL, new ImageIcon(
102: CLEAR_SQL_LOG_ICON_FILENAME), Boolean.FALSE);
103: List listOfButtons = new ArrayList();
104: listOfButtons.add(buttonToClearSQLLog);
105: ButtonsPanel buttonsPanel = new ButtonsPanel(listOfButtons);
106: this .frame.getContentPane().add(buttonsPanel);
107:
108: //Add the UI as an observor to the SQLLog
109: SQLLog.getInstance().addObserver(this);
110: }
111: }
|