View Javadoc

1   /*
2    * This file is a part of CAST project.
3    * (c) Copyright 2007, AGH University of Science & Technology
4    * https://caribou.iisg.agh.edu.pl/trac/cast
5    *
6    * Licensed under the Eclipse Public License, Version 1.0 (the "License").
7    * You may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    * http://www.eclipse.org/legal/epl-v10.html
10   */
11  /*
12   * File: FitZoomAction.java
13   * Created: 2007-00-00
14   * Author: kornel
15   * $Id: FitZoomAction.java 2892 2009-05-22 10:14:10Z apohllo $
16   */
17  
18  package pl.edu.agh.cast.editor.action;
19  
20  import org.eclipse.gef.Disposable;
21  import org.eclipse.gef.editparts.ZoomListener;
22  import org.eclipse.gef.editparts.ZoomManager;
23  import org.eclipse.jface.action.Action;
24  import org.eclipse.jface.resource.ImageDescriptor;
25  
26  import pl.edu.agh.cast.util.Messages;
27  
28  /**
29   * This class represents action which fits zoom level.
30   *
31   * @author AGH CAST Team
32   */
33  public class FitZoomAction extends Action implements ZoomListener, Disposable {
34  
35  	/**
36  	 * ID of the action.
37  	 */
38  	public static final String ID = "fitZoomAction"; //$NON-NLS-1$
39  
40  	/**
41  	 * The ZoomManager used to zoom in or out.
42  	 */
43  	protected ZoomManager zoomManager;
44  
45  	/**
46  	 * Public constructor.
47  	 *
48  	 * @param text
49  	 *            the action's text, or <code>null</code> if there is no text
50  	 * @param image
51  	 *            the action's image, or <code>null</code> if there is no image
52  	 * @param zoomManager
53  	 *            the ZoomManager used to zoom in or out
54  	 */
55  	public FitZoomAction(String text, ImageDescriptor image, ZoomManager zoomManager) {
56  		super(text, image);
57  		this.zoomManager = zoomManager;
58  		zoomManager.addZoomListener(this);
59  		setToolTipText(Messages.FitZoomAction_0);
60  		setId(ID);
61  		setActionDefinitionId(ID);
62  	}
63  
64  	/**
65  	 * {@inheritDoc}
66  	 *
67  	 * @see org.eclipse.gef.Disposable#dispose()
68  	 */
69  	public void dispose() {
70  		zoomManager.removeZoomListener(this);
71  	}
72  
73  	/**
74  	 * {@inheritDoc}
75  	 *
76  	 * @see org.eclipse.jface.action.Action#run()
77  	 */
78  	@Override
79  	public void run() {
80  		zoomManager.setZoomAsText(ZoomManager.FIT_ALL);
81  	}
82  
83  	/**
84  	 * {@inheritDoc}
85  	 *
86  	 * @see org.eclipse.gef.editparts.ZoomListener#zoomChanged(double)
87  	 */
88  	public void zoomChanged(double zoom) {
89  		setEnabled(true);
90  	}
91  
92  }