001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.workfloweditor.flowchart;
020:
021: import java.awt.event.MouseEvent;
022: import java.util.Iterator;
023:
024: import javax.swing.event.MouseInputAdapter;
025:
026: import org.openharmonise.workfloweditor.flowchart.shapes.*;
027:
028: /**
029: * The move handler deals with mouse guestures for moving shapes.
030: *
031: * @author Matthew Large
032: * @version $Revision: 1.1 $
033: *
034: */
035: public class MoveMouseHandler extends MouseInputAdapter {
036:
037: /**
038: * Workflow diagram.
039: */
040: private FlowChart m_chart = null;
041:
042: /**
043: * Selected shape.
044: */
045: private AbstractWorkflowShape m_selectedShape = null;
046:
047: /**
048: * X co-ordinate within selected shape.
049: */
050: private int m_nXoffset = 0;
051:
052: /**
053: * Y co-ordinate within the selected shape.
054: */
055: private int m_nYoffset = 0;
056:
057: /**
058: * Constructs a new move handler.
059: *
060: * @param chart Workflow diagram
061: */
062: public MoveMouseHandler(FlowChart chart) {
063: super ();
064: this .m_chart = chart;
065: }
066:
067: /* (non-Javadoc)
068: * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
069: */
070: public void mouseDragged(MouseEvent me) {
071: if (this .m_selectedShape != null) {
072: this .m_selectedShape.setX(me.getX() - this .m_nXoffset);
073: this .m_selectedShape.setY(me.getY() - this .m_nYoffset);
074: this .m_chart.repaint();
075: }
076: }
077:
078: /* (non-Javadoc)
079: * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
080: */
081: public void mousePressed(MouseEvent me) {
082: Iterator itor = this .m_chart.getShapes().iterator();
083: while (itor.hasNext()) {
084: AbstractWorkflowShape shape = (AbstractWorkflowShape) itor
085: .next();
086: if (shape instanceof AbstractMoveableShape) {
087: AbstractMoveableShape moveableShape = (AbstractMoveableShape) shape;
088: if (moveableShape.controlPointContains(me.getX(), me
089: .getY())) {
090: this .m_selectedShape = moveableShape;
091: this .m_nXoffset = (int) (me.getX() - this .m_selectedShape
092: .getX());
093: this .m_nYoffset = (int) (me.getY() - this .m_selectedShape
094: .getY());
095: break;
096: }
097: }
098: }
099: }
100:
101: /* (non-Javadoc)
102: * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
103: */
104: public void mouseReleased(MouseEvent me) {
105: this .m_selectedShape = null;
106: this .m_nXoffset = 0;
107: this .m_nYoffset = 0;
108: }
109:
110: }
|