001: /* Soot - a J*va Optimization Framework
002: * Copyright (C) 2005 Jennifer Lhotak
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the
016: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
017: * Boston, MA 02111-1307, USA.
018: */
019:
020: package ca.mcgill.sable.graph;
021:
022: import org.eclipse.core.resources.IMarker;
023: import org.eclipse.core.runtime.IProgressMonitor;
024: import org.eclipse.ui.*;
025: import org.eclipse.gef.ui.parts.*;
026: import org.eclipse.gef.*;
027: import org.eclipse.gef.editparts.*;
028: import ca.mcgill.sable.graph.model.*;
029: import ca.mcgill.sable.graph.editparts.*;
030:
031: import org.eclipse.gef.palette.*;
032: import org.eclipse.jface.action.*;
033: import org.eclipse.gef.ui.actions.*;
034: import ca.mcgill.sable.graph.actions.*;
035:
036: import java.util.*;
037:
038: public class GraphEditor extends GraphicalEditor {
039:
040: private Graph graph;
041:
042: /**
043: *
044: */
045: public GraphEditor() {
046: DefaultEditDomain defaultEditDomain = new DefaultEditDomain(
047: this );
048: setEditDomain(defaultEditDomain);
049: }
050:
051: /* (non-Javadoc)
052: * @see org.eclipse.gef.ui.parts.GraphicalEditor#initializeGraphicalViewer()
053: */
054: protected void initializeGraphicalViewer() {
055: getGraphicalViewer().setContents(graph);
056: }
057:
058: protected void configureGraphicalViewer() {
059: super .configureGraphicalViewer();
060: ScalableRootEditPart root = new ScalableRootEditPart();
061: getGraphicalViewer().setRootEditPart(root);
062:
063: ZoomManager zManager = root.getZoomManager();
064: double[] zoomLevels = new double[10];
065: for (int i = 0; i < zoomLevels.length; i++) {
066: zoomLevels[i] = (i + 1) * 0.25;
067: }
068: zManager.setZoomLevels(zoomLevels);
069: IAction zoomIn = new ZoomInAction(zManager);
070: IAction zoomOut = new ZoomOutAction(
071: ((ScalableRootEditPart) getGraphicalViewer()
072: .getRootEditPart()).getZoomManager());
073:
074: getActionRegistry().registerAction(zoomIn);
075: getActionRegistry().registerAction(zoomOut);
076:
077: IAction printAction = new PrintAction(this );
078: getActionRegistry().registerAction(printAction);
079:
080: getSite().getKeyBindingService().registerAction(zoomIn);
081: getSite().getKeyBindingService().registerAction(zoomOut);
082:
083: getGraphicalViewer().setEditPartFactory(new PartFactory());
084: getGraphicalViewer().setKeyHandler(
085: new GraphicalViewerKeyHandler(getGraphicalViewer()));
086:
087: }
088:
089: public void setMenuProvider(ContextMenuProvider prov) {
090: getGraphicalViewer().setContextMenu(prov);
091: getSite().registerContextMenu(prov, getGraphicalViewer());
092: }
093:
094: public void setPartFactory(PartFactory factory) {
095: getGraphicalViewer().setEditPartFactory(factory);
096: }
097:
098: protected void setInput(IEditorInput input) {
099: super .setInput(input);
100: if (input instanceof Graph) {
101: setGraph((Graph) input);
102: }
103: }
104:
105: /* (non-Javadoc)
106: * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor)
107: */
108: public void doSave(IProgressMonitor monitor) {
109: }
110:
111: /* (non-Javadoc)
112: * @see org.eclipse.ui.ISaveablePart#doSaveAs()
113: */
114: public void doSaveAs() {
115: }
116:
117: /* (non-Javadoc)
118: * @see org.eclipse.ui.IEditorPart#gotoMarker(org.eclipse.core.resources.IMarker)
119: */
120: public void gotoMarker(IMarker marker) {
121: }
122:
123: /* (non-Javadoc)
124: * @see org.eclipse.ui.ISaveablePart#isDirty()
125: */
126: public boolean isDirty() {
127: return false;
128: }
129:
130: /* (non-Javadoc)
131: * @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed()
132: */
133: public boolean isSaveAsAllowed() {
134: return false;
135: }
136:
137: /**
138: * @return
139: */
140: public Graph getGraph() {
141: return graph;
142: }
143:
144: /**
145: * @param graph
146: */
147: public void setGraph(Graph g) {
148: graph = g;
149: }
150:
151: public void setTitle(String name) {
152: super .setTitle(name);
153: }
154:
155: public void setTitleTooltip(String text) {
156: super .setTitleToolTip(text);
157: }
158:
159: public void createActions() {
160: super .createActions();
161: ActionRegistry registry = getActionRegistry();
162: IAction action = new SimpleSelectAction(this );
163: registry.registerAction(action);
164: getSelectionActions().add(action.getId());
165: }
166:
167: public ActionRegistry getGraphEditorActionRegistry() {
168: return getActionRegistry();
169: }
170:
171: public GraphicalViewer getGraphEditorGraphicalViewer() {
172: return getGraphicalViewer();
173: }
174:
175: public List getGraphEditorSelectionActions() {
176: return getSelectionActions();
177: }
178:
179: public String getToolTipText() {
180: return getTitle();
181: }
182:
183: public String getTitleToolTip() {
184: return super.getTitleToolTip();
185: }
186:
187: }
|