root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / toc / FPopupMenu.java @ 597
History | View | Annotate | Download (11 KB)
1 |
/*
|
---|---|
2 |
* Created on 02-mar-2004
|
3 |
*
|
4 |
* To change the template for this generated file go to
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
6 |
*/
|
7 |
package com.iver.cit.gvsig.gui.toc; |
8 |
|
9 |
import java.awt.Color; |
10 |
import java.awt.Font; |
11 |
import java.awt.event.ActionEvent; |
12 |
import java.awt.event.ActionListener; |
13 |
import java.util.ArrayList; |
14 |
|
15 |
import javax.swing.JColorChooser; |
16 |
import javax.swing.JDialog; |
17 |
import javax.swing.JFrame; |
18 |
import javax.swing.JMenuItem; |
19 |
import javax.swing.JPopupMenu; |
20 |
import javax.swing.tree.DefaultMutableTreeNode; |
21 |
|
22 |
import com.hardcode.gdbms.engine.data.DriverException; |
23 |
import com.iver.cit.gvsig.fmap.FMap; |
24 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
25 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
26 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
27 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
28 |
import com.iver.cit.gvsig.fmap.layers.FLyrDefault; |
29 |
import com.iver.cit.gvsig.fmap.layers.FLyrRaster; |
30 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
31 |
import com.iver.cit.gvsig.gui.Panels.AdjustTransparencyPanel; |
32 |
import com.iver.cit.gvsig.gui.legendmanager.FLegendManagerWindow; |
33 |
import com.iver.mdiApp.App; |
34 |
import com.iver.mdiApp.Utilities; |
35 |
|
36 |
class FSymbolChangeColorTocMenuEntry extends TocMenuEntry { |
37 |
FPopupMenu menu; |
38 |
private JMenuItem color; |
39 |
public void initialize(FPopupMenu m) { |
40 |
this.menu = m;
|
41 |
if (menu.nodo.getUserObject() instanceof FSymbol) { |
42 |
color = new JMenuItem(Utilities.getMessage(this, "Cambio_Color")); |
43 |
color.setFont(FPopupMenu.theFont); |
44 |
menu.add(color); |
45 |
menu.enable(); |
46 |
|
47 |
//Cambio color
|
48 |
color.addActionListener(new ActionListener() { |
49 |
public void actionPerformed(ActionEvent e) { |
50 |
JDialog dlg;
|
51 |
JColorChooser colorChooser;
|
52 |
colorChooser = new JColorChooser(); |
53 |
dlg = JColorChooser.createDialog((JFrame) null, |
54 |
Utilities.getMessage(this, "Elegir_Color"), |
55 |
true, colorChooser, null, null); |
56 |
dlg.show(true);
|
57 |
|
58 |
((FSymbol) menu.nodo.getUserObject()).setColor((Color) colorChooser.getColor());
|
59 |
menu.getMapContext().fireLegendEvent(); |
60 |
menu.getMapContext().fireInvalidEvent(); |
61 |
|
62 |
} |
63 |
}); |
64 |
} |
65 |
} |
66 |
} |
67 |
|
68 |
class FLyrVectChangeStyleTocMenuEntry extends TocMenuEntry { |
69 |
FPopupMenu menu; |
70 |
private JMenuItem estilo; |
71 |
public void initialize(FPopupMenu m) { |
72 |
this.menu = m;
|
73 |
TocItemBranch elTema = null;
|
74 |
FLayer lyr = null;
|
75 |
|
76 |
if (menu.nodo.getUserObject() instanceof TocItemBranch) { |
77 |
elTema = (TocItemBranch) menu.nodo.getUserObject(); |
78 |
lyr = elTema.getLayer(); |
79 |
if (lyr instanceof ClassifiableVectorial) { |
80 |
estilo = new JMenuItem(Utilities.getMessage(this, "Cambio_Estilo")); |
81 |
menu.add(estilo); |
82 |
estilo.setFont(FPopupMenu.theFont); |
83 |
//Cambio estilo
|
84 |
estilo.addActionListener(new ActionListener() { |
85 |
public void actionPerformed(ActionEvent e) { |
86 |
// TODO:
|
87 |
FLegendManagerWindow m_LegendEditor = new FLegendManagerWindow();
|
88 |
try {
|
89 |
m_LegendEditor.setMapContext(menu.getMapContext()); |
90 |
} catch (DriverException e1) {
|
91 |
e1.printStackTrace(); |
92 |
} |
93 |
if (App.instance == null) { |
94 |
JDialog dlg = new JDialog(); |
95 |
|
96 |
m_LegendEditor.setPreferredSize(m_LegendEditor.getSize()); |
97 |
dlg.getContentPane().add(m_LegendEditor); |
98 |
dlg.setModal(false);
|
99 |
dlg.pack(); |
100 |
dlg.show(); |
101 |
|
102 |
} else
|
103 |
App.instance.getMDIContext().addView(m_LegendEditor); |
104 |
|
105 |
|
106 |
} |
107 |
}); |
108 |
} |
109 |
} |
110 |
} |
111 |
} |
112 |
|
113 |
class NotFLyrRasterChangeColorTocMenuEntry extends TocMenuEntry { |
114 |
FPopupMenu menu; |
115 |
private JMenuItem color; |
116 |
public void initialize(FPopupMenu m) { |
117 |
this.menu = m;
|
118 |
TocItemBranch elTema = null;
|
119 |
FLayer lyr = null;
|
120 |
|
121 |
if (menu.nodo.getUserObject() instanceof TocItemBranch) { |
122 |
elTema = (TocItemBranch) menu.nodo.getUserObject(); |
123 |
lyr = elTema.getLayer(); |
124 |
if (!(lyr instanceof FLyrRaster)) { |
125 |
color = new JMenuItem(Utilities.getMessage(this, "Cambio_Color")); |
126 |
menu.add(color); |
127 |
color.setFont(FPopupMenu.theFont); |
128 |
menu.enable(); |
129 |
menu.addSeparator(); |
130 |
//Cambio color
|
131 |
color.addActionListener(new ActionListener() { |
132 |
public void actionPerformed(ActionEvent e) { |
133 |
JDialog dlg;
|
134 |
JColorChooser colorChooser;
|
135 |
TocItemBranch elTema = (TocItemBranch) menu.nodo.getUserObject(); |
136 |
FLayer lyr = elTema.getLayer(); |
137 |
|
138 |
if (lyr instanceof ClassifiableVectorial) { |
139 |
colorChooser = new JColorChooser(); |
140 |
dlg = JColorChooser.createDialog((JFrame) null, |
141 |
Utilities.getMessage(this, "Elegir_Color"), |
142 |
true, colorChooser, null, null); |
143 |
dlg.show(true);
|
144 |
|
145 |
|
146 |
// TODO:
|
147 |
// FLyrVect lyrVect = (FLyrVect) lyr;
|
148 |
// lyrVect.getLegend().getDefaultSymbol().m_Color = (Color) colorChooser.getColor();
|
149 |
// lyrVect.getRenderer().setLegendType(FConstant.LEGEND_TYPE_DEFAULT);
|
150 |
menu.getMapContext().fireLegendEvent(); |
151 |
menu.getMapContext().fireInvalidEvent(); |
152 |
//}
|
153 |
} |
154 |
} |
155 |
}); |
156 |
} |
157 |
} |
158 |
} |
159 |
} |
160 |
|
161 |
class FLyrRasterAdjustTransparencyTocMenuEntry extends TocMenuEntry { |
162 |
FPopupMenu menu; |
163 |
private JMenuItem transparency; |
164 |
public void initialize(FPopupMenu m) { |
165 |
this.menu = m;
|
166 |
TocItemBranch elTema = null;
|
167 |
FLayer lyr = null;
|
168 |
|
169 |
if (menu.nodo.getUserObject() instanceof TocItemBranch) { |
170 |
elTema = (TocItemBranch) menu.nodo.getUserObject(); |
171 |
lyr = elTema.getLayer(); |
172 |
// Opcciones para capas raster
|
173 |
if ((lyr instanceof FLyrRaster)) { |
174 |
|
175 |
transparency = new JMenuItem(Utilities.getMessage(this, "adjust_transparency")); |
176 |
menu.add( transparency ); |
177 |
transparency.setFont(FPopupMenu.theFont); |
178 |
menu.enable(); |
179 |
menu.addSeparator(); |
180 |
//Cambio color
|
181 |
transparency.addActionListener(new ActionListener() { |
182 |
public void actionPerformed(ActionEvent e) { |
183 |
FLayer lyr = ((TocItemBranch) menu.nodo.getUserObject()).getLayer(); |
184 |
AdjustTransparencyPanel transPanel = new AdjustTransparencyPanel((FLyrDefault) lyr);
|
185 |
//transPanel.setFLayer((FLyrDefault) lyr);
|
186 |
transPanel.openJDialog(); |
187 |
/*dlg = JColorChooser.createDialog((JFrame) null,
|
188 |
Utilities.getMessage(this, "adjust_transparency"),
|
189 |
true, panel, null, null);
|
190 |
dlg.show(true);*/
|
191 |
/*JDialog dlg = new JDialog();
|
192 |
|
193 |
transPanel.setPreferredSize(transPanel.getSize());
|
194 |
dlg.getContentPane().add(transPanel);
|
195 |
dlg.setModal(true);
|
196 |
dlg.pack();
|
197 |
dlg.show();
|
198 |
*/
|
199 |
//((FLyrDefault) lyr).setTransparency(transPanel.getAlpha());
|
200 |
//view.repaintMap();
|
201 |
} |
202 |
}); |
203 |
} |
204 |
} |
205 |
} |
206 |
} |
207 |
|
208 |
class ZoomAlTemaTocMenuEntry extends TocMenuEntry { |
209 |
FPopupMenu menu; |
210 |
private JMenuItem zoom; |
211 |
public void initialize(FPopupMenu m) { |
212 |
this.menu = m;
|
213 |
|
214 |
if (menu.nodo.getUserObject() instanceof TocItemBranch) { |
215 |
zoom = new JMenuItem(Utilities.getMessage(this, "Zoom_al_Tema")); |
216 |
menu.add(zoom); |
217 |
zoom.setFont(FPopupMenu.theFont); |
218 |
|
219 |
zoom.addActionListener(new ActionListener() { |
220 |
public void actionPerformed(ActionEvent e) { |
221 |
TocItemBranch elTema = (TocItemBranch) menu.nodo.getUserObject(); |
222 |
FLayer lyr = elTema.getLayer(); |
223 |
|
224 |
try {
|
225 |
menu.getMapContext().getViewPort().setExtent(lyr.getFullExtent()); |
226 |
} catch (DriverIOException e1) {
|
227 |
// TODO Auto-generated catch block
|
228 |
e1.printStackTrace(); |
229 |
} |
230 |
menu.getMapContext().fireInvalidEvent(); |
231 |
} |
232 |
}); |
233 |
} |
234 |
} |
235 |
} |
236 |
|
237 |
class EliminarCapaTocMenuEntry extends TocMenuEntry { |
238 |
FPopupMenu menu; |
239 |
private JMenuItem removeLayer; |
240 |
public void initialize(FPopupMenu m) { |
241 |
this.menu = m;
|
242 |
|
243 |
if (menu.nodo.getUserObject() instanceof TocItemBranch) { |
244 |
menu.addSeparator(); |
245 |
removeLayer = new JMenuItem(Utilities.getMessage(this, "eliminar_capa")); |
246 |
menu.add(removeLayer); |
247 |
removeLayer.setFont(FPopupMenu.theFont); |
248 |
removeLayer.addActionListener(new ActionListener() { |
249 |
public void actionPerformed(ActionEvent e) { |
250 |
TocItemBranch elTema = (TocItemBranch) menu.nodo.getUserObject(); |
251 |
FLayer lyr = elTema.getLayer(); |
252 |
|
253 |
try {
|
254 |
menu.getMapContext().getLayers().removeLayer(lyr); |
255 |
menu.getMapContext().fireInvalidEvent(); |
256 |
menu.getMapContext().fireLegendEvent(); |
257 |
|
258 |
} catch (CancelationException e1) {
|
259 |
// TODO Auto-generated catch block
|
260 |
e1.printStackTrace(); |
261 |
} |
262 |
} |
263 |
}); |
264 |
} |
265 |
} |
266 |
} |
267 |
|
268 |
/**
|
269 |
* Menu de bot?n derecho para el TOC.
|
270 |
* Se pueden a?adir entradas facilmente desde una extensi?n,
|
271 |
* creando una clase derivando de TocMenuEntry, y a?adiendola en
|
272 |
* est?tico (o en tiempo de carga de la extensi?n) a FPopupMenu.
|
273 |
* (Las entradas actuales est?n hechas de esa manera).
|
274 |
*
|
275 |
* @author vcn To change the template for this generated type comment go to
|
276 |
* Window>Preferences>Java>Code Generation>Code and
|
277 |
* Comments
|
278 |
*/
|
279 |
|
280 |
public class FPopupMenu extends JPopupMenu { |
281 |
private static ArrayList menuEntrys = null; |
282 |
public DefaultMutableTreeNode nodo; |
283 |
private FMap mapContext;
|
284 |
//private JMenuItem capa;
|
285 |
// Lo de fijar la fuente es porque en linux se ve?a mal si no se fija.
|
286 |
// TODO: Esto no funcionar? para idiomas como el chino. Hay que cambiarlo.
|
287 |
public final static Font theFont = new Font("SansSerif", Font.PLAIN, 10); |
288 |
|
289 |
static {
|
290 |
menuEntrys = new ArrayList(); |
291 |
menuEntrys.add(new FSymbolChangeColorTocMenuEntry());
|
292 |
menuEntrys.add(new FLyrVectChangeStyleTocMenuEntry());
|
293 |
menuEntrys.add(new NotFLyrRasterChangeColorTocMenuEntry());
|
294 |
menuEntrys.add(new FLyrRasterAdjustTransparencyTocMenuEntry());
|
295 |
menuEntrys.add(new ZoomAlTemaTocMenuEntry());
|
296 |
menuEntrys.add(new EliminarCapaTocMenuEntry());
|
297 |
} |
298 |
|
299 |
public static void addEntry(TocMenuEntry entry) { |
300 |
menuEntrys.add(entry); |
301 |
} |
302 |
|
303 |
/**
|
304 |
* Creates a new FPopupMenu object.
|
305 |
*
|
306 |
* @param nodo DOCUMENT ME!
|
307 |
* @param vista DOCUMENT ME!
|
308 |
*/
|
309 |
public FPopupMenu(FMap mc, DefaultMutableTreeNode node) { |
310 |
//super();
|
311 |
this.mapContext = mc;
|
312 |
this.nodo = node;
|
313 |
|
314 |
//salir = new MenuItem("Salir");
|
315 |
|
316 |
for (int i=0; i<menuEntrys.size(); i++) { |
317 |
((TocMenuEntry) menuEntrys.get(i)).initialize(this);
|
318 |
} |
319 |
} |
320 |
|
321 |
public FMap getMapContext() { return mapContext; } |
322 |
|
323 |
} |