001: package net.sourceforge.squirrel_sql.fw.gui;
002:
003: /*
004: * Copyright (C) 2001-20064 Colin Bell
005: * colbell@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: import java.awt.Frame;
022: import java.awt.Rectangle;
023: import java.awt.Window;
024:
025: import javax.swing.JInternalFrame;
026:
027: import net.sourceforge.squirrel_sql.fw.util.beanwrapper.RectangleWrapper;
028: import net.sourceforge.squirrel_sql.fw.xml.IXMLAboutToBeWritten;
029:
030: /**
031: * This bean will store the state of a window or an internal frame object.
032: *
033: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
034: */
035: public class WindowState implements IXMLAboutToBeWritten {
036: /**
037: * Window whose state is being stored. Only one of <TT>_window</TT>,
038: * <TT>_frame</tt> and <TT>_internalFrame</TT> can be non-null.
039: */
040: private Window _window;
041:
042: /**
043: * JInternalFrame whose state is being stored. Only one of <TT>_window</TT>,
044: * <TT>_frame</tt> and <TT>_internalFrame</TT> can be non-null.
045: */
046: private JInternalFrame _internalFrame;
047:
048: /**
049: * Frame whose state is being stored. Only one of <TT>_window</TT>,
050: * <TT>_frame</tt> and <TT>_internalFrame</TT> can be non-null.
051: */
052: private Frame _frame;
053:
054: /** Window bounds. */
055: private RectangleWrapper _bounds = new RectangleWrapper(
056: new Rectangle(600, 400));
057:
058: /** Was the window visible. */
059: private boolean _visible = true;
060:
061: /** Extended state for frame only. */
062: private int _frameExtendedState = 0;
063:
064: public interface IPropertyNames {
065: String BOUNDS = "bounds";
066: String FRAME_EXTENDED_STATE = "frameExtendedState";
067: String VISIBLE = "visible";
068: }
069:
070: /**
071: * Default ctor.
072: */
073: public WindowState() {
074: super ();
075: }
076:
077: /**
078: * Ctor storing the state of the passed <CODE>Window</CODE>.
079: *
080: * @param window Window to store the state of.
081: */
082: public WindowState(Window window) {
083: super ();
084: _window = window;
085: }
086:
087: /**
088: * Ctor storing the state of the passed <CODE>JInternalFrame</CODE>.
089: *
090: * @param internalFrame JInternalFrame to store the state of.
091: */
092: public WindowState(JInternalFrame internalFrame) {
093: super ();
094: _internalFrame = internalFrame;
095: }
096:
097: /**
098: * Ctor storing the state of the passed <CODE>Frame</CODE>.
099: *
100: * @param frame frame to store the state of.
101: */
102: public WindowState(Frame frame) {
103: super ();
104: _frame = frame;
105: }
106:
107: /**
108: * Set this objects state to that of the passed object. Think of this as
109: * being like an assignment operator
110: *
111: * @param obj Object to copy state from
112: *
113: * @throws IllegalArgumentException
114: * Thrown if <tt>null</tt> <tt>WindowState</tt> passed.
115: */
116: public void copyFrom(WindowState obj) {
117: if (obj == null) {
118: throw new IllegalArgumentException("WindowState == null");
119: }
120:
121: setBounds(obj.getBounds());
122: setVisible(obj.isVisible());
123: setFrameExtendedState(obj.getFrameExtendedState());
124: }
125:
126: /**
127: * This bean is about to be written out to XML so load its values from its
128: * window.
129: */
130: public void aboutToBeWritten() {
131: refresh();
132: }
133:
134: public RectangleWrapper getBounds() {
135: refresh();
136: return _bounds;
137: }
138:
139: public void setBounds(RectangleWrapper value) {
140: _bounds = value;
141: _window = null;
142: _internalFrame = null;
143: }
144:
145: public boolean isVisible() {
146: refresh();
147: return _visible;
148: }
149:
150: public void setVisible(boolean value) {
151: _visible = value;
152: }
153:
154: public int getFrameExtendedState() {
155: refresh();
156: return _frameExtendedState;
157: }
158:
159: public void setFrameExtendedState(int value) {
160: _frameExtendedState = value;
161: }
162:
163: private void refresh() {
164: Rectangle windRc = null;
165: if (_window != null) {
166: windRc = _window.getBounds();
167: _visible = _window.isVisible();
168: } else if (_internalFrame != null) {
169: windRc = _internalFrame.getBounds();
170: _visible = _internalFrame.isVisible();
171: } else if (_frame != null) {
172: windRc = _frame.getBounds();
173: _visible = _frame.isVisible();
174: _frameExtendedState = _frame.getExtendedState();
175: }
176:
177: if (windRc != null) {
178: if (_bounds == null) {
179: _bounds = new RectangleWrapper();
180: }
181: _bounds.setFrom(windRc);
182: }
183: }
184: }
|