16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26
27 package javax.swing;
28
29 import com.sun.awt.AWTUtilities;
30 import sun.awt.AWTAccessor;
31 import sun.awt.SunToolkit;
32
33 import java.awt.*;
34 import java.beans.PropertyVetoException;
35
36 /** This is an implementation of the <code>DesktopManager</code>.
37 * It currently implements the basic behaviors for managing
38 * <code>JInternalFrame</code>s in an arbitrary parent.
39 * <code>JInternalFrame</code>s that are not children of a
40 * <code>JDesktop</code> will use this component
41 * to handle their desktop-like actions.
42 * <p>This class provides a policy for the various JInternalFrame methods,
43 * it is not meant to be called directly rather the various JInternalFrame
44 * methods will call into the DesktopManager.</p>
45 * @see JDesktopPane
46 * @see JInternalFrame
47 * @author David Kloba
48 * @author Steve Wilson
49 * @since 1.2
50 */
51 @SuppressWarnings("serial") // No Interesting Non-Transient State
52 public class DefaultDesktopManager implements DesktopManager, java.io.Serializable {
53 static final String HAS_BEEN_ICONIFIED_PROPERTY = "wasIconOnce";
54
55 static final int DEFAULT_DRAG_MODE = 0;
56 static final int OUTLINE_DRAG_MODE = 1;
57 static final int FASTER_DRAG_MODE = 2;
58
59 int dragMode = DEFAULT_DRAG_MODE;
60
66 /**
67 * Set to true when the user actually drags a frame vs clicks on it
68 * to start the drag operation. This is only used when dragging with
69 * FASTER_DRAG_MODE.
70 */
71 private transient boolean didDrag;
72
73 /** Normally this method will not be called. If it is, it
74 * tries to determine the appropriate parent from the desktopIcon of the frame.
75 * Will remove the desktopIcon from its parent if it successfully adds the frame.
76 */
77 public void openFrame(JInternalFrame f) {
78 if(f.getDesktopIcon().getParent() != null) {
79 f.getDesktopIcon().getParent().add(f);
80 removeIconFor(f);
81 }
82 }
83
84 /**
85 * Removes the frame, and, if necessary, the
86 * <code>desktopIcon</code>, from its parent.
87 * @param f the <code>JInternalFrame</code> to be removed
88 */
89 public void closeFrame(JInternalFrame f) {
90 JDesktopPane d = f.getDesktopPane();
91 if (d == null) {
92 return;
93 }
94 boolean findNext = f.isSelected();
95 Container c = f.getParent();
96 JInternalFrame nextFrame = null;
97 if (findNext) {
98 nextFrame = d.getNextFrame(f);
99 try { f.setSelected(false); } catch (PropertyVetoException e2) { }
100 }
101 if(c != null) {
102 c.remove(f); // Removes the focus.
103 c.repaint(f.getX(), f.getY(), f.getWidth(), f.getHeight());
104 }
105 removeIconFor(f);
106 if(f.getNormalBounds() != null)
107 f.setNormalBounds(null);
127 // That method will handle the maximization of the frame.
128 f.setIcon(false);
129 } catch (PropertyVetoException e2) {
130 }
131 } else {
132 f.setNormalBounds(f.getBounds());
133 Rectangle desktopBounds = f.getParent().getBounds();
134 setBoundsForFrame(f, 0, 0,
135 desktopBounds.width, desktopBounds.height);
136 }
137
138 // Set the maximized frame as selected.
139 try {
140 f.setSelected(true);
141 } catch (PropertyVetoException e2) {
142 }
143 }
144
145 /**
146 * Restores the frame back to its size and position prior
147 * to a <code>maximizeFrame</code> call.
148 * @param f the <code>JInternalFrame</code> to be restored
149 */
150 public void minimizeFrame(JInternalFrame f) {
151 // If the frame was an icon restore it back to an icon.
152 if (f.isIcon()) {
153 iconifyFrame(f);
154 return;
155 }
156
157 if ((f.getNormalBounds()) != null) {
158 Rectangle r = f.getNormalBounds();
159 f.setNormalBounds(null);
160 try { f.setSelected(true); } catch (PropertyVetoException e2) { }
161 setBoundsForFrame(f, r.x, r.y, r.width, r.height);
162 }
163 }
164
165 /**
166 * Removes the frame from its parent and adds its
167 * <code>desktopIcon</code> to the parent.
168 * @param f the <code>JInternalFrame</code> to be iconified
169 */
170 public void iconifyFrame(JInternalFrame f) {
171 JInternalFrame.JDesktopIcon desktopIcon;
172 Container c = f.getParent();
173 JDesktopPane d = f.getDesktopPane();
174 boolean findNext = f.isSelected();
175 desktopIcon = f.getDesktopIcon();
176 if(!wasIcon(f)) {
177 Rectangle r = getBoundsForIconOf(f);
178 desktopIcon.setBounds(r.x, r.y, r.width, r.height);
179 // we must validate the hierarchy to not break the hw/lw mixing
180 desktopIcon.revalidate();
181 setWasIcon(f, Boolean.TRUE);
182 }
183
184 if (c == null || d == null) {
185 return;
186 }
187
188 if (c instanceof JLayeredPane) {
196 // normal bounds to maximized state.
197 if (!f.isMaximum()) {
198 f.setNormalBounds(f.getBounds());
199 }
200 d.setComponentOrderCheckingEnabled(false);
201 c.remove(f);
202 c.add(desktopIcon);
203 d.setComponentOrderCheckingEnabled(true);
204 c.repaint(f.getX(), f.getY(), f.getWidth(), f.getHeight());
205 if (findNext) {
206 if (d.selectFrame(true) == null) {
207 // The icon is the last frame.
208 f.restoreSubcomponentFocus();
209 }
210 }
211 }
212
213 /**
214 * Removes the desktopIcon from its parent and adds its frame
215 * to the parent.
216 * @param f the <code>JInternalFrame</code> to be de-iconified
217 */
218 public void deiconifyFrame(JInternalFrame f) {
219 JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();
220 Container c = desktopIcon.getParent();
221 JDesktopPane d = f.getDesktopPane();
222 if (c != null && d != null) {
223 c.add(f);
224 // If the frame is to be restored to a maximized state make
225 // sure it still fills the whole desktop.
226 if (f.isMaximum()) {
227 Rectangle desktopBounds = c.getBounds();
228 if (f.getWidth() != desktopBounds.width ||
229 f.getHeight() != desktopBounds.height) {
230 setBoundsForFrame(f, 0, 0,
231 desktopBounds.width, desktopBounds.height);
232 }
233 }
234 removeIconFor(f);
235 if (f.isSelected()) {
236 f.moveToFront();
237 f.restoreSubcomponentFocus();
238 }
239 else {
240 try {
241 f.setSelected(true);
242 } catch (PropertyVetoException e2) {}
243
244 }
245 }
246 }
247
248 /** This will activate <b>f</b> moving it to the front. It will
249 * set the current active frame's (if any)
250 * <code>IS_SELECTED_PROPERTY</code> to <code>false</code>.
251 * There can be only one active frame across all Layers.
252 * @param f the <code>JInternalFrame</code> to be activated
253 */
254 public void activateFrame(JInternalFrame f) {
255 Container p = f.getParent();
256 Component[] c;
257 JDesktopPane d = f.getDesktopPane();
258 JInternalFrame currentlyActiveFrame =
259 (d == null) ? null : d.getSelectedFrame();
260 // fix for bug: 4162443
261 if(p == null) {
262 // If the frame is not in parent, its icon maybe, check it
263 p = f.getDesktopIcon().getParent();
264 if(p == null)
265 return;
266 }
267 // we only need to keep track of the currentActive InternalFrame, if any
268 if (currentlyActiveFrame == null){
269 if (d != null) { d.setSelectedFrame(f);}
270 } else if (currentlyActiveFrame != f) {
271 // if not the same frame as the current active
272 // we deactivate the current
331 } else {
332 if (p.getDragMode() == JDesktopPane.OUTLINE_DRAG_MODE ) {
333 dragMode = OUTLINE_DRAG_MODE;
334 } else if ( p.getDragMode() == JDesktopPane.LIVE_DRAG_MODE
335 && f instanceof JInternalFrame
336 && ((JInternalFrame)f).isOpaque()) {
337 dragMode = FASTER_DRAG_MODE;
338 } else {
339 dragMode = DEFAULT_DRAG_MODE;
340 }
341 }
342 }
343 }
344
345 private transient Point currentLoc = null;
346
347 /**
348 * Moves the visible location of the frame being dragged
349 * to the location specified. The means by which this occurs can vary depending
350 * on the dragging algorithm being used. The actual logical location of the frame
351 * might not change until <code>endDraggingFrame</code> is called.
352 */
353 public void dragFrame(JComponent f, int newX, int newY) {
354
355 if (dragMode == OUTLINE_DRAG_MODE) {
356 JDesktopPane desktopPane = getDesktopPane(f);
357 if (desktopPane != null){
358 Graphics g = JComponent.safelyGetGraphics(desktopPane);
359
360 g.setXORMode(Color.white);
361 if (currentLoc != null) {
362 g.drawRect(currentLoc.x, currentLoc.y,
363 f.getWidth()-1, f.getHeight()-1);
364 }
365 g.drawRect( newX, newY, f.getWidth()-1, f.getHeight()-1);
366 /* Work around for 6635462: XOR mode may cause a SurfaceLost on first use.
367 * Swing doesn't expect that its XOR drawRect did
368 * not complete, so believes that on re-entering at
369 * the next update location, that there is an XOR rect
370 * to draw out at "currentLoc". But in fact
371 * its now got a new clean surface without that rect,
393 if ( dragMode == OUTLINE_DRAG_MODE && currentLoc != null) {
394 setBoundsForFrame(f, currentLoc.x, currentLoc.y, f.getWidth(), f.getHeight() );
395 currentLoc = null;
396 } else if (dragMode == FASTER_DRAG_MODE) {
397 currentBounds = null;
398 if (desktopGraphics != null) {
399 desktopGraphics.dispose();
400 desktopGraphics = null;
401 }
402 desktopBounds = null;
403 ((JInternalFrame)f).isDragging = false;
404 }
405 }
406
407 // implements javax.swing.DesktopManager
408 public void beginResizingFrame(JComponent f, int direction) {
409 setupDragMode(f);
410 }
411
412 /**
413 * Calls <code>setBoundsForFrame</code> with the new values.
414 * @param f the component to be resized
415 * @param newX the new x-coordinate
416 * @param newY the new y-coordinate
417 * @param newWidth the new width
418 * @param newHeight the new height
419 */
420 public void resizeFrame(JComponent f, int newX, int newY, int newWidth, int newHeight) {
421
422 if ( dragMode == DEFAULT_DRAG_MODE || dragMode == FASTER_DRAG_MODE ) {
423 setBoundsForFrame(f, newX, newY, newWidth, newHeight);
424 } else {
425 JDesktopPane desktopPane = getDesktopPane(f);
426 if (desktopPane != null){
427 Graphics g = JComponent.safelyGetGraphics(desktopPane);
428
429 g.setXORMode(Color.white);
430 if (currentBounds != null) {
431 g.drawRect( currentBounds.x, currentBounds.y, currentBounds.width-1, currentBounds.height-1);
432 }
433 g.drawRect( newX, newY, newWidth-1, newHeight-1);
438 if (!sData.isSurfaceLost()) {
439 currentBounds = new Rectangle (newX, newY, newWidth, newHeight);
440 }
441
442 g.setPaintMode();
443 g.dispose();
444 }
445 }
446
447 }
448
449 // implements javax.swing.DesktopManager
450 public void endResizingFrame(JComponent f) {
451 if ( dragMode == OUTLINE_DRAG_MODE && currentBounds != null) {
452 setBoundsForFrame(f, currentBounds.x, currentBounds.y, currentBounds.width, currentBounds.height );
453 currentBounds = null;
454 }
455 }
456
457
458 /** This moves the <code>JComponent</code> and repaints the damaged areas. */
459 public void setBoundsForFrame(JComponent f, int newX, int newY, int newWidth, int newHeight) {
460 f.setBounds(newX, newY, newWidth, newHeight);
461 // we must validate the hierarchy to not break the hw/lw mixing
462 f.revalidate();
463 }
464
465 /**
466 * Convenience method to remove the desktopIcon of <b>f</b> is necessary.
467 *
468 * @param f the {@code JInternalFrame} for which to remove the
469 * {@code desktopIcon}
470 */
471 protected void removeIconFor(JInternalFrame f) {
472 JInternalFrame.JDesktopIcon di = f.getDesktopIcon();
473 Container c = di.getParent();
474 if(c != null) {
475 c.remove(di);
476 c.repaint(di.getX(), di.getY(), di.getWidth(), di.getHeight());
477 }
478 }
573 x = 0;
574 y -= h;
575 }
576 }
577
578 return(availableRectangle);
579 }
580
581 /**
582 * Stores the bounds of the component just before a maximize call.
583 * @param f the component about to be resized
584 * @param r the normal bounds to be saved away
585 */
586 protected void setPreviousBounds(JInternalFrame f, Rectangle r) {
587 f.setNormalBounds(r);
588 }
589
590 /**
591 * Gets the normal bounds of the component prior to the component
592 * being maximized.
593 * @param f the <code>JInternalFrame</code> of interest
594 * @return the normal bounds of the component
595 */
596 protected Rectangle getPreviousBounds(JInternalFrame f) {
597 return f.getNormalBounds();
598 }
599
600 /**
601 * Sets that the component has been iconized and the bounds of the
602 * <code>desktopIcon</code> are valid.
603 *
604 * @param f the {@code JInternalFrame} of interest
605 * @param value a {@code Boolean} signifying if component has been iconized
606 */
607 protected void setWasIcon(JInternalFrame f, Boolean value) {
608 if (value != null) {
609 f.putClientProperty(HAS_BEEN_ICONIFIED_PROPERTY, value);
610 }
611 }
612
613 /**
614 * Returns <code>true</code> if the component has been iconized
615 * and the bounds of the <code>desktopIcon</code> are valid,
616 * otherwise returns <code>false</code>.
617 *
618 * @param f the <code>JInternalFrame</code> of interest
619 * @return <code>true</code> if the component has been iconized;
620 * otherwise returns <code>false</code>
621 */
622 protected boolean wasIcon(JInternalFrame f) {
623 return (f.getClientProperty(HAS_BEEN_ICONIFIED_PROPERTY) == Boolean.TRUE);
624 }
625
626
627 JDesktopPane getDesktopPane( JComponent frame ) {
628 JDesktopPane pane = null;
629 Component c = frame.getParent();
630
631 // Find the JDesktopPane
632 while ( pane == null ) {
633 if ( c instanceof JDesktopPane ) {
634 pane = (JDesktopPane)c;
635 }
636 else if ( c == null ) {
637 break;
638 }
639 else {
640 c = c.getParent();
|
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26
27 package javax.swing;
28
29 import com.sun.awt.AWTUtilities;
30 import sun.awt.AWTAccessor;
31 import sun.awt.SunToolkit;
32
33 import java.awt.*;
34 import java.beans.PropertyVetoException;
35
36 /** This is an implementation of the {@code DesktopManager}.
37 * It currently implements the basic behaviors for managing
38 * {@code JInternalFrame}s in an arbitrary parent.
39 * {@code JInternalFrame}s that are not children of a
40 * {@code JDesktop} will use this component
41 * to handle their desktop-like actions.
42 * <p>This class provides a policy for the various JInternalFrame methods,
43 * it is not meant to be called directly rather the various JInternalFrame
44 * methods will call into the DesktopManager.</p>
45 * @see JDesktopPane
46 * @see JInternalFrame
47 * @author David Kloba
48 * @author Steve Wilson
49 * @since 1.2
50 */
51 @SuppressWarnings("serial") // No Interesting Non-Transient State
52 public class DefaultDesktopManager implements DesktopManager, java.io.Serializable {
53 static final String HAS_BEEN_ICONIFIED_PROPERTY = "wasIconOnce";
54
55 static final int DEFAULT_DRAG_MODE = 0;
56 static final int OUTLINE_DRAG_MODE = 1;
57 static final int FASTER_DRAG_MODE = 2;
58
59 int dragMode = DEFAULT_DRAG_MODE;
60
66 /**
67 * Set to true when the user actually drags a frame vs clicks on it
68 * to start the drag operation. This is only used when dragging with
69 * FASTER_DRAG_MODE.
70 */
71 private transient boolean didDrag;
72
73 /** Normally this method will not be called. If it is, it
74 * tries to determine the appropriate parent from the desktopIcon of the frame.
75 * Will remove the desktopIcon from its parent if it successfully adds the frame.
76 */
77 public void openFrame(JInternalFrame f) {
78 if(f.getDesktopIcon().getParent() != null) {
79 f.getDesktopIcon().getParent().add(f);
80 removeIconFor(f);
81 }
82 }
83
84 /**
85 * Removes the frame, and, if necessary, the
86 * {@code desktopIcon}, from its parent.
87 * @param f the {@code JInternalFrame} to be removed
88 */
89 public void closeFrame(JInternalFrame f) {
90 JDesktopPane d = f.getDesktopPane();
91 if (d == null) {
92 return;
93 }
94 boolean findNext = f.isSelected();
95 Container c = f.getParent();
96 JInternalFrame nextFrame = null;
97 if (findNext) {
98 nextFrame = d.getNextFrame(f);
99 try { f.setSelected(false); } catch (PropertyVetoException e2) { }
100 }
101 if(c != null) {
102 c.remove(f); // Removes the focus.
103 c.repaint(f.getX(), f.getY(), f.getWidth(), f.getHeight());
104 }
105 removeIconFor(f);
106 if(f.getNormalBounds() != null)
107 f.setNormalBounds(null);
127 // That method will handle the maximization of the frame.
128 f.setIcon(false);
129 } catch (PropertyVetoException e2) {
130 }
131 } else {
132 f.setNormalBounds(f.getBounds());
133 Rectangle desktopBounds = f.getParent().getBounds();
134 setBoundsForFrame(f, 0, 0,
135 desktopBounds.width, desktopBounds.height);
136 }
137
138 // Set the maximized frame as selected.
139 try {
140 f.setSelected(true);
141 } catch (PropertyVetoException e2) {
142 }
143 }
144
145 /**
146 * Restores the frame back to its size and position prior
147 * to a {@code maximizeFrame} call.
148 * @param f the {@code JInternalFrame} to be restored
149 */
150 public void minimizeFrame(JInternalFrame f) {
151 // If the frame was an icon restore it back to an icon.
152 if (f.isIcon()) {
153 iconifyFrame(f);
154 return;
155 }
156
157 if ((f.getNormalBounds()) != null) {
158 Rectangle r = f.getNormalBounds();
159 f.setNormalBounds(null);
160 try { f.setSelected(true); } catch (PropertyVetoException e2) { }
161 setBoundsForFrame(f, r.x, r.y, r.width, r.height);
162 }
163 }
164
165 /**
166 * Removes the frame from its parent and adds its
167 * {@code desktopIcon} to the parent.
168 * @param f the {@code JInternalFrame} to be iconified
169 */
170 public void iconifyFrame(JInternalFrame f) {
171 JInternalFrame.JDesktopIcon desktopIcon;
172 Container c = f.getParent();
173 JDesktopPane d = f.getDesktopPane();
174 boolean findNext = f.isSelected();
175 desktopIcon = f.getDesktopIcon();
176 if(!wasIcon(f)) {
177 Rectangle r = getBoundsForIconOf(f);
178 desktopIcon.setBounds(r.x, r.y, r.width, r.height);
179 // we must validate the hierarchy to not break the hw/lw mixing
180 desktopIcon.revalidate();
181 setWasIcon(f, Boolean.TRUE);
182 }
183
184 if (c == null || d == null) {
185 return;
186 }
187
188 if (c instanceof JLayeredPane) {
196 // normal bounds to maximized state.
197 if (!f.isMaximum()) {
198 f.setNormalBounds(f.getBounds());
199 }
200 d.setComponentOrderCheckingEnabled(false);
201 c.remove(f);
202 c.add(desktopIcon);
203 d.setComponentOrderCheckingEnabled(true);
204 c.repaint(f.getX(), f.getY(), f.getWidth(), f.getHeight());
205 if (findNext) {
206 if (d.selectFrame(true) == null) {
207 // The icon is the last frame.
208 f.restoreSubcomponentFocus();
209 }
210 }
211 }
212
213 /**
214 * Removes the desktopIcon from its parent and adds its frame
215 * to the parent.
216 * @param f the {@code JInternalFrame} to be de-iconified
217 */
218 public void deiconifyFrame(JInternalFrame f) {
219 JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();
220 Container c = desktopIcon.getParent();
221 JDesktopPane d = f.getDesktopPane();
222 if (c != null && d != null) {
223 c.add(f);
224 // If the frame is to be restored to a maximized state make
225 // sure it still fills the whole desktop.
226 if (f.isMaximum()) {
227 Rectangle desktopBounds = c.getBounds();
228 if (f.getWidth() != desktopBounds.width ||
229 f.getHeight() != desktopBounds.height) {
230 setBoundsForFrame(f, 0, 0,
231 desktopBounds.width, desktopBounds.height);
232 }
233 }
234 removeIconFor(f);
235 if (f.isSelected()) {
236 f.moveToFront();
237 f.restoreSubcomponentFocus();
238 }
239 else {
240 try {
241 f.setSelected(true);
242 } catch (PropertyVetoException e2) {}
243
244 }
245 }
246 }
247
248 /** This will activate <b>f</b> moving it to the front. It will
249 * set the current active frame's (if any)
250 * {@code IS_SELECTED_PROPERTY} to {@code false}.
251 * There can be only one active frame across all Layers.
252 * @param f the {@code JInternalFrame} to be activated
253 */
254 public void activateFrame(JInternalFrame f) {
255 Container p = f.getParent();
256 Component[] c;
257 JDesktopPane d = f.getDesktopPane();
258 JInternalFrame currentlyActiveFrame =
259 (d == null) ? null : d.getSelectedFrame();
260 // fix for bug: 4162443
261 if(p == null) {
262 // If the frame is not in parent, its icon maybe, check it
263 p = f.getDesktopIcon().getParent();
264 if(p == null)
265 return;
266 }
267 // we only need to keep track of the currentActive InternalFrame, if any
268 if (currentlyActiveFrame == null){
269 if (d != null) { d.setSelectedFrame(f);}
270 } else if (currentlyActiveFrame != f) {
271 // if not the same frame as the current active
272 // we deactivate the current
331 } else {
332 if (p.getDragMode() == JDesktopPane.OUTLINE_DRAG_MODE ) {
333 dragMode = OUTLINE_DRAG_MODE;
334 } else if ( p.getDragMode() == JDesktopPane.LIVE_DRAG_MODE
335 && f instanceof JInternalFrame
336 && ((JInternalFrame)f).isOpaque()) {
337 dragMode = FASTER_DRAG_MODE;
338 } else {
339 dragMode = DEFAULT_DRAG_MODE;
340 }
341 }
342 }
343 }
344
345 private transient Point currentLoc = null;
346
347 /**
348 * Moves the visible location of the frame being dragged
349 * to the location specified. The means by which this occurs can vary depending
350 * on the dragging algorithm being used. The actual logical location of the frame
351 * might not change until {@code endDraggingFrame} is called.
352 */
353 public void dragFrame(JComponent f, int newX, int newY) {
354
355 if (dragMode == OUTLINE_DRAG_MODE) {
356 JDesktopPane desktopPane = getDesktopPane(f);
357 if (desktopPane != null){
358 Graphics g = JComponent.safelyGetGraphics(desktopPane);
359
360 g.setXORMode(Color.white);
361 if (currentLoc != null) {
362 g.drawRect(currentLoc.x, currentLoc.y,
363 f.getWidth()-1, f.getHeight()-1);
364 }
365 g.drawRect( newX, newY, f.getWidth()-1, f.getHeight()-1);
366 /* Work around for 6635462: XOR mode may cause a SurfaceLost on first use.
367 * Swing doesn't expect that its XOR drawRect did
368 * not complete, so believes that on re-entering at
369 * the next update location, that there is an XOR rect
370 * to draw out at "currentLoc". But in fact
371 * its now got a new clean surface without that rect,
393 if ( dragMode == OUTLINE_DRAG_MODE && currentLoc != null) {
394 setBoundsForFrame(f, currentLoc.x, currentLoc.y, f.getWidth(), f.getHeight() );
395 currentLoc = null;
396 } else if (dragMode == FASTER_DRAG_MODE) {
397 currentBounds = null;
398 if (desktopGraphics != null) {
399 desktopGraphics.dispose();
400 desktopGraphics = null;
401 }
402 desktopBounds = null;
403 ((JInternalFrame)f).isDragging = false;
404 }
405 }
406
407 // implements javax.swing.DesktopManager
408 public void beginResizingFrame(JComponent f, int direction) {
409 setupDragMode(f);
410 }
411
412 /**
413 * Calls {@code setBoundsForFrame} with the new values.
414 * @param f the component to be resized
415 * @param newX the new x-coordinate
416 * @param newY the new y-coordinate
417 * @param newWidth the new width
418 * @param newHeight the new height
419 */
420 public void resizeFrame(JComponent f, int newX, int newY, int newWidth, int newHeight) {
421
422 if ( dragMode == DEFAULT_DRAG_MODE || dragMode == FASTER_DRAG_MODE ) {
423 setBoundsForFrame(f, newX, newY, newWidth, newHeight);
424 } else {
425 JDesktopPane desktopPane = getDesktopPane(f);
426 if (desktopPane != null){
427 Graphics g = JComponent.safelyGetGraphics(desktopPane);
428
429 g.setXORMode(Color.white);
430 if (currentBounds != null) {
431 g.drawRect( currentBounds.x, currentBounds.y, currentBounds.width-1, currentBounds.height-1);
432 }
433 g.drawRect( newX, newY, newWidth-1, newHeight-1);
438 if (!sData.isSurfaceLost()) {
439 currentBounds = new Rectangle (newX, newY, newWidth, newHeight);
440 }
441
442 g.setPaintMode();
443 g.dispose();
444 }
445 }
446
447 }
448
449 // implements javax.swing.DesktopManager
450 public void endResizingFrame(JComponent f) {
451 if ( dragMode == OUTLINE_DRAG_MODE && currentBounds != null) {
452 setBoundsForFrame(f, currentBounds.x, currentBounds.y, currentBounds.width, currentBounds.height );
453 currentBounds = null;
454 }
455 }
456
457
458 /** This moves the {@code JComponent} and repaints the damaged areas. */
459 public void setBoundsForFrame(JComponent f, int newX, int newY, int newWidth, int newHeight) {
460 f.setBounds(newX, newY, newWidth, newHeight);
461 // we must validate the hierarchy to not break the hw/lw mixing
462 f.revalidate();
463 }
464
465 /**
466 * Convenience method to remove the desktopIcon of <b>f</b> is necessary.
467 *
468 * @param f the {@code JInternalFrame} for which to remove the
469 * {@code desktopIcon}
470 */
471 protected void removeIconFor(JInternalFrame f) {
472 JInternalFrame.JDesktopIcon di = f.getDesktopIcon();
473 Container c = di.getParent();
474 if(c != null) {
475 c.remove(di);
476 c.repaint(di.getX(), di.getY(), di.getWidth(), di.getHeight());
477 }
478 }
573 x = 0;
574 y -= h;
575 }
576 }
577
578 return(availableRectangle);
579 }
580
581 /**
582 * Stores the bounds of the component just before a maximize call.
583 * @param f the component about to be resized
584 * @param r the normal bounds to be saved away
585 */
586 protected void setPreviousBounds(JInternalFrame f, Rectangle r) {
587 f.setNormalBounds(r);
588 }
589
590 /**
591 * Gets the normal bounds of the component prior to the component
592 * being maximized.
593 * @param f the {@code JInternalFrame} of interest
594 * @return the normal bounds of the component
595 */
596 protected Rectangle getPreviousBounds(JInternalFrame f) {
597 return f.getNormalBounds();
598 }
599
600 /**
601 * Sets that the component has been iconized and the bounds of the
602 * {@code desktopIcon} are valid.
603 *
604 * @param f the {@code JInternalFrame} of interest
605 * @param value a {@code Boolean} signifying if component has been iconized
606 */
607 protected void setWasIcon(JInternalFrame f, Boolean value) {
608 if (value != null) {
609 f.putClientProperty(HAS_BEEN_ICONIFIED_PROPERTY, value);
610 }
611 }
612
613 /**
614 * Returns {@code true} if the component has been iconized
615 * and the bounds of the {@code desktopIcon} are valid,
616 * otherwise returns {@code false}.
617 *
618 * @param f the {@code JInternalFrame} of interest
619 * @return {@code true} if the component has been iconized;
620 * otherwise returns {@code false}
621 */
622 protected boolean wasIcon(JInternalFrame f) {
623 return (f.getClientProperty(HAS_BEEN_ICONIFIED_PROPERTY) == Boolean.TRUE);
624 }
625
626
627 JDesktopPane getDesktopPane( JComponent frame ) {
628 JDesktopPane pane = null;
629 Component c = frame.getParent();
630
631 // Find the JDesktopPane
632 while ( pane == null ) {
633 if ( c instanceof JDesktopPane ) {
634 pane = (JDesktopPane)c;
635 }
636 else if ( c == null ) {
637 break;
638 }
639 else {
640 c = c.getParent();
|