1 /*
2 * File: ScaleMonthAction.java
3 * Copyright (c) 2004-2007 Peter Kliem (Peter.Kliem@jaret.de)
4 * A commercial license is available, see http://www.jaret.de.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 package de.jaret.util.ui.timebars.swt.util.actions;
21
22 import org.eclipse.jface.action.Action;
23
24 import de.jaret.util.ui.timebars.TimeBarViewerDelegate;
25 import de.jaret.util.ui.timebars.swt.TimeBarViewer;
26
27 /**
28 * Scale the time scale to approx one month.
29 *
30 * @author Peter Kliem
31 * @version $Id: ScaleMonthAction.java 160 2007-01-02 22:02:40Z olk $
32 */
33 public class ScaleMonthAction extends Action {
34 /** the timebarviewer th action has been constructed for. */
35 private final TimeBarViewer _viewer;
36 /** the delegate of the timebarviewer. */
37 private final TimeBarViewerDelegate _delegate;
38
39 /**
40 * Constructor.
41 *
42 * @param viewer timebar viewer
43 * @param delegate delegate of the viewer.
44 */
45 public ScaleMonthAction(TimeBarViewer viewer, TimeBarViewerDelegate delegate) {
46 _viewer = viewer;
47 _delegate = delegate;
48 }
49
50 /**
51 * {@inheritDoc}
52 */
53 public void run() {
54 int width = _delegate.getDiagramRect().width;
55 double pps = (double) width / (30.0 * 24.0 * 60.0 * 60.0);
56 _viewer.setPixelPerSecond(pps);
57 }
58
59 /**
60 * {@inheritDoc}
61 */
62 public String getText() {
63 return "Scale to month";
64 }
65 }