KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > apps > svgbrowser > TransformHistory


1 /*
2
3    Copyright 2001,2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.apps.svgbrowser;
19
20 import java.awt.geom.AffineTransform JavaDoc;
21 import java.util.ArrayList JavaDoc;
22 import java.util.List JavaDoc;
23
24 /**
25  * This class implements a transform history mechanism.
26  *
27  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
28  * @version $Id: TransformHistory.java,v 1.4 2004/08/18 07:12:27 vhardy Exp $
29  */

30 public class TransformHistory {
31     
32     /**
33      * The transform stack.
34      */

35     protected List JavaDoc transforms = new ArrayList JavaDoc();
36
37     /**
38      * The current position in the stack.
39      */

40     protected int position = -1;
41
42     /**
43      * Goes back of one position in the history.
44      * Assumes that <tt>canGoBack()</tt> is true.
45      */

46     public void back() {
47         position -= 2;
48     }
49
50     /**
51      * Whether it is possible to go back.
52      */

53     public boolean canGoBack() {
54         return position > 0;
55     }
56
57     /**
58      * Goes forward of one position in the history.
59      * Assumes that <tt>canGoForward()</tt> is true.
60      */

61     public void forward() {
62     }
63
64     /**
65      * Whether it is possible to go forward.
66      */

67     public boolean canGoForward() {
68         return position < transforms.size() - 1;
69     }
70
71     /**
72      * Returns the current transform.
73      */

74     public AffineTransform JavaDoc currentTransform() {
75         return (AffineTransform JavaDoc)transforms.get(position + 1);
76     }
77
78     /**
79      * Adds a transform to the history.
80      */

81     public void update(AffineTransform JavaDoc at) {
82         if (position < -1) {
83             position = -1;
84         }
85         if (++position < transforms.size()) {
86             if (!transforms.get(position).equals(at)) {
87                 transforms = transforms.subList(0, position + 1);
88             }
89             transforms.set(position, at);
90         } else {
91             transforms.add(at);
92         }
93     }
94 }
95
Popular Tags