001: package net.sourceforge.squirrel_sql.plugins.oracle.dboutput;
002:
003: /*
004: * Copyright (C) 2004 Jason Height
005: * jmheight@users.sourceforge.net
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021:
022: import java.awt.event.ActionEvent;
023: import java.awt.event.ActionListener;
024: import java.awt.*;
025: import java.util.prefs.Preferences;
026:
027: import javax.swing.*;
028: import javax.swing.event.ChangeEvent;
029: import javax.swing.event.ChangeListener;
030: import javax.swing.event.InternalFrameAdapter;
031: import javax.swing.event.InternalFrameEvent;
032:
033: import net.sourceforge.squirrel_sql.fw.id.IIdentifier;
034: import net.sourceforge.squirrel_sql.fw.gui.ToolBar;
035: import net.sourceforge.squirrel_sql.fw.util.Resources;
036: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
037: import net.sourceforge.squirrel_sql.fw.util.StringManager;
038: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
039: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
040:
041: import net.sourceforge.squirrel_sql.client.IApplication;
042: import net.sourceforge.squirrel_sql.client.session.ISession;
043: import net.sourceforge.squirrel_sql.plugins.oracle.OracleInternalFrame;
044: import net.sourceforge.squirrel_sql.plugins.oracle.OracleInternalFrameCallback;
045:
046: public class DBOutputInternalFrame extends OracleInternalFrame {
047: private static final String PREF_PART_DB_OUTPUT_FRAME = "DBOutputFrame";
048:
049: private static final StringManager s_stringMgr = StringManagerFactory
050: .getStringManager(DBOutputInternalFrame.class);
051:
052: /**
053: * Application API.
054: */
055: private final IApplication _app;
056:
057: /**
058: * ID of the session for this window.
059: */
060: private IIdentifier _sessionId;
061:
062: private DBOutputPanel _dbOutputPanel;
063: /**
064: * Toolbar for window.
065: */
066: private DBOutputToolBar _toolBar;
067:
068: private Resources _resources;
069:
070: public DBOutputInternalFrame(ISession session, Resources resources) {
071: // I18n[oracle.dbOutputTitle=Oracle DB output for: {0}]
072: super (session, s_stringMgr.getString("oracle.dbOutputTitle",
073: session.getTitle()));
074: _app = session.getApplication();
075: _resources = resources;
076: _sessionId = session.getIdentifier();
077: createGUI(session);
078: }
079:
080: public DBOutputPanel getDBOutputPanel() {
081: return _dbOutputPanel;
082: }
083:
084: private void createGUI(ISession session) {
085: addInternalFrameListener(new InternalFrameAdapter() {
086: public void internalFrameClosing(InternalFrameEvent e) {
087: onInternalFrameClosing();
088: }
089: });
090:
091: Icon icon = _resources.getIcon(getClass(), "frameIcon"); //i18n
092: if (icon != null) {
093: setFrameIcon(icon);
094: }
095:
096: OracleInternalFrameCallback cb = new OracleInternalFrameCallback() {
097:
098: public void createPanelAndToolBar(boolean stayOnTop,
099: int autoRefeshPeriod) {
100: _dbOutputPanel = new DBOutputPanel(getSession(),
101: autoRefeshPeriod);
102: _toolBar = new DBOutputToolBar(getSession(), stayOnTop,
103: autoRefeshPeriod);
104: JPanel contentPanel = new JPanel(new BorderLayout());
105: contentPanel.add(_toolBar, BorderLayout.NORTH);
106: contentPanel.add(_dbOutputPanel, BorderLayout.CENTER);
107: setContentPane(contentPanel);
108:
109: _dbOutputPanel.setAutoRefreshPeriod(autoRefeshPeriod);
110: }
111: };
112:
113: initFromPrefs(PREF_PART_DB_OUTPUT_FRAME, cb);
114: }
115:
116: private void onInternalFrameClosing() {
117:
118: internalFrameClosing(_toolBar.isStayOnTop(), _dbOutputPanel
119: .getAutoRefreshPeriod());
120:
121: //Turn off auto refresh when we are shutting down.
122: _dbOutputPanel.setAutoRefresh(false);
123: }
124:
125: /**
126: * The class representing the toolbar at the top of a dboutput internal frame
127: */
128: private class DBOutputToolBar extends OracleToolBar {
129: private JCheckBox _autoRefresh;
130:
131: DBOutputToolBar(ISession session, boolean stayOnTop,
132: int autoRefeshPeriod) {
133: super ();
134: createGUI(session, stayOnTop, autoRefeshPeriod);
135: }
136:
137: private void createGUI(ISession session, boolean stayOnTop,
138: int autoRefeshPeriod) {
139: IApplication app = session.getApplication();
140: setUseRolloverButtons(true);
141: setFloatable(false);
142: add(new GetDBOutputAction(app, _resources, _dbOutputPanel));
143: add(new ClearDBOutputAction(app, _resources, _dbOutputPanel));
144:
145: addStayOnTop(stayOnTop);
146:
147: //Create checkbox for enabling auto refresh
148: // i18n[oracle.dboutputEnableAutoRefer=Enable auto refresh]
149: _autoRefresh = new JCheckBox(s_stringMgr
150: .getString("oracle.dboutputEnableAutoRefer"), false);
151: _autoRefresh.addActionListener(new ActionListener() {
152: public void actionPerformed(ActionEvent e) {
153: _dbOutputPanel.setAutoRefresh(_autoRefresh
154: .isSelected());
155: }
156: });
157: add(_autoRefresh);
158:
159: //Create spinner for update period
160: final SpinnerNumberModel model = new SpinnerNumberModel(
161: autoRefeshPeriod, 1, 60, 5);
162: JSpinner refreshRate = new JSpinner(model);
163: refreshRate.addChangeListener(new ChangeListener() {
164: public void stateChanged(ChangeEvent e) {
165: _dbOutputPanel.setAutoRefreshPeriod(model
166: .getNumber().intValue());
167: }
168: });
169: add(refreshRate);
170: // i18n[oracle.Seconds2=(seconds)]
171: add(new JLabel(s_stringMgr.getString("oracle.Seconds2")));
172: }
173:
174: }
175: }
|