KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > graph > GraphEditor


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2005 Jennifer Lhotak
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20
21 package ca.mcgill.sable.graph;
22
23 import org.eclipse.core.resources.IMarker;
24 import org.eclipse.core.runtime.IProgressMonitor;
25 import org.eclipse.ui.*;
26 import org.eclipse.gef.ui.parts.*;
27 import org.eclipse.gef.*;
28 import org.eclipse.gef.editparts.*;
29 import ca.mcgill.sable.graph.model.*;
30 import ca.mcgill.sable.graph.editparts.*;
31
32 import org.eclipse.gef.palette.*;
33 import org.eclipse.jface.action.*;
34 import org.eclipse.gef.ui.actions.*;
35 import ca.mcgill.sable.graph.actions.*;
36
37 import java.util.*;
38
39
40 public class GraphEditor extends GraphicalEditor {
41
42     private Graph graph;
43     
44     /**
45      *
46      */

47     public GraphEditor() {
48         DefaultEditDomain defaultEditDomain = new DefaultEditDomain(this);
49         setEditDomain(defaultEditDomain);
50     }
51
52     /* (non-Javadoc)
53      * @see org.eclipse.gef.ui.parts.GraphicalEditor#initializeGraphicalViewer()
54      */

55     protected void initializeGraphicalViewer() {
56         getGraphicalViewer().setContents(graph);
57     }
58     
59     protected void configureGraphicalViewer() {
60         super.configureGraphicalViewer();
61         ScalableRootEditPart root = new ScalableRootEditPart();
62         getGraphicalViewer().setRootEditPart(root);
63         
64         ZoomManager zManager = root.getZoomManager();
65         double [] zoomLevels = new double[10];
66         for (int i = 0; i < zoomLevels.length; i++){
67             zoomLevels[i] = (i + 1) * 0.25;
68         }
69         zManager.setZoomLevels(zoomLevels);
70         IAction zoomIn = new ZoomInAction(zManager);
71         IAction zoomOut = new ZoomOutAction(((ScalableRootEditPart)getGraphicalViewer().getRootEditPart()).getZoomManager());
72
73         getActionRegistry().registerAction(zoomIn);
74         getActionRegistry().registerAction(zoomOut);
75         
76         IAction printAction = new PrintAction(this);
77         getActionRegistry().registerAction(printAction);
78         
79         getSite().getKeyBindingService().registerAction(zoomIn);
80         getSite().getKeyBindingService().registerAction(zoomOut);
81     
82         getGraphicalViewer().setEditPartFactory(new PartFactory());
83         getGraphicalViewer().setKeyHandler(new GraphicalViewerKeyHandler(getGraphicalViewer()));
84         
85     }
86     
87     public void setMenuProvider(ContextMenuProvider prov){
88         getGraphicalViewer().setContextMenu(prov);
89         getSite().registerContextMenu(prov, getGraphicalViewer());
90     }
91     
92     public void setPartFactory(PartFactory factory){
93         getGraphicalViewer().setEditPartFactory(factory);
94     }
95     
96     protected void setInput(IEditorInput input){
97         super.setInput(input);
98         if (input instanceof Graph){
99             setGraph((Graph)input);
100         }
101     }
102     
103     /* (non-Javadoc)
104      * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor)
105      */

106     public void doSave(IProgressMonitor monitor) {
107     }
108
109     /* (non-Javadoc)
110      * @see org.eclipse.ui.ISaveablePart#doSaveAs()
111      */

112     public void doSaveAs() {
113     }
114
115     /* (non-Javadoc)
116      * @see org.eclipse.ui.IEditorPart#gotoMarker(org.eclipse.core.resources.IMarker)
117      */

118     public void gotoMarker(IMarker marker) {
119     }
120
121     /* (non-Javadoc)
122      * @see org.eclipse.ui.ISaveablePart#isDirty()
123      */

124     public boolean isDirty() {
125         return false;
126     }
127
128     /* (non-Javadoc)
129      * @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed()
130      */

131     public boolean isSaveAsAllowed() {
132         return false;
133     }
134
135     /**
136      * @return
137      */

138     public Graph getGraph() {
139         return graph;
140     }
141
142     /**
143      * @param graph
144      */

145     public void setGraph(Graph g) {
146         graph = g;
147     }
148
149     public void setTitle(String JavaDoc name){
150         super.setTitle(name);
151     }
152     
153     public void setTitleTooltip(String JavaDoc text){
154         super.setTitleToolTip(text);
155     }
156     
157     public void createActions(){
158         super.createActions();
159         ActionRegistry registry = getActionRegistry();
160         IAction action = new SimpleSelectAction(this);
161         registry.registerAction(action);
162         getSelectionActions().add(action.getId());
163     }
164     
165     public ActionRegistry getGraphEditorActionRegistry(){
166         return getActionRegistry();
167     }
168     
169     public GraphicalViewer getGraphEditorGraphicalViewer(){
170         return getGraphicalViewer();
171     }
172     
173     public List getGraphEditorSelectionActions(){
174         return getSelectionActions();
175     }
176     
177
178     public String JavaDoc getToolTipText(){
179         return getTitle();
180     }
181     
182     public String JavaDoc getTitleToolTip(){
183         return super.getTitleToolTip();
184     }
185
186     
187 }
188
Popular Tags