tmf: Give proper names to SD messages variables
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / handlers / Zoom.java
1 /**********************************************************************
2 * Copyright (c) 2005, 2013 IBM Corporation, Ericsson
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
12
13 package org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers;
14
15 import org.eclipse.jface.action.Action;
16 import org.eclipse.jface.action.ActionContributionItem;
17 import org.eclipse.jface.action.IAction;
18 import org.eclipse.jface.action.IContributionItem;
19 import org.eclipse.jface.action.IToolBarManager;
20 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
21 import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants;
22 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView;
23 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget;
24 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.Messages;
25 import org.eclipse.swt.SWT;
26 import org.eclipse.swt.graphics.Cursor;
27 import org.eclipse.swt.widgets.Display;
28 import org.eclipse.ui.IActionBars;
29
30 /**
31 * Action class implementation for zooming in, out or reset of zoom.
32 *
33 * @version 1.0
34 * @author sveyrier
35 *
36 */
37 public class Zoom extends Action {
38
39 // ------------------------------------------------------------------------
40 // Constants
41 // ------------------------------------------------------------------------
42 /**
43 * The Action ID for zooming in.
44 */
45 public final static String ZOOM_IN_ID = "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ZoomInCoolBar"; //$NON-NLS-1$
46 /**
47 * The Action ID for zooming out.
48 */
49 public final static String ZOOM_OUT_ID = "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ZoomOutCoolBar"; //$NON-NLS-1$
50 /**
51 * The Action ID for reset zooming.
52 */
53 public final static String RESET_ZOOM_ID = "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ResetZoom"; //$NON-NLS-1$
54 /**
55 * The Action ID for no zoominf.
56 */
57 public final static String NO_ZOOM_ID = "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.NoZoom"; //$NON-NLS-1$
58
59 // ------------------------------------------------------------------------
60 // Attributes
61 // ------------------------------------------------------------------------
62 /**
63 * The sequence diagram view reference
64 */
65 protected SDView fView = null;
66 /**
67 * Flag to indicate last zoom in.
68 */
69 protected boolean fLastZoomIn = false;
70 /**
71 * Flag to indicate last zoom out.
72 */
73 protected boolean fLastZoomOut = false;
74 /**
75 * Flag to indicate last zoom.
76 */
77 protected boolean fLastZoom = true;
78 /**
79 * The cursor used when zooming in.
80 */
81 private final Cursor fZoomInCursor;
82 /**
83 * The cursor used when zooming out.
84 */
85 private final Cursor fZoomOutCursor;
86
87 /**
88 * The different zoom actions
89 */
90 public static enum ZoomType {
91 /** No zoom information */
92 ZOOM_NONE,
93 /** Zoom in */
94 ZOOM_IN,
95 /** Zoom out */
96 ZOOM_OUT,
97 /** Reset to the default zoom level */
98 ZOOM_RESET
99 }
100
101 // ------------------------------------------------------------------------
102 // Constructors
103 // ------------------------------------------------------------------------
104
105 /**
106 * Constructor
107 * @param view The view reference
108 * @param type The type of zoom.
109 */
110 public Zoom(SDView view, ZoomType type) {
111 super("", AS_RADIO_BUTTON);//$NON-NLS-1$
112
113 fView = view;
114
115 // Pre-create zooming cursors
116 fZoomInCursor = new Cursor(Display.getCurrent(),
117 Activator.getDefault().getImageFromImageRegistry(ITmfImageConstants.IMG_UI_ZOOM_IN).getImageData(),
118 Activator.getDefault().getImageFromImageRegistry(ITmfImageConstants.IMG_UI_ZOOM).getImageData(), 0, 0);
119
120 fZoomOutCursor = new Cursor(Display.getCurrent(),
121 Activator.getDefault().getImageFromImageRegistry(ITmfImageConstants.IMG_UI_ZOOM_OUT).getImageData(),
122 Activator.getDefault().getImageFromImageRegistry(ITmfImageConstants.IMG_UI_ZOOM).getImageData(), 0, 0);
123
124 switch (type) {
125 case ZOOM_IN:
126 setText(Messages.SequenceDiagram_ZoomIn);
127 setToolTipText(Messages.SequenceDiagram_ZoomInTheDiagram);
128 setId(ZOOM_IN_ID);
129 setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_IN_MENU));
130 break;
131
132 case ZOOM_OUT:
133 setText(Messages.SequenceDiagram_ZoomOut);
134 setToolTipText(Messages.SequenceDiagram_ZoomOutTheDiagram);
135 setId(ZOOM_OUT_ID);
136 setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_OUT_MENU));
137 break;
138
139 case ZOOM_RESET:
140 setText(Messages.SequenceDiagram_ResetZoomFactor);
141 setToolTipText(Messages.SequenceDiagram_ResetZoomFactor);
142 setId(RESET_ZOOM_ID);
143 setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_HOME_MENU));
144 break;
145
146 case ZOOM_NONE:
147 default:
148 setText(Messages.SequenceDiagram_Select);
149 setToolTipText(Messages.SequenceDiagram_Select);
150 setId(NO_ZOOM_ID);
151 setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SELECT_MENU));
152 break;
153 }
154 }
155
156 // ------------------------------------------------------------------------
157 // Methods
158 // ------------------------------------------------------------------------
159
160 @Override
161 public void run() {
162
163 if ((fView == null) || (fView.getSDWidget() == null)) {
164 return;
165 }
166
167 SDWidget viewer = fView.getSDWidget();
168
169 if (getId().equals(ZOOM_OUT_ID)) {
170 // Eclipse 3.0 M7 workaround
171 if (fLastZoomOut == isChecked()) {
172 setChecked(!isChecked());
173 }
174
175 viewer.setZoomOutMode(isChecked());
176 fLastZoomOut = isChecked();
177 fLastZoom = false;
178 if (isChecked()) {
179 viewer.setCursor(fZoomOutCursor);
180 setActionChecked(NO_ZOOM_ID, false);
181 } else {
182 viewer.setCursor(new Cursor(Display.getDefault(), SWT.CURSOR_ARROW));
183 setActionChecked(NO_ZOOM_ID, true);
184 }
185 } else if (getId().equals(ZOOM_IN_ID)) {
186 // Eclipse 3.0 M7 workaround
187 if (fLastZoomIn == isChecked()) {
188 setChecked(!isChecked());
189 }
190
191 viewer.setZoomInMode(isChecked());
192 fLastZoomIn = isChecked();
193 fLastZoom = false;
194 if (isChecked()) {
195 viewer.setCursor(fZoomInCursor);
196 setActionChecked(NO_ZOOM_ID, false);
197 } else {
198 viewer.setCursor(new Cursor(Display.getDefault(), SWT.CURSOR_ARROW));
199 setActionChecked(NO_ZOOM_ID, true);
200 }
201 } else if (getId().equals(RESET_ZOOM_ID)) {
202 viewer.resetZoomFactor();
203
204 // The reset action is a radio button only to uncheck the zoom in and out button
205 // when it is clicked. This avoid adding code to do it manually
206 // We only have to force it to false every time
207 fLastZoom = false;
208 setChecked(false);
209 setActionChecked(NO_ZOOM_ID, true);
210 } else if (getId().equals(NO_ZOOM_ID)) {
211 setChecked(true);
212 viewer.setZoomInMode(false);
213 viewer.setZoomInMode(false);
214 viewer.setCursor(new Cursor(Display.getDefault(), SWT.CURSOR_ARROW));
215 }
216 }
217
218 /**
219 * Set action check state of a view action for a given action ID.
220 *
221 * @param id The action ID
222 * @param checked true to check the action, false to uncheck the action
223 */
224 protected void setActionChecked(String id, boolean checked) {
225 if (fView != null) {
226 IActionBars bar = fView.getViewSite().getActionBars();
227 if (bar == null) {
228 return;
229 }
230 IToolBarManager barManager = bar.getToolBarManager();
231 if (barManager == null) {
232 return;
233 }
234 IContributionItem nextPage = barManager.find(id);
235 if (nextPage instanceof ActionContributionItem) {
236 IAction action = ((ActionContributionItem) nextPage).getAction();
237 if (action != null) {
238 action.setChecked(checked);
239 }
240 }
241 }
242 }
243 }
This page took 0.03929 seconds and 6 git commands to generate.