root / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / core / util / Crono.java @ 5412
History | View | Annotate | Download (4.69 KB)
1 |
/*
|
---|---|
2 |
* Created on 20-feb-2006
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
/* CVS MESSAGES:
|
45 |
*
|
46 |
* $Id: Crono.java 5412 2006-05-24 21:15:07Z azabala $
|
47 |
* $Log$
|
48 |
* Revision 1.1 2006-05-24 21:12:36 azabala
|
49 |
* primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
|
50 |
*
|
51 |
* Revision 1.1 2006/02/20 19:43:27 azabala
|
52 |
* *** empty log message ***
|
53 |
*
|
54 |
*
|
55 |
*/
|
56 |
package com.iver.cit.gvsig.geoprocess.core.util; |
57 |
|
58 |
import java.awt.*; |
59 |
import java.awt.geom.*; |
60 |
import java.awt.event.*; |
61 |
import javax.swing.*; |
62 |
|
63 |
/**
|
64 |
* Component to see time (used to monitoring long processes).
|
65 |
*
|
66 |
* @author azabala
|
67 |
*
|
68 |
*/
|
69 |
public class Crono extends JComponent implements ActionListener { |
70 |
/**
|
71 |
*
|
72 |
*/
|
73 |
private static final long serialVersionUID = -7534000624022602134L; |
74 |
|
75 |
private final int ox = 4; |
76 |
|
77 |
private final int oy = 4; |
78 |
|
79 |
private int tam; |
80 |
|
81 |
private long start; |
82 |
|
83 |
private long end; |
84 |
|
85 |
private boolean counting; |
86 |
|
87 |
private Timer timer; |
88 |
|
89 |
/**
|
90 |
* @roseuid 3CA83ED3006E
|
91 |
*/
|
92 |
public Crono() {
|
93 |
this(50); |
94 |
} |
95 |
|
96 |
/**
|
97 |
* @roseuid 3CA83ED3006F
|
98 |
*/
|
99 |
public Crono(int tam) { |
100 |
this.tam = tam;
|
101 |
start = end = System.currentTimeMillis();
|
102 |
timer = new Timer(1000, this); |
103 |
setPreferredSize(new Dimension(tam + 8, tam + 30)); |
104 |
counting = false;
|
105 |
} |
106 |
|
107 |
/**
|
108 |
* @roseuid 3CA83ED3007E
|
109 |
*/
|
110 |
public void actionPerformed(ActionEvent e) { |
111 |
end = System.currentTimeMillis();
|
112 |
repaint(); |
113 |
} |
114 |
|
115 |
/**
|
116 |
* @roseuid 3CA83ED30080
|
117 |
*/
|
118 |
private float posx(int radio, int grados) { |
119 |
return (float) (radio * Math.cos(Math.toRadians(grados - 90))); |
120 |
} |
121 |
|
122 |
/**
|
123 |
* @roseuid 3CA83ED3008D
|
124 |
*/
|
125 |
private float posy(int radio, int grados) { |
126 |
return (float) (radio * Math.sin(Math.toRadians(grados - 90))); |
127 |
} |
128 |
|
129 |
/**
|
130 |
* @roseuid 3CA83ED30090
|
131 |
*/
|
132 |
public void paintComponent(Graphics gr) { |
133 |
this.paintBorder(gr);
|
134 |
Graphics2D g = (Graphics2D) gr; |
135 |
if (counting)
|
136 |
g.setColor(Color.red);
|
137 |
else
|
138 |
g.setColor(Color.green);
|
139 |
g.setStroke(new BasicStroke(3)); |
140 |
g.fillArc(ox, oy, tam, tam, 0, 360); |
141 |
g.setColor(getForeground()); |
142 |
g.drawArc(ox, oy, tam, tam, 0, 360); |
143 |
int radio = tam / 2; |
144 |
int cx = radio + ox;
|
145 |
int cy = radio + oy;
|
146 |
for (int i = 0; i < 360; i += 30) { |
147 |
float x0 = cx + posx(radio, i);
|
148 |
float y0 = cy + posy(radio, i);
|
149 |
float x1 = cx + posx(radio - 5, i); |
150 |
float y1 = cy + posy(radio - 5, i); |
151 |
g.draw(new Line2D.Double(x0, y0, x1, y1)); |
152 |
} |
153 |
|
154 |
long v = end - start;
|
155 |
long m = v / 1000; |
156 |
long mili = v - m * 1000; |
157 |
long s = m / 60; |
158 |
long secs = m - s * 60; |
159 |
long mi = s / 60; |
160 |
long mins = s - mi * 60; |
161 |
|
162 |
float mx = cx + posx(radio - 10, (int) secs * 6); |
163 |
float my = cy + posy(radio - 10, (int) secs * 6); |
164 |
g.draw(new Line2D.Float(cx, cy, mx, my)); |
165 |
mx = cx + posx(radio - 20, (int) mins * 6); |
166 |
my = cy + posy(radio - 20, (int) mins * 6); |
167 |
g.draw(new Line2D.Float(cx, cy, mx, my)); |
168 |
|
169 |
String str = mins + " mins " + secs + " secs"; |
170 |
g.drawString(str, 0, tam + 20); |
171 |
} |
172 |
|
173 |
/**
|
174 |
* Para el reloj y vuelve a la situacion inicial.
|
175 |
*
|
176 |
* @roseuid 3CA83ED3009C
|
177 |
*/
|
178 |
public void reset() { |
179 |
timer.stop(); |
180 |
counting = false;
|
181 |
start = end = System.currentTimeMillis();
|
182 |
repaint(); |
183 |
} |
184 |
|
185 |
/**
|
186 |
* Comienza a contar.
|
187 |
*
|
188 |
* @roseuid 3CA83ED3009D
|
189 |
*/
|
190 |
public void start() { |
191 |
timer.start(); |
192 |
counting = true;
|
193 |
start = System.currentTimeMillis();
|
194 |
} |
195 |
|
196 |
/**
|
197 |
* Para de contar
|
198 |
*
|
199 |
* @roseuid 3CA83ED3009E
|
200 |
*/
|
201 |
public void stop() { |
202 |
end = System.currentTimeMillis();
|
203 |
timer.stop(); |
204 |
counting = false;
|
205 |
repaint(); |
206 |
} |
207 |
|
208 |
/**
|
209 |
* retorna el tiempo transcurrido en mili-segundos.
|
210 |
*
|
211 |
* @roseuid 3CA83ED3009F
|
212 |
*/
|
213 |
public long getElapsed() { |
214 |
if (counting)
|
215 |
return System.currentTimeMillis() - start; |
216 |
else
|
217 |
return (end - start);
|
218 |
} |
219 |
} |