001: package net.sourceforge.squirrel_sql.client.gui.session;
002:
003: /*
004: * Copyright (C) 2001-2003 Colin Bell
005: * colbell@users.sourceforge.net
006: *
007: * Copyright (C) 2003 Jason Height
008: * jmheight@users.sourceforge.net
009: *
010: * This library is free software; you can redistribute it and/or
011: * modify it under the terms of the GNU Lesser General Public
012: * License as published by the Free Software Foundation; either
013: * version 2.1 of the License, or (at your option) any later version.
014: *
015: * This library is distributed in the hope that it will be useful,
016: * but WITHOUT ANY WARRANTY; without even the implied warranty of
017: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
018: * Lesser General Public License for more details.
019: *
020: * You should have received a copy of the GNU Lesser General Public
021: * License along with this library; if not, write to the Free Software
022: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
023: */
024: import net.sourceforge.squirrel_sql.client.IApplication;
025: import net.sourceforge.squirrel_sql.client.action.ActionCollection;
026: import net.sourceforge.squirrel_sql.client.session.*;
027: import net.sourceforge.squirrel_sql.client.session.action.*;
028: import net.sourceforge.squirrel_sql.client.session.mainpanel.SQLPanel;
029: import net.sourceforge.squirrel_sql.fw.gui.ToolBar;
030: import net.sourceforge.squirrel_sql.fw.gui.StatusBar;
031:
032: import javax.swing.*;
033: import javax.swing.event.InternalFrameAdapter;
034: import javax.swing.event.InternalFrameEvent;
035: import java.awt.*;
036:
037: public class SQLInternalFrame extends BaseSessionInternalFrame
038: implements ISQLInternalFrame {
039: /** Application API. */
040: private final IApplication _app;
041:
042: private SQLPanel _sqlPanel;
043: /** Toolbar for window. */
044: private SQLToolBar _toolBar;
045:
046: private StatusBar _statusBar = new StatusBar();
047:
048: public SQLInternalFrame(ISession session) {
049: super (session, session.getTitle(), true, true, true, true);
050: _app = session.getApplication();
051: setVisible(false);
052: createGUI(session);
053: }
054:
055: public SQLPanel getSQLPanel() {
056: return _sqlPanel;
057: }
058:
059: public ISQLPanelAPI getSQLPanelAPI() {
060: return _sqlPanel.getSQLPanelAPI();
061: }
062:
063: private void createGUI(ISession session) {
064: setVisible(false);
065: final IApplication app = session.getApplication();
066: Icon icon = app.getResources().getIcon(getClass(), "frameIcon"); //i18n
067: if (icon != null) {
068: setFrameIcon(icon);
069: }
070:
071: // This is to fix a problem with the JDK (up to version 1.3)
072: // where focus events were not generated correctly. The sympton
073: // is being unable to key into the text entry field unless you click
074: // elsewhere after focus is gained by the internal frame.
075: // See bug ID 4309079 on the JavaSoft bug parade (plus others).
076: addInternalFrameListener(new InternalFrameAdapter() {
077: public void internalFrameActivated(InternalFrameEvent evt) {
078: // Window window = SwingUtilities
079: // .windowForComponent(SQLInternalFrame.this.getSQLPanel());
080: // Component focusOwner = (window != null) ? window
081: // .getFocusOwner() : null;
082: // if (focusOwner != null)
083: // {
084: // FocusEvent lost = new FocusEvent(focusOwner,
085: // FocusEvent.FOCUS_LOST);
086: // FocusEvent gained = new FocusEvent(focusOwner,
087: // FocusEvent.FOCUS_GAINED);
088: // window.dispatchEvent(lost);
089: // window.dispatchEvent(gained);
090: // window.dispatchEvent(lost);
091: // focusOwner.requestFocus();
092: // }
093:
094: SwingUtilities.invokeLater(new Runnable() {
095: public void run() {
096: _sqlPanel.getSQLEntryPanel().getTextComponent()
097: .requestFocus();
098: }
099: });
100: }
101:
102: public void internalFrameClosing(InternalFrameEvent e) {
103: _sqlPanel.sessionWindowClosing();
104: }
105: });
106:
107: _sqlPanel = new SQLPanel(getSession(), false);
108:
109: // Needed to make the panel set the divider location from preferences
110: _sqlPanel.setVisible(true);
111:
112: _toolBar = new SQLToolBar(getSession(), _sqlPanel
113: .getSQLPanelAPI());
114: JPanel contentPanel = new JPanel(new BorderLayout());
115: contentPanel.add(_toolBar, BorderLayout.NORTH);
116: contentPanel.add(_sqlPanel, BorderLayout.CENTER);
117:
118: Font fn = app.getFontInfoStore().getStatusBarFontInfo()
119: .createFont();
120: _statusBar.setFont(fn);
121: contentPanel.add(_statusBar, BorderLayout.SOUTH);
122:
123: RowColumnLabel lblRowCol = new RowColumnLabel(_sqlPanel
124: .getSQLEntryPanel());
125: _statusBar.addJComponent(lblRowCol);
126:
127: setContentPane(contentPanel);
128: validate();
129: }
130:
131: public void requestFocus() {
132: SwingUtilities.invokeLater(new Runnable() {
133: public void run() {
134: _sqlPanel.getSQLEntryPanel().requestFocus();
135: }
136: });
137:
138: }
139:
140: public void addSeparatorToToolbar() {
141: if (null != _toolBar) {
142: _toolBar.addSeparator();
143: }
144: }
145:
146: public void addToToolbar(Action action) {
147: if (null != _toolBar) {
148: _toolBar.add(action);
149: }
150: }
151:
152: public void addToToolsPopUp(String selectionString, Action action) {
153: getSQLPanelAPI().addToToolsPopUp(selectionString, action);
154: }
155:
156: public boolean hasSQLPanelAPI() {
157: return true;
158: }
159:
160: /** The class representing the toolbar at the top of a sql internal frame*/
161: private class SQLToolBar extends ToolBar {
162: SQLToolBar(ISession session, ISQLPanelAPI panel) {
163: super ();
164: createGUI(session, panel);
165: }
166:
167: private void createGUI(ISession session, ISQLPanelAPI panel) {
168: ActionCollection actions = session.getApplication()
169: .getActionCollection();
170: setUseRolloverButtons(true);
171: setFloatable(false);
172: add(actions.get(ExecuteSqlAction.class));
173: addSeparator();
174: add(actions.get(FileNewAction.class));
175: add(actions.get(FileOpenAction.class));
176: add(actions.get(FileAppendAction.class));
177: add(actions.get(FileSaveAction.class));
178: add(actions.get(FileSaveAsAction.class));
179: add(actions.get(FilePrintAction.class));
180: add(actions.get(FileCloseAction.class));
181: addSeparator();
182: add(actions.get(PreviousSqlAction.class));
183: add(actions.get(NextSqlAction.class));
184: add(actions.get(SelectSqlAction.class));
185: addSeparator();
186: add(actions.get(SQLFilterAction.class));
187: actions.get(SQLFilterAction.class).setEnabled(true);
188: }
189: }
190: }
|