Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / raster / beans / canvas / layers / InfoLayer.java @ 22103

History | View | Annotate | Download (5.4 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.raster.beans.canvas.layers;
20

    
21
import java.awt.Color;
22
import java.awt.Graphics;
23
import java.awt.Graphics2D;
24
import java.awt.RenderingHints;
25
import java.awt.geom.Rectangle2D;
26
import java.util.ArrayList;
27

    
28
import org.gvsig.raster.beans.canvas.DrawableElement;
29
import org.gvsig.raster.util.MathUtils;
30
/**
31
 * Capa para GCanvas que muestra el maximo y minimo de una banda
32
 * 
33
 * @version 04/03/2008
34
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
35
 */
36
public class InfoLayer extends DrawableElement {
37
        private Color color = null;
38
        private double min = 0.0;
39
        private double max = 1.0;
40
        private String statusRight = null;
41
        private String statusLeft = null;
42

    
43
        /**
44
         * Creacion de un InfoLayer especificando el color
45
         * @param c
46
         */
47
        public InfoLayer(Color c) {
48
                color = c;
49
        }
50

    
51
        /**
52
         * Definir el borde que va a tener el componente
53
         */
54
        public void firstActions() {
55
                canvas.addBorder(0, 15, 0, 15);
56
        }
57
        
58
        /**
59
         * Establecer los valores maximo y minimo para dicha capa
60
         * @param min
61
         * @param max
62
         */
63
        public void setLimits(double min, double max) {
64
                this.min = min;
65
                this.max = max;
66
        }
67

    
68
        /*
69
         * (non-Javadoc)
70
         * @see org.gvsig.raster.beans.canvas.DrawableElement#paint(java.awt.Graphics)
71
         */
72
        protected void paint(Graphics g) {
73
                
74
                Graphics2D graphics2 = (Graphics2D) g;
75

    
76
                RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
77
                hints.add(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
78
                graphics2.setRenderingHints(hints);
79

    
80
                graphics2.setColor(color);
81
                graphics2.setFont(new java.awt.Font("Times", 1, 12));
82
                
83
                String min2 = MathUtils.clipDecimals(min, 1) + "";
84
                String max2 = MathUtils.clipDecimals(max, 1) + "";
85

    
86
                Rectangle2D rectangle2D = graphics2.getFontMetrics().getStringBounds(max2, g);
87
                
88
                graphics2.drawString(min2, canvas.getCanvasMinX(), canvas.getCanvasMinX() + 12);
89
                graphics2.drawString(max2, (int) (canvas.getWidth() - rectangle2D.getWidth() - canvas.getCanvasMinX()), canvas.getCanvasMinX() + 12);
90
                
91
                if (statusRight != null) {
92
                        rectangle2D = graphics2.getFontMetrics().getStringBounds(statusRight, g);
93
                        graphics2.drawString(statusRight, (int) (canvas.getWidth() - rectangle2D.getWidth() - canvas.getCanvasMinX()), (int) canvas.getHeight() - canvas.getCanvasMinX());
94
                }
95

    
96
                if (statusLeft != null) {
97
                        graphics2.drawString(statusLeft, canvas.getCanvasMinX(), (int) canvas.getHeight() - canvas.getCanvasMinX());
98
                }
99
                
100
                ArrayList list = canvas.getDrawableElements(MinMaxLines.class);
101
                if (list.size() > 0) {
102
                        MinMaxLines minMaxLines = (MinMaxLines) list.get(0);
103

    
104
                        double minP = min + (minMaxLines.getMinDistance() * (max - min));
105
                        double maxP = min + (minMaxLines.getMaxDistance() * (max - min));
106
                        min2 = MathUtils.clipDecimals(minP, 1) + "";
107
                        max2 = MathUtils.clipDecimals(maxP, 1) + "";
108

    
109
                        list = canvas.getDrawableElements(GraphicHistogram.class);
110
                        if (list.size() > 0) {
111
                                GraphicHistogram histogram = (GraphicHistogram) list.get(0);
112
                                double[] ds = histogram.getHistogramValues();
113
                                double total = 0.0D;
114
                                double totalmin = 0.0D;
115
                                double totalmax = 0.0D;
116
                                for (int i = 0; i < ds.length; i++) {
117
                                        double value = min + (((double) (i * (max - min))) / (double) (ds.length - 1.0D));
118
                                        total += ds[i];
119
                                        if (minP > value)
120
                                                totalmin += ds[i];
121
                                        if (maxP < value)
122
                                                totalmax += ds[i];
123
                                }
124

    
125
                                totalmin = (100.0D * totalmin) / total;
126
                                totalmax = (100.0D * totalmax) / total;
127

    
128
                                min2 = min2 + " (" + MathUtils.clipDecimals(totalmin, 2) + "%)";
129
                                max2 = max2 + " (" + MathUtils.clipDecimals(totalmax, 2) + "%)";
130
                        }
131

    
132
                        rectangle2D = graphics2.getFontMetrics().getStringBounds(max2, g);
133

    
134
                        if (statusLeft == null)
135
                                graphics2.drawString(min2, canvas.getCanvasMinX(), (int) canvas.getHeight() - canvas.getCanvasMinX());
136

    
137
                        if (statusRight == null)
138
                                graphics2.drawString(max2, (int) (canvas.getWidth() - rectangle2D.getWidth() - canvas.getCanvasMinX()), (int) canvas.getHeight() - canvas.getCanvasMinX());
139
                }
140
        }
141
        
142
        /**
143
         * @return the min
144
         */
145
        public double getMin() {
146
                return min;
147
        }
148

    
149
        /**
150
         * @return the max
151
         */
152
        public double getMax() {
153
                return max;
154
        }
155
        
156
        /**
157
         * @param status the status to set
158
         */
159
        public void setStatusRight(String statusRight) {
160
                this.statusRight = statusRight;
161
        }
162
        
163
        /**
164
         * @param statusLeft the statusLeft to set
165
         */
166
        public void setStatusLeft(String statusLeft) {
167
                this.statusLeft = statusLeft;
168
        }
169
        
170
        public void firstDrawActions() {}
171
}