01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: AutoScrollElementDrag.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.gui.old;
09:
10: import java.awt.*;
11: import java.awt.event.MouseEvent;
12: import javax.swing.*;
13:
14: class AutoScrollElementDrag extends AutoScroll {
15: private Point mElementDragReference = null;
16: private Point mElementDragOffset = null;
17: private Point mElementDragDestination = null;
18:
19: AutoScrollElementDrag(StructurePanel structurePanel,
20: Point dragElementStartPoint, Point firstDestination,
21: JComponent element) {
22: super (structurePanel);
23: mElementDragReference = new Point(dragElementStartPoint);
24: mElementDragOffset = new Point(0, 0);
25: initializeAutoScroll(firstDestination, element);
26: }
27:
28: Point convertDestinationPoint(Point destination) {
29: destination.x += getMouseEventGeneratingComponent().getX();
30: destination.y += getMouseEventGeneratingComponent().getY();
31:
32: return destination;
33: }
34:
35: void prepareVisualAssistanceCustom() {
36: }
37:
38: void calculateVisualAssistanceCustom(Point destination,
39: int horizontalId, int verticalId) {
40: mElementDragDestination = new Point(destination);
41: }
42:
43: void eraseVisualAssistanceCustom(Graphics2D g2d) {
44: }
45:
46: void updateVisualAssistanceAfterScroll(int horizontalOffset,
47: int verticalOffset) {
48: mElementDragOffset.x = horizontalOffset;
49: mElementDragOffset.y = verticalOffset;
50: }
51:
52: void drawVisualAssistanceCustom(Graphics2D g2d) {
53: if (mElementDragDestination != null) {
54: int drag_x = (mElementDragDestination.x - getMouseEventGeneratingComponent()
55: .getX())
56: - mElementDragReference.x;
57: int drag_y = (mElementDragDestination.y - getMouseEventGeneratingComponent()
58: .getY())
59: - mElementDragReference.y;
60: mElementDragOffset.x += drag_x;
61: mElementDragOffset.y += drag_y;
62: }
63: getStructurePanel().repositionElementsDuringDrag(
64: (Element) getMouseEventGeneratingComponent(),
65: mElementDragOffset.x, mElementDragOffset.y);
66: mElementDragOffset.x = 0;
67: mElementDragOffset.y = 0;
68: mElementDragDestination = null;
69: }
70:
71: void cleanupVisualAssistanceCustom() {
72: }
73:
74: public void mouseEntered(MouseEvent e) {
75: Point location = convertDestinationPoint(new Point(e.getPoint()));
76: if (getStructurePanel().isLocationOutsideStructurepanelView(
77: location.x, location.y)) {
78: calculateDifferences(e.getPoint());
79: } else {
80: finishAutoScroll();
81: }
82: }
83:
84: public void mouseDragged(MouseEvent e) {
85: Point location = convertDestinationPoint(new Point(e.getPoint()));
86: if (getStructurePanel().isLocationOutsideStructurepanelView(
87: location.x, location.y)) {
88: calculateDifferences(e.getPoint());
89: } else {
90: finishAutoScroll();
91: }
92: }
93: }
|