Merged gcj-eclipse branch to trunk.

From-SVN: r120621
This commit is contained in:
Tom Tromey
2007-01-09 19:58:05 +00:00
parent c648dedbde
commit 97b8365caf
17478 changed files with 606493 additions and 100744 deletions
+118 -25
View File
@@ -38,13 +38,14 @@ exception statement from your version. */
package java.awt.dnd;
import gnu.classpath.NotImplementedException;
import java.awt.Component;
import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.datatransfer.FlavorMap;
import java.awt.datatransfer.SystemFlavorMap;
import java.awt.dnd.peer.DropTargetPeer;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@@ -54,6 +55,8 @@ import java.io.Serializable;
import java.util.EventListener;
import java.util.TooManyListenersException;
import javax.swing.Timer;
/**
* @author Michael Koch
* @since 1.2
@@ -69,30 +72,87 @@ public class DropTarget
protected static class DropTargetAutoScroller
implements ActionListener
{
/**
* The threshold that keeps the autoscroller running.
*/
private static final int HYSTERESIS = 10;
/**
* The initial timer delay.
*/
private static final int DELAY = 100;
private Component component;
private Point point;
/**
* The timer that triggers autoscrolling.
*/
private Timer timer;
/**
* The outer region of the scroller. This is the component's size.
*/
private Rectangle outer;
/**
* The inner region of the scroller. This is the component size without
* the autoscroll insets.
*/
private Rectangle inner;
protected DropTargetAutoScroller (Component c, Point p)
{
component = c;
point = p;
timer = new Timer(DELAY, this);
timer.setCoalesce(true);
timer.start();
}
protected void updateLocation (Point newLocn)
{
Point previous = point;
point = newLocn;
if (Math.abs(point.x - previous.x) > HYSTERESIS
|| Math.abs(point.y - previous.y) > HYSTERESIS)
{
if (timer.isRunning())
timer.stop();
}
else
{
if (! timer.isRunning())
timer.start();
}
}
protected void stop ()
throws NotImplementedException
{
// FIXME: implement this
timer.start();
}
public void actionPerformed (ActionEvent e)
throws NotImplementedException
{
// FIXME: implement this
Autoscroll autoScroll = (Autoscroll) component;
// First synchronize the inner and outer rectangles.
Insets i = autoScroll.getAutoscrollInsets();
int width = component.getWidth();
int height = component.getHeight();
if (width != outer.width || height != outer.height)
outer.setBounds(0, 0, width, height);
if (inner.x != i.left || inner.y != i.top)
inner.setLocation(i.left, i.top);
int inWidth = width - i.left - i.right;
int inHeight = height - i.top - i.bottom;
if (inWidth != inner.width || inHeight != inner.height)
inner.setSize(inWidth, inHeight);
// Scroll if the outer rectangle contains the location, but the
// inner doesn't.
if (outer.contains(point) && ! inner.contains(point))
autoScroll.autoscroll(point);
}
}
@@ -113,7 +173,7 @@ public class DropTarget
*/
public DropTarget ()
{
this (null, 0, null, true, null);
this (null, DnDConstants.ACTION_COPY_OR_MOVE, null, true, null);
}
/**
@@ -124,7 +184,7 @@ public class DropTarget
*/
public DropTarget (Component c, DropTargetListener dtl)
{
this (c, 0, dtl, true, null);
this (c, DnDConstants.ACTION_COPY_OR_MOVE, dtl, true, null);
}
/**
@@ -164,7 +224,11 @@ public class DropTarget
setComponent(c);
setDefaultActions(i);
dropTargetListener = dtl;
flavorMap = fm;
if (fm == null)
flavorMap = SystemFlavorMap.getDefaultFlavorMap();
else
flavorMap = fm;
setActive (b);
@@ -177,6 +241,8 @@ public class DropTarget
*/
public void setComponent (Component c)
{
if (component != null)
clearAutoscroll();
component = c;
}
@@ -207,6 +273,8 @@ public class DropTarget
public void setActive (boolean active)
{
this.active = active;
if (! active)
clearAutoscroll();
}
public boolean isActive()
@@ -225,8 +293,14 @@ public class DropTarget
public void addDropTargetListener (DropTargetListener dtl)
throws TooManyListenersException
{
if (dtl == null)
return;
if (dtl.equals(this))
throw new IllegalArgumentException();
if (dropTargetListener != null)
throw new TooManyListenersException ();
throw new TooManyListenersException();
dropTargetListener = dtl;
}
@@ -239,30 +313,47 @@ public class DropTarget
public void dragEnter(DropTargetDragEvent dtde)
{
if (dropTargetListener != null)
dropTargetListener.dragEnter(dtde);
if (active)
{
if (dropTargetListener != null)
dropTargetListener.dragEnter(dtde);
initializeAutoscrolling(dtde.getLocation());
}
}
public void dragOver(DropTargetDragEvent dtde)
{
if (dropTargetListener != null)
dropTargetListener.dragOver(dtde);
if (active)
{
if (dropTargetListener != null)
dropTargetListener.dragOver(dtde);
updateAutoscroll(dtde.getLocation());
}
}
public void dropActionChanged(DropTargetDragEvent dtde)
{
if (dropTargetListener != null)
dropTargetListener.dropActionChanged(dtde);
if (active)
{
if (dropTargetListener != null)
dropTargetListener.dropActionChanged(dtde);
updateAutoscroll(dtde.getLocation());
}
}
public void dragExit(DropTargetEvent dte)
{
if (dropTargetListener != null)
dropTargetListener.dragExit(dte);
if (active)
{
if (dropTargetListener != null)
dropTargetListener.dragExit(dte);
clearAutoscroll();
}
}
public void drop(DropTargetDropEvent dtde)
{
clearAutoscroll();
if (dropTargetListener != null)
dropTargetListener.drop(dtde);
}
@@ -321,15 +412,13 @@ public class DropTarget
protected DropTarget.DropTargetAutoScroller createDropTargetAutoScroller
(Component c, Point p)
{
if (autoscroller == null)
autoscroller = new DropTarget.DropTargetAutoScroller (c, p);
return autoscroller;
return new DropTarget.DropTargetAutoScroller (c, p);
}
protected void initializeAutoscrolling(Point p)
{
createDropTargetAutoScroller (component, p);
if (component instanceof Autoscroll) // Checks for null too.
autoscroller = createDropTargetAutoScroller (component, p);
}
protected void updateAutoscroll(Point dragCursorLocn)
@@ -340,6 +429,10 @@ public class DropTarget
protected void clearAutoscroll()
{
autoscroller = null;
if (autoscroller != null)
{
autoscroller.stop();
autoscroller = null;
}
}
} // class DropTarget