/**********************************************************************
- * Copyright (c) 2005, 2008, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2014 IBM Corporation, Ericsson
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- * $Id: Zoom.java,v 1.3 2008/01/24 02:28:52 apnan Exp $
- *
- * Contributors:
- * IBM - Initial API and implementation
- * Bernd Hufmann - Updated for TMF
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ * Bernd Hufmann - Updated for TMF
**********************************************************************/
+
package org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers;
-import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IToolBarManager;
-import org.eclipse.linuxtools.tmf.ui.ITmfImageConstants;
-import org.eclipse.linuxtools.tmf.ui.TmfUiPlugin;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants;
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView;
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget;
-import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.SDMessages;
+import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.Messages;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IActionBars;
/**
+ * Action class implementation for zooming in, out or reset of zoom.
+ *
+ * @version 1.0
* @author sveyrier
- *
+ *
*/
-public class Zoom extends Action {
+public class Zoom extends BaseSDAction {
+
+ // ------------------------------------------------------------------------
+ // Constants
+ // ------------------------------------------------------------------------
+ /**
+ * The Action ID for zooming in.
+ */
+ public static final String ZOOM_IN_ID = "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ZoomInCoolBar"; //$NON-NLS-1$
+ /**
+ * The Action ID for zooming out.
+ */
+ public static final String ZOOM_OUT_ID = "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ZoomOutCoolBar"; //$NON-NLS-1$
+ /**
+ * The Action ID for reset zooming.
+ */
+ public static final String RESET_ZOOM_ID = "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ResetZoom"; //$NON-NLS-1$
+ /**
+ * The Action ID for no zoominf.
+ */
+ public static final String NO_ZOOM_ID = "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.NoZoom"; //$NON-NLS-1$
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
- public final static String ZOOM_IN_ID = "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ZoomInCoolBar"; //$NON-NLS-1$
- public final static String ZOOM_OUT_ID = "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ZoomOutCoolBar"; //$NON-NLS-1$
- public final static String RESET_ZOOM_ID = "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ResetZoom"; //$NON-NLS-1$
- public final static String NO_ZOOM_ID = "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.NoZoom"; //$NON-NLS-1$
-
- protected SDView fView = null;
- protected boolean fLastZoomIn = false;
- protected boolean fLastZoomOut = false;
- protected boolean fLastZoom = true;
-
- private static Cursor fZoomInCursor;
- private static Cursor fZoomOutCursor;
+ /**
+ * Flag to indicate last zoom in.
+ */
+ private boolean fLastZoomIn = false;
+ /**
+ * Flag to indicate last zoom out.
+ */
+ private boolean fLastZoomOut = false;
+ /**
+ * The cursor used when zooming in.
+ */
+ private final Cursor fZoomInCursor;
+ /**
+ * The cursor used when zooming out.
+ */
+ private final Cursor fZoomOutCursor;
+ /**
+ * The different zoom actions
+ */
public static enum ZoomType {
- ZOOM_NONE, ZOOM_IN, ZOOM_OUT, ZOOM_RESET
- };
+ /** No zoom information */
+ ZOOM_NONE,
+ /** Zoom in */
+ ZOOM_IN,
+ /** Zoom out */
+ ZOOM_OUT,
+ /** Reset to the default zoom level */
+ ZOOM_RESET
+ }
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
- public Zoom(SDView _view, ZoomType type) {
- super("", AS_RADIO_BUTTON);//$NON-NLS-1$
- fView = _view;
-
- if ((fZoomInCursor != null) && (!fZoomInCursor.isDisposed())) {
- fZoomInCursor.dispose();
- }
- if ((fZoomOutCursor != null) && (!fZoomOutCursor.isDisposed())) {
- fZoomOutCursor.dispose();
- }
+ /**
+ * Constructor
+ * @param view The view reference
+ * @param type The type of zoom.
+ */
+ public Zoom(SDView view, ZoomType type) {
+ super(view, "", AS_RADIO_BUTTON); //$NON-NLS-1$
// Pre-create zooming cursors
- fZoomInCursor = new Cursor(Display.getCurrent(),
- TmfUiPlugin.getDefault().getImageFromImageRegistry(ITmfImageConstants.IMG_UI_ZOOM_IN).getImageData(),
- TmfUiPlugin.getDefault().getImageFromImageRegistry(ITmfImageConstants.IMG_UI_ZOOM).getImageData(), 0, 0);
-
- fZoomOutCursor = new Cursor(Display.getCurrent(),
- TmfUiPlugin.getDefault().getImageFromImageRegistry(ITmfImageConstants.IMG_UI_ZOOM_OUT).getImageData(),
- TmfUiPlugin.getDefault().getImageFromImageRegistry(ITmfImageConstants.IMG_UI_ZOOM).getImageData(), 0, 0);
+ fZoomInCursor = new Cursor(Display.getCurrent(),
+ Activator.getDefault().getImageFromImageRegistry(ITmfImageConstants.IMG_UI_ZOOM_IN).getImageData(),
+ Activator.getDefault().getImageFromImageRegistry(ITmfImageConstants.IMG_UI_ZOOM).getImageData(), 0, 0);
+
+ fZoomOutCursor = new Cursor(Display.getCurrent(),
+ Activator.getDefault().getImageFromImageRegistry(ITmfImageConstants.IMG_UI_ZOOM_OUT).getImageData(),
+ Activator.getDefault().getImageFromImageRegistry(ITmfImageConstants.IMG_UI_ZOOM).getImageData(), 0, 0);
switch (type) {
case ZOOM_IN:
- setText(SDMessages._47);
- setToolTipText(SDMessages._48);
+ setText(Messages.SequenceDiagram_ZoomIn);
+ setToolTipText(Messages.SequenceDiagram_ZoomInTheDiagram);
setId(ZOOM_IN_ID);
- setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_IN_MENU));
+ setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_IN_MENU));
break;
case ZOOM_OUT:
- setText(SDMessages._51);
- setToolTipText(SDMessages._52);
+ setText(Messages.SequenceDiagram_ZoomOut);
+ setToolTipText(Messages.SequenceDiagram_ZoomOutTheDiagram);
setId(ZOOM_OUT_ID);
- setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_OUT_MENU));
+ setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_OUT_MENU));
break;
case ZOOM_RESET:
- setText(SDMessages._49);
- setToolTipText(SDMessages._50);
+ setText(Messages.SequenceDiagram_ResetZoomFactor);
+ setToolTipText(Messages.SequenceDiagram_ResetZoomFactor);
setId(RESET_ZOOM_ID);
- setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_HOME_MENU));
+ setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_HOME_MENU));
break;
+ case ZOOM_NONE:
default:
- // ZoomType.NONE
- setText(SDMessages._53);
- setToolTipText(SDMessages._54);
- setId(NO_ZOOM_ID);
- setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SELECT_MENU));
+ setText(Messages.SequenceDiagram_Select);
+ setToolTipText(Messages.SequenceDiagram_Select);
+ setId(NO_ZOOM_ID);
+ setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SELECT_MENU));
break;
}
}
// ------------------------------------------------------------------------
- // Operations
+ // Methods
// ------------------------------------------------------------------------
- /*
- * (non-Javadoc)
- * @see org.eclipse.jface.action.Action#run()
- */
+
@Override
public void run() {
-
- if ((fView == null) || (fView.getSDWidget() == null)) {
+
+ if ((getView() == null) || (getView().getSDWidget() == null)) {
return;
}
- SDWidget viewer = fView.getSDWidget();
+ SDWidget viewer = getView().getSDWidget();
if (getId().equals(ZOOM_OUT_ID)) {
// Eclipse 3.0 M7 workaround
viewer.setZoomOutMode(isChecked());
fLastZoomOut = isChecked();
- fLastZoom = false;
if (isChecked()) {
viewer.setCursor(fZoomOutCursor);
setActionChecked(NO_ZOOM_ID, false);
viewer.setZoomInMode(isChecked());
fLastZoomIn = isChecked();
- fLastZoom = false;
if (isChecked()) {
viewer.setCursor(fZoomInCursor);
setActionChecked(NO_ZOOM_ID, false);
// The reset action is a radio button only to uncheck the zoom in and out button
// when it is clicked. This avoid adding code to do it manually
// We only have to force it to false every time
- fLastZoom = false;
setChecked(false);
setActionChecked(NO_ZOOM_ID, true);
} else if (getId().equals(NO_ZOOM_ID)) {
/**
* Set action check state of a view action for a given action ID.
+ *
* @param id The action ID
* @param checked true to check the action, false to uncheck the action
*/
protected void setActionChecked(String id, boolean checked) {
- if (fView != null) {
- IActionBars bar = fView.getViewSite().getActionBars();
+ if (getView() != null) {
+ IActionBars bar = getView().getViewSite().getActionBars();
if (bar == null) {
return;
}
return;
}
IContributionItem nextPage = barManager.find(id);
- if (nextPage != null && nextPage instanceof ActionContributionItem) {
+ if (nextPage instanceof ActionContributionItem) {
IAction action = ((ActionContributionItem) nextPage).getAction();
if (action != null) {
action.setChecked(checked);
}
}
}
+
+ /**
+ * Dispose the action and its resources
+ *
+ * @since 3.2
+ */
+ public void dispose() {
+ fZoomInCursor.dispose();
+ fZoomOutCursor.dispose();
+ }
}