Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / ViewPort.java @ 214

History | View | Annotate | Download (4.73 KB)

1
/* Generated by Together */
2

    
3
package com.iver.cit.gvsig.fmap;
4

    
5
import java.awt.Color;
6
import java.awt.Dimension;
7
import java.awt.geom.AffineTransform;
8
import java.awt.geom.Point2D;
9
import java.awt.geom.Rectangle2D;
10
import java.util.ArrayList;
11

    
12
public class ViewPort {        
13
        public static int KILOMETROS = 1;
14
        public static int METROS = 2;
15
        public static int MILLAS = 3;
16
        public static int YARDAS = 4;
17
        public static int PIES = 5;
18
        public static int PULGADAS = 6;
19

    
20
    private Rectangle2D extent;
21
    private Rectangle2D adjustedExtent;
22
    private ExtentHistory extents = new ExtentHistory();
23
    private Dimension imageSize;
24
    private AffineTransform trans = new AffineTransform();
25
        private int distanceUnits = METROS;
26
        private int mapUnits = METROS;
27

    
28
    private ArrayList extentListeners;
29
    private Point2D offset = new Point2D.Double(0, 0);
30
    private Rectangle2D clip;
31
        private Color backColor = Color.WHITE;
32
        
33
        private double scale;
34

    
35
        public boolean addExtentListener(ExtentListener arg0) {
36
                return extentListeners.add(arg0);
37
        }
38

    
39
        public boolean removeExtentListener(ExtentListener arg0) {
40
                return extentListeners.remove(arg0);
41
        }
42

    
43
    public int fromMapDistance(double d) {
44
            //TODO Implementar bien
45
            return -1;
46
    }
47

    
48
    public Point2D fromMapPoint(double x, double y) {
49
            //TODO Implementar bien
50
            return null;
51
    }
52

    
53
    public Point2D toMapPoint(int x, int y) {
54
            //TODO Implementar bien
55
            return null;
56
    }
57

    
58
    public double toMapDistance(int d) {
59
            //TODO Implementar bien
60
            return -1;
61
    }
62

    
63
    public Point2D toMapPoint(Point2D pScreen) {
64
            //TODO Implementar bien
65
            return null;
66
    }
67

    
68
    public void setPreviousExtent() {
69
    }
70

    
71
    public Rectangle2D getExtent() {
72
            return extent;
73
    }
74

    
75
    public void setExtent(Rectangle2D r) {
76
            extent = r;
77
            //TODO calcular la escala sin usar setScale
78
            
79
            //Calcula la transformaci?n af?n
80
            calculateAffineTransform();
81
    }
82

    
83
    public void setScale(double scale) {
84
            this.scale = scale;
85
            
86
            //TODO calcular el extent sin usar setExtent
87
            
88
            //Calcula la transformaci?n af?n
89
            calculateAffineTransform();
90
    }
91

    
92
    /**
93
     * Devuelve la escala. Debe estar siempre actualizada y
94
     * no calcularse nunca aqu? pues se utiliza en el dibujado
95
     * para cada geometr?a
96
     * @return
97
     */
98
    public double getScale() {
99
            return scale;
100
    }
101

    
102
        /**
103
         * @return
104
         */
105
        public AffineTransform getAffineTransform() {
106
                return trans;
107
        }
108
        /**
109
         * @return Returns the imageSize.
110
         */
111
        public Dimension getImageSize() {
112
                return imageSize;
113
        }
114
        /**
115
         * @param imageSize The imageSize to set.
116
         */
117
        public void setImageSize(Dimension imageSize) {
118
                this.imageSize = imageSize;
119
                calculateAffineTransform();
120
        }
121

    
122
        /**
123
         * 
124
         */
125
        private void calculateAffineTransform() {
126
                if ((imageSize == null) || (extent == null)) return;
127
                        
128
        AffineTransform escalado = new AffineTransform();
129
        AffineTransform translacion = new AffineTransform();
130

    
131
        double escalaX;
132
        double escalaY;
133

    
134
        escalaX = imageSize.getWidth() / extent.getWidth();
135
        escalaY = imageSize.getHeight() / extent.getHeight();
136

    
137
        adjustedExtent = new Rectangle2D.Double();
138
        if (escalaX < escalaY) {
139
            scale = escalaX;
140
            adjustedExtent.setRect(extent.getX(), extent.getY(), extent.getWidth(), imageSize.getHeight() / scale);
141
        } else {
142
            scale = escalaY;
143
            adjustedExtent.setRect(extent.getX(), extent.getY(), imageSize.getWidth() / scale, extent.getHeight());
144
        }
145

    
146
        translacion.setToTranslation(-adjustedExtent.getX(), -adjustedExtent.getY() -
147
                        adjustedExtent.getHeight());
148
        escalado.setToScale(scale, -scale);
149

    
150
        AffineTransform offsetTrans = new AffineTransform();
151
        offsetTrans.setToTranslation(offset.getX(), offset.getY());
152

    
153
        trans.setToIdentity();
154
        trans.concatenate(offsetTrans);
155
        trans.concatenate(escalado);
156

    
157
        trans.concatenate(translacion);
158
        }
159

    
160
        public void setBackColor(Color c) {
161
                backColor = c;
162
        }
163

    
164
        public Color getBackColor() {
165
                return backColor;
166
        }
167
        /**
168
         * @return Returns the adjustedExtent.
169
         */
170
        public Rectangle2D getAdjustedExtent() {
171
                return adjustedExtent;
172
        }
173
        /**
174
         * @return Returns the distanceUnits.
175
         */
176
        public int getDistanceUnits() {
177
                return distanceUnits;
178
        }
179
        /**
180
         * @param distanceUnits The distanceUnits to set.
181
         */
182
        public void setDistanceUnits(int distanceUnits) {
183
                this.distanceUnits = distanceUnits;
184
        }
185
        /**
186
         * @return Returns the mapUnits.
187
         */
188
        public int getMapUnits() {
189
                return mapUnits;
190
        }
191
        /**
192
         * @param mapUnits The mapUnits to set.
193
         */
194
        public void setMapUnits(int mapUnits) {
195
                this.mapUnits = mapUnits;
196
        }        
197
        
198
        public int getImageWidth(){
199
                return imageSize.width;
200
        }
201
        
202
        public int getImageHeight(){
203
                return imageSize.height;
204
        }
205
}