1 /*
2 * This file is a part of CAST project.
3 * (c) Copyright 2009, 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: ExtendedZoomManager.java
13 * Created: 2009-03-01
14 * Author: skalkow
15 * $Id: ExtendedZoomManager.java 2489 2009-03-01 14:12:32Z skalkow $
16 */
17
18 package pl.edu.agh.cast.editor;
19
20 import java.util.LinkedList;
21 import java.util.List;
22
23 import org.eclipse.draw2d.ScalableFigure;
24 import org.eclipse.draw2d.Viewport;
25 import org.eclipse.gef.editparts.ZoomManager;
26
27 /**
28 * Represents implementation of {@link ZoomManager} with changed default zoom levels.
29 *
30 * @author AGH CAST Team
31 */
32 public class ExtendedZoomManager extends ZoomManager {
33
34 /**
35 * Zoom levels table which contains standard zoom levels and scales zoom levels.
36 */
37 private double[] zoomLevels;
38
39 /**
40 * Table with standard zoom levels.
41 */
42 private static final double[] standardZoomLevels = { .5, .75, 1.0, 1.5, 2.0, 2.5, 3, 4 };
43
44 /**
45 * Public constructor.
46 *
47 * @param pane
48 * the {@link ScalableFigure} associated with this ZoomManager
49 * @param viewport
50 * the {@link Viewport} associated with this ZoomManager
51 */
52 public ExtendedZoomManager(ScalableFigure pane, Viewport viewport) {
53 super(pane, viewport);
54 }
55
56 /** {@inheritDoc} */
57 public double getMaxZoom() {
58 if (zoomLevels != null) {
59 return zoomLevels[zoomLevels.length - 1];
60 } else {
61 return super.getMaxZoom();
62 }
63 }
64
65 /** {@inheritDoc} */
66 public double getMinZoom() {
67 if (zoomLevels != null) {
68 return zoomLevels[0];
69 } else {
70 return super.getMinZoom();
71 }
72 }
73
74 /**
75 * Generates zoom levels list, based on given fit all zoom level value.
76 *
77 * @param fitAllZoomValue
78 * double value of zoom level, which corresponds with FIT_ALL zoom level.
79 */
80 public void scaleZoomLevels(double fitAllZoomValue) {
81 // add scaled zoom levels
82 List<Double> zoomLevelsList = new LinkedList<Double>();
83 while (fitAllZoomValue < 0.5) {
84 zoomLevelsList.add(new Double(fitAllZoomValue));
85 fitAllZoomValue *= 2.0;
86 }
87 // add standard zoom levels
88 for (double zoomLevel : standardZoomLevels) {
89 zoomLevelsList.add(new Double(zoomLevel));
90 }
91
92 // set new zoom levels
93 int i = 0;
94 this.zoomLevels = new double[zoomLevelsList.size()];
95 for (Double zoomValue : zoomLevelsList) {
96 this.zoomLevels[i++] = zoomValue.doubleValue();
97 }
98 setZoomLevels(this.zoomLevels);
99 }
100
101 }