1 /**********************************************************************
2 * Copyright (c) 2005, 2012 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
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
;
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
.SDMessages
;
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
;
31 * Action class implementation for zooming in, out or reset of zoom.
37 public class Zoom
extends Action
{
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
43 * The Action ID for zooming in.
45 public final static String ZOOM_IN_ID
= "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ZoomInCoolBar"; //$NON-NLS-1$
47 * The Action ID for zooming out.
49 public final static String ZOOM_OUT_ID
= "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ZoomOutCoolBar"; //$NON-NLS-1$
51 * The Action ID for reset zooming.
53 public final static String RESET_ZOOM_ID
= "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ResetZoom"; //$NON-NLS-1$
55 * The Action ID for no zoominf.
57 public final static String NO_ZOOM_ID
= "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.NoZoom"; //$NON-NLS-1$
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
63 * The sequence diagram view reference
65 protected SDView fView
= null;
67 * Flag to indicate last zoom in.
69 protected boolean fLastZoomIn
= false;
71 * Flag to indicate last zoom out.
73 protected boolean fLastZoomOut
= false;
75 * Flag to indicate last zoom.
77 protected boolean fLastZoom
= true;
79 * The cursor used when zooming in.
81 private final Cursor fZoomInCursor
;
83 * The cursor used when zooming out.
85 private final Cursor fZoomOutCursor
;
88 * The different zoom actions
90 public static enum ZoomType
{
91 /** No zoom information */
97 /** Reset to the default zoom level */
101 // ------------------------------------------------------------------------
103 // ------------------------------------------------------------------------
107 * @param view The view reference
108 * @param type The type of zoom.
110 public Zoom(SDView view
, ZoomType type
) {
111 super("", AS_RADIO_BUTTON
);//$NON-NLS-1$
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);
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);
126 setText(SDMessages
._47
);
127 setToolTipText(SDMessages
._48
);
129 setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
133 setText(SDMessages
._51
);
134 setToolTipText(SDMessages
._52
);
136 setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
140 setText(SDMessages
._49
);
141 setToolTipText(SDMessages
._50
);
142 setId(RESET_ZOOM_ID
);
143 setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HOME_MENU
));
148 setText(SDMessages
._53
);
149 setToolTipText(SDMessages
._54
);
151 setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SELECT_MENU
));
156 // ------------------------------------------------------------------------
158 // ------------------------------------------------------------------------
161 * @see org.eclipse.jface.action.Action#run()
166 if ((fView
== null) || (fView
.getSDWidget() == null)) {
170 SDWidget viewer
= fView
.getSDWidget();
172 if (getId().equals(ZOOM_OUT_ID
)) {
173 // Eclipse 3.0 M7 workaround
174 if (fLastZoomOut
== isChecked()) {
175 setChecked(!isChecked());
178 viewer
.setZoomOutMode(isChecked());
179 fLastZoomOut
= isChecked();
182 viewer
.setCursor(fZoomOutCursor
);
183 setActionChecked(NO_ZOOM_ID
, false);
185 viewer
.setCursor(new Cursor(Display
.getDefault(), SWT
.CURSOR_ARROW
));
186 setActionChecked(NO_ZOOM_ID
, true);
188 } else if (getId().equals(ZOOM_IN_ID
)) {
189 // Eclipse 3.0 M7 workaround
190 if (fLastZoomIn
== isChecked()) {
191 setChecked(!isChecked());
194 viewer
.setZoomInMode(isChecked());
195 fLastZoomIn
= isChecked();
198 viewer
.setCursor(fZoomInCursor
);
199 setActionChecked(NO_ZOOM_ID
, false);
201 viewer
.setCursor(new Cursor(Display
.getDefault(), SWT
.CURSOR_ARROW
));
202 setActionChecked(NO_ZOOM_ID
, true);
204 } else if (getId().equals(RESET_ZOOM_ID
)) {
205 viewer
.resetZoomFactor();
207 // The reset action is a radio button only to uncheck the zoom in and out button
208 // when it is clicked. This avoid adding code to do it manually
209 // We only have to force it to false every time
212 setActionChecked(NO_ZOOM_ID
, true);
213 } else if (getId().equals(NO_ZOOM_ID
)) {
215 viewer
.setZoomInMode(false);
216 viewer
.setZoomInMode(false);
217 viewer
.setCursor(new Cursor(Display
.getDefault(), SWT
.CURSOR_ARROW
));
222 * Set action check state of a view action for a given action ID.
224 * @param id The action ID
225 * @param checked true to check the action, false to uncheck the action
227 protected void setActionChecked(String id
, boolean checked
) {
229 IActionBars bar
= fView
.getViewSite().getActionBars();
233 IToolBarManager barManager
= bar
.getToolBarManager();
234 if (barManager
== null) {
237 IContributionItem nextPage
= barManager
.find(id
);
238 if (nextPage
instanceof ActionContributionItem
) {
239 IAction action
= ((ActionContributionItem
) nextPage
).getAction();
240 if (action
!= null) {
241 action
.setChecked(checked
);