Revision 37338 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/toc/gui/FPopupMenu.java
FPopupMenu.java | ||
---|---|---|
52 | 52 |
import java.util.Arrays; |
53 | 53 |
import java.util.Comparator; |
54 | 54 |
import java.util.Iterator; |
55 |
import java.util.List; |
|
55 | 56 |
|
56 | 57 |
import javax.swing.JMenuItem; |
57 | 58 |
import javax.swing.JPopupMenu; |
58 | 59 |
import javax.swing.tree.DefaultMutableTreeNode; |
59 | 60 |
|
61 |
import org.gvsig.fmap.swing.toc.TOC; |
|
62 |
import org.gvsig.fmap.swing.toc.TOCFactory; |
|
63 |
import org.gvsig.fmap.swing.toc.TOCLocator; |
|
64 |
import org.gvsig.fmap.swing.toc.TOCManager; |
|
65 |
import org.gvsig.fmap.swing.toc.action.TOCAction; |
|
66 |
import org.gvsig.fmap.swing.toc.action.TOCActionAdapter; |
|
67 |
import org.gvsig.tools.service.ServiceException; |
|
68 |
|
|
69 |
import com.iver.andami.messages.NotificationManager; |
|
70 |
import com.iver.cit.gvsig.TOCImplementationExtension; |
|
60 | 71 |
import com.iver.cit.gvsig.fmap.MapContext; |
72 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
61 | 73 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
62 | 74 |
import com.iver.cit.gvsig.project.documents.IContextMenuAction; |
63 | 75 |
import com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction; |
... | ... | |
78 | 90 |
import com.iver.cit.gvsig.project.documents.view.toc.actions.ReloadLayerTocMenuEntry; |
79 | 91 |
import com.iver.cit.gvsig.project.documents.view.toc.actions.ShowLayerErrorsTocMenuEntry; |
80 | 92 |
import com.iver.cit.gvsig.project.documents.view.toc.actions.ZoomAlTemaTocMenuEntry; |
93 |
import com.iver.cit.gvsig.project.documents.view.toc.util.TOCMenuItemComparator; |
|
81 | 94 |
import com.iver.utiles.extensionPoints.ExtensionPoint; |
82 | 95 |
import com.iver.utiles.extensionPoints.ExtensionPoints; |
83 | 96 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
... | ... | |
98 | 111 |
//private static ArrayList menuEntrys = new ArrayList(); |
99 | 112 |
private DefaultMutableTreeNode nodo; |
100 | 113 |
protected MapContext mapContext; |
114 |
private TOC toc = null; |
|
101 | 115 |
private ExtensionPoint extensionPoint; |
102 | 116 |
private FLayer[] selecteds; |
103 | 117 |
//private JMenuItem capa; |
104 | 118 |
// Lo de fijar la fuente es porque en linux se ve?a mal si no se fija. |
105 | 119 |
// TODO: Esto no funcionar? para idiomas como el chino. Hay que cambiarlo. |
106 | 120 |
public final static Font theFont = new Font("SansSerif", Font.PLAIN, 10); |
107 |
|
|
108 |
public static void registerExtensionPoint() { |
|
109 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
|
110 |
extensionPoints.add("View_TocActions","FSymbolChangeColor",new ChangeSymbolTocMenuEntry()); |
|
111 |
extensionPoints.add("View_TocActions","ChangeName",new ChangeNameTocMenuEntry()); |
|
112 |
extensionPoints.add("View_TocActions","FLyrVectEditProperties",new FLyrVectEditPropertiesTocMenuEntry()); |
|
113 |
extensionPoints.add("View_TocActions","ZoomAlTema",new ZoomAlTemaTocMenuEntry()); |
|
114 |
//extensionPoints.add("View_TocActions","ZoomPixelCursor",new ZoomPixelCursorTocMenuEntry()); |
|
115 |
extensionPoints.add("View_TocActions","EliminarCapa",new EliminarCapaTocMenuEntry()); |
|
116 |
extensionPoints.add("View_TocActions","VerErroresCapa",new ShowLayerErrorsTocMenuEntry()); |
|
117 |
extensionPoints.add("View_TocActions","ReloadLayer",new ReloadLayerTocMenuEntry()); |
|
118 |
extensionPoints.add("View_TocActions","LayersGroup",new LayersGroupTocMenuEntry()); |
|
119 |
extensionPoints.add("View_TocActions","LayersUngroup",new LayersUngroupTocMenuEntry()); |
|
120 |
extensionPoints.add("View_TocActions","FirstLayer",new FirstLayerTocMenuEntry()); |
|
121 |
|
|
122 |
extensionPoints.add("View_TocActions","Copy",new CopyLayersTocMenuEntry()); |
|
123 |
extensionPoints.add("View_TocActions","Cut",new CutLayersTocMenuEntry()); |
|
124 |
extensionPoints.add("View_TocActions","Paste",new PasteLayersTocMenuEntry()); |
|
125 |
//extensionPoints.add("View_TocActions","RasterProperties",new FLyrRasterAdjustPropertiesTocMenuEntry()); |
|
126 |
//extensionPoints.add("View_TocActions","RasterProperties",new RasterPropertiesTocMenuEntry()); |
|
127 |
|
|
128 |
|
|
129 |
} |
|
130 |
static { |
|
131 |
/* Cambiados |
|
132 |
FPopupMenu.addEntry(new FSymbolChangeColorTocMenuEntry()); |
|
133 |
FPopupMenu.addEntry(new ChangeNameTocMenuEntry()); |
|
134 |
FPopupMenu.addEntry(new FLyrVectEditPropertiesTocMenuEntry()); |
|
135 |
|
|
136 |
|
|
137 |
FPopupMenu.addEntry(new ZoomAlTemaTocMenuEntry()); |
|
138 |
FPopupMenu.addEntry(new ZoomPixelCursorTocMenuEntry()); |
|
139 |
|
|
140 |
|
|
141 |
FPopupMenu.addEntry(new EliminarCapaTocMenuEntry()); |
|
142 |
FPopupMenu.addEntry(new ReloadLayerTocMenuEntry()); |
|
143 |
|
|
144 |
FPopupMenu.addEntry(new LayersGroupTocMenuEntry()); |
|
145 |
FPopupMenu.addEntry(new LayersUngroupTocMenuEntry()); |
|
146 |
|
|
147 |
|
|
148 |
FPopupMenu.addEntry(new FirstLayerTocMenuEntry()); |
|
149 |
*/ |
|
150 |
//FPopupMenu.addEntry(new FLyrRasterAdjustPropertiesTocMenuEntry()); |
|
151 |
} |
|
152 |
|
|
153 |
|
|
121 |
|
|
154 | 122 |
/** |
155 | 123 |
* @deprecated |
156 | 124 |
*/ |
157 | 125 |
public static void addEntry(TocMenuEntry entry) { |
158 | 126 |
|
159 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
|
160 |
|
|
161 | 127 |
OldTocContextMenuAction action = new OldTocContextMenuAction(); |
162 | 128 |
action.setEntry(entry); |
163 |
String name =entry.getClass().getName(); |
|
164 |
name = name.substring(name.lastIndexOf(".")+1); |
|
165 |
extensionPoints.add("View_TocActions",name,action); |
|
166 |
|
|
129 |
|
|
130 |
TOCManager tm = TOCLocator.getInstance().getTOCManager(); |
|
131 |
tm.addServiceFactory(action); |
|
167 | 132 |
} |
168 | 133 |
|
169 | 134 |
/** |
170 | 135 |
* @deprecated |
171 | 136 |
*/ |
172 |
public static Object getEntry(String className) { |
|
137 |
|
|
138 |
/* |
|
139 |
public static Object getEntry(String className, boolean[][] bb) { |
|
173 | 140 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
174 | 141 |
OldTocContextMenuAction action = null; |
175 | 142 |
try { |
... | ... | |
189 | 156 |
return null; |
190 | 157 |
} |
191 | 158 |
} |
159 |
*/ |
|
192 | 160 |
|
193 | 161 |
/** |
194 | 162 |
* Creates a new FPopupMenu object. |
... | ... | |
196 | 164 |
* @param nodo DOCUMENT ME! |
197 | 165 |
* @param vista DOCUMENT ME! |
198 | 166 |
*/ |
199 |
public FPopupMenu(MapContext mc, DefaultMutableTreeNode node) { |
|
167 |
public FPopupMenu(TOC _toc, MapContext mc, DefaultMutableTreeNode node) {
|
|
200 | 168 |
super(); |
169 |
toc = _toc; |
|
201 | 170 |
this.initialize(mc,node); |
202 | 171 |
} |
203 | 172 |
|
... | ... | |
206 | 175 |
this.nodo = node; |
207 | 176 |
|
208 | 177 |
//salir = new MenuItem("Salir"); |
209 |
this.extensionPoint = (ExtensionPoint)ExtensionPointsSingleton.getInstance().get("View_TocActions");
|
|
178 |
extensionPoint = (ExtensionPoint)ExtensionPointsSingleton.getInstance().get("View_TocActions"); |
|
210 | 179 |
this.selecteds = this.mapContext.getLayers().getActives(); |
211 | 180 |
|
212 |
IContextMenuAction[] actions = this.getActionList();
|
|
181 |
List<TOCAction> actions = this.getActionList();
|
|
213 | 182 |
if (actions == null){ |
214 | 183 |
return; |
215 | 184 |
} |
216 | 185 |
this.createMenuElements(actions); |
217 | 186 |
|
218 | 187 |
this.loadOldStileOptions(); |
219 |
|
|
220 |
|
|
221 | 188 |
} |
222 | 189 |
|
223 | 190 |
public MapContext getMapContext() { return mapContext; } |
... | ... | |
231 | 198 |
return this.nodo; |
232 | 199 |
} |
233 | 200 |
|
234 |
private IContextMenuAction[] getActionList() { |
|
235 |
ArrayList actionArrayList = new ArrayList(); |
|
236 |
Iterator iter = this.extensionPoint.keySet().iterator(); |
|
201 |
private List<TOCAction> getActionList() { |
|
202 |
|
|
203 |
TOCManager tm = TOCLocator.getInstance().getTOCManager(); |
|
204 |
List<TOCAction> result_list = null; |
|
205 |
List<TOCAction> result_list_sort = null; |
|
206 |
|
|
207 |
try { |
|
208 |
result_list = tm.getActions(toc); |
|
209 |
} catch (ServiceException se) { |
|
210 |
NotificationManager.addError("While getting actions for fpopupmenu", se); |
|
211 |
return null; |
|
212 |
} |
|
213 |
|
|
214 |
|
|
215 |
|
|
237 | 216 |
AbstractTocContextMenuAction action; |
238 | 217 |
boolean contains=false; |
239 | 218 |
ITocItem tocItem=(ITocItem)this.getNodeUserObject(); |
... | ... | |
245 | 224 |
}else{ |
246 | 225 |
contains=true; |
247 | 226 |
} |
227 |
|
|
248 | 228 |
if (contains){ |
249 |
while (iter.hasNext()) { |
|
250 |
action = null; |
|
251 |
try { |
|
252 |
action = (AbstractTocContextMenuAction)this.extensionPoint.create((String)iter.next()); |
|
253 |
} catch (InstantiationException e) { |
|
254 |
// TODO Auto-generated catch block |
|
255 |
e.printStackTrace(); |
|
256 |
} catch (IllegalAccessException e) { |
|
257 |
// TODO Auto-generated catch block |
|
258 |
e.printStackTrace(); |
|
259 |
} |
|
260 |
if (action != null && !(action instanceof OldTocContextMenuAction)) { |
|
261 |
action.setMapContext(this.mapContext); |
|
262 |
if (action.isVisible((ITocItem)this.getNodeUserObject(),this.selecteds)) { |
|
263 |
actionArrayList.add(action); |
|
264 |
} |
|
265 |
} |
|
266 | 229 |
|
230 |
result_list_sort = new ArrayList<TOCAction>(); |
|
231 |
TOCAction[] ta_array = (TOCAction[]) result_list.toArray(new TOCAction[0]); |
|
232 |
Arrays.sort(ta_array, new TOCMenuItemComparator()); |
|
233 |
int len = ta_array.length; |
|
234 |
for (int i=0; i<len; i++) { |
|
235 |
result_list_sort.add(ta_array[i]); |
|
267 | 236 |
} |
268 |
IContextMenuAction[] result = (IContextMenuAction[])Array.newInstance(IContextMenuAction.class,actionArrayList.size()); |
|
269 |
System.arraycopy(actionArrayList.toArray(),0,result,0,actionArrayList.size()); |
|
270 |
Arrays.sort(result,new CompareAction()); |
|
271 |
return result; |
|
237 |
return result_list_sort; |
|
238 |
|
|
239 |
|
|
240 |
// Iterator iter = this.extensionPoint.keySet().iterator(); |
|
241 |
// while (iter.hasNext()) { |
|
242 |
// action = null; |
|
243 |
// try { |
|
244 |
// action = (AbstractTocContextMenuAction)this.extensionPoint.create((String)iter.next()); |
|
245 |
// } catch (InstantiationException e) { |
|
246 |
// // TODO Auto-generated catch block |
|
247 |
// e.printStackTrace(); |
|
248 |
// } catch (IllegalAccessException e) { |
|
249 |
// // TODO Auto-generated catch block |
|
250 |
// e.printStackTrace(); |
|
251 |
// } |
|
252 |
// if (action != null && !(action instanceof OldTocContextMenuAction)) { |
|
253 |
// action.setMapContext(this.mapContext); |
|
254 |
// if (action.isVisible((ITocItem)this.getNodeUserObject(),this.selecteds)) { |
|
255 |
// actionArrayList.add(action); |
|
256 |
// } |
|
257 |
// } |
|
258 |
// |
|
259 |
// } |
|
260 |
// IContextMenuAction[] result = (IContextMenuAction[])Array.newInstance(IContextMenuAction.class,actionArrayList.size()); |
|
261 |
// System.arraycopy(actionArrayList.toArray(),0,result,0,actionArrayList.size()); |
|
262 |
// Arrays.sort(result,new CompareAction()); |
|
263 |
// return result; |
|
272 | 264 |
} |
273 | 265 |
return null; |
274 | 266 |
|
275 | 267 |
} |
276 | 268 |
|
269 |
/* |
|
277 | 270 |
public class CompareAction implements Comparator{ |
278 | 271 |
public int compare(Object o1, Object o2) { |
279 | 272 |
return this.compare((IContextMenuAction)o1,(IContextMenuAction)o2); |
... | ... | |
288 | 281 |
return key1.compareTo(key2); |
289 | 282 |
} |
290 | 283 |
} |
284 |
*/ |
|
291 | 285 |
|
292 |
private void createMenuElements(IContextMenuAction[] actions) { |
|
286 |
private void createMenuElements(List<TOCAction> actions) { |
|
287 |
|
|
293 | 288 |
String group = null; |
294 |
for (int i=0;i < actions.length;i++) { |
|
295 |
IContextMenuAction action = actions[i]; |
|
296 |
MenuItem item = new MenuItem(action.getText(),action); |
|
289 |
String item_group = null; |
|
290 |
TOCAction action = null; |
|
291 |
|
|
292 |
for (int i=0;i < actions.size();i++) { |
|
293 |
|
|
294 |
action = actions.get(i); |
|
295 |
|
|
296 |
if (!action.isVisible() || |
|
297 |
(action instanceof TOCActionAdapter && |
|
298 |
((TOCActionAdapter) action).getContextMenuAction() instanceof OldTocContextMenuAction)) { |
|
299 |
continue; |
|
300 |
} |
|
301 |
|
|
302 |
JMenuItem item = new JMenuItem(action); |
|
297 | 303 |
item.setFont(theFont); |
298 |
item.setEnabled(action.isEnabled(this.getNodeUserObject(),this.selecteds)); |
|
299 |
if (!action.getGroup().equals(group)) { |
|
304 |
item.setEnabled(action.isEnabled()); |
|
305 |
item_group = action.getValue(TOCAction.GROUP).toString(); |
|
306 |
if (group == null || item_group.compareToIgnoreCase(group) != 0) { |
|
300 | 307 |
if (group != null) this.addSeparator(); |
301 |
group = action.getGroup();
|
|
308 |
group = item_group;
|
|
302 | 309 |
} |
303 | 310 |
this.add(item); |
304 | 311 |
} |
312 |
|
|
313 |
// comprobamos si el ultimo elemento es un seprardor |
|
314 |
// not here |
|
315 |
/* |
|
316 |
if (this.getComponentCount()>0 && this.getComponent(this.getComponentCount()-1) instanceof Separator) { |
|
317 |
//Si lo es lo eliminamos |
|
318 |
this.remove(this.getComponentCount()-1); |
|
319 |
} |
|
320 |
*/ |
|
305 | 321 |
|
322 |
|
|
306 | 323 |
} |
307 | 324 |
|
308 | 325 |
|
326 |
/* |
|
309 | 327 |
public class MenuItem extends JMenuItem implements ActionListener{ |
310 | 328 |
private IContextMenuAction action; |
311 | 329 |
public MenuItem(String text,IContextMenuAction documentAction) { |
... | ... | |
322 | 340 |
this.action.execute(FPopupMenu.this.getNodeUserObject(), FPopupMenu.this.selecteds); |
323 | 341 |
} |
324 | 342 |
} |
343 |
*/ |
|
325 | 344 |
|
326 | 345 |
private void loadOldStileOptions() { |
327 | 346 |
boolean first = true; |
Also available in: Unified diff