KickJava   Java API By Example, From Geeks To Geeks.

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


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.FigureCanvas;
32 import org.eclipse.draw2d.Viewport;
33 import org.eclipse.draw2d.geometry.Point;
34 import org.eclipse.gef.EditPartViewer;
35 import org.eclipse.gef.Request;
36 import org.eclipse.gef.SnapToHelper;
37 import org.eclipse.gef.requests.CreationFactory;
38 import org.eclipse.gef.tools.CreationTool;
39 import org.eclipse.gef.ui.parts.ScrollingGraphicalViewer;
40
41 import org.nightlabs.editor2d.request.EditorCreateRequest;
42 import org.nightlabs.editor2d.request.EditorRequestConstants;
43
44
45 public abstract class EditorCreationTool
46 extends CreationTool
47 //extends TargetingTool
48
implements EditorRequestConstants
49 {
50   protected SnapToHelper helper;
51   
52   public static final Logger LOGGER = Logger.getLogger(EditorCreationTool.class);
53     
54   /**
55    * @param aFactory
56    */

57   public EditorCreationTool(CreationFactory aFactory) {
58     super(aFactory);
59   }
60
61   /**
62    * Creates a {@link EditorCreateRequest} and sets this tool's factory on the request.
63    * @see org.eclipse.gef.tools.TargetingTool#createTargetRequest()
64    */

65   protected Request createTargetRequest()
66   {
67     EditorCreateRequest request = new EditorCreateRequest();
68     request.setFactory(getFactory());
69     return request;
70   }
71   
72   protected Point getRealLocation()
73   {
74     Point p = getLocation();
75     Point realLocation;
76     
77     EditPartViewer view = getCurrentViewer();
78     if (view instanceof ScrollingGraphicalViewer)
79     {
80       ScrollingGraphicalViewer viewer = (ScrollingGraphicalViewer) view;
81       FigureCanvas canvas = (FigureCanvas) viewer.getControl();
82       Viewport viewport = canvas.getViewport();
83       Point viewLocation = viewport.getViewLocation();
84       realLocation = p.getTranslated(viewLocation);
85       return realLocation;
86     }
87     return p;
88   }
89   
90   protected EditorCreateRequest getEditorCreateRequest() {
91     return (EditorCreateRequest)getTargetRequest();
92   }
93     
94   /**
95    * @see org.eclipse.gef.tools.AbstractTool#getDebugName()
96    */

97   protected String JavaDoc getDebugName() {
98     return "EditorCreation Tool";//$NON-NLS-1$
99
}
100 }
101
102
103
Popular Tags