KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nightlabs > editor2d > tools > ShapeEditTracker


1 /* *****************************************************************************
2  * NightLabs Editor2D - Graphical editor framework *
3  * Copyright (C) 2004-2005 NightLabs - http://NightLabs.org *
4  * Project author: Daniel Mazurek <Daniel.Mazurek [at] nightlabs [dot] org> *
5  * *
6  * This library is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin St, Fifth Floor, *
20  * Boston, MA 02110-1301 USA *
21  * *
22  * Or get it online : *
23  * http://www.gnu.org/copyleft/lesser.html *
24  * *
25  * *
26  ******************************************************************************/

27
28 package org.nightlabs.editor2d.tools;
29
30 import java.util.List JavaDoc;
31
32 import org.apache.log4j.Logger;
33 import org.eclipse.gef.EditPart;
34 import org.eclipse.gef.Request;
35
36 import org.nightlabs.editor2d.edit.ShapeDrawComponentEditPart;
37 import org.nightlabs.editor2d.j2d.GeneralShape;
38 import org.nightlabs.editor2d.request.EditorEditShapeRequest;
39
40 // TODO; Use SelectEditPartTracker instead to avoid multiple Selections
41
public class ShapeEditTracker
42 extends AbstractDragTracker
43 {
44   public static final Logger LOGGER = Logger.getLogger(ShapeEditTracker.class);
45   
46   protected ShapeDrawComponentEditPart getShapeDrawComponentEditPart() {
47     return (ShapeDrawComponentEditPart) owner;
48   }
49   protected GeneralShape getGeneralShape() {
50     return getShapeDrawComponentEditPart().getGeneralShape();
51   }
52 // protected ShapeFigure sourceFigure;
53
protected int pathSegmentIndex;
54   
55   public ShapeEditTracker(ShapeDrawComponentEditPart owner, int pathSegmentIndex)
56   {
57     super(owner);
58     this.pathSegmentIndex = pathSegmentIndex;
59   }
60   
61   protected String JavaDoc getCommandName() {
62     return REQ_EDIT_SHAPE;
63   }
64   
65   /**
66    * @see org.eclipse.gef.tools.AbstractTool#deactivate()
67    */

68   public void deactivate()
69   {
70     super.deactivate();
71 // sourceFigure = null;
72
}
73         
74   /**
75    * @see org.eclipse.gef.tools.AbstractTool#getDebugName()
76    */

77   protected String JavaDoc getDebugName()
78   {
79     return "Edit Shape Handle Tracker";//$NON-NLS-1$
80
}
81         
82   /**
83    * @see org.eclipse.gef.tools.SimpleDragTracker#createSourceRequest()
84    */

85   protected Request createSourceRequest()
86   {
87     EditorEditShapeRequest request = new EditorEditShapeRequest();
88     request.setType(REQ_EDIT_SHAPE);
89     request.setPathSegmentIndex(pathSegmentIndex);
90     request.setLocation(getLocation());
91     List JavaDoc selectedEditParts = getCurrentViewer().getSelectedEditParts();
92     if (selectedEditParts != null && !selectedEditParts.isEmpty()) {
93       EditPart selectedEditPart = (EditPart)selectedEditParts.get(0);
94         request.setTargetEditPart(selectedEditPart);
95     }
96     return request;
97   }
98         
99   /**
100    * @see org.eclipse.gef.tools.SimpleDragTracker#updateSourceRequest()
101    */

102   protected void updateSourceRequest()
103   {
104     EditorEditShapeRequest request = (EditorEditShapeRequest) getSourceRequest();
105       request.setLocation(getLocation());
106   }
107     
108 }
109
Popular Tags