KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > workfloweditor > flowchart > MoveMouseHandler


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.workfloweditor.flowchart;
20
21 import java.awt.event.MouseEvent JavaDoc;
22 import java.util.Iterator JavaDoc;
23
24 import javax.swing.event.MouseInputAdapter JavaDoc;
25
26 import org.openharmonise.workfloweditor.flowchart.shapes.*;
27
28
29 /**
30  * The move handler deals with mouse guestures for moving shapes.
31  *
32  * @author Matthew Large
33  * @version $Revision: 1.1 $
34  *
35  */

36 public class MoveMouseHandler extends MouseInputAdapter JavaDoc {
37
38     /**
39      * Workflow diagram.
40      */

41     private FlowChart m_chart = null;
42
43     /**
44      * Selected shape.
45      */

46     private AbstractWorkflowShape m_selectedShape = null;
47     
48     /**
49      * X co-ordinate within selected shape.
50      */

51     private int m_nXoffset = 0;
52     
53     /**
54      * Y co-ordinate within the selected shape.
55      */

56     private int m_nYoffset = 0;
57
58     /**
59      * Constructs a new move handler.
60      *
61      * @param chart Workflow diagram
62      */

63     public MoveMouseHandler(FlowChart chart) {
64         super();
65         this.m_chart = chart;
66     }
67
68     /* (non-Javadoc)
69      * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
70      */

71     public void mouseDragged(MouseEvent JavaDoc me) {
72         if(this.m_selectedShape!=null) {
73             this.m_selectedShape.setX( me.getX()-this.m_nXoffset );
74             this.m_selectedShape.setY( me.getY()-this.m_nYoffset );
75             this.m_chart.repaint();
76         }
77     }
78
79     /* (non-Javadoc)
80      * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
81      */

82     public void mousePressed(MouseEvent JavaDoc me) {
83         Iterator JavaDoc itor = this.m_chart.getShapes().iterator();
84         while (itor.hasNext()) {
85             AbstractWorkflowShape shape = (AbstractWorkflowShape) itor.next();
86             if(shape instanceof AbstractMoveableShape) {
87                 AbstractMoveableShape moveableShape = (AbstractMoveableShape) shape;
88                 if(moveableShape.controlPointContains(me.getX(), me.getY())) {
89                     this.m_selectedShape = moveableShape;
90                     this.m_nXoffset = (int) (me.getX()-this.m_selectedShape.getX());
91                     this.m_nYoffset = (int) (me.getY()-this.m_selectedShape.getY());
92                     break;
93                 }
94             }
95         }
96     }
97
98     /* (non-Javadoc)
99      * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
100      */

101     public void mouseReleased(MouseEvent JavaDoc me) {
102         this.m_selectedShape = null;
103         this.m_nXoffset = 0;
104         this.m_nYoffset = 0;
105     }
106
107 }
108
Popular Tags