001: package net.sourceforge.squirrel_sql.client.session.mainpanel;
002:
003: /*
004: * Copyright (C) 2001-2004 Johan Compagner
005: * jcompagner@j-com.nl
006: *
007: * Modifications Copyright (C) 2003-2004 Jason Height
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
022: */
023: import java.awt.*;
024: import java.awt.event.ActionListener;
025: import java.awt.event.ActionEvent;
026:
027: import javax.swing.*;
028:
029: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
030: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
031: import net.sourceforge.squirrel_sql.fw.util.StringManager;
032: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
033:
034: import net.sourceforge.squirrel_sql.client.IApplication;
035: import net.sourceforge.squirrel_sql.client.gui.BaseInternalFrame;
036: import net.sourceforge.squirrel_sql.client.gui.session.BaseSessionInternalFrame;
037: import net.sourceforge.squirrel_sql.client.session.ISession;
038: import net.sourceforge.squirrel_sql.client.session.action.ReturnResultTabAction;
039:
040: /**
041: * JASON: Rename to ResultInternalFrame
042: * Torn off frame that contains SQL results.
043: *
044: * @author <A HREF="mailto:jcompagner@j-com.nl">Johan Compagner</A>
045: */
046: public class ResultFrame extends BaseSessionInternalFrame {
047: /** Logger for this class. */
048: private static ILogger s_log = LoggerController
049: .createLogger(ResultFrame.class);
050:
051: private static final StringManager s_stringMgr = StringManagerFactory
052: .getStringManager(ResultFrame.class);
053:
054: /** SQL Results. */
055: private IResultTab _tab;
056: private JCheckBox _chkOnTop;
057:
058: /**
059: * Ctor.
060: *
061: * @param session Current session.
062: * @param tab SQL results tab.
063: *
064: * @throws IllegalArgumentException
065: * If a <TT>null</TT> <TT>ISession</TT> or
066: * <TT>ResultTab</TT> passed.
067: */
068: public ResultFrame(ISession session, IResultTab tab) {
069: super (session, getFrameTitle(session, tab), true, true, true,
070: true);
071: _tab = tab;
072:
073: setDefaultCloseOperation(DISPOSE_ON_CLOSE);
074:
075: final Container cont = getContentPane();
076: cont.setLayout(new BorderLayout());
077: final IApplication app = session.getApplication();
078:
079: JPanel pnlButtons = new JPanel(new GridBagLayout());
080: GridBagConstraints gbc;
081:
082: JButton rtnBtn = new JButton(new ReturnResultTabAction(app,
083: this ));
084: gbc = new GridBagConstraints(0, 0, 1, 1, 0, 0,
085: GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
086: new Insets(0, 5, 0, 5), 0, 0);
087: pnlButtons.add(rtnBtn, gbc);
088:
089: // i18n[resultFrame.stayOnTop=Stay on top]
090: _chkOnTop = new JCheckBox(s_stringMgr
091: .getString("resultFrame.stayOnTop"));
092: gbc = new GridBagConstraints(1, 0, 1, 1, 0, 0,
093: GridBagConstraints.WEST, GridBagConstraints.NONE,
094: new Insets(0, 5, 0, 5), 0, 0);
095: pnlButtons.add(_chkOnTop, gbc);
096: _chkOnTop.setSelected(true);
097:
098: _chkOnTop.addActionListener(new ActionListener() {
099: public void actionPerformed(ActionEvent e) {
100: onStayOnTopChanged();
101: }
102: });
103:
104: gbc = new GridBagConstraints(2, 0, 1, 1, 1, 0,
105: GridBagConstraints.WEST, GridBagConstraints.NONE,
106: new Insets(0, 5, 0, 5), 0, 0);
107: pnlButtons.add(new JPanel(), gbc);
108:
109: cont.add(pnlButtons, BorderLayout.NORTH);
110: cont.add(tab.getOutputComponent(), BorderLayout.CENTER);
111: }
112:
113: private void onStayOnTopChanged() {
114: if (_chkOnTop.isSelected()) {
115: getDesktopPane().setLayer(this ,
116: JLayeredPane.PALETTE_LAYER.intValue());
117: } else {
118: getDesktopPane().setLayer(this ,
119: JLayeredPane.DEFAULT_LAYER.intValue());
120: }
121:
122: // Needs to be done in both cases because if the window goes back to
123: // the default layer it goes back behind all other windows too.
124: toFront();
125: }
126:
127: /**
128: * Close this window.
129: */
130: public void dispose() {
131: if (_tab != null) {
132: _tab.closeTab();
133: _tab = null;
134: }
135: super .dispose();
136: }
137:
138: public void returnToTabbedPane() {
139: s_log.debug("ResultFrame.returnToTabbedPane()");
140: getContentPane().remove(_tab.getOutputComponent());
141: _tab.returnToTabbedPane();
142: _tab = null;
143: dispose();
144: }
145:
146: private static String getFrameTitle(ISession session, IResultTab tab)
147: throws IllegalArgumentException {
148: if (tab == null) {
149: throw new IllegalArgumentException("Null ResultTab passed");
150: }
151: if (session == null) {
152: throw new IllegalArgumentException("Null ISession passed");
153: }
154:
155: return session.getTitle() + " - " + tab.getViewableSqlString();
156: }
157: }
|