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
.ITmfImageConstants
;
22 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.TmfUiPlugin
;
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 static Cursor fZoomInCursor
;
84 * The cursor used when zooming out.
86 private static Cursor fZoomOutCursor
;
88 public static enum ZoomType
{
89 ZOOM_NONE
, ZOOM_IN
, ZOOM_OUT
, ZOOM_RESET
92 // ------------------------------------------------------------------------
94 // ------------------------------------------------------------------------
98 * @param _view The view reference
99 * @param type The type of zoom.
101 public Zoom(SDView _view
, ZoomType type
) {
102 super("", AS_RADIO_BUTTON
);//$NON-NLS-1$
106 if ((fZoomInCursor
!= null) && (!fZoomInCursor
.isDisposed())) {
107 fZoomInCursor
.dispose();
110 if ((fZoomOutCursor
!= null) && (!fZoomOutCursor
.isDisposed())) {
111 fZoomOutCursor
.dispose();
114 // Pre-create zooming cursors
115 fZoomInCursor
= new Cursor(Display
.getCurrent(),
116 TmfUiPlugin
.getDefault().getImageFromImageRegistry(ITmfImageConstants
.IMG_UI_ZOOM_IN
).getImageData(),
117 TmfUiPlugin
.getDefault().getImageFromImageRegistry(ITmfImageConstants
.IMG_UI_ZOOM
).getImageData(), 0, 0);
119 fZoomOutCursor
= new Cursor(Display
.getCurrent(),
120 TmfUiPlugin
.getDefault().getImageFromImageRegistry(ITmfImageConstants
.IMG_UI_ZOOM_OUT
).getImageData(),
121 TmfUiPlugin
.getDefault().getImageFromImageRegistry(ITmfImageConstants
.IMG_UI_ZOOM
).getImageData(), 0, 0);
125 setText(SDMessages
._47
);
126 setToolTipText(SDMessages
._48
);
128 setImageDescriptor(TmfUiPlugin
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
132 setText(SDMessages
._51
);
133 setToolTipText(SDMessages
._52
);
135 setImageDescriptor(TmfUiPlugin
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
139 setText(SDMessages
._49
);
140 setToolTipText(SDMessages
._50
);
141 setId(RESET_ZOOM_ID
);
142 setImageDescriptor(TmfUiPlugin
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HOME_MENU
));
147 setText(SDMessages
._53
);
148 setToolTipText(SDMessages
._54
);
150 setImageDescriptor(TmfUiPlugin
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SELECT_MENU
));
155 // ------------------------------------------------------------------------
157 // ------------------------------------------------------------------------
160 * @see org.eclipse.jface.action.Action#run()
165 if ((fView
== null) || (fView
.getSDWidget() == null)) {
169 SDWidget viewer
= fView
.getSDWidget();
171 if (getId().equals(ZOOM_OUT_ID
)) {
172 // Eclipse 3.0 M7 workaround
173 if (fLastZoomOut
== isChecked()) {
174 setChecked(!isChecked());
177 viewer
.setZoomOutMode(isChecked());
178 fLastZoomOut
= isChecked();
181 viewer
.setCursor(fZoomOutCursor
);
182 setActionChecked(NO_ZOOM_ID
, false);
184 viewer
.setCursor(new Cursor(Display
.getDefault(), SWT
.CURSOR_ARROW
));
185 setActionChecked(NO_ZOOM_ID
, true);
187 } else if (getId().equals(ZOOM_IN_ID
)) {
188 // Eclipse 3.0 M7 workaround
189 if (fLastZoomIn
== isChecked()) {
190 setChecked(!isChecked());
193 viewer
.setZoomInMode(isChecked());
194 fLastZoomIn
= isChecked();
197 viewer
.setCursor(fZoomInCursor
);
198 setActionChecked(NO_ZOOM_ID
, false);
200 viewer
.setCursor(new Cursor(Display
.getDefault(), SWT
.CURSOR_ARROW
));
201 setActionChecked(NO_ZOOM_ID
, true);
203 } else if (getId().equals(RESET_ZOOM_ID
)) {
204 viewer
.resetZoomFactor();
206 // The reset action is a radio button only to uncheck the zoom in and out button
207 // when it is clicked. This avoid adding code to do it manually
208 // We only have to force it to false every time
211 setActionChecked(NO_ZOOM_ID
, true);
212 } else if (getId().equals(NO_ZOOM_ID
)) {
214 viewer
.setZoomInMode(false);
215 viewer
.setZoomInMode(false);
216 viewer
.setCursor(new Cursor(Display
.getDefault(), SWT
.CURSOR_ARROW
));
221 * Set action check state of a view action for a given action ID.
223 * @param id The action ID
224 * @param checked true to check the action, false to uncheck the action
226 protected void setActionChecked(String id
, boolean checked
) {
228 IActionBars bar
= fView
.getViewSite().getActionBars();
232 IToolBarManager barManager
= bar
.getToolBarManager();
233 if (barManager
== null) {
236 IContributionItem nextPage
= barManager
.find(id
);
237 if (nextPage
!= null && nextPage
instanceof ActionContributionItem
) {
238 IAction action
= ((ActionContributionItem
) nextPage
).getAction();
239 if (action
!= null) {
240 action
.setChecked(checked
);