1 /**********************************************************************
2 * Copyright (c) 2005, 2008, 2011 IBM Corporation and others.
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
7 * $Id: Zoom.java,v 1.3 2008/01/24 02:28:52 apnan Exp $
10 * IBM - Initial API and implementation
11 * Bernd Hufmann - Updated for TMF
12 **********************************************************************/
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
.tmf
.ui
.ITmfImageConstants
;
21 import org
.eclipse
.linuxtools
.tmf
.ui
.TmfUiPlugin
;
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
;
34 public class Zoom
extends Action
{
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
39 public final static String ZOOM_IN_ID
= "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ZoomInCoolBar"; //$NON-NLS-1$
40 public final static String ZOOM_OUT_ID
= "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ZoomOutCoolBar"; //$NON-NLS-1$
41 public final static String RESET_ZOOM_ID
= "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ResetZoom"; //$NON-NLS-1$
42 public final static String NO_ZOOM_ID
= "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.NoZoom"; //$NON-NLS-1$
44 protected SDView fView
= null;
45 protected boolean fLastZoomIn
= false;
46 protected boolean fLastZoomOut
= false;
47 protected boolean fLastZoom
= true;
49 private static Cursor fZoomInCursor
;
50 private static Cursor fZoomOutCursor
;
52 public static enum ZoomType
{
53 ZOOM_NONE
, ZOOM_IN
, ZOOM_OUT
, ZOOM_RESET
56 // ------------------------------------------------------------------------
58 // ------------------------------------------------------------------------
59 public Zoom(SDView _view
, ZoomType type
) {
60 super("", AS_RADIO_BUTTON
);//$NON-NLS-1$
64 if ((fZoomInCursor
!= null) && (!fZoomInCursor
.isDisposed())) {
65 fZoomInCursor
.dispose();
67 if ((fZoomOutCursor
!= null) && (!fZoomOutCursor
.isDisposed())) {
68 fZoomOutCursor
.dispose();
71 // Pre-create zooming cursors
72 fZoomInCursor
= new Cursor(Display
.getCurrent(),
73 TmfUiPlugin
.getDefault().getImageFromImageRegistry(ITmfImageConstants
.IMG_UI_ZOOM_IN
).getImageData(),
74 TmfUiPlugin
.getDefault().getImageFromImageRegistry(ITmfImageConstants
.IMG_UI_ZOOM
).getImageData(), 0, 0);
76 fZoomOutCursor
= new Cursor(Display
.getCurrent(),
77 TmfUiPlugin
.getDefault().getImageFromImageRegistry(ITmfImageConstants
.IMG_UI_ZOOM_OUT
).getImageData(),
78 TmfUiPlugin
.getDefault().getImageFromImageRegistry(ITmfImageConstants
.IMG_UI_ZOOM
).getImageData(), 0, 0);
82 setText(SDMessages
._47
);
83 setToolTipText(SDMessages
._48
);
85 setImageDescriptor(TmfUiPlugin
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
89 setText(SDMessages
._51
);
90 setToolTipText(SDMessages
._52
);
92 setImageDescriptor(TmfUiPlugin
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
96 setText(SDMessages
._49
);
97 setToolTipText(SDMessages
._50
);
99 setImageDescriptor(TmfUiPlugin
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HOME_MENU
));
104 setText(SDMessages
._53
);
105 setToolTipText(SDMessages
._54
);
107 setImageDescriptor(TmfUiPlugin
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SELECT_MENU
));
112 // ------------------------------------------------------------------------
114 // ------------------------------------------------------------------------
117 * @see org.eclipse.jface.action.Action#run()
122 if ((fView
== null) || (fView
.getSDWidget() == null)) {
126 SDWidget viewer
= fView
.getSDWidget();
128 if (getId().equals(ZOOM_OUT_ID
)) {
129 // Eclipse 3.0 M7 workaround
130 if (fLastZoomOut
== isChecked()) {
131 setChecked(!isChecked());
134 viewer
.setZoomOutMode(isChecked());
135 fLastZoomOut
= isChecked();
138 viewer
.setCursor(fZoomOutCursor
);
139 setActionChecked(NO_ZOOM_ID
, false);
141 viewer
.setCursor(new Cursor(Display
.getDefault(), SWT
.CURSOR_ARROW
));
142 setActionChecked(NO_ZOOM_ID
, true);
144 } else if (getId().equals(ZOOM_IN_ID
)) {
145 // Eclipse 3.0 M7 workaround
146 if (fLastZoomIn
== isChecked()) {
147 setChecked(!isChecked());
150 viewer
.setZoomInMode(isChecked());
151 fLastZoomIn
= isChecked();
154 viewer
.setCursor(fZoomInCursor
);
155 setActionChecked(NO_ZOOM_ID
, false);
157 viewer
.setCursor(new Cursor(Display
.getDefault(), SWT
.CURSOR_ARROW
));
158 setActionChecked(NO_ZOOM_ID
, true);
160 } else if (getId().equals(RESET_ZOOM_ID
)) {
161 viewer
.resetZoomFactor();
163 // The reset action is a radio button only to uncheck the zoom in and out button
164 // when it is clicked. This avoid adding code to do it manually
165 // We only have to force it to false every time
168 setActionChecked(NO_ZOOM_ID
, true);
169 } else if (getId().equals(NO_ZOOM_ID
)) {
171 viewer
.setZoomInMode(false);
172 viewer
.setZoomInMode(false);
173 viewer
.setCursor(new Cursor(Display
.getDefault(), SWT
.CURSOR_ARROW
));
178 * Set action check state of a view action for a given action ID.
179 * @param id The action ID
180 * @param checked true to check the action, false to uncheck the action
182 protected void setActionChecked(String id
, boolean checked
) {
184 IActionBars bar
= fView
.getViewSite().getActionBars();
188 IToolBarManager barManager
= bar
.getToolBarManager();
189 if (barManager
== null) {
192 IContributionItem nextPage
= barManager
.find(id
);
193 if (nextPage
!= null && nextPage
instanceof ActionContributionItem
) {
194 IAction action
= ((ActionContributionItem
) nextPage
).getAction();
195 if (action
!= null) {
196 action
.setChecked(checked
);