KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > DefaultDesktopManager


1 /*
2  * @(#)DefaultDesktopManager.java 1.52 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8
9 package javax.swing;
10
11 import java.awt.*;
12 import java.beans.PropertyVetoException JavaDoc;
13 import java.beans.PropertyChangeEvent JavaDoc;
14 import javax.swing.border.Border JavaDoc;
15 import java.awt.event.ComponentListener JavaDoc;
16 import java.awt.event.ComponentAdapter JavaDoc;
17 import java.awt.event.ComponentEvent JavaDoc;
18
19 /** This is an implementation of the <code>DesktopManager</code>.
20   * It currently implements the basic behaviors for managing
21   * <code>JInternalFrame</code>s in an arbitrary parent.
22   * <code>JInternalFrame</code>s that are not children of a
23   * <code>JDesktop</code> will use this component
24   * to handle their desktop-like actions.
25   * <p>This class provides a policy for the various JInternalFrame methods,
26   * it is not meant to be called directly rather the various JInternalFrame
27   * methods will call into the DesktopManager.</p>
28   * @see JDesktopPane
29   * @see JInternalFrame
30   * @version 1.52 12/19/03
31   * @author David Kloba
32   * @author Steve Wilson
33   */

34 public class DefaultDesktopManager implements DesktopManager JavaDoc, java.io.Serializable JavaDoc {
35     final static String JavaDoc HAS_BEEN_ICONIFIED_PROPERTY = "wasIconOnce";
36
37     final static int DEFAULT_DRAG_MODE = 0;
38     final static int OUTLINE_DRAG_MODE = 1;
39     final static int FASTER_DRAG_MODE = 2;
40   
41     int dragMode = DEFAULT_DRAG_MODE;
42
43     private transient Rectangle currentBounds = null;
44     private transient Graphics desktopGraphics = null;
45     private transient Rectangle desktopBounds = null;
46     private transient Rectangle[] floatingItems = {};
47
48
49     /** Normally this method will not be called. If it is, it
50       * try to determine the appropriate parent from the desktopIcon of the frame.
51       * Will remove the desktopIcon from its parent if it successfully adds the frame.
52       */

53     public void openFrame(JInternalFrame JavaDoc f) {
54         if(f.getDesktopIcon().getParent() != null) {
55             f.getDesktopIcon().getParent().add(f);
56             removeIconFor(f);
57         }
58     }
59
60     /**
61      * Removes the frame, and, if necessary, the
62      * <code>desktopIcon</code>, from its parent.
63      * @param f the <code>JInternalFrame</code> to be removed
64      */

65     public void closeFrame(JInternalFrame JavaDoc f) {
66         boolean findNext = f.isSelected();
67     Container c = f.getParent();
68     if (findNext)
69         try { f.setSelected(false); } catch (PropertyVetoException JavaDoc e2) { }
70         if(c != null) {
71             c.remove(f);
72             c.repaint(f.getX(), f.getY(), f.getWidth(), f.getHeight());
73         }
74         removeIconFor(f);
75         if(f.getNormalBounds() != null)
76             f.setNormalBounds(null);
77         if(wasIcon(f))
78             setWasIcon(f, null);
79     if (findNext) activateNextFrame(c);
80     }
81
82     /**
83      * Resizes the frame to fill its parents bounds.
84      * @param f the frame to be resized
85      */

86     public void maximizeFrame(JInternalFrame JavaDoc f) {
87         if (f.isIcon()) {
88             try {
89                 // In turn calls deiconifyFrame in the desktop manager.
90
// That method will handle the maximization of the frame.
91
f.setIcon(false);
92             } catch (PropertyVetoException JavaDoc e2) {
93             }
94         } else {
95             f.setNormalBounds(f.getBounds());
96             Rectangle desktopBounds = f.getParent().getBounds();
97             setBoundsForFrame(f, 0, 0,
98                 desktopBounds.width, desktopBounds.height);
99         }
100
101         // Set the maximized frame as selected.
102
try {
103             f.setSelected(true);
104         } catch (PropertyVetoException JavaDoc e2) {
105         }
106     }
107
108     /**
109      * Restores the frame back to its size and position prior
110      * to a <code>maximizeFrame</code> call.
111      * @param f the <code>JInternalFrame</code> to be restored
112      */

113     public void minimizeFrame(JInternalFrame JavaDoc f) {
114         // If the frame was an icon restore it back to an icon.
115
if (f.isIcon()) {
116             iconifyFrame(f);
117             return;
118         }
119
120         if ((f.getNormalBounds()) != null) {
121             Rectangle r = f.getNormalBounds();
122         f.setNormalBounds(null);
123             try { f.setSelected(true); } catch (PropertyVetoException JavaDoc e2) { }
124             setBoundsForFrame(f, r.x, r.y, r.width, r.height);
125         }
126     }
127
128     /**
129      * Removes the frame from its parent and adds its
130      * <code>desktopIcon</code> to the parent.
131      * @param f the <code>JInternalFrame</code> to be iconified
132      */

133     public void iconifyFrame(JInternalFrame JavaDoc f) {
134         JInternalFrame.JDesktopIcon JavaDoc desktopIcon;
135         Container c = f.getParent();
136     JDesktopPane JavaDoc d = f.getDesktopPane();
137     boolean findNext = f.isSelected();
138
139         desktopIcon = f.getDesktopIcon();
140         if(!wasIcon(f)) {
141             Rectangle r = getBoundsForIconOf(f);
142             desktopIcon.setBounds(r.x, r.y, r.width, r.height);
143             setWasIcon(f, Boolean.TRUE);
144         }
145
146     if (c == null) {
147             return;
148         }
149
150     if (c instanceof JLayeredPane JavaDoc) {
151         JLayeredPane JavaDoc lp = (JLayeredPane JavaDoc)c;
152         int layer = lp.getLayer(f);
153         lp.putLayer(desktopIcon, layer);
154     }
155
156         // If we are maximized we already have the normal bounds recorded
157
// don't try to re-record them, otherwise we incorrectly set the
158
// normal bounds to maximized state.
159
if (!f.isMaximum()) {
160             f.setNormalBounds(f.getBounds());
161         }
162         c.remove(f);
163         c.add(desktopIcon);
164         c.repaint(f.getX(), f.getY(), f.getWidth(), f.getHeight());
165         try {
166             f.setSelected(false);
167         } catch (PropertyVetoException JavaDoc e2) {
168         }
169
170     // Get topmost of the remaining frames
171
if (findNext) {
172       activateNextFrame(c);
173     }
174     }
175
176     void activateNextFrame(Container c) {
177       int i;
178       JInternalFrame JavaDoc nextFrame = null;
179       if (c == null) return;
180       for (i = 0; i < c.getComponentCount(); i++) {
181     if (c.getComponent(i) instanceof JInternalFrame JavaDoc) {
182       nextFrame = (JInternalFrame JavaDoc) c.getComponent(i);
183       break;
184     }
185       }
186       if (nextFrame != null) {
187     try { nextFrame.setSelected(true); }
188     catch (PropertyVetoException JavaDoc e2) { }
189     nextFrame.moveToFront();
190       }
191       
192     }
193
194     /**
195      * Removes the desktopIcon from its parent and adds its frame
196      * to the parent.
197      * @param f the <code>JInternalFrame</code> to be de-iconified
198      */

199     public void deiconifyFrame(JInternalFrame JavaDoc f) {
200         JInternalFrame.JDesktopIcon JavaDoc desktopIcon = f.getDesktopIcon();
201         Container c = desktopIcon.getParent();
202         if (c != null) {
203             c.add(f);
204             // If the frame is to be restored to a maximized state make
205
// sure it still fills the whole desktop.
206
if (f.isMaximum()) {
207                 Rectangle desktopBounds = c.getBounds();
208                 if (f.getWidth() != desktopBounds.width ||
209                         f.getHeight() != desktopBounds.height) {
210                     setBoundsForFrame(f, 0, 0,
211                         desktopBounds.width, desktopBounds.height);
212                 }
213             }
214             removeIconFor(f);
215             if (f.isSelected()) {
216                 f.moveToFront();
217             } else {
218                 try {
219                     f.setSelected(true);
220                 } catch (PropertyVetoException JavaDoc e2) {
221                 }
222             }
223         }
224     }
225
226     /** This will activate <b>f</b> moving it to the front. It will
227       * set the current active frame's (if any)
228       * <code>IS_SELECTED_PROPERTY</code> to <code>false</code>.
229       * There can be only one active frame across all Layers.
230       * @param f the <code>JInternalFrame</code> to be activated
231       */

232     public void activateFrame(JInternalFrame JavaDoc f) {
233         Container p = f.getParent();
234         Component[] c;
235     JDesktopPane JavaDoc d = f.getDesktopPane();
236     JInternalFrame JavaDoc currentlyActiveFrame =
237       (d == null) ? null : d.getSelectedFrame();
238     // fix for bug: 4162443
239
if(p == null) {
240             // If the frame is not in parent, its icon maybe, check it
241
p = f.getDesktopIcon().getParent();
242             if(p == null)
243                 return;
244         }
245     // we only need to keep track of the currentActive InternalFrame, if any
246
if (currentlyActiveFrame == null){
247       if (d != null) { d.setSelectedFrame(f);}
248     } else if (currentlyActiveFrame != f) {
249       // if not the same frame as the current active
250
// we deactivate the current
251
if (currentlyActiveFrame.isSelected()) {
252         try {
253           currentlyActiveFrame.setSelected(false);
254         }
255         catch(PropertyVetoException JavaDoc e2) {}
256       }
257       if (d != null) { d.setSelectedFrame(f);}
258     }
259     f.moveToFront();
260     }
261     
262     // implements javax.swing.DesktopManager
263
public void deactivateFrame(JInternalFrame JavaDoc f) {
264       JDesktopPane JavaDoc d = f.getDesktopPane();
265       JInternalFrame JavaDoc currentlyActiveFrame =
266       (d == null) ? null : d.getSelectedFrame();
267       if (currentlyActiveFrame == f)
268     d.setSelectedFrame(null);
269     }
270
271     // implements javax.swing.DesktopManager
272
public void beginDraggingFrame(JComponent JavaDoc f) {
273         setupDragMode(f);
274
275     if (dragMode == FASTER_DRAG_MODE) {
276       floatingItems = findFloatingItems(f);
277       currentBounds = f.getBounds();
278       desktopBounds = f.getParent().getBounds();
279       desktopBounds.x = 0;
280       desktopBounds.y = 0;
281       desktopGraphics = f.getParent().getGraphics();
282       ((JInternalFrame JavaDoc)f).isDragging = true;
283     }
284     
285     }
286
287     private void setupDragMode(JComponent JavaDoc f) {
288         JDesktopPane JavaDoc p = getDesktopPane(f);
289         if (p != null) {
290             String JavaDoc mode = (String JavaDoc)p.getClientProperty("JDesktopPane.dragMode");
291             if (mode != null && mode.equals("outline")) {
292                 dragMode = OUTLINE_DRAG_MODE;
293             } else if (mode != null && mode.equals("faster")
294                     && f instanceof JInternalFrame JavaDoc
295                     && ((JInternalFrame JavaDoc)f).isOpaque()) {
296                 dragMode = FASTER_DRAG_MODE;
297             } else {
298                 if (p.getDragMode() == JDesktopPane.OUTLINE_DRAG_MODE ) {
299                     dragMode = OUTLINE_DRAG_MODE;
300                 } else if ( p.getDragMode() == JDesktopPane.LIVE_DRAG_MODE
301                         && f instanceof JInternalFrame JavaDoc
302                         && ((JInternalFrame JavaDoc)f).isOpaque()) {
303                     dragMode = FASTER_DRAG_MODE;
304                 } else {
305                     dragMode = DEFAULT_DRAG_MODE;
306                 }
307             }
308         }
309     }
310
311     private transient Point currentLoc = null;
312
313     /**
314       * Moves the visible location of the frame being dragged
315       * to the location specified. The means by which this occurs can vary depending
316       * on the dragging algorithm being used. The actual logical location of the frame
317       * might not change until <code>endDraggingFrame</code> is called.
318       */

319     public void dragFrame(JComponent JavaDoc f, int newX, int newY) {
320
321         if (dragMode == OUTLINE_DRAG_MODE) {
322         JDesktopPane JavaDoc desktopPane = getDesktopPane(f);
323         if (desktopPane != null){
324           Graphics g = desktopPane.getGraphics();
325
326           g.setXORMode(Color.white);
327           if (currentLoc != null) {
328             g.drawRect(currentLoc.x, currentLoc.y,
329                         f.getWidth()-1, f.getHeight()-1);
330           }
331           g.drawRect( newX, newY, f.getWidth()-1, f.getHeight()-1);
332           currentLoc = new Point (newX, newY);
333           g.dispose();
334         }
335     } else if (dragMode == FASTER_DRAG_MODE) {
336       dragFrameFaster(f, newX, newY);
337     } else {
338         setBoundsForFrame(f, newX, newY, f.getWidth(), f.getHeight());
339     }
340     }
341
342     // implements javax.swing.DesktopManager
343
public void endDraggingFrame(JComponent JavaDoc f) {
344         if ( dragMode == OUTLINE_DRAG_MODE && currentLoc != null) {
345         setBoundsForFrame(f, currentLoc.x, currentLoc.y, f.getWidth(), f.getHeight() );
346         currentLoc = null;
347     } else if (dragMode == FASTER_DRAG_MODE) {
348         currentBounds = null;
349         if (desktopGraphics != null) {
350             desktopGraphics.dispose();
351             desktopGraphics = null;
352         }
353         desktopBounds = null;
354         ((JInternalFrame JavaDoc)f).isDragging = false;
355     }
356     }
357
358     // implements javax.swing.DesktopManager
359
public void beginResizingFrame(JComponent JavaDoc f, int direction) {
360         setupDragMode(f);
361     }
362
363     /**
364      * Calls <code>setBoundsForFrame</code> with the new values.
365      * @param f the component to be resized
366      * @param newX the new x-coordinate
367      * @param newY the new y-coordinate
368      * @param newWidth the new width
369      * @param newHeight the new height
370      */

371     public void resizeFrame(JComponent JavaDoc f, int newX, int newY, int newWidth, int newHeight) {
372
373         if ( dragMode == DEFAULT_DRAG_MODE || dragMode == FASTER_DRAG_MODE ) {
374         setBoundsForFrame(f, newX, newY, newWidth, newHeight);
375     } else {
376         JDesktopPane JavaDoc desktopPane = getDesktopPane(f);
377         if (desktopPane != null){
378           Graphics g = desktopPane.getGraphics();
379
380           g.setXORMode(Color.white);
381           if (currentBounds != null) {
382             g.drawRect( currentBounds.x, currentBounds.y, currentBounds.width-1, currentBounds.height-1);
383           }
384           g.drawRect( newX, newY, newWidth-1, newHeight-1);
385           currentBounds = new Rectangle (newX, newY, newWidth, newHeight);
386           g.setPaintMode();
387           g.dispose();
388         }
389     }
390
391     }
392
393     // implements javax.swing.DesktopManager
394
public void endResizingFrame(JComponent JavaDoc f) {
395         if ( dragMode == OUTLINE_DRAG_MODE && currentBounds != null) {
396         setBoundsForFrame(f, currentBounds.x, currentBounds.y, currentBounds.width, currentBounds.height );
397         currentBounds = null;
398     }
399     }
400
401
402     /** This moves the <code>JComponent</code> and repaints the damaged areas. */
403     public void setBoundsForFrame(JComponent JavaDoc f, int newX, int newY, int newWidth, int newHeight) {
404         boolean didResize = (f.getWidth() != newWidth || f.getHeight() != newHeight);
405         f.setBounds(newX, newY, newWidth, newHeight);
406         if(didResize) {
407             f.validate();
408         }
409     }
410
411     /** Convenience method to remove the desktopIcon of <b>f</b> is necessary. */
412     protected void removeIconFor(JInternalFrame JavaDoc f) {
413         JInternalFrame.JDesktopIcon JavaDoc di = f.getDesktopIcon();
414         Container c = di.getParent();
415         if(c != null) {
416             c.remove(di);
417             c.repaint(di.getX(), di.getY(), di.getWidth(), di.getHeight());
418         }
419     }
420
421     /** The iconifyFrame() code calls this to determine the proper bounds
422       * for the desktopIcon.
423       */

424
425     protected Rectangle getBoundsForIconOf(JInternalFrame JavaDoc f) {
426       //
427
// Get the icon for this internal frame and its preferred size
428
//
429

430       JInternalFrame.JDesktopIcon JavaDoc icon = f.getDesktopIcon();
431       Dimension prefSize = icon.getPreferredSize();
432       //
433
// Get the parent bounds and child components.
434
//
435

436       Container c = f.getParent();
437       if (c == null) {
438       c = f.getDesktopIcon().getParent();
439       }
440
441       if (c == null) {
442     /* the frame has not yet been added to the parent; how about (0,0) ?*/
443     return new Rectangle(0, 0, prefSize.width, prefSize.height);
444       }
445     
446       Rectangle parentBounds = c.getBounds();
447       Component [] components = c.getComponents();
448
449
450       //
451
// Iterate through valid default icon locations and return the
452
// first one that does not intersect any other icons.
453
//
454

455       Rectangle availableRectangle = null;
456       JInternalFrame.JDesktopIcon JavaDoc currentIcon = null;
457
458       int x = 0;
459       int y = parentBounds.height - prefSize.height;
460       int w = prefSize.width;
461       int h = prefSize.height;
462
463       boolean found = false;
464
465       while (!found) {
466
467     availableRectangle = new Rectangle(x,y,w,h);
468
469     found = true;
470
471     for ( int i=0; i<components.length; i++ ) {
472
473       //
474
// Get the icon for this component
475
//
476

477       if ( components[i] instanceof JInternalFrame JavaDoc ) {
478         currentIcon = ((JInternalFrame JavaDoc)components[i]).getDesktopIcon();
479       }
480       else if ( components[i] instanceof JInternalFrame.JDesktopIcon JavaDoc ){
481         currentIcon = (JInternalFrame.JDesktopIcon JavaDoc)components[i];
482       } else
483         /* found a child that's neither an internal frame nor
484            an icon. I don't believe this should happen, but at
485            present it does and causes a null pointer exception.
486            Even when that gets fixed, this code protects against
487            the npe. hania */

488         continue;
489       
490       //
491
// If this icon intersects the current location, get next location.
492
//
493

494       if ( !currentIcon.equals(icon) ) {
495         if ( availableRectangle.intersects(currentIcon.getBounds()) ) {
496           found = false;
497           break;
498         }
499       }
500     }
501
502     if (currentIcon == null)
503       /* didn't find any useful children above. This probably shouldn't
504        happen, but this check protects against an npe if it ever does
505        (and it's happening now) */

506       return availableRectangle;
507
508     x += currentIcon.getBounds().width;
509
510     if ( x + w > parentBounds.width ) {
511       x = 0;
512       y -= h;
513     }
514       }
515         
516       return(availableRectangle);
517     }
518
519     /**
520      * Stores the bounds of the component just before a maximize call.
521      * @param f the component about to be resized
522      * @param r the normal bounds to be saved away
523      */

524     protected void setPreviousBounds(JInternalFrame JavaDoc f, Rectangle r) {
525     f.setNormalBounds(r);
526     }
527
528     /**
529      * Gets the normal bounds of the component prior to the component
530      * being maximized.
531      * @param f the <code>JInternalFrame</code> of interest
532      * @return the normal bounds of the component
533      */

534     protected Rectangle getPreviousBounds(JInternalFrame JavaDoc f) {
535         return f.getNormalBounds();
536     }
537
538     /**
539      * Sets that the component has been iconized and the bounds of the
540      * <code>desktopIcon</code> are valid.
541      */

542     protected void setWasIcon(JInternalFrame JavaDoc f, Boolean JavaDoc value) {
543     if (value != null) {
544         f.putClientProperty(HAS_BEEN_ICONIFIED_PROPERTY, value);
545     }
546     }
547
548     /**
549      * Returns <code>true</code> if the component has been iconized
550      * and the bounds of the <code>desktopIcon</code> are valid,
551      * otherwise returns <code>false</code>.
552      *
553      * @param f the <code>JInternalFrame</code> of interest
554      * @return <code>true</code> if the component has been iconized;
555      * otherwise returns <code>false</code>
556      */

557     protected boolean wasIcon(JInternalFrame JavaDoc f) {
558         return (f.getClientProperty(HAS_BEEN_ICONIFIED_PROPERTY) == Boolean.TRUE);
559     }
560
561
562     JDesktopPane JavaDoc getDesktopPane( JComponent JavaDoc frame ) {
563         JDesktopPane JavaDoc pane = null;
564     Component c = frame.getParent();
565
566         // Find the JDesktopPane
567
while ( pane == null ) {
568         if ( c instanceof JDesktopPane JavaDoc ) {
569             pane = (JDesktopPane JavaDoc)c;
570         }
571         else if ( c == null ) {
572             break;
573         }
574         else {
575             c = c.getParent();
576         }
577     }
578
579     return pane;
580     }
581
582
583   // =========== stuff for faster frame dragging ===================
584

585    private void dragFrameFaster(JComponent JavaDoc f, int newX, int newY) {
586
587       Rectangle previousBounds = new Rectangle(currentBounds.x,
588                                                currentBounds.y,
589                                                currentBounds.width,
590                                                currentBounds.height);
591
592    // move the frame
593
currentBounds.x = newX;
594       currentBounds.y = newY;
595    
596       emergencyCleanup(f);
597       
598       boolean floaterCollision = isFloaterCollision(previousBounds, currentBounds);
599   
600     // System.out.println(previousBounds);
601
Rectangle visBounds = previousBounds.intersection(desktopBounds);
602     // System.out.println(previousBounds);
603

604
605      // System.out.println(visBounds);
606

607       if(!floaterCollision) {
608       // blit the frame to the new location
609
// if we're under a floater we can't blit
610
desktopGraphics.copyArea(visBounds.x,
611                                visBounds.y,
612                                visBounds.width,
613                                visBounds.height,
614                                newX - previousBounds.x,
615                                newY - previousBounds.y);
616       }
617  
618       JComponent JavaDoc parent = (JComponent JavaDoc)f.getParent();
619         
620       f.setBounds(currentBounds);
621
622       if(floaterCollision) {
623     // since we couldn't blit we just redraw as fast as possible
624
// the isDragging mucking is to avoid activating emergency cleanup
625
((JInternalFrame JavaDoc)f).isDragging = false;
626     parent.paintImmediately(currentBounds);
627         ((JInternalFrame JavaDoc)f).isDragging = true;
628       }
629
630       // fake out the repaint manager. We'll take care of everything
631
RepaintManager JavaDoc currentManager = RepaintManager.currentManager(f);
632
633       currentManager.markCompletelyClean(parent);
634       currentManager.markCompletelyClean(f);
635
636       // compute the minimal newly exposed area
637
// if the rects intersect then we use computeDifference. Otherwise
638
// we'll repaint the entire previous bounds
639
Rectangle[] dirtyRects = null;
640       if ( previousBounds.intersects(currentBounds) ) {
641       dirtyRects = SwingUtilities.computeDifference(previousBounds, currentBounds);
642       } else {
643           dirtyRects = new Rectangle[1];
644       dirtyRects[0] = previousBounds;
645       // System.out.println("no intersection");
646
};
647
648       // Fix the damage
649
for (int i = 0; i < dirtyRects.length; i++) {
650          parent.paintImmediately(dirtyRects[i]);
651       }
652
653       // new areas of blit were exposed
654
if ( !(visBounds.equals(previousBounds)) ) {
655          dirtyRects = SwingUtilities.computeDifference(previousBounds, desktopBounds);
656          for (int i = 0; i < dirtyRects.length; i++) {
657             dirtyRects[i].x += newX - previousBounds.x;
658             dirtyRects[i].y += newY - previousBounds.y;
659             ((JInternalFrame JavaDoc)f).isDragging = false;
660             
661             parent.paintImmediately(dirtyRects[i]);
662             ((JInternalFrame JavaDoc)f).isDragging = true;
663             
664            // System.out.println(dirtyRects[i]);
665
}
666    
667       }
668    }
669
670    private boolean isFloaterCollision(Rectangle moveFrom, Rectangle moveTo) {
671       if (floatingItems.length == 0) {
672         // System.out.println("no floaters");
673
return false;
674       }
675
676       for (int i = 0; i < floatingItems.length; i++) {
677          boolean intersectsFrom = moveFrom.intersects(floatingItems[i]);
678          if (intersectsFrom) {
679             return true;
680          }
681          boolean intersectsTo = moveTo.intersects(floatingItems[i]);
682          if (intersectsTo) {
683             return true;
684          }
685       }
686
687       return false;
688    }
689
690    private Rectangle[] findFloatingItems(JComponent JavaDoc f) {
691       Container desktop = f.getParent();
692       Component[] children = desktop.getComponents();
693       int i = 0;
694       for (i = 0; i < children.length; i++) {
695          if (children[i] == f) {
696             break;
697          }
698       }
699       // System.out.println(i);
700
Rectangle[] floaters = new Rectangle[i];
701       for (i = 0; i < floaters.length; i++) {
702          floaters[i] = children[i].getBounds();
703       }
704
705       return floaters;
706    }
707
708    /**
709      * This method is here to clean up problems associated
710      * with a race condition which can occur when the full contents
711      * of a copyArea's source argument is not available onscreen.
712      * This uses brute force to clean up in case of possible damage
713      */

714    private void emergencyCleanup(final JComponent JavaDoc f) {
715
716         if ( ((JInternalFrame JavaDoc)f).danger ) {
717            
718            SwingUtilities.invokeLater( new Runnable JavaDoc(){
719                                        public void run(){
720   
721                                        ((JInternalFrame JavaDoc)f).isDragging = false;
722                                        f.paintImmediately(0,0,
723                                                           f.getWidth(),
724                                                           f.getHeight());
725                                         
726                                         //finalFrame.repaint();
727
((JInternalFrame JavaDoc)f).isDragging = true;
728                                         // System.out.println("repair complete");
729
}});
730                                        
731              ((JInternalFrame JavaDoc)f).danger = false;
732         }
733     
734    }
735
736
737 }
738
739
Popular Tags