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
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
.ActionContributionItem
;
16 import org
.eclipse
.jface
.action
.IAction
;
17 import org
.eclipse
.jface
.action
.IContributionItem
;
18 import org
.eclipse
.jface
.action
.IToolBarManager
;
19 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
20 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.ITmfImageConstants
;
21 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.SDView
;
22 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.SDWidget
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.util
.Messages
;
24 import org
.eclipse
.swt
.SWT
;
25 import org
.eclipse
.swt
.graphics
.Cursor
;
26 import org
.eclipse
.swt
.widgets
.Display
;
27 import org
.eclipse
.ui
.IActionBars
;
30 * Action class implementation for zooming in, out or reset of zoom.
36 public class Zoom
extends BaseSDAction
{
38 // ------------------------------------------------------------------------
40 // ------------------------------------------------------------------------
42 * The Action ID for zooming in.
44 public final static String ZOOM_IN_ID
= "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ZoomInCoolBar"; //$NON-NLS-1$
46 * The Action ID for zooming out.
48 public final static String ZOOM_OUT_ID
= "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ZoomOutCoolBar"; //$NON-NLS-1$
50 * The Action ID for reset zooming.
52 public final static String RESET_ZOOM_ID
= "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ResetZoom"; //$NON-NLS-1$
54 * The Action ID for no zoominf.
56 public final static String NO_ZOOM_ID
= "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.NoZoom"; //$NON-NLS-1$
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
62 * Flag to indicate last zoom in.
64 private boolean fLastZoomIn
= false;
66 * Flag to indicate last zoom out.
68 private boolean fLastZoomOut
= false;
70 * The cursor used when zooming in.
72 private final Cursor fZoomInCursor
;
74 * The cursor used when zooming out.
76 private final Cursor fZoomOutCursor
;
79 * The different zoom actions
81 public static enum ZoomType
{
82 /** No zoom information */
88 /** Reset to the default zoom level */
92 // ------------------------------------------------------------------------
94 // ------------------------------------------------------------------------
98 * @param view The view reference
99 * @param type The type of zoom.
101 public Zoom(SDView view
, ZoomType type
) {
102 super(view
, "", AS_RADIO_BUTTON
); //$NON-NLS-1$
104 // Pre-create zooming cursors
105 fZoomInCursor
= new Cursor(Display
.getCurrent(),
106 Activator
.getDefault().getImageFromImageRegistry(ITmfImageConstants
.IMG_UI_ZOOM_IN
).getImageData(),
107 Activator
.getDefault().getImageFromImageRegistry(ITmfImageConstants
.IMG_UI_ZOOM
).getImageData(), 0, 0);
109 fZoomOutCursor
= new Cursor(Display
.getCurrent(),
110 Activator
.getDefault().getImageFromImageRegistry(ITmfImageConstants
.IMG_UI_ZOOM_OUT
).getImageData(),
111 Activator
.getDefault().getImageFromImageRegistry(ITmfImageConstants
.IMG_UI_ZOOM
).getImageData(), 0, 0);
115 setText(Messages
.SequenceDiagram_ZoomIn
);
116 setToolTipText(Messages
.SequenceDiagram_ZoomInTheDiagram
);
118 setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
122 setText(Messages
.SequenceDiagram_ZoomOut
);
123 setToolTipText(Messages
.SequenceDiagram_ZoomOutTheDiagram
);
125 setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
129 setText(Messages
.SequenceDiagram_ResetZoomFactor
);
130 setToolTipText(Messages
.SequenceDiagram_ResetZoomFactor
);
131 setId(RESET_ZOOM_ID
);
132 setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HOME_MENU
));
137 setText(Messages
.SequenceDiagram_Select
);
138 setToolTipText(Messages
.SequenceDiagram_Select
);
140 setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SELECT_MENU
));
145 // ------------------------------------------------------------------------
147 // ------------------------------------------------------------------------
152 if ((getView() == null) || (getView().getSDWidget() == null)) {
156 SDWidget viewer
= getView().getSDWidget();
158 if (getId().equals(ZOOM_OUT_ID
)) {
159 // Eclipse 3.0 M7 workaround
160 if (fLastZoomOut
== isChecked()) {
161 setChecked(!isChecked());
164 viewer
.setZoomOutMode(isChecked());
165 fLastZoomOut
= isChecked();
167 viewer
.setCursor(fZoomOutCursor
);
168 setActionChecked(NO_ZOOM_ID
, false);
170 viewer
.setCursor(new Cursor(Display
.getDefault(), SWT
.CURSOR_ARROW
));
171 setActionChecked(NO_ZOOM_ID
, true);
173 } else if (getId().equals(ZOOM_IN_ID
)) {
174 // Eclipse 3.0 M7 workaround
175 if (fLastZoomIn
== isChecked()) {
176 setChecked(!isChecked());
179 viewer
.setZoomInMode(isChecked());
180 fLastZoomIn
= isChecked();
182 viewer
.setCursor(fZoomInCursor
);
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(RESET_ZOOM_ID
)) {
189 viewer
.resetZoomFactor();
191 // The reset action is a radio button only to uncheck the zoom in and out button
192 // when it is clicked. This avoid adding code to do it manually
193 // We only have to force it to false every time
195 setActionChecked(NO_ZOOM_ID
, true);
196 } else if (getId().equals(NO_ZOOM_ID
)) {
198 viewer
.setZoomInMode(false);
199 viewer
.setZoomInMode(false);
200 viewer
.setCursor(new Cursor(Display
.getDefault(), SWT
.CURSOR_ARROW
));
205 * Set action check state of a view action for a given action ID.
207 * @param id The action ID
208 * @param checked true to check the action, false to uncheck the action
210 protected void setActionChecked(String id
, boolean checked
) {
211 if (getView() != null) {
212 IActionBars bar
= getView().getViewSite().getActionBars();
216 IToolBarManager barManager
= bar
.getToolBarManager();
217 if (barManager
== null) {
220 IContributionItem nextPage
= barManager
.find(id
);
221 if (nextPage
instanceof ActionContributionItem
) {
222 IAction action
= ((ActionContributionItem
) nextPage
).getAction();
223 if (action
!= null) {
224 action
.setChecked(checked
);