root / trunk / examples / exaExample1 / src / com / iver / example / MyPrivateInfo.java @ 6885
History | View | Annotate | Download (2.27 KB)
1 |
/*
|
---|---|
2 |
* Created on 25-may-2005
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
*/
|
9 |
package com.iver.example; |
10 |
|
11 |
import com.iver.andami.PluginServices; |
12 |
import com.iver.andami.plugins.Extension; |
13 |
import com.iver.andami.ui.mdiManager.IWindow; |
14 |
import com.iver.cit.gvsig.fmap.MapContext; |
15 |
import com.iver.cit.gvsig.fmap.MapControl; |
16 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior; |
17 |
import com.iver.cit.gvsig.gui.View; |
18 |
import com.iver.cit.gvsig.project.ProjectView; |
19 |
import com.iver.example.tools.MyInfoListener; |
20 |
|
21 |
|
22 |
/**
|
23 |
* @author Fjp
|
24 |
*
|
25 |
* Main class of this extension example.
|
26 |
* The first time the method "execute" is called, we check if
|
27 |
* we have already created MyInfoListener, and if not, we
|
28 |
* create it and add to the mapControl. Then, if we receive the
|
29 |
* acction command "MYINFO", we set this tool as active.
|
30 |
*/
|
31 |
public class MyPrivateInfo extends Extension { |
32 |
|
33 |
MyInfoListener il = null;
|
34 |
public void initialize() { |
35 |
|
36 |
|
37 |
} |
38 |
|
39 |
public void execute(String actionCommand) { |
40 |
View vista = (View) PluginServices.getMDIManager().getActiveWindow(); |
41 |
MapControl mapCtrl = vista.getMapControl(); |
42 |
if (il == null) // We create it for the first time. |
43 |
{ |
44 |
il = new MyInfoListener(mapCtrl);
|
45 |
mapCtrl.addMapTool("myInfo", new PointBehavior(il)); |
46 |
} |
47 |
|
48 |
if (actionCommand.compareTo("MYINFO") == 0) |
49 |
{ |
50 |
mapCtrl.setTool("myInfo");
|
51 |
} |
52 |
} |
53 |
|
54 |
public boolean isEnabled() { |
55 |
return true; |
56 |
} |
57 |
|
58 |
/* (non-Javadoc)
|
59 |
* @see com.iver.andami.plugins.Extension#isVisible()
|
60 |
*
|
61 |
* This tool will be visible only if the View class is the active view.
|
62 |
*/
|
63 |
public boolean isVisible() { |
64 |
IWindow f = PluginServices.getMDIManager() |
65 |
.getActiveWindow(); |
66 |
|
67 |
if (f == null) { |
68 |
return false; |
69 |
} |
70 |
|
71 |
if (f.getClass() == View.class) { |
72 |
View vista = (View) f; |
73 |
ProjectView model = vista.getModel(); |
74 |
MapContext mapa = model.getMapContext(); |
75 |
|
76 |
return mapa.getLayers().getLayersCount() > 0; |
77 |
} else {
|
78 |
return false; |
79 |
} |
80 |
} |
81 |
|
82 |
} |