Revision 11624 trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/pixelincrease/PixelncreaseDialog.java
PixelncreaseDialog.java | ||
---|---|---|
22 | 22 |
import java.awt.Color; |
23 | 23 |
import java.awt.Graphics; |
24 | 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; |
|
25 | 29 |
import java.awt.geom.AffineTransform; |
26 | 30 |
import java.awt.image.BufferedImage; |
27 | 31 |
|
32 |
import javax.swing.JCheckBoxMenuItem; |
|
33 |
import javax.swing.JMenuItem; |
|
28 | 34 |
import javax.swing.JPanel; |
35 |
import javax.swing.JPopupMenu; |
|
36 |
import javax.swing.event.PopupMenuEvent; |
|
37 |
import javax.swing.event.PopupMenuListener; |
|
29 | 38 |
|
30 | 39 |
import com.iver.andami.PluginServices; |
31 | 40 |
import com.iver.andami.ui.mdiManager.IWindow; |
32 | 41 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
33 | 42 |
import com.iver.cit.gvsig.fmap.tools.CompoundBehavior; |
34 |
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
|
35 | 43 |
import com.iver.cit.gvsig.project.documents.view.gui.IView; |
36 | 44 |
|
37 | 45 |
|
... | ... | |
40 | 48 |
* |
41 | 49 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
42 | 50 |
*/ |
43 |
public class PixelncreaseDialog extends JPanel implements IWindow { |
|
51 |
public class PixelncreaseDialog extends JPanel implements IWindow, MouseListener {
|
|
44 | 52 |
final private static long serialVersionUID = -3370601314380922368L; |
53 |
private JPopupMenu menu = null; |
|
45 | 54 |
/** |
46 | 55 |
* Ancho y alto de la ventana |
47 | 56 |
*/ |
... | ... | |
75 | 84 |
*/ |
76 | 85 |
int red = 0, green = 0, blue = 0; |
77 | 86 |
private WindowInfo m_viewinfo = null; |
87 |
public boolean clear = false; |
|
88 |
private Color color = Color.red; |
|
89 |
private JCheckBoxMenuItem[] entry = new JCheckBoxMenuItem[6]; |
|
78 | 90 |
|
79 | 91 |
/** |
80 | 92 |
* Constructor de la ventana de dialogo para gvSIG. |
... | ... | |
83 | 95 |
BorderLayout layout = new BorderLayout(); |
84 | 96 |
setLayout(layout); |
85 | 97 |
setSize(width, height); |
98 |
addMouseListener(this); |
|
86 | 99 |
|
87 | 100 |
IWindow active = PluginServices.getMDIManager().getActiveWindow(); |
88 | 101 |
if(active instanceof IView) { |
... | ... | |
92 | 105 |
posWindowY = wInfo.getY(); |
93 | 106 |
} |
94 | 107 |
|
95 |
//A?adimos el behavior al del MapControl |
|
96 |
//Behavior b = view.getMapControl().getCurrentMapTool(); |
|
97 |
//if(b instanceof CompoundBehavior) |
|
98 | 108 |
CompoundBehavior.setAllControlsBehavior(new PixelIncreaseBehavior(this)); |
109 |
initMenu(); |
|
99 | 110 |
|
100 | 111 |
} |
101 | 112 |
|
102 | 113 |
/** |
114 |
* Inicializa el men? contextual con las opciones de selecci?n del |
|
115 |
* zoom. |
|
116 |
*/ |
|
117 |
private void initMenu() { |
|
118 |
menu = new JPopupMenu(); |
|
119 |
PopupMenuListener lis = new PopupMenuListener() { |
|
120 |
public void popupMenuCanceled( PopupMenuEvent evt ) { |
|
121 |
clear = true; |
|
122 |
repaint(); |
|
123 |
} |
|
124 |
|
|
125 |
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { |
|
126 |
} |
|
127 |
|
|
128 |
public void popupMenuWillBecomeVisible(PopupMenuEvent e) { |
|
129 |
} |
|
130 |
}; |
|
131 |
menu.addPopupMenuListener(lis); |
|
132 |
|
|
133 |
ActionListener al = new ActionListener() { |
|
134 |
public void actionPerformed( ActionEvent evt ){ |
|
135 |
String txt = ((JMenuItem)evt.getSource()).getText(); |
|
136 |
if(txt.compareTo("X4") == 0) { |
|
137 |
scale = 4; |
|
138 |
for (int i = 1; i <= 3; i++) |
|
139 |
entry[i].setSelected(false); |
|
140 |
entry[0].setSelected(true); |
|
141 |
} |
|
142 |
if(txt.compareTo("X8") == 0) { |
|
143 |
scale = 8; |
|
144 |
entry[0].setSelected(false); |
|
145 |
entry[1].setSelected(true); |
|
146 |
entry[2].setSelected(false); |
|
147 |
entry[3].setSelected(false); |
|
148 |
} |
|
149 |
if(txt.compareTo("X16") == 0) { |
|
150 |
scale = 16; |
|
151 |
entry[0].setSelected(false); |
|
152 |
entry[1].setSelected(false); |
|
153 |
entry[2].setSelected(true); |
|
154 |
entry[3].setSelected(false); |
|
155 |
} |
|
156 |
if(txt.compareTo("X32") == 0) { |
|
157 |
scale = 32; |
|
158 |
for (int i = 0; i < 3; i++) |
|
159 |
entry[i].setSelected(false); |
|
160 |
entry[3].setSelected(true); |
|
161 |
} |
|
162 |
if(txt.compareTo(PluginServices.getText(this, "green")) == 0) { |
|
163 |
color = Color.GREEN; |
|
164 |
entry[4].setSelected(false); |
|
165 |
entry[5].setSelected(true); |
|
166 |
} |
|
167 |
if(txt.compareTo(PluginServices.getText(this, "red")) == 0) { |
|
168 |
color = Color.RED; |
|
169 |
entry[4].setSelected(true); |
|
170 |
entry[5].setSelected(false); |
|
171 |
} |
|
172 |
} |
|
173 |
}; |
|
174 |
|
|
175 |
entry[0] = new JCheckBoxMenuItem( "X4" ); |
|
176 |
entry[0].addActionListener( al ); |
|
177 |
menu.add(entry[0]); |
|
178 |
entry[1] = new JCheckBoxMenuItem( "X8" ); |
|
179 |
entry[1].setSelected(true); |
|
180 |
entry[1].addActionListener( al ); |
|
181 |
menu.add(entry[1]); |
|
182 |
entry[2] = new JCheckBoxMenuItem( "X16" ); |
|
183 |
entry[2].addActionListener( al ); |
|
184 |
menu.add(entry[2]); |
|
185 |
entry[3] = new JCheckBoxMenuItem( "X32" ); |
|
186 |
entry[3].addActionListener( al ); |
|
187 |
menu.add(entry[3]); |
|
188 |
entry[4] = new JCheckBoxMenuItem( PluginServices.getText(this, "red") ); |
|
189 |
entry[4].addActionListener( al ); |
|
190 |
entry[4].setSelected(true); |
|
191 |
menu.add(entry[4]); |
|
192 |
entry[5] = new JCheckBoxMenuItem( PluginServices.getText(this, "green") ); |
|
193 |
entry[5].addActionListener( al ); |
|
194 |
menu.add(entry[5]); |
|
195 |
} |
|
196 |
|
|
197 |
/** |
|
103 | 198 |
* Obtiene el buffer de la vista activa y lo dibuja sobre el panel |
104 | 199 |
* con los datos de escala y desplazamiento seleccionados. |
105 | 200 |
*/ |
106 | 201 |
protected void paintComponent(Graphics g) { |
202 |
if(clear) { |
|
203 |
g.setColor(Color.WHITE); |
|
204 |
g.fillRect(0, 0, width, height); |
|
205 |
return; |
|
206 |
} |
|
207 |
|
|
107 | 208 |
if(view != null) { |
108 | 209 |
int dto = 30; //Desplazamiento del zoom en vertical |
109 | 210 |
int sizeCrux = 10; |
... | ... | |
124 | 225 |
|
125 | 226 |
//Dibujamos la informaci?n RGB y la cruz |
126 | 227 |
//g.setXORMode(Color.WHITE); |
127 |
g.setColor(Color.RED);
|
|
228 |
g.setColor(color);
|
|
128 | 229 |
int middleW = width >> 1; |
129 | 230 |
int middleH = ((height - dto) >> 1); |
130 | 231 |
g.drawLine(middleW - sizeCrux, middleH, middleW + sizeCrux, middleH); |
... | ... | |
206 | 307 |
this.view = view; |
207 | 308 |
} |
208 | 309 |
|
310 |
/* |
|
311 |
* (non-Javadoc) |
|
312 |
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent) |
|
313 |
*/ |
|
314 |
public void mouseClicked(MouseEvent e) { |
|
315 |
} |
|
316 |
|
|
317 |
/* |
|
318 |
* (non-Javadoc) |
|
319 |
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent) |
|
320 |
*/ |
|
321 |
public void mouseEntered(MouseEvent e) { |
|
322 |
} |
|
323 |
|
|
324 |
/* |
|
325 |
* (non-Javadoc) |
|
326 |
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent) |
|
327 |
*/ |
|
328 |
public void mouseExited(MouseEvent e) { |
|
329 |
} |
|
330 |
|
|
331 |
/* |
|
332 |
* (non-Javadoc) |
|
333 |
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent) |
|
334 |
*/ |
|
335 |
public void mousePressed(MouseEvent e) { |
|
336 |
if(e.getButton() == MouseEvent.BUTTON3) { |
|
337 |
menu.show( e.getComponent(), e.getX(), e.getY() ); |
|
338 |
clear = true; |
|
339 |
repaint(); |
|
340 |
} |
|
341 |
} |
|
342 |
|
|
343 |
/* |
|
344 |
* (non-Javadoc) |
|
345 |
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent) |
|
346 |
*/ |
|
347 |
public void mouseReleased(MouseEvent e) { |
|
348 |
} |
|
349 |
|
|
209 | 350 |
} |
Also available in: Unified diff