KickJava   Java API By Example, From Geeks To Geeks.

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


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.eclipse.draw2d.PositionConstants;
33 import org.eclipse.gef.GraphicalEditPart;
34 import org.eclipse.gef.Request;
35 import org.eclipse.swt.graphics.Cursor;
36
37 import org.nightlabs.editor2d.custom.EditorCursors;
38 import org.nightlabs.editor2d.edit.AbstractDrawComponentEditPart;
39 import org.nightlabs.editor2d.request.EditorShearRequest;
40 import org.nightlabs.editor2d.util.J2DUtil;
41
42
43 public class ShearTracker
44 extends AbstractDragTracker
45 {
46   protected int direction;
47   
48   /**
49    * @param owner
50    */

51   public ShearTracker(GraphicalEditPart owner, int direction) {
52     super(owner);
53     this.direction = direction;
54   }
55
56   /* (non-Javadoc)
57    * @see org.eclipse.gef.tools.SimpleDragTracker#createSourceRequest()
58    */

59   protected Request createSourceRequest()
60   {
61     EditorShearRequest request = new EditorShearRequest();
62     request.setType(REQ_SHEAR);
63     request.setLocation(getLocation());
64     request.setDirection(direction);
65     List JavaDoc selectedParts = getCurrentViewer().getSelectedEditParts();
66     if (!selectedParts.isEmpty()) {
67       AbstractDrawComponentEditPart part = (AbstractDrawComponentEditPart) selectedParts.get(0);
68       request.setShearBounds(J2DUtil.toDraw2D(part.getDrawComponent().getBounds()));
69     }
70     request.setEditParts(selectedParts);
71     return request;
72   }
73
74   /* (non-Javadoc)
75    * @see org.eclipse.gef.tools.SimpleDragTracker#updateSourceRequest()
76    */

77   protected void updateSourceRequest()
78   {
79 // Point loq = getLocation().getCopy();
80
// loq.translate(getStartLocation());
81
// getEditorShearRequest().setLocation(loq);
82
getEditorShearRequest().setLocation(getLocation());
83   }
84  
85   protected EditorShearRequest getEditorShearRequest() {
86     return (EditorShearRequest) getSourceRequest();
87   }
88   
89   /* (non-Javadoc)
90    * @see org.eclipse.gef.tools.AbstractTool#getCommandName()
91    */

92   protected String JavaDoc getCommandName() {
93     return REQ_SHEAR;
94   }
95
96   /**
97    * @see org.eclipse.gef.tools.AbstractTool#getDefaultCursor()
98    */

99   protected Cursor getDefaultCursor()
100   {
101     switch(direction)
102     {
103         case(PositionConstants.NORTH):
104         case(PositionConstants.SOUTH):
105           return EditorCursors.SHEAR_HORIZONTAL;
106         case(PositionConstants.WEST):
107         case(PositionConstants.EAST):
108           return EditorCursors.SHEAR_VERTICAL;
109     }
110     return EditorCursors.NO;
111   }
112 }
113
Popular Tags