001: package net.sourceforge.squirrel_sql.plugins.oracle;
002:
003: import net.sourceforge.squirrel_sql.client.gui.session.BaseSessionInternalFrame;
004: import net.sourceforge.squirrel_sql.client.session.ISession;
005: import net.sourceforge.squirrel_sql.fw.gui.ToolBar;
006: import net.sourceforge.squirrel_sql.fw.util.StringManager;
007: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
008: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
009: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
010:
011: import javax.swing.*;
012: import java.util.prefs.Preferences;
013: import java.awt.*;
014: import java.awt.event.ActionListener;
015: import java.awt.event.ActionEvent;
016: import java.beans.PropertyVetoException;
017:
018: public class OracleInternalFrame extends BaseSessionInternalFrame {
019: private static final String PREF_KEY_ORACLE_FRAME_REPL = "@@";
020:
021: private static final String PREF_KEY_ORACLE_FRAME_X = "Squirrel.oracle."
022: + PREF_KEY_ORACLE_FRAME_REPL + "_X";
023: private static final String PREF_KEY_ORACLE_FRAME_Y = "Squirrel.oracle."
024: + PREF_KEY_ORACLE_FRAME_REPL + "_Y";
025: private static final String PREF_KEY_ORACLE_FRAME_WIDTH = "Squirrel.oracle."
026: + PREF_KEY_ORACLE_FRAME_REPL + "_WIDTH";
027: private static final String PREF_KEY_ORACLE_FRAME_HEIGHT = "Squirrel.oracle."
028: + PREF_KEY_ORACLE_FRAME_REPL + "_HEIGHT";
029: private static final String PREF_KEY_ORACLE_FRAME_STAY_ON_TOP = "Squirrel.oracle."
030: + PREF_KEY_ORACLE_FRAME_REPL + "_STAY_ON_TOP";
031: private static final String PREF_KEY_ORACLE_FRAME_AUTO_REFRESH_SEC = "Squirrel.oracle."
032: + PREF_KEY_ORACLE_FRAME_REPL + "_AUTO_REFRESH_SEC";
033:
034: private static final StringManager s_stringMgr = StringManagerFactory
035: .getStringManager(OracleInternalFrame.class);
036:
037: private static final ILogger s_log = LoggerController
038: .createLogger(OracleInternalFrame.class);
039: private String _repl = "";
040:
041: public OracleInternalFrame(ISession session, String title) {
042: super (session, title, true, true, true, true);
043:
044: setBorder(BorderFactory.createRaisedBevelBorder());
045: }
046:
047: protected void initFromPrefs(String repl,
048: OracleInternalFrameCallback callBack) {
049: _repl = repl;
050: final int x = Preferences.userRoot().getInt(
051: PREF_KEY_ORACLE_FRAME_X.replaceAll(
052: PREF_KEY_ORACLE_FRAME_REPL, _repl), 0);
053: final int y = Preferences.userRoot().getInt(
054: PREF_KEY_ORACLE_FRAME_Y.replaceAll(
055: PREF_KEY_ORACLE_FRAME_REPL, _repl), 0);
056: final int width = Preferences.userRoot().getInt(
057: PREF_KEY_ORACLE_FRAME_WIDTH.replaceAll(
058: PREF_KEY_ORACLE_FRAME_REPL, _repl), 400);
059: final int height = Preferences.userRoot().getInt(
060: PREF_KEY_ORACLE_FRAME_HEIGHT.replaceAll(
061: PREF_KEY_ORACLE_FRAME_REPL, _repl), 200);
062: final boolean stayOnTop = Preferences.userRoot().getBoolean(
063: PREF_KEY_ORACLE_FRAME_STAY_ON_TOP.replaceAll(
064: PREF_KEY_ORACLE_FRAME_REPL, _repl), false);
065: int autoRefeshPeriod = Preferences.userRoot().getInt(
066: PREF_KEY_ORACLE_FRAME_AUTO_REFRESH_SEC.replaceAll(
067: PREF_KEY_ORACLE_FRAME_REPL, _repl), 10);
068: autoRefeshPeriod = Math.max(1, autoRefeshPeriod);
069:
070: callBack.createPanelAndToolBar(stayOnTop, autoRefeshPeriod);
071:
072: SwingUtilities.invokeLater(new Runnable() {
073: public void run() {
074: Rectangle rectMain = getSession().getApplication()
075: .getMainFrame().getDesktopPane().getBounds();
076: Rectangle rect = new Rectangle();
077: rect.x = x;
078: if (rectMain.width - x < 50)
079: rect.x = 0;
080:
081: rect.y = y;
082: if (rectMain.height - y < 50)
083: rect.y = 0;
084:
085: rect.width = Math.max(100, width);
086: rect.height = Math.max(100, height);
087: if (rect.x + rect.width > rectMain.width
088: || rect.y + rect.height > rectMain.height) {
089: rect.x = 0;
090: rect.width = 400;
091: rect.y = 0;
092: rect.height = 200;
093: }
094:
095: try {
096: setMaximum(false);
097: } catch (PropertyVetoException e) {
098: s_log.error(e);
099: }
100: setBounds(rect);
101:
102: setVisible(true);
103: }
104: });
105: }
106:
107: protected void internalFrameClosing(boolean stayOnTop,
108: int autoRefreshPeriod) {
109: Rectangle rect = getBounds();
110:
111: Preferences.userRoot().putInt(
112: PREF_KEY_ORACLE_FRAME_X.replaceAll(
113: PREF_KEY_ORACLE_FRAME_REPL, _repl), rect.x);
114: Preferences.userRoot().putInt(
115: PREF_KEY_ORACLE_FRAME_Y.replaceAll(
116: PREF_KEY_ORACLE_FRAME_REPL, _repl), rect.y);
117: Preferences.userRoot().putInt(
118: PREF_KEY_ORACLE_FRAME_WIDTH.replaceAll(
119: PREF_KEY_ORACLE_FRAME_REPL, _repl), rect.width);
120: Preferences.userRoot()
121: .putInt(
122: PREF_KEY_ORACLE_FRAME_HEIGHT.replaceAll(
123: PREF_KEY_ORACLE_FRAME_REPL, _repl),
124: rect.height);
125: Preferences.userRoot().putBoolean(
126: PREF_KEY_ORACLE_FRAME_STAY_ON_TOP.replaceAll(
127: PREF_KEY_ORACLE_FRAME_REPL, _repl), stayOnTop);
128: Preferences.userRoot().putInt(
129: PREF_KEY_ORACLE_FRAME_AUTO_REFRESH_SEC.replaceAll(
130: PREF_KEY_ORACLE_FRAME_REPL, _repl),
131: autoRefreshPeriod);
132: }
133:
134: public class OracleToolBar extends ToolBar {
135: private JCheckBox _stayOnTop;
136:
137: protected void addStayOnTop(boolean stayOnTop) {
138: // i18n[oracle.dboutputStayOnTop=Stay on top]
139: _stayOnTop = new JCheckBox(s_stringMgr
140: .getString("oracle.dboutputStayOnTop"), false);
141: _stayOnTop.setSelected(stayOnTop);
142:
143: SwingUtilities.invokeLater(new Runnable() {
144: public void run() {
145: onStayOnTopChanged(_stayOnTop.isSelected());
146: _stayOnTop.addActionListener(new ActionListener() {
147: public void actionPerformed(ActionEvent e) {
148: onStayOnTopChanged(_stayOnTop.isSelected());
149: }
150: });
151: }
152: });
153:
154: add(_stayOnTop);
155: }
156:
157: private void onStayOnTopChanged(boolean selected) {
158: if (selected) {
159: getDesktopPane().setLayer(OracleInternalFrame.this ,
160: JLayeredPane.PALETTE_LAYER.intValue());
161: } else {
162: getDesktopPane().setLayer(OracleInternalFrame.this ,
163: JLayeredPane.DEFAULT_LAYER.intValue());
164: }
165:
166: // Needs to be done in both cases because if the window goes back to
167: // the default layer it goes back behind all other windows too.
168: toFront();
169: }
170:
171: public boolean isStayOnTop() {
172: return _stayOnTop.isSelected();
173: }
174:
175: }
176:
177: }
|