KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > soot > ui > SootOutputView


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 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.soot.ui;
22
23
24 import org.eclipse.jface.text.*;
25 import org.eclipse.jface.action.*;
26 import org.eclipse.swt.widgets.*;
27 import org.eclipse.ui.part.*;
28 import org.eclipse.swt.*;
29 import org.eclipse.ui.*;
30
31
32 public class SootOutputView extends ViewPart implements ITextListener, IDocumentListener {
33     private TextViewer textViewer;
34     
35     private Control control;
36     private Action selectAllAction;
37     private Action copyAction;
38         
39     public SootOutputView() {
40         super();
41     }
42     
43     public void createPartControl(Composite parent) {
44         setTextViewer(new TextViewer(parent, getSWTStyles()));
45         getTextViewer().setEditable(false);
46         setControl(parent);
47         createActions();
48         createContextMenu();
49         hookGlobalActions();
50     }
51     
52     private void createActions() {
53         selectAllAction = new Action("selectAll"){
54             public void run() {
55                 selectAll();
56             }
57         };
58         copyAction = new Action("copy"){
59             public void run() {
60                 copy();
61             }
62         };
63     }
64     
65     private void selectAll() {
66         getTextViewer().setSelection(new TextSelection(getTextViewer().getTopIndexStartOffset(), getTextViewer().getDocument().getLength()));
67     }
68     
69     private void copy() {
70         getTextViewer().doOperation(ITextOperationTarget.COPY);
71     }
72     
73
74     private void createContextMenu() {
75         // Create menu manager.
76
MenuManager menuMgr = new MenuManager();
77         menuMgr.setRemoveAllWhenShown(true);
78         menuMgr.addMenuListener(new IMenuListener() {
79             public void menuAboutToShow(IMenuManager mgr) {
80                 fillContextMenu(mgr);
81             }
82         });
83                 
84         // Create menu.
85
Menu menu = menuMgr.createContextMenu(getTextViewer().getControl());
86         getTextViewer().getControl().setMenu(menu);
87                 
88         // Register menu for extension.
89
getSite().registerContextMenu(menuMgr, getTextViewer());
90     }
91     
92     private void fillContextMenu(IMenuManager mgr) {
93         mgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
94         mgr.add(new Separator());
95         mgr.add(copyAction);
96         mgr.add(selectAllAction);
97         mgr.add(new Separator());
98
99     }
100     
101     private void hookGlobalActions() {
102         IActionBars bars = getViewSite().getActionBars();
103         bars.setGlobalActionHandler(IWorkbenchActionConstants.COPY, copyAction);
104         bars.setGlobalActionHandler(IWorkbenchActionConstants.SELECT_ALL, selectAllAction);
105         
106     }
107     
108
109     
110     private static int getSWTStyles() {
111         int styles= SWT.H_SCROLL | SWT.V_SCROLL;
112         return styles;
113     }
114
115     public void setFocus() {
116         getTextViewer().getControl().setFocus();
117     }
118     
119     
120     
121     /**
122      * Returns the control.
123      * @return Control
124      */

125     public Control getControl() {
126         return control;
127     }
128
129     /**
130      * Sets the control.
131      * @param control The control to set
132      */

133     public void setControl(Control control) {
134         this.control = control;
135     }
136
137     public void textChanged(TextEvent e) {
138         
139     }
140     
141     public void documentAboutToBeChanged(DocumentEvent e) {
142     }
143     
144     public void documentChanged(DocumentEvent e) {
145         
146     }
147
148     /**
149      * Returns the viewer.
150      * @return TextViewer
151      */

152     public TextViewer getTextViewer() {
153         return textViewer;
154     }
155
156     /**
157      * Sets the viewer.
158      * @param viewer The viewer to set
159      */

160     public void setTextViewer(TextViewer textViewer) {
161         this.textViewer = textViewer;
162     }
163
164 }
165
Popular Tags