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
.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
;
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(Messages
.SequenceDiagram_ZoomIn
);
127 setToolTipText(Messages
.SequenceDiagram_ZoomInTheDiagram
);
129 setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
133 setText(Messages
.SequenceDiagram_ZoomOut
);
134 setToolTipText(Messages
.SequenceDiagram_ZoomOutTheDiagram
);
136 setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
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
));
148 setText(Messages
.SequenceDiagram_Select
);
149 setToolTipText(Messages
.SequenceDiagram_Select
);
151 setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SELECT_MENU
));
156 // ------------------------------------------------------------------------
158 // ------------------------------------------------------------------------
163 if ((fView
== null) || (fView
.getSDWidget() == null)) {
167 SDWidget viewer
= fView
.getSDWidget();
169 if (getId().equals(ZOOM_OUT_ID
)) {
170 // Eclipse 3.0 M7 workaround
171 if (fLastZoomOut
== isChecked()) {
172 setChecked(!isChecked());
175 viewer
.setZoomOutMode(isChecked());
176 fLastZoomOut
= isChecked();
179 viewer
.setCursor(fZoomOutCursor
);
180 setActionChecked(NO_ZOOM_ID
, false);
182 viewer
.setCursor(new Cursor(Display
.getDefault(), SWT
.CURSOR_ARROW
));
183 setActionChecked(NO_ZOOM_ID
, true);
185 } else if (getId().equals(ZOOM_IN_ID
)) {
186 // Eclipse 3.0 M7 workaround
187 if (fLastZoomIn
== isChecked()) {
188 setChecked(!isChecked());
191 viewer
.setZoomInMode(isChecked());
192 fLastZoomIn
= isChecked();
195 viewer
.setCursor(fZoomInCursor
);
196 setActionChecked(NO_ZOOM_ID
, false);
198 viewer
.setCursor(new Cursor(Display
.getDefault(), SWT
.CURSOR_ARROW
));
199 setActionChecked(NO_ZOOM_ID
, true);
201 } else if (getId().equals(RESET_ZOOM_ID
)) {
202 viewer
.resetZoomFactor();
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
209 setActionChecked(NO_ZOOM_ID
, true);
210 } else if (getId().equals(NO_ZOOM_ID
)) {
212 viewer
.setZoomInMode(false);
213 viewer
.setZoomInMode(false);
214 viewer
.setCursor(new Cursor(Display
.getDefault(), SWT
.CURSOR_ARROW
));
219 * Set action check state of a view action for a given action ID.
221 * @param id The action ID
222 * @param checked true to check the action, false to uncheck the action
224 protected void setActionChecked(String id
, boolean checked
) {
226 IActionBars bar
= fView
.getViewSite().getActionBars();
230 IToolBarManager barManager
= bar
.getToolBarManager();
231 if (barManager
== null) {
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
);