001: /*
002: * Copyright (C) 2004 NNL Technology AB
003: * Visit www.infonode.net for information about InfoNode(R)
004: * products and how to contact NNL Technology AB.
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
019: * MA 02111-1307, USA.
020: */
021:
022: // $Id: DockingWindowDragSource.java,v 1.7 2005/06/10 14:13:41 johan Exp $
023: package net.infonode.docking.drag;
024:
025: import net.infonode.gui.draggable.DraggableComponent;
026: import net.infonode.gui.draggable.DraggableComponentAdapter;
027: import net.infonode.gui.draggable.DraggableComponentEvent;
028:
029: import javax.swing.*;
030: import java.awt.*;
031:
032: /**
033: * Handles the drag and drop of a {@link net.infonode.docking.DockingWindow} triggered by mouse events on a
034: * {@link JComponent}. {@link DockingWindowDragSource} handles drag abort with the right mouse button and
035: * the key set in the {@link net.infonode.docking.properties.RootWindowProperties#ABORT_DRAG_KEY} property of the
036: * {@link net.infonode.docking.RootWindow} which is the drop target.
037: *
038: * @author $Author: johan $
039: * @version $Revision: 1.7 $
040: * @since IDW 1.3.0
041: */
042: public class DockingWindowDragSource {
043: private DraggableComponent draggableComponent;
044: private DockingWindowDragger dragger;
045: private Point startPoint;
046:
047: /**
048: * Constructor.
049: *
050: * @param component the component on which to listen to mouse events that affects the drag and drop of a
051: * {@link net.infonode.docking.DockingWindow}
052: * @param draggerProvider provides the {@link DockingWindowDragger} when the drag operation begins, typically
053: * this provider gets the dragger by calling
054: * {@link net.infonode.docking.DockingWindow#startDrag(net.infonode.docking.RootWindow)}
055: * on the window which should be dragged
056: */
057: public DockingWindowDragSource(JComponent component,
058: final DockingWindowDraggerProvider draggerProvider) {
059: draggableComponent = new DraggableComponent(component);
060: draggableComponent.setReorderEnabled(false);
061: draggableComponent.setEnableInsideDrag(true);
062:
063: draggableComponent.addListener(new DraggableComponentAdapter() {
064: public void dragAborted(DraggableComponentEvent event) {
065: abortDrag();
066: }
067:
068: public void dragged(DraggableComponentEvent event) {
069: if (dragger == null) {
070: startPoint = event.getMouseEvent().getPoint();
071: dragger = draggerProvider.getDragger(event
072: .getMouseEvent());
073:
074: if (dragger == null) {
075: draggableComponent.abortDrag();
076: return;
077: }
078:
079: draggableComponent.setAbortDragKeyCode(dragger
080: .getDropTarget().getRootWindowProperties()
081: .getAbortDragKey());
082: }
083:
084: /*if (startPoint != null &&
085: Math.abs(startPoint.x - event.getMouseEvent().getX()) +
086: Math.abs(startPoint.y - event.getMouseEvent().getY()) < 16)
087: return;*/
088:
089: startPoint = null;
090: dragger.dragWindow(event.getMouseEvent());
091: }
092:
093: public void dropped(DraggableComponentEvent event) {
094: if (dragger != null) {
095: dragger.dropWindow(event.getMouseEvent());
096: dragger = null;
097: startPoint = null;
098: }
099: }
100: });
101: }
102:
103: /**
104: * Aborts the currect drag operation.
105: */
106: public void abortDrag() {
107: if (dragger != null)
108: dragger.abortDrag();
109:
110: dragger = null;
111: startPoint = null;
112: }
113:
114: }
|