1 /**********************************************************************
2 * Copyright (c) 2005, 2008 IBM Corporation and others.
3 * Copyright (c) 2011, 2012 Ericsson.
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
11 * IBM - Initial API and implementation
12 * Bernd Hufmann - Updated for TMF
13 **********************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
;
16 import org
.eclipse
.jface
.action
.Action
;
17 import org
.eclipse
.jface
.action
.ActionContributionItem
;
18 import org
.eclipse
.jface
.action
.IAction
;
19 import org
.eclipse
.jface
.action
.IContributionItem
;
20 import org
.eclipse
.jface
.action
.IToolBarManager
;
21 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
22 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.ITmfImageConstants
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.SDView
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.SDWidget
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.util
.SDMessages
;
26 import org
.eclipse
.swt
.SWT
;
27 import org
.eclipse
.swt
.graphics
.Cursor
;
28 import org
.eclipse
.swt
.widgets
.Display
;
29 import org
.eclipse
.ui
.IActionBars
;
32 * Action class implementation for zooming in, out or reset of zoom.
38 public class Zoom
extends Action
{
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
44 * The Action ID for zooming in.
46 public final static String ZOOM_IN_ID
= "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ZoomInCoolBar"; //$NON-NLS-1$
48 * The Action ID for zooming out.
50 public final static String ZOOM_OUT_ID
= "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ZoomOutCoolBar"; //$NON-NLS-1$
52 * The Action ID for reset zooming.
54 public final static String RESET_ZOOM_ID
= "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ResetZoom"; //$NON-NLS-1$
56 * The Action ID for no zoominf.
58 public final static String NO_ZOOM_ID
= "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.NoZoom"; //$NON-NLS-1$
60 // ------------------------------------------------------------------------
62 // ------------------------------------------------------------------------
64 * The sequence diagram view reference
66 protected SDView fView
= null;
68 * Flag to indicate last zoom in.
70 protected boolean fLastZoomIn
= false;
72 * Flag to indicate last zoom out.
74 protected boolean fLastZoomOut
= false;
76 * Flag to indicate last zoom.
78 protected boolean fLastZoom
= true;
80 * The cursor used when zooming in.
82 private final Cursor fZoomInCursor
;
84 * The cursor used when zooming out.
86 private final Cursor fZoomOutCursor
;
89 * The different zoom actions
91 public static enum ZoomType
{
92 /** No zoom information */
98 /** Reset to the default zoom level */
102 // ------------------------------------------------------------------------
104 // ------------------------------------------------------------------------
108 * @param view The view reference
109 * @param type The type of zoom.
111 public Zoom(SDView view
, ZoomType type
) {
112 super("", AS_RADIO_BUTTON
);//$NON-NLS-1$
116 // Pre-create zooming cursors
117 fZoomInCursor
= new Cursor(Display
.getCurrent(),
118 Activator
.getDefault().getImageFromImageRegistry(ITmfImageConstants
.IMG_UI_ZOOM_IN
).getImageData(),
119 Activator
.getDefault().getImageFromImageRegistry(ITmfImageConstants
.IMG_UI_ZOOM
).getImageData(), 0, 0);
121 fZoomOutCursor
= new Cursor(Display
.getCurrent(),
122 Activator
.getDefault().getImageFromImageRegistry(ITmfImageConstants
.IMG_UI_ZOOM_OUT
).getImageData(),
123 Activator
.getDefault().getImageFromImageRegistry(ITmfImageConstants
.IMG_UI_ZOOM
).getImageData(), 0, 0);
127 setText(SDMessages
._47
);
128 setToolTipText(SDMessages
._48
);
130 setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
134 setText(SDMessages
._51
);
135 setToolTipText(SDMessages
._52
);
137 setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
141 setText(SDMessages
._49
);
142 setToolTipText(SDMessages
._50
);
143 setId(RESET_ZOOM_ID
);
144 setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HOME_MENU
));
149 setText(SDMessages
._53
);
150 setToolTipText(SDMessages
._54
);
152 setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SELECT_MENU
));
157 // ------------------------------------------------------------------------
159 // ------------------------------------------------------------------------
162 * @see org.eclipse.jface.action.Action#run()
167 if ((fView
== null) || (fView
.getSDWidget() == null)) {
171 SDWidget viewer
= fView
.getSDWidget();
173 if (getId().equals(ZOOM_OUT_ID
)) {
174 // Eclipse 3.0 M7 workaround
175 if (fLastZoomOut
== isChecked()) {
176 setChecked(!isChecked());
179 viewer
.setZoomOutMode(isChecked());
180 fLastZoomOut
= isChecked();
183 viewer
.setCursor(fZoomOutCursor
);
184 setActionChecked(NO_ZOOM_ID
, false);
186 viewer
.setCursor(new Cursor(Display
.getDefault(), SWT
.CURSOR_ARROW
));
187 setActionChecked(NO_ZOOM_ID
, true);
189 } else if (getId().equals(ZOOM_IN_ID
)) {
190 // Eclipse 3.0 M7 workaround
191 if (fLastZoomIn
== isChecked()) {
192 setChecked(!isChecked());
195 viewer
.setZoomInMode(isChecked());
196 fLastZoomIn
= isChecked();
199 viewer
.setCursor(fZoomInCursor
);
200 setActionChecked(NO_ZOOM_ID
, false);
202 viewer
.setCursor(new Cursor(Display
.getDefault(), SWT
.CURSOR_ARROW
));
203 setActionChecked(NO_ZOOM_ID
, true);
205 } else if (getId().equals(RESET_ZOOM_ID
)) {
206 viewer
.resetZoomFactor();
208 // The reset action is a radio button only to uncheck the zoom in and out button
209 // when it is clicked. This avoid adding code to do it manually
210 // We only have to force it to false every time
213 setActionChecked(NO_ZOOM_ID
, true);
214 } else if (getId().equals(NO_ZOOM_ID
)) {
216 viewer
.setZoomInMode(false);
217 viewer
.setZoomInMode(false);
218 viewer
.setCursor(new Cursor(Display
.getDefault(), SWT
.CURSOR_ARROW
));
223 * Set action check state of a view action for a given action ID.
225 * @param id The action ID
226 * @param checked true to check the action, false to uncheck the action
228 protected void setActionChecked(String id
, boolean checked
) {
230 IActionBars bar
= fView
.getViewSite().getActionBars();
234 IToolBarManager barManager
= bar
.getToolBarManager();
235 if (barManager
== null) {
238 IContributionItem nextPage
= barManager
.find(id
);
239 if (nextPage
instanceof ActionContributionItem
) {
240 IAction action
= ((ActionContributionItem
) nextPage
).getAction();
241 if (action
!= null) {
242 action
.setChecked(checked
);