KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.log4j.Logger;
31 import org.eclipse.draw2d.geometry.Point;
32 import org.eclipse.gef.Request;
33 import org.eclipse.swt.graphics.Cursor;
34
35 import org.nightlabs.editor2d.custom.EditorCursors;
36 import org.nightlabs.editor2d.edit.AbstractDrawComponentEditPart;
37 import org.nightlabs.editor2d.request.EditorRotateRequest;
38 import org.nightlabs.editor2d.util.EditorUtil;
39
40 public class RotateTracker
41 extends AbstractDragTracker
42 {
43   public static final Logger LOGGER = Logger.getLogger(RotateTracker.class);
44   protected int direction;
45   
46   public RotateTracker(AbstractDrawComponentEditPart owner, int direction)
47   {
48     super(owner);
49     this.direction = direction;
50   }
51
52   protected AbstractDrawComponentEditPart getAbstractDrawComponentEditPart() {
53     return (AbstractDrawComponentEditPart) owner;
54   }
55   
56   /**
57    * @see org.eclipse.gef.tools.SimpleDragTracker#createSourceRequest()
58    */

59   protected Request createSourceRequest()
60   {
61     EditorRotateRequest rotateRequest = new EditorRotateRequest();
62     rotateRequest.setType(REQ_ROTATE);
63     rotateRequest.setLocation(getLocation());
64     rotateRequest.setEditParts(getCurrentViewer().getSelectedEditParts());
65     return rotateRequest;
66   }
67         
68   protected String JavaDoc getCommandName()
69   {
70     return REQ_ROTATE;
71   }
72
73   /**
74    * @see org.eclipse.gef.tools.AbstractTool#getDefaultCursor()
75    */

76   protected Cursor getDefaultCursor()
77   {
78     return EditorCursors.ROTATE;
79   }
80           
81   protected Point rotationCenter;
82   
83   /**
84    * @see org.eclipse.gef.tools.SimpleDragTracker#updateSourceRequest()
85    */

86   protected void updateSourceRequest()
87   {
88     if (getEditorRotateRequest().getRotationCenter() == null && owner != null)
89     {
90         if (getEditorRotateRequest().getEditParts().size() > 1) {
91           rotationCenter = EditorUtil.getCenter(getEditorRotateRequest().getEditParts());
92           getEditorRotateRequest().setRotationCenter(rotationCenter);
93           getEditorRotateRequest().setMultiple(true);
94         }
95         else {
96         rotationCenter = new Point(getAbstractDrawComponentEditPart().getDrawComponent().getRotationX(),
97             getAbstractDrawComponentEditPart().getDrawComponent().getRotationY());
98         getEditorRotateRequest().setRotationCenter(rotationCenter);
99         getEditorRotateRequest().setMultiple(false);
100         }
101     }
102     getEditorRotateRequest().setLocation(getLocation());
103         
104     LOGGER.debug("updateSourceRequest.rotation = "+getEditorRotateRequest().getRotation());
105     LOGGER.debug("rotationCenter = "+rotationCenter);
106     LOGGER.debug("location = "+getLocation());
107   }
108   
109   protected EditorRotateRequest getEditorRotateRequest()
110   {
111     return (EditorRotateRequest) getSourceRequest();
112   }
113   
114   protected String JavaDoc getDebugName()
115   {
116     return "Rotate Handle Tracker";//$NON-NLS-1$
117
}
118
119   // Override to avoid the single selection of the EditPart whiches handle has been selected
120
protected void performSelection()
121     {
122         
123     }
124 }
125
Popular Tags