Revision 4224

View differences:

trunk/applications/appgvSIG/src/com/iver/cit/gvsig/ThemeToAnnotationExtension.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 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
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig;
42

  
43
import com.hardcode.gdbms.engine.data.driver.DriverException;
44
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException;
45
import com.iver.andami.PluginServices;
46
import com.iver.andami.plugins.Extension;
47
import com.iver.andami.ui.mdiManager.View;
48
import com.iver.cit.gvsig.fmap.FMap;
49
import com.iver.cit.gvsig.fmap.core.FShape;
50
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
51
import com.iver.cit.gvsig.fmap.layers.FLayer;
52
import com.iver.cit.gvsig.fmap.layers.FLyrAnnotation;
53
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
54
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
55
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
56
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend;
57
import com.iver.cit.gvsig.gui.Panels.MappingFieldsToAnotation;
58
import com.iver.cit.gvsig.project.ProjectView;
59

  
60

  
61
/**
62
 * DOCUMENT ME!
63
 *
64
 * @author Vicente Caballero Navarro
65
 */
66
public class ThemeToAnnotationExtension implements Extension {
67
    private FMap map=null;
68
	/**
69
     * @see com.iver.andami.plugins.Extension#inicializar()
70
     */
71
    public void inicializar() {
72
    }
73

  
74
    /**
75
     * @see com.iver.andami.plugins.Extension#execute(java.lang.String)
76
     */
77
    public void execute(String actionCommand) {
78
        if ("THEMETOANNOTATION".equals(actionCommand)) {
79
            FLyrVect lv=(FLyrVect)map.getLayers().getActives()[0];
80
            FLyrAnnotation la=new FLyrAnnotation();
81
            la.setSource(lv.getSource());
82
            //la.createSpatialIndex();
83
            try {
84
				la.setLegend(LegendFactory.createSingleSymbolLegend(FShape.TEXT));
85
			} catch (FieldNotFoundException e) {
86
				// TODO Auto-generated catch block
87
				e.printStackTrace();
88
			} catch (com.iver.cit.gvsig.fmap.DriverException e) {
89
				// TODO Auto-generated catch block
90
				e.printStackTrace();
91
			}
92
			MappingFieldsToAnotation mfta=new MappingFieldsToAnotation(la);
93
            PluginServices.getMDIManager().addView(mfta);
94
            map.getLayers().addLayer(la);
95
            map.getLayers().removeLayer(lv);
96
        }
97
    }
98

  
99
    /**
100
     * @see com.iver.andami.plugins.Extension#isEnabled()
101
     */
102
    public boolean isEnabled() {
103
    	View v = PluginServices.getMDIManager().getActiveView();
104

  
105
        if (v == null) {
106
            return false;
107
        } else if (v.getClass() == com.iver.cit.gvsig.gui.View.class) {
108
        	com.iver.cit.gvsig.gui.View vista=(com.iver.cit.gvsig.gui.View)v;
109
        	ProjectView model = vista.getModel();
110
    		map = model.getMapContext();
111
    		FLayer[] layers=map.getLayers().getActives();
112
    		if (layers.length==1){
113
    			if (layers[0] instanceof FLyrVect){
114
    				FLyrVect lv=(FLyrVect)layers[0];
115
    				SelectableDataSource sds=lv.getSource().getRecordset();
116
    				try {
117
						if (sds.getFieldCount()>0)
118
							return true;
119
					} catch (DriverException e) {
120
						return false;
121
					}
122
    			}
123
    		}
124
    		return false;
125
        } else {
126
            return false;
127
        }
128
    }
129

  
130
    /**
131
     * @see com.iver.andami.plugins.Extension#isVisible()
132
     */
133
    public boolean isVisible() {
134
        View v = PluginServices.getMDIManager().getActiveView();
135

  
136
        if (v == null) {
137
            return false;
138
        } else if (v.getClass() == com.iver.cit.gvsig.gui.View.class) {
139
            return true;
140
        } else {
141
            return false;
142
        }
143
    }
144
}
0 145

  

Also available in: Unified diff