001: /* ====================================================================
002: * The QueryForm License, Version 1.1
003: *
004: * Copyright (c) 1998 - 2003 David F. Glasser. All rights
005: * reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The end-user documentation included with the redistribution,
020: * if any, must include the following acknowledgment:
021: * "This product includes software developed by
022: * David F. Glasser."
023: * Alternately, this acknowledgment may appear in the software itself,
024: * if and wherever such third-party acknowledgments normally appear.
025: *
026: * 4. The names "QueryForm" and "David F. Glasser" must
027: * not be used to endorse or promote products derived from this
028: * software without prior written permission. For written
029: * permission, please contact dglasser@pobox.com.
030: *
031: * 5. Products derived from this software may not be called "QueryForm",
032: * nor may "QueryForm" appear in their name, without prior written
033: * permission of David F. Glasser.
034: *
035: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
036: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
037: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
038: * DISCLAIMED. IN NO EVENT SHALL DAVID F. GLASSER, THE APACHE SOFTWARE
039: * FOUNDATION OR ITS CONTRIBUTORS, OR ANY AUTHORS OR DISTRIBUTORS
040: * OF THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This product includes software developed by the
051: * Apache Software Foundation (http://www.apache.org/).
052: *
053: * ====================================================================
054: *
055: * $Source: /cvsroot/qform/qform/src/org/glasser/swing/ScrollingDesktopManager.java,v $
056: * $Revision: 1.1 $
057: * $Author: dglasser $
058: * $Date: 2003/01/26 01:02:15 $
059: *
060: * --------------------------------------------------------------------
061: */
062: package org.glasser.swing;
063:
064: import java.util.*;
065: import javax.swing.*;
066: import java.awt.*;
067: import java.beans.PropertyVetoException;
068:
069: public class ScrollingDesktopManager extends DefaultDesktopManager {
070:
071: /**
072: * Searches up the ancestor hierarchy for the given JInternalFrame until
073: * it finds a JScrollPane, and then calls validate() on that scrollpane.
074: */
075: private void validateScrollPane(JComponent f) {
076:
077: Component parent = f;
078: while ((parent = parent.getParent()) != null) {
079: if (parent instanceof JScrollPane) {
080: // System.out.println("About to validate scrollpane");
081: parent.validate();
082: break;
083: }
084: }
085: }
086:
087: /** Generally, this indicates that the frame should be restored to it's
088: * size and position prior to a maximizeFrame() call.
089: */
090: public void minimizeFrame(JInternalFrame f) {
091:
092: super .minimizeFrame(f);
093: validateScrollPane(f);
094:
095: }
096:
097: /** If possible, display this frame in an appropriate location.
098: * Normally, this is not called, as the creator of the JInternalFrame
099: * will add the frame to the appropriate parent.
100: */
101: public void openFrame(JInternalFrame f) {
102: super .openFrame(f);
103: validateScrollPane(f);
104: }
105:
106: /** Generally, this call should remove the frame from it's parent. */
107: public void closeFrame(JInternalFrame f) {
108: super .closeFrame(f);
109: validateScrollPane(f);
110: }
111:
112: /** Generally, remove any iconic representation that is present and restore the
113: * frame to it's original size and location.
114: */
115: public void deiconifyFrame(JInternalFrame f) {
116: super .deiconifyFrame(f);
117: validateScrollPane(f);
118: }
119:
120: /** Generally, the frame should be resized to match it's parents bounds. */
121: /**
122: * Resizes the frame to fill its parents bounds.
123: * @param the frame to be resized
124: */
125: public void maximizeFrame(JInternalFrame f) {
126:
127: Rectangle p;
128: if (!f.isIcon()) {
129: Container c = GUIHelper.getViewport(f);
130: if (c == null)
131: return;
132: p = c.getBounds();
133: } else {
134: Container c = f.getDesktopIcon().getParent();
135: if (c == null)
136: return;
137: p = c.getBounds();
138: try {
139: f.setIcon(false);
140: } catch (PropertyVetoException e2) {
141: }
142: }
143: f.setNormalBounds(f.getBounds());
144: setBoundsForFrame(f, 0, 0, p.width, p.height);
145: try {
146: f.setSelected(true);
147: } catch (PropertyVetoException e2) {
148: }
149:
150: removeIconFor(f);
151: }
152:
153: // /**
154: // * Generally, indicate that this frame has lost focus. This is usually called
155: // * after the JInternalFrame's IS_SELECTED_PROPERTY has been set to false.
156: // */
157: // public void deactivateFrame(JInternalFrame f) {
158: // super.deactivateFrame(f);
159: // validateScrollPane(f);
160: // }
161: //
162: //
163: /** Generally, remove this frame from it's parent and add an iconic representation. */
164: public void iconifyFrame(JInternalFrame f) {
165: super .iconifyFrame(f);
166: validateScrollPane(f);
167: }
168:
169: //
170: //
171: //// /** The user has moved the frame. Calls to this method will be preceded by calls
172: // * to beginDraggingFrame().
173: // * Normally <b>f</b> will be a JInternalFrame.
174: // */
175: // public void dragFrame(JComponent f, int newX, int newY) {
176: // super.dragFrame(f, newX, newY);
177: // }
178: //
179: //
180: // /**
181: // * Generally, indicate that this frame has focus. This is usually called after
182: // * the JInternalFrame's IS_SELECTED_PROPERTY has been set to true.
183: // */
184: // public void activateFrame(JInternalFrame f) {
185: // super.activateFrame(f);
186: // validateScrollPane(f);
187: // }
188:
189: /** This methods is normally called when the user has indicated that
190: * they will begin resizing the frame. This method should be called
191: * prior to any resizeFrame() calls to allow the DesktopManager to prepare any
192: * necessary state. Normally <b>f</b> will be a JInternalFrame.
193: */
194: public void beginResizingFrame(JComponent f, int direction) {
195: super .beginResizingFrame(f, direction);
196: }
197:
198: /** This method is normally called when the user has indicated that
199: * they will begin dragging a component around. This method should be called
200: * prior to any dragFrame() calls to allow the DesktopManager to prepare any
201: * necessary state. Normally <b>f</b> will be a JInternalFrame.
202: */
203: public void beginDraggingFrame(JComponent f) {
204: super .beginDraggingFrame(f);
205: }
206:
207: /** This method signals the end of the resize session. Any state maintained by
208: * the DesktopManager can be removed here. Normally <b>f</b> will be a JInternalFrame.
209: */
210: public void endResizingFrame(JComponent f) {
211: super .endResizingFrame(f);
212: // System.out.println("END RESIZING " + f.getBounds());
213: if (f instanceof JInternalFrame) {
214: validateScrollPane((JInternalFrame) f);
215: }
216: }
217:
218: /** This method signals the end of the dragging session. Any state maintained by
219: * the DesktopManager can be removed here. Normally <b>f</b> will be a JInternalFrame.
220: */
221: public void endDraggingFrame(JComponent f) {
222: super .endDraggingFrame(f);
223: // System.out.println("END DRAGGING " + f.getBounds());
224: // if(f instanceof JInternalFrame) {
225: validateScrollPane(f);
226: // }
227: }
228:
229: /** The user has resized the component. Calls to this method will be preceded by calls
230: * to beginResizingFrame().
231: * Normally <b>f</b> will be a JInternalFrame.
232: */
233: public void resizeFrame(JComponent f, int newX, int newY,
234: int newWidth, int newHeight) {
235: // System.out.println("TRC: " + getClass().getName() + ".resizeFrame()");
236: super .resizeFrame(f, newX, newY, newWidth, newHeight);
237: }
238:
239: /** This is a primitive reshape method.*/
240: public void setBoundsForFrame(JComponent f, int newX, int newY,
241: int newWidth, int newHeight) {
242: // System.out.println("TRC: " + getClass().getName() + ".setBoundsForFrame()");
243: super.setBoundsForFrame(f, newX, newY, newWidth, newHeight);
244: }
245:
246: }
|