root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / filter / FilterTocMenuEntry.java @ 11507
History | View | Annotate | Download (9.34 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.filter; |
20 |
|
21 |
import java.util.ArrayList; |
22 |
|
23 |
import javax.swing.event.TreeSelectionEvent; |
24 |
import javax.swing.event.TreeSelectionListener; |
25 |
import javax.swing.tree.DefaultTreeModel; |
26 |
|
27 |
import org.gvsig.fmap.layers.FLyrRasterSE; |
28 |
import org.gvsig.gui.beans.treelist.TreeListContainer; |
29 |
import org.gvsig.gui.beans.treelist.event.TreeListEvent; |
30 |
import org.gvsig.gui.beans.treelist.listeners.TreeListComponentListener; |
31 |
import org.gvsig.rastertools.filter.ui.RasterFilterDialog; |
32 |
import org.gvsig.rastertools.filter.ui.RasterFilterPanel; |
33 |
|
34 |
import com.iver.andami.PluginServices; |
35 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
36 |
import com.iver.cit.gvsig.gui.panels.IRasterPropertiesRegistrable; |
37 |
import com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction; |
38 |
import com.iver.cit.gvsig.project.documents.view.toc.ITocItem; |
39 |
/**
|
40 |
* Punto de entrada del menu para los filtros
|
41 |
*
|
42 |
* @version 02/05/2007
|
43 |
* @author Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
44 |
*/
|
45 |
public class FilterTocMenuEntry extends AbstractTocContextMenuAction implements TreeSelectionListener, TreeListComponentListener { |
46 |
private ArrayList listeners = new ArrayList(); |
47 |
private RasterFilterDialog rasterFilterDialog = null; |
48 |
private int width = 620; |
49 |
private int height = 310; |
50 |
|
51 |
/*
|
52 |
* (non-Javadoc)
|
53 |
* @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getGroup()
|
54 |
*/
|
55 |
public String getGroup() { |
56 |
return "RasterTools"; |
57 |
} |
58 |
|
59 |
/*
|
60 |
* (non-Javadoc)
|
61 |
* @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getGroupOrder()
|
62 |
*/
|
63 |
public int getGroupOrder() { |
64 |
return 55; |
65 |
} |
66 |
|
67 |
/*
|
68 |
* (non-Javadoc)
|
69 |
* @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getOrder()
|
70 |
*/
|
71 |
public int getOrder() { |
72 |
return 0; |
73 |
} |
74 |
|
75 |
/*
|
76 |
* (non-Javadoc)
|
77 |
* @see com.iver.cit.gvsig.project.documents.IContextMenuAction#getText()
|
78 |
*/
|
79 |
public String getText() { |
80 |
return PluginServices.getText(this, "filtros"); |
81 |
} |
82 |
|
83 |
/**
|
84 |
* Los objetos que quieren que se ejecute su listerner deben ser registrados a
|
85 |
* traves de este m?todo. Cuando se ejecute el actionPerformed se buscar?
|
86 |
* todos los objetos registrados y ejecutar? el actionPerformed de cada uno,
|
87 |
*
|
88 |
* @param obj Objeto a registrar
|
89 |
*/
|
90 |
public void register(Object obj) { |
91 |
if (obj instanceof IRasterPropertiesRegistrable) |
92 |
listeners.add(obj); |
93 |
} |
94 |
|
95 |
/*
|
96 |
* (non-Javadoc)
|
97 |
* @see com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction#isEnabled(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
|
98 |
*/
|
99 |
public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
100 |
return selectedItems.length == 1; |
101 |
} |
102 |
|
103 |
/*
|
104 |
* (non-Javadoc)
|
105 |
* @see com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction#isVisible(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
|
106 |
*/
|
107 |
public boolean isVisible(ITocItem item, FLayer[] selectedItems) { |
108 |
if (isTocItemBranch(item))
|
109 |
return (getNodeLayer(item) instanceof FLyrRasterSE); |
110 |
return false; |
111 |
} |
112 |
|
113 |
/**
|
114 |
* Construye el arbol para el men? de filtros disponibles
|
115 |
*/
|
116 |
private void menuBuild() { |
117 |
TreeListContainer lc = rasterFilterDialog.getSelector(); |
118 |
lc.getTree().addTreeSelectionListener(this);
|
119 |
lc.addTreeListListener(this);
|
120 |
lc.addClass(PluginServices.getText(this, "detecci?n_bordes"), 0); |
121 |
lc.addEntry(PluginServices.getText(this, "sobel"), PluginServices.getText(this, "detecci?n_bordes"), "sobel"); |
122 |
lc.addEntry(PluginServices.getText(this, "roberts"), PluginServices.getText(this, "detecci?n_bordes"), "roberts"); |
123 |
lc.addEntry(PluginServices.getText(this, "laplace"), PluginServices.getText(this, "detecci?n_bordes"), "laplace"); |
124 |
lc.addEntry(PluginServices.getText(this, "prewitt"), PluginServices.getText(this, "detecci?n_bordes"), "prewitt"); |
125 |
lc.addEntry(PluginServices.getText(this, "frei_chen"), PluginServices.getText(this, "detecci?n_bordes"), "frei_chen"); |
126 |
lc.addClass(PluginServices.getText(this, "suavizado"), 1); |
127 |
lc.addEntry(PluginServices.getText(this, "paso_bajo"), PluginServices.getText(this, "suavizado"), "paso_bajo"); |
128 |
lc.addEntry(PluginServices.getText(this, "mediana"), PluginServices.getText(this, "suavizado"), "mediana"); |
129 |
lc.addEntry(PluginServices.getText(this, "media"), PluginServices.getText(this, "suavizado"), "media"); |
130 |
lc.addEntry(PluginServices.getText(this, "gauss"), PluginServices.getText(this, "suavizado"), "gauss"); |
131 |
lc.getTree().expandRow(0);
|
132 |
} |
133 |
|
134 |
public void execute(ITocItem item, FLayer[] selectedItems) { |
135 |
FLayer lyr = null;
|
136 |
lyr = getNodeLayer(item); |
137 |
|
138 |
if (lyr instanceof FLyrRasterSE) { |
139 |
rasterFilterDialog = new RasterFilterDialog((FLyrRasterSE) lyr, width, height);
|
140 |
|
141 |
// Construimos el men?
|
142 |
menuBuild(); |
143 |
|
144 |
// Cargamos el panel que es visible para el usuario
|
145 |
loadVisiblePanel(); |
146 |
|
147 |
rasterFilterDialog.setLayer(lyr); |
148 |
|
149 |
PluginServices.getMDIManager().addWindow(rasterFilterDialog); |
150 |
} |
151 |
} |
152 |
|
153 |
/**
|
154 |
* Carga el panel que es visible al usuario. Si hay filtros en la lista se
|
155 |
* mostrar? el primero de la lista sino se mostrar? el primero del arbol de
|
156 |
* filtros.
|
157 |
*/
|
158 |
private void loadVisiblePanel() { |
159 |
String firstFilter = ""; |
160 |
TreeListContainer lc = rasterFilterDialog.getSelector(); |
161 |
DefaultTreeModel modelTree = (DefaultTreeModel) lc.getTree().getModel(); |
162 |
|
163 |
firstFilter = modelTree.getChild(modelTree.getChild(modelTree.getRoot(), 0), 0).toString(); |
164 |
lc.getTree().expandRow(1);
|
165 |
lc.getTree().setSelectionInterval(2, 2); |
166 |
|
167 |
int pos = RasterFilterPanel.getPos(firstFilter);
|
168 |
// Si pos es -1 es pq para el primero de la lista no existe panel para ?l.
|
169 |
if (pos == -1) |
170 |
return;
|
171 |
else {
|
172 |
rasterFilterDialog.setVisiblePanel(pos); |
173 |
rasterFilterDialog.getPFilter().setTitle(PluginServices.getText(this, "filtro_de") + " " + firstFilter); |
174 |
} |
175 |
} |
176 |
|
177 |
/**
|
178 |
* Este m?todo se ejecuta cada vez que cambia el valor seleccionado en el
|
179 |
* men?, es decir cuando se pincha sobre una entrada de men? define que
|
180 |
* acciones se realizan. En ?l, hay que definir para cada entrada (addEntry)
|
181 |
* que hallamos puesto en la funci?n menuBuild cual ser? el comportamiento de
|
182 |
* esta, es decir que panel se muestra cuando se selecciona dicha entrada.
|
183 |
*/
|
184 |
public void valueChanged(TreeSelectionEvent e) { |
185 |
String path = null; |
186 |
try {
|
187 |
path = e.getNewLeadSelectionPath().toString(); |
188 |
} catch (NullPointerException exc) { |
189 |
return;
|
190 |
} |
191 |
if (path == null) |
192 |
return;
|
193 |
/*
|
194 |
String selection = path.substring(path.lastIndexOf(", ") + 2, path.lastIndexOf("]"));
|
195 |
|
196 |
TreeListContainer lc = rasterFilterDialog.getSelector();
|
197 |
|
198 |
actionsForFirstDerivativeFilter(0, selection, "sobel", lc, sobel);
|
199 |
actionsForFirstDerivativeFilter(1, selection, "roberts", lc, roberts);
|
200 |
actionsForFirstDerivativeFilter(2, selection, "prewitt", lc, prewitt);
|
201 |
actionsForFirstDerivativeFilter(3, selection, "frei_chen", lc, frei_chen);
|
202 |
actionsForConvolutionFilter(4, selection, "paso_bajo", lc, paso_bajo);
|
203 |
actionsForConvolutionFilter(5, selection, "mediana", lc, mediana);
|
204 |
actionsForConvolutionFilter(6, selection, "media", lc, media);
|
205 |
actionsForConvolutionFilter(7, selection, "gauss", lc, gauss);
|
206 |
actionsForConvolutionFilter(8, selection, "laplace", lc, laplace);
|
207 |
*/
|
208 |
} |
209 |
|
210 |
/**
|
211 |
* Este m?todo es ejecutado cuando se inserta un nuevo elemento en la lista
|
212 |
* @param e TreeListEvent
|
213 |
*/
|
214 |
public void elementAdded(TreeListEvent e) { |
215 |
int pos = RasterFilterPanel.getPos(e.getElementAdded());
|
216 |
try {
|
217 |
if (pos > -1) |
218 |
rasterFilterDialog.getPanel(pos).setEnabled(true);
|
219 |
} catch (ArrayIndexOutOfBoundsException exc) { |
220 |
return;
|
221 |
} |
222 |
} |
223 |
|
224 |
/**
|
225 |
* Este m?todo activa el panel visible si su filtro correspondiente est? en la
|
226 |
* lista de filtros activos sino lo desactiva.
|
227 |
*
|
228 |
* @param lc Lista a comprobar si est? el filtro insertado
|
229 |
* @param filter Nombre del filtro del cual se comprueba si est? en la lista
|
230 |
*/
|
231 |
/*
|
232 |
private void setEnableVisiblePanel(TreeListContainer lc, String filter) {
|
233 |
if (lc.isInList(PluginServices.getText(this, filter)))
|
234 |
rasterFilterDialog.getVisiblePanel().setEnabled(true);
|
235 |
else
|
236 |
rasterFilterDialog.getVisiblePanel().setEnabled(false);
|
237 |
}
|
238 |
*/
|
239 |
|
240 |
/**
|
241 |
* Este m?todo es ejecutado cuando se elimina un elemento de la lista
|
242 |
* @param e TreeListEvent
|
243 |
*/
|
244 |
public void elementRemoved(TreeListEvent e) { |
245 |
int pos = RasterFilterPanel.getPos(e.getElementRemoved());
|
246 |
try {
|
247 |
if (pos > -1) |
248 |
rasterFilterDialog.getPanel(pos).setEnabled(false);
|
249 |
} catch (ArrayIndexOutOfBoundsException exc) { |
250 |
return;
|
251 |
} |
252 |
} |
253 |
|
254 |
/**
|
255 |
* Este m?todo es ejecutado cuando se mueve un elemento de la lista
|
256 |
* @param e TreeListEvent
|
257 |
*/
|
258 |
public void elementMoved(TreeListEvent arg0) { |
259 |
} |
260 |
} |