root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / pixelincrease / PixelIncreaseDialog.java @ 24986
History | View | Annotate | Download (10.1 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 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.rastertools.pixelincrease; |
20 |
|
21 |
import java.awt.BorderLayout; |
22 |
import java.awt.Color; |
23 |
import java.awt.Graphics; |
24 |
import java.awt.Graphics2D; |
25 |
import java.awt.event.ActionEvent; |
26 |
import java.awt.event.ActionListener; |
27 |
import java.awt.event.MouseEvent; |
28 |
import java.awt.event.MouseListener; |
29 |
import java.awt.geom.AffineTransform; |
30 |
import java.awt.image.BufferedImage; |
31 |
|
32 |
import javax.swing.JCheckBoxMenuItem; |
33 |
import javax.swing.JMenuItem; |
34 |
import javax.swing.JPanel; |
35 |
import javax.swing.JPopupMenu; |
36 |
import javax.swing.event.PopupMenuEvent; |
37 |
import javax.swing.event.PopupMenuListener; |
38 |
|
39 |
import com.iver.andami.PluginServices; |
40 |
import com.iver.andami.ui.mdiManager.IWindow; |
41 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
42 |
import com.iver.cit.gvsig.fmap.tools.CompoundBehavior; |
43 |
import com.iver.cit.gvsig.project.documents.view.gui.IView; |
44 |
|
45 |
|
46 |
/**
|
47 |
* Panel del zoom de la vista sobre el cursor.
|
48 |
*
|
49 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
50 |
*/
|
51 |
public class PixelIncreaseDialog extends JPanel implements IWindow, MouseListener { |
52 |
final private static long serialVersionUID = -3370601314380922368L; |
53 |
private JPopupMenu menu = null; |
54 |
/**
|
55 |
* Ancho y alto de la ventana
|
56 |
*/
|
57 |
private int width = 170; |
58 |
private int height = 170; |
59 |
/**
|
60 |
* Ancho y alto de la ventana
|
61 |
*/
|
62 |
private int w = 0; |
63 |
private int h = 0; |
64 |
/**
|
65 |
* Posici?n de la ventana en X y en Y
|
66 |
*/
|
67 |
private int posWindowX = 0; |
68 |
private int posWindowY = 0; |
69 |
/**
|
70 |
* Escala del zoom
|
71 |
*/
|
72 |
private int scale = 8; |
73 |
/**
|
74 |
* Vista asociada al inspector de pixels
|
75 |
*/
|
76 |
public IView view = null; |
77 |
/**
|
78 |
* Posici?n en X e Y donde se comienza a dibujar dentro del inspector de pixeles
|
79 |
*/
|
80 |
private int posX = 0; |
81 |
private int posY = 0; |
82 |
/**
|
83 |
* Posici?n del pixel en X e Y en relaci?n a las coordenadas del buffer de la vista
|
84 |
*/
|
85 |
public int pixX = 0; |
86 |
public int pixY = 0; |
87 |
/**
|
88 |
* Valores RGB del pixel seleccionado
|
89 |
*/
|
90 |
int red = 0, green = 0, blue = 0; |
91 |
private WindowInfo m_viewinfo = null; |
92 |
private boolean clear = false; |
93 |
private Color color = Color.red; |
94 |
private JCheckBoxMenuItem[] entry = new JCheckBoxMenuItem[6]; |
95 |
|
96 |
/**
|
97 |
* Constructor de la ventana de dialogo para gvSIG.
|
98 |
*/
|
99 |
public PixelIncreaseDialog() {
|
100 |
BorderLayout layout = new BorderLayout(); |
101 |
setLayout(layout); |
102 |
setSize(width, height); |
103 |
addMouseListener(this);
|
104 |
|
105 |
IWindow active = PluginServices.getMDIManager().getActiveWindow(); |
106 |
if(active instanceof IView) { |
107 |
view = (IView)active; |
108 |
WindowInfo wInfo = PluginServices.getMDIManager().getWindowInfo(active); |
109 |
posWindowX = wInfo.getX() + wInfo.getWidth() - width; |
110 |
posWindowY = wInfo.getY(); |
111 |
} |
112 |
|
113 |
CompoundBehavior.setAllControlsBehavior(new PixelIncreaseBehavior(this)); |
114 |
initMenu(); |
115 |
|
116 |
} |
117 |
|
118 |
/**
|
119 |
*
|
120 |
* @param clear
|
121 |
*/
|
122 |
public void setClear(boolean clear) { |
123 |
this.clear = clear;
|
124 |
} |
125 |
|
126 |
/**
|
127 |
* Inicializa el men? contextual con las opciones de selecci?n del
|
128 |
* zoom.
|
129 |
*/
|
130 |
private void initMenu() { |
131 |
menu = new JPopupMenu(); |
132 |
PopupMenuListener lis = new PopupMenuListener() { |
133 |
public void popupMenuCanceled( PopupMenuEvent evt ) { |
134 |
clear = true;
|
135 |
repaint(); |
136 |
} |
137 |
|
138 |
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { |
139 |
} |
140 |
|
141 |
public void popupMenuWillBecomeVisible(PopupMenuEvent e) { |
142 |
} |
143 |
}; |
144 |
menu.addPopupMenuListener(lis); |
145 |
|
146 |
ActionListener al = new ActionListener() { |
147 |
public void actionPerformed( ActionEvent evt ){ |
148 |
String txt = ((JMenuItem)evt.getSource()).getText(); |
149 |
if(txt.compareTo("X4") == 0) { |
150 |
scale = 4;
|
151 |
for (int i = 1; i <= 3; i++) |
152 |
entry[i].setSelected(false);
|
153 |
entry[0].setSelected(true); |
154 |
} |
155 |
if(txt.compareTo("X8") == 0) { |
156 |
scale = 8;
|
157 |
entry[0].setSelected(false); |
158 |
entry[1].setSelected(true); |
159 |
entry[2].setSelected(false); |
160 |
entry[3].setSelected(false); |
161 |
} |
162 |
if(txt.compareTo("X16") == 0) { |
163 |
scale = 16;
|
164 |
entry[0].setSelected(false); |
165 |
entry[1].setSelected(false); |
166 |
entry[2].setSelected(true); |
167 |
entry[3].setSelected(false); |
168 |
} |
169 |
if(txt.compareTo("X32") == 0) { |
170 |
scale = 32;
|
171 |
for (int i = 0; i < 3; i++) |
172 |
entry[i].setSelected(false);
|
173 |
entry[3].setSelected(true); |
174 |
} |
175 |
if(txt.compareTo(PluginServices.getText(this, "green")) == 0) { |
176 |
color = Color.GREEN;
|
177 |
entry[4].setSelected(false); |
178 |
entry[5].setSelected(true); |
179 |
} |
180 |
if(txt.compareTo(PluginServices.getText(this, "red")) == 0) { |
181 |
color = Color.RED;
|
182 |
entry[4].setSelected(true); |
183 |
entry[5].setSelected(false); |
184 |
} |
185 |
} |
186 |
}; |
187 |
|
188 |
entry[0] = new JCheckBoxMenuItem( "X4" ); |
189 |
entry[0].addActionListener( al );
|
190 |
menu.add(entry[0]);
|
191 |
entry[1] = new JCheckBoxMenuItem( "X8" ); |
192 |
entry[1].setSelected(true); |
193 |
entry[1].addActionListener( al );
|
194 |
menu.add(entry[1]);
|
195 |
entry[2] = new JCheckBoxMenuItem( "X16" ); |
196 |
entry[2].addActionListener( al );
|
197 |
menu.add(entry[2]);
|
198 |
entry[3] = new JCheckBoxMenuItem( "X32" ); |
199 |
entry[3].addActionListener( al );
|
200 |
menu.add(entry[3]);
|
201 |
entry[4] = new JCheckBoxMenuItem( PluginServices.getText(this, "red") ); |
202 |
entry[4].addActionListener( al );
|
203 |
entry[4].setSelected(true); |
204 |
menu.add(entry[4]);
|
205 |
entry[5] = new JCheckBoxMenuItem( PluginServices.getText(this, "green") ); |
206 |
entry[5].addActionListener( al );
|
207 |
menu.add(entry[5]);
|
208 |
} |
209 |
|
210 |
/**
|
211 |
* Obtiene el buffer de la vista activa y lo dibuja sobre el panel
|
212 |
* con los datos de escala y desplazamiento seleccionados.
|
213 |
*/
|
214 |
protected void paintComponent(Graphics g) { |
215 |
w = getVisibleRect().width; |
216 |
h = getVisibleRect().height; |
217 |
|
218 |
if(clear) {
|
219 |
g.setColor(Color.BLACK);
|
220 |
g.fillRect(0, 0, w, h); |
221 |
return;
|
222 |
} |
223 |
|
224 |
if(view != null) { |
225 |
int sizeCrux = 10; |
226 |
|
227 |
//Obtenemos valores RGB del Image
|
228 |
BufferedImage img = view.getMapControl().getImage();
|
229 |
int value = 0; |
230 |
try {
|
231 |
value = img.getRGB(pixX, pixY); |
232 |
} catch (ArrayIndexOutOfBoundsException e) { |
233 |
|
234 |
} |
235 |
red = ((value & 0x00ff0000) >> 16); |
236 |
green = ((value & 0x0000ff00) >> 8); |
237 |
blue = (value & 0x000000ff);
|
238 |
|
239 |
//Dibujamos el graphics con el zoom
|
240 |
g.setColor(Color.BLACK);
|
241 |
g.fillRect(0, 0, w, h); |
242 |
((Graphics2D)g).scale(scale, scale);
|
243 |
g.drawImage(img, posX, posY , this);
|
244 |
((Graphics2D)g).setTransform(new AffineTransform()); |
245 |
|
246 |
//Dibujamos la informaci?n RGB y la cruz
|
247 |
//g.setXORMode(Color.WHITE);
|
248 |
g.setColor(color); |
249 |
int middleW = w >> 1; |
250 |
int middleH = h >> 1; |
251 |
g.drawLine(middleW - sizeCrux, middleH, middleW + sizeCrux, middleH); |
252 |
g.drawLine(middleW, middleH - sizeCrux, middleW , middleH + sizeCrux); |
253 |
g.drawString(red + "," + green + "," + blue, w - 85, h - 3); |
254 |
} |
255 |
} |
256 |
|
257 |
/**
|
258 |
* @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
|
259 |
*/
|
260 |
public WindowInfo getWindowInfo() {
|
261 |
m_viewinfo = new WindowInfo(WindowInfo.MODELESSDIALOG);
|
262 |
m_viewinfo.setTitle(PluginServices.getText(this, "increase")); |
263 |
m_viewinfo.setX(posWindowX); |
264 |
m_viewinfo.setY(posWindowY); |
265 |
return m_viewinfo;
|
266 |
} |
267 |
|
268 |
/**
|
269 |
* Asigna el zoom de la vista sobre el inspector de pixels
|
270 |
* @param scale Escala
|
271 |
*/
|
272 |
public void setScale(int scale) { |
273 |
this.scale = scale;
|
274 |
} |
275 |
|
276 |
/**
|
277 |
* Asigna la posici?n en X del control donde se empieza a dibujar
|
278 |
* @param posX posici?n X del Graphics donde se empieza a dibujar
|
279 |
*/
|
280 |
public void setPosX(int posX) { |
281 |
this.posX = posX;
|
282 |
} |
283 |
|
284 |
/**
|
285 |
* Asigna la posici?n en Y del control donde se empieza a dibujar
|
286 |
* @param posY posici?n Y del Graphics donde se empieza a dibujar
|
287 |
*/
|
288 |
public void setPosY(int posY) { |
289 |
this.posY = posY;
|
290 |
} |
291 |
|
292 |
/**
|
293 |
* Obtiene el alto del control
|
294 |
*/
|
295 |
public int getHeight() { |
296 |
return (h == 0) ? height : h; |
297 |
} |
298 |
|
299 |
/**
|
300 |
* Obtiene el ancho del control
|
301 |
*/
|
302 |
public int getWidth() { |
303 |
return (w == 0) ? width : w; |
304 |
} |
305 |
|
306 |
/**
|
307 |
* Obtiene el factor de escala
|
308 |
* @return
|
309 |
*/
|
310 |
public int getScale() { |
311 |
return scale;
|
312 |
} |
313 |
|
314 |
/**
|
315 |
* Obtiene la vista asociada al inspector de pixeles
|
316 |
* @return IView
|
317 |
*/
|
318 |
public IView getView() {
|
319 |
return view;
|
320 |
} |
321 |
|
322 |
/**
|
323 |
* Asigna la vista asociada al inspector de pixeles
|
324 |
* @param IView
|
325 |
*/
|
326 |
public void setView(IView view) { |
327 |
this.view = view;
|
328 |
} |
329 |
|
330 |
/*
|
331 |
* (non-Javadoc)
|
332 |
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
333 |
*/
|
334 |
public void mouseClicked(MouseEvent e) { |
335 |
clear = true;
|
336 |
repaint(); |
337 |
} |
338 |
|
339 |
/*
|
340 |
* (non-Javadoc)
|
341 |
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
|
342 |
*/
|
343 |
public void mouseEntered(MouseEvent e) { |
344 |
clear = true;
|
345 |
repaint(); |
346 |
} |
347 |
|
348 |
/*
|
349 |
* (non-Javadoc)
|
350 |
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
|
351 |
*/
|
352 |
public void mouseExited(MouseEvent e) { |
353 |
clear = true;
|
354 |
repaint(); |
355 |
} |
356 |
|
357 |
/*
|
358 |
* (non-Javadoc)
|
359 |
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
|
360 |
*/
|
361 |
public void mousePressed(MouseEvent e) { |
362 |
if(e.getButton() == MouseEvent.BUTTON3) { |
363 |
menu.show( e.getComponent(), e.getX(), e.getY() ); |
364 |
clear = true;
|
365 |
repaint(); |
366 |
} |
367 |
} |
368 |
|
369 |
/*
|
370 |
* (non-Javadoc)
|
371 |
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
|
372 |
*/
|
373 |
public void mouseReleased(MouseEvent e) { |
374 |
} |
375 |
|
376 |
public Object getWindowProfile() { |
377 |
return WindowInfo.PROPERTIES_PROFILE;
|
378 |
} |
379 |
|
380 |
} |