/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/** This is an implementation of the <code>DesktopManager</code>.
* It currently implements the basic behaviors for managing
* <code>JInternalFrame</code>s in an arbitrary parent.
* <code>JInternalFrame</code>s that are not children of a
* <code>JDesktop</code> will use this component
* to handle their desktop-like actions.
* <p>This class provides a policy for the various JInternalFrame methods,
* it is not meant to be called directly rather the various JInternalFrame
* methods will call into the DesktopManager.</p>
* @see JDesktopPane
* @see JInternalFrame
* @author David Kloba
* @author Steve Wilson
*/
/**
* Set to true when the user actually drags a frame vs clicks on it
* to start the drag operation. This is only used when dragging with
* FASTER_DRAG_MODE.
*/
private transient boolean didDrag;
/** Normally this method will not be called. If it is, it
* try to determine the appropriate parent from the desktopIcon of the frame.
* Will remove the desktopIcon from its parent if it successfully adds the frame.
*/
removeIconFor(f);
}
}
/**
* Removes the frame, and, if necessary, the
* <code>desktopIcon</code>, from its parent.
* @param f the <code>JInternalFrame</code> to be removed
*/
JDesktopPane d = f.getDesktopPane();
if (d == null) {
return;
}
boolean findNext = f.isSelected();
if (findNext) {
nextFrame = d.getNextFrame(f);
}
if(c != null) {
c.remove(f); // Removes the focus.
}
removeIconFor(f);
if(f.getNormalBounds() != null)
f.setNormalBounds(null);
if(wasIcon(f))
setWasIcon(f, null);
try { nextFrame.setSelected(true); }
catch (PropertyVetoException e2) { }
// It was selected and was the last component on the desktop.
d.requestFocus();
}
}
/**
* Resizes the frame to fill its parents bounds.
* @param f the frame to be resized
*/
if (f.isIcon()) {
try {
// In turn calls deiconifyFrame in the desktop manager.
// That method will handle the maximization of the frame.
f.setIcon(false);
} catch (PropertyVetoException e2) {
}
} else {
f.setNormalBounds(f.getBounds());
}
// Set the maximized frame as selected.
try {
f.setSelected(true);
} catch (PropertyVetoException e2) {
}
}
/**
* Restores the frame back to its size and position prior
* to a <code>maximizeFrame</code> call.
* @param f the <code>JInternalFrame</code> to be restored
*/
// If the frame was an icon restore it back to an icon.
if (f.isIcon()) {
iconifyFrame(f);
return;
}
if ((f.getNormalBounds()) != null) {
Rectangle r = f.getNormalBounds();
f.setNormalBounds(null);
}
}
/**
* Removes the frame from its parent and adds its
* <code>desktopIcon</code> to the parent.
* @param f the <code>JInternalFrame</code> to be iconified
*/
JDesktopPane d = f.getDesktopPane();
boolean findNext = f.isSelected();
desktopIcon = f.getDesktopIcon();
if(!wasIcon(f)) {
Rectangle r = getBoundsForIconOf(f);
}
return;
}
if (c instanceof JLayeredPane) {
}
// If we are maximized we already have the normal bounds recorded
// don't try to re-record them, otherwise we incorrectly set the
// normal bounds to maximized state.
if (!f.isMaximum()) {
f.setNormalBounds(f.getBounds());
}
d.setComponentOrderCheckingEnabled(false);
c.remove(f);
c.add(desktopIcon);
d.setComponentOrderCheckingEnabled(true);
if (findNext) {
if (d.selectFrame(true) == null) {
// The icon is the last frame.
}
}
}
/**
* Removes the desktopIcon from its parent and adds its frame
* to the parent.
* @param f the <code>JInternalFrame</code> to be de-iconified
*/
JDesktopPane d = f.getDesktopPane();
c.add(f);
// If the frame is to be restored to a maximized state make
// sure it still fills the whole desktop.
if (f.isMaximum()) {
}
}
removeIconFor(f);
if (f.isSelected()) {
f.moveToFront();
}
else {
try {
f.setSelected(true);
} catch (PropertyVetoException e2) {}
}
}
}
/** This will activate <b>f</b> moving it to the front. It will
* set the current active frame's (if any)
* <code>IS_SELECTED_PROPERTY</code> to <code>false</code>.
* There can be only one active frame across all Layers.
* @param f the <code>JInternalFrame</code> to be activated
*/
Component[] c;
JDesktopPane d = f.getDesktopPane();
// fix for bug: 4162443
if(p == null) {
// If the frame is not in parent, its icon maybe, check it
p = f.getDesktopIcon().getParent();
if(p == null)
return;
}
// we only need to keep track of the currentActive InternalFrame, if any
if (currentlyActiveFrame == null){
if (d != null) { d.setSelectedFrame(f);}
} else if (currentlyActiveFrame != f) {
// if not the same frame as the current active
// we deactivate the current
if (currentlyActiveFrame.isSelected()) {
try {
currentlyActiveFrame.setSelected(false);
}
catch(PropertyVetoException e2) {}
}
if (d != null) { d.setSelectedFrame(f);}
}
f.moveToFront();
}
// implements javax.swing.DesktopManager
JDesktopPane d = f.getDesktopPane();
if (currentlyActiveFrame == f)
d.setSelectedFrame(null);
}
// implements javax.swing.DesktopManager
setupDragMode(f);
if (dragMode == FASTER_DRAG_MODE) {
currentBounds = f.getBounds();
if (desktop instanceof JComponent) {
}
else {
}
((JInternalFrame)f).isDragging = true;
didDrag = false;
}
}
JDesktopPane p = getDesktopPane(f);
if (p != null) {
&& f instanceof JInternalFrame
&& ((JInternalFrame)f).isOpaque() &&
} else {
&& f instanceof JInternalFrame
&& ((JInternalFrame)f).isOpaque()) {
} else {
}
}
}
}
/**
* Moves the visible location of the frame being dragged
* to the location specified. The means by which this occurs can vary depending
* on the dragging algorithm being used. The actual logical location of the frame
* might not change until <code>endDraggingFrame</code> is called.
*/
if (dragMode == OUTLINE_DRAG_MODE) {
if (desktopPane != null){
if (currentLoc != null) {
}
/* Work around for 6635462: XOR mode may cause a SurfaceLost on first use.
* Swing doesn't expect that its XOR drawRect did
* not complete, so believes that on re-entering at
* the next update location, that there is an XOR rect
* to draw out at "currentLoc". But in fact
* its now got a new clean surface without that rect,
* so drawing it "out" in fact draws it on, leaving garbage.
*/
if (!sData.isSurfaceLost()) {
}
;
g.dispose();
}
} else if (dragMode == FASTER_DRAG_MODE) {
} else {
}
}
// implements javax.swing.DesktopManager
currentLoc = null;
} else if (dragMode == FASTER_DRAG_MODE) {
if (desktopGraphics != null) {
}
((JInternalFrame)f).isDragging = false;
}
}
// implements javax.swing.DesktopManager
setupDragMode(f);
}
/**
* Calls <code>setBoundsForFrame</code> with the new values.
* @param f the component to be resized
* @param newX the new x-coordinate
* @param newY the new y-coordinate
* @param newWidth the new width
* @param newHeight the new height
*/
} else {
if (desktopPane != null){
if (currentBounds != null) {
}
// Work around for 6635462, see comment in dragFrame()
if (!sData.isSurfaceLost()) {
}
g.setPaintMode();
g.dispose();
}
}
}
// implements javax.swing.DesktopManager
}
}
/** This moves the <code>JComponent</code> and repaints the damaged areas. */
f.revalidate();
}
/** Convenience method to remove the desktopIcon of <b>f</b> is necessary. */
if(c != null) {
}
}
/** The iconifyFrame() code calls this to determine the proper bounds
* for the desktopIcon.
*/
//
// Get the icon for this internal frame and its preferred size
//
//
// Get the parent bounds and child components.
//
if (c == null) {
c = f.getDesktopIcon().getParent();
}
if (c == null) {
/* the frame has not yet been added to the parent; how about (0,0) ?*/
}
//
// Iterate through valid default icon locations and return the
// first one that does not intersect any other icons.
//
int x = 0;
boolean found = false;
while (!found) {
availableRectangle = new Rectangle(x,y,w,h);
found = true;
//
// Get the icon for this component
//
if ( components[i] instanceof JInternalFrame ) {
}
} else
/* found a child that's neither an internal frame nor
an icon. I don't believe this should happen, but at
present it does and causes a null pointer exception.
Even when that gets fixed, this code protects against
the npe. hania */
continue;
//
// If this icon intersects the current location, get next location.
//
found = false;
break;
}
}
}
if (currentIcon == null)
/* didn't find any useful children above. This probably shouldn't
happen, but this check protects against an npe if it ever does
(and it's happening now) */
return availableRectangle;
if ( x + w > parentBounds.width ) {
x = 0;
y -= h;
}
}
return(availableRectangle);
}
/**
* Stores the bounds of the component just before a maximize call.
* @param f the component about to be resized
* @param r the normal bounds to be saved away
*/
f.setNormalBounds(r);
}
/**
* Gets the normal bounds of the component prior to the component
* being maximized.
* @param f the <code>JInternalFrame</code> of interest
* @return the normal bounds of the component
*/
return f.getNormalBounds();
}
/**
* Sets that the component has been iconized and the bounds of the
* <code>desktopIcon</code> are valid.
*/
}
}
/**
* Returns <code>true</code> if the component has been iconized
* and the bounds of the <code>desktopIcon</code> are valid,
* otherwise returns <code>false</code>.
*
* @param f the <code>JInternalFrame</code> of interest
* @return <code>true</code> if the component has been iconized;
* otherwise returns <code>false</code>
*/
}
// Find the JDesktopPane
if ( c instanceof JDesktopPane ) {
pane = (JDesktopPane)c;
}
else if ( c == null ) {
break;
}
else {
c = c.getParent();
}
}
return pane;
}
// =========== stuff for faster frame dragging ===================
// move the frame
currentBounds.x = newX;
currentBounds.y = newY;
if (didDrag) {
// Only initiate cleanup if we have actually done a drag.
emergencyCleanup(f);
}
else {
didDrag = true;
// We reset the danger field as until now we haven't actually
// moved the internal frame so we don't need to initiate repaint.
((JInternalFrame)f).danger = false;
}
try {
if(!floaterCollision) {
visBounds.y,
newX - previousBounds.x,
newY - previousBounds.y,
true);
}
if(floaterCollision) {
// since we couldn't blit we just redraw as fast as possible
// the isDragging mucking is to avoid activating emergency
// cleanup
((JInternalFrame)f).isDragging = false;
((JInternalFrame)f).isDragging = true;
}
// fake out the repaint manager. We'll take care of everything
// compute the minimal newly exposed area
// if the rects intersect then we use computeDifference. Otherwise
// we'll repaint the entire previous bounds
} else {
};
// Fix the damage
}
// new areas of blit were exposed
((JInternalFrame)f).isDragging = false;
((JInternalFrame)f).isDragging = true;
}
}
} finally {
}
// update window if it's non-opaque
(tk instanceof SunToolkit) &&
{
}
}
// System.out.println("no floaters");
return false;
}
if (intersectsFrom) {
return true;
}
if (intersectsTo) {
return true;
}
}
return false;
}
int i = 0;
if (children[i] == f) {
break;
}
}
// System.out.println(i);
}
return floaters;
}
/**
* This method is here to clean up problems associated
* with a race condition which can occur when the full contents
* of a copyArea's source argument is not available onscreen.
* This uses brute force to clean up in case of possible damage
*/
if ( ((JInternalFrame)f).danger ) {
public void run(){
((JInternalFrame)f).isDragging = false;
f.getWidth(),
f.getHeight());
//finalFrame.repaint();
((JInternalFrame)f).isDragging = true;
// System.out.println("repair complete");
}});
((JInternalFrame)f).danger = false;
}
}
}