diff options
author | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-01-09 19:58:05 +0000 |
---|---|---|
committer | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-01-09 19:58:05 +0000 |
commit | 65bf3316cf384588453604be6b4f0ed3751a8b0f (patch) | |
tree | 996a5f57d4a68c53473382e45cb22f574cb3e4db /libjava/classpath/java/awt/dnd | |
parent | 8fc56618a84446beccd45b80381cdfe0e94050df (diff) | |
download | gcc-65bf3316cf384588453604be6b4f0ed3751a8b0f.tar.gz |
Merged gcj-eclipse branch to trunk.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@120621 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/java/awt/dnd')
9 files changed, 203 insertions, 88 deletions
diff --git a/libjava/classpath/java/awt/dnd/DragGestureEvent.java b/libjava/classpath/java/awt/dnd/DragGestureEvent.java index 351ae540072..2a22abb12aa 100644 --- a/libjava/classpath/java/awt/dnd/DragGestureEvent.java +++ b/libjava/classpath/java/awt/dnd/DragGestureEvent.java @@ -59,7 +59,7 @@ public class DragGestureEvent extends EventObject private Component component; private final Point origin; private final int action; - private List events; + private List<InputEvent> events; private DragGestureRecognizer dgr; /** @@ -71,15 +71,15 @@ public class DragGestureEvent extends EventObject * @throws IllegalArgumentException - if input parameters are null */ public DragGestureEvent(DragGestureRecognizer dgr, int action, Point origin, - List events) - { + List<? extends InputEvent> events) + { super(dgr); if (origin == null || events == null || dgr == null) throw new IllegalArgumentException(); - + this.origin = origin; this.action = action; - this.events = events; + this.events = (List<InputEvent>) events; this.dgr = dgr; this.component = dgr.getComponent(); this.dragSource = dgr.getDragSource(); @@ -130,7 +130,7 @@ public class DragGestureEvent extends EventObject * * @return an iterator representation of the List of events. */ - public Iterator iterator() + public Iterator<InputEvent> iterator() { return events.iterator(); } @@ -155,7 +155,7 @@ public class DragGestureEvent extends EventObject { return events.toArray(array); } - + /** * Gets the user's preferred action. * diff --git a/libjava/classpath/java/awt/dnd/DragGestureRecognizer.java b/libjava/classpath/java/awt/dnd/DragGestureRecognizer.java index 32bbc56da5d..3973e528481 100644 --- a/libjava/classpath/java/awt/dnd/DragGestureRecognizer.java +++ b/libjava/classpath/java/awt/dnd/DragGestureRecognizer.java @@ -1,5 +1,5 @@ /* DragGestureRecognizer.java -- - Copyright (C) 2002,2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,8 +38,6 @@ exception statement from your version. */ package java.awt.dnd; -import gnu.classpath.NotImplementedException; - import java.awt.Component; import java.awt.Point; import java.awt.event.InputEvent; @@ -52,6 +50,8 @@ import java.util.TooManyListenersException; /** * STUBBED + * @author Michael Koch (konqueror@gmx.de) + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) * @since 1.2 */ public abstract class DragGestureRecognizer implements Serializable @@ -65,7 +65,7 @@ public abstract class DragGestureRecognizer implements Serializable protected Component component; protected transient DragGestureListener dragGestureListener; protected int sourceActions; - protected ArrayList events = new ArrayList(); + protected ArrayList<InputEvent> events = new ArrayList<InputEvent>(); protected DragGestureRecognizer(DragSource ds, Component c, int sa, DragGestureListener dgl) @@ -127,11 +127,12 @@ public abstract class DragGestureRecognizer implements Serializable return events.size() > 0 ? (InputEvent) events.get(0) : null; } + /** + * Resets the recognizer. If a gesture is currently recognize, discard it. + */ public void resetRecognizer() - throws NotImplementedException { - events = new ArrayList(); - // FIXME: Not implemented fully. + events.clear(); } /** @@ -164,6 +165,7 @@ public abstract class DragGestureRecognizer implements Serializable if(dragGestureListener != null) dragGestureListener.dragGestureRecognized (new DragGestureEvent(this, dragAction, p, events)); + resetRecognizer(); } protected void appendEvent(InputEvent e) diff --git a/libjava/classpath/java/awt/dnd/DragSource.java b/libjava/classpath/java/awt/dnd/DragSource.java index 48fa2388ee2..cd4a93a3e3f 100644 --- a/libjava/classpath/java/awt/dnd/DragSource.java +++ b/libjava/classpath/java/awt/dnd/DragSource.java @@ -105,16 +105,15 @@ public class DragSource implements Serializable ds = null; throw new HeadlessException(); } - + if (ds == null) ds = new DragSource(); return ds; } public static boolean isDragImageSupported() - throws NotImplementedException { - // FIXME: Implement this + // In all cases, Sun returns false here. return false; } @@ -140,8 +139,6 @@ public class DragSource implements Serializable // This function sends the same message to the context, which then forwards // it to the peer, passing itself as a parameter. Now, the native system has // access to the Transferable through the context. - - // FIXME: Add check to determine if dragging. try { @@ -228,15 +225,16 @@ public class DragSource implements Serializable { return flavorMap; } - - public DragGestureRecognizer createDragGestureRecognizer(Class recognizer, - Component c, - int actions, - DragGestureListener dgl) + + public <T extends DragGestureRecognizer> T + createDragGestureRecognizer(Class<T> recognizer, + Component c, + int actions, + DragGestureListener dgl) { - return Toolkit.getDefaultToolkit().createDragGestureRecognizer(recognizer, - this, c, - actions, dgl); + return (T) Toolkit.getDefaultToolkit().createDragGestureRecognizer(recognizer, + this, c, + actions, dgl); } public DragGestureRecognizer createDefaultDragGestureRecognizer(Component c, @@ -299,23 +297,23 @@ public class DragSource implements Serializable /** * @since 1.4 */ - public EventListener[] getListeners (Class listenerType) + public <T extends EventListener> T[] getListeners (Class<T> listenerType) { if (listenerType == DragSourceListener.class) return DnDEventMulticaster.getListeners (dragSourceListener, - listenerType); + listenerType); if (listenerType == DragSourceMotionListener.class) return DnDEventMulticaster.getListeners (dragSourceMotionListener, - listenerType); + listenerType); // Return an empty EventListener array. - return new EventListener [0]; + return (T[]) new EventListener [0]; } /** * TODO - * @return + * @return TODO * * @since 1.5 */ @@ -323,6 +321,6 @@ public class DragSource implements Serializable throws NotImplementedException { // FIXME: Not implemented. - return 4; + return 8; } } // class DragSource diff --git a/libjava/classpath/java/awt/dnd/DragSourceContext.java b/libjava/classpath/java/awt/dnd/DragSourceContext.java index 1fee5c0c304..ed1cbaa4454 100644 --- a/libjava/classpath/java/awt/dnd/DragSourceContext.java +++ b/libjava/classpath/java/awt/dnd/DragSourceContext.java @@ -38,8 +38,6 @@ exception statement from your version. */ package java.awt.dnd; -import gnu.classpath.NotImplementedException; - import java.awt.Component; import java.awt.Cursor; import java.awt.Image; @@ -268,7 +266,8 @@ public class DragSourceContext for (int i = 0; i < dsl.length; i++) dsl[i].dragExit(e); - updateCurrentCursor(0, 0, DEFAULT); + updateCurrentCursor(DnDConstants.ACTION_NONE, DnDConstants.ACTION_NONE, + DEFAULT); } /** @@ -340,26 +339,45 @@ public class DragSourceContext * @param status - the status of the cursor (constant). */ protected void updateCurrentCursor(int dropOp, int targetAct, int status) - throws NotImplementedException { - // FIXME: Not implemented fully - if (!useCustomCursor) + if (! useCustomCursor) { - Cursor cursor = null; + Cursor newCursor = null; switch (status) { + default: + targetAct = DnDConstants.ACTION_NONE; case ENTER: - break; case CHANGED: - break; case OVER: - break; - default: - break; + int action = dropOp & targetAct; + if (action == DnDConstants.ACTION_NONE) + { + if ((dropOp & DnDConstants.ACTION_LINK) != 0) + newCursor = DragSource.DefaultLinkNoDrop; + else if ((dropOp & DnDConstants.ACTION_MOVE) != 0) + newCursor = DragSource.DefaultMoveNoDrop; + else + newCursor = DragSource.DefaultCopyNoDrop; + } + else + { + if ((dropOp & DnDConstants.ACTION_LINK) != 0) + newCursor = DragSource.DefaultLinkDrop; + else if ((dropOp & DnDConstants.ACTION_MOVE) != 0) + newCursor = DragSource.DefaultMoveDrop; + else + newCursor = DragSource.DefaultCopyDrop; + } } - this.cursor = cursor; - peer.setCursor(cursor); + if (cursor == null || ! cursor.equals(newCursor)) + { + cursor = newCursor; + DragSourceContextPeer p = peer; + if (p != null) + p.setCursor(cursor); + } } } } // class DragSourceContext diff --git a/libjava/classpath/java/awt/dnd/DropTarget.java b/libjava/classpath/java/awt/dnd/DropTarget.java index a3650567f09..63be5ac046d 100644 --- a/libjava/classpath/java/awt/dnd/DropTarget.java +++ b/libjava/classpath/java/awt/dnd/DropTarget.java @@ -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 diff --git a/libjava/classpath/java/awt/dnd/DropTargetContext.java b/libjava/classpath/java/awt/dnd/DropTargetContext.java index 31945c34bb1..d970e2e0881 100644 --- a/libjava/classpath/java/awt/dnd/DropTargetContext.java +++ b/libjava/classpath/java/awt/dnd/DropTargetContext.java @@ -1,5 +1,5 @@ /* DropTargetContext.java -- - Copyright (C) 2002, 2003, 2004, 2006, Free Software Foundation + Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation This file is part of GNU Classpath. @@ -49,6 +49,7 @@ import java.util.List; /** * @author Michael Koch (konqueror@gmx.de) + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) * @since 1.2 */ public class DropTargetContext implements Serializable @@ -128,51 +129,51 @@ public class DropTargetContext implements Serializable * * @exception InvalidDnDOperationException If a drop is not outstanding. */ - public void dropComplete(boolean success) + public void dropComplete (boolean success) { if (dtcp != null) dtcp.dropComplete(success); } - protected void acceptDrag(int dragOperation) + protected void acceptDrag (int dragOperation) { if (dtcp != null) dtcp.acceptDrag(dragOperation); } - protected void rejectDrag() + protected void rejectDrag () { if (dtcp != null) dtcp.rejectDrag(); } - protected void acceptDrop(int dropOperation) + protected void acceptDrop (int dropOperation) { if (dtcp != null) dtcp.acceptDrop(dropOperation); } - protected void rejectDrop() + protected void rejectDrop () { if (dtcp != null) dtcp.rejectDrop(); } - protected DataFlavor[] getCurrentDataFlavors() + protected DataFlavor[] getCurrentDataFlavors () { if (dtcp != null) dtcp.getTransferDataFlavors(); return null; } - protected List getCurrentDataFlavorsAsList() + protected List<DataFlavor> getCurrentDataFlavorsAsList () { - return Arrays.asList(getCurrentDataFlavors()); + return Arrays.asList(getCurrentDataFlavors ()); } - protected boolean isDataFlavorSupported(DataFlavor flavor) + protected boolean isDataFlavorSupported (DataFlavor flavor) { - return getCurrentDataFlavorsAsList().contains(flavor); + return getCurrentDataFlavorsAsList().contains (flavor); } /** diff --git a/libjava/classpath/java/awt/dnd/DropTargetDragEvent.java b/libjava/classpath/java/awt/dnd/DropTargetDragEvent.java index 89bf1778a71..58feb438767 100644 --- a/libjava/classpath/java/awt/dnd/DropTargetDragEvent.java +++ b/libjava/classpath/java/awt/dnd/DropTargetDragEvent.java @@ -108,7 +108,7 @@ public class DropTargetDragEvent extends DropTargetEvent return context.getCurrentDataFlavors (); } - public List getCurrentDataFlavorsAsList () + public List<DataFlavor> getCurrentDataFlavorsAsList () { return context.getCurrentDataFlavorsAsList (); } @@ -147,7 +147,6 @@ public class DropTargetDragEvent extends DropTargetEvent */ public Transferable getTransferable() { - // FIXME: Not implemented - return null; + return context.getTransferable(); } } // class DropTargetDragEvent diff --git a/libjava/classpath/java/awt/dnd/DropTargetDropEvent.java b/libjava/classpath/java/awt/dnd/DropTargetDropEvent.java index 9754bb11ef5..dd85ef712c5 100644 --- a/libjava/classpath/java/awt/dnd/DropTargetDropEvent.java +++ b/libjava/classpath/java/awt/dnd/DropTargetDropEvent.java @@ -1,5 +1,5 @@ /* DropTargetDropEvent.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -123,7 +123,7 @@ public class DropTargetDropEvent extends DropTargetEvent return context.getCurrentDataFlavors(); } - public List getCurrentDataFlavorsAsList() + public List<DataFlavor> getCurrentDataFlavorsAsList() { return context.getCurrentDataFlavorsAsList(); } diff --git a/libjava/classpath/java/awt/dnd/DropTargetEvent.java b/libjava/classpath/java/awt/dnd/DropTargetEvent.java index f75f756d037..cb2aec6402e 100644 --- a/libjava/classpath/java/awt/dnd/DropTargetEvent.java +++ b/libjava/classpath/java/awt/dnd/DropTargetEvent.java @@ -41,6 +41,10 @@ import java.util.EventObject; public class DropTargetEvent extends EventObject { + + /** + * Serialization identifier for Sun 1.5 compatability + */ private static final long serialVersionUID = 2821229066521922993L; protected DropTargetContext context; |