Revision 14821 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/ThemeToAnnotationExtension.java

View differences:

ThemeToAnnotationExtension.java
79 79
public class ThemeToAnnotationExtension extends Extension {
80 80
    private MapContext map=null;
81 81
    private IWindow view=null;
82
	/**
82
    /**
83 83
     * @see com.iver.andami.plugins.IExtension#initialize()
84 84
     */
85 85
    public void initialize() {
86
    	registerIcons();
86 87
    }
87 88

  
89
    private void registerIcons(){
90

  
91
    }
92

  
88 93
    /**
89 94
     * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
90 95
     */
91 96

  
92 97
    public class MyFinishAction extends FinishAction {
93
    	private JWizardComponents myWizardComponents;
94
    	private MapContext map;
95
    	private FLyrVect layerVectorial;
96
    	private FLyrAnnotation layerAnnotation;
98
        private JWizardComponents myWizardComponents;
99
        private MapContext map;
100
        private FLyrVect layerVectorial;
101
        private FLyrAnnotation layerAnnotation;
97 102

  
98
		public MyFinishAction(JWizardComponents wizardComponents, MapContext map,FLyrVect layerVectorial, FLyrAnnotation layerAnnotation ) {
99
			super(wizardComponents);
100
			this.map = map;
101
			this.layerVectorial = layerVectorial;
102
			this.layerAnnotation = layerAnnotation;
103
			myWizardComponents = wizardComponents;
103
        public MyFinishAction(JWizardComponents wizardComponents, MapContext map,FLyrVect layerVectorial, FLyrAnnotation layerAnnotation ) {
104
            super(wizardComponents);
105
            this.map = map;
106
            this.layerVectorial = layerVectorial;
107
            this.layerAnnotation = layerAnnotation;
108
            myWizardComponents = wizardComponents;
104 109

  
105
		}
110
        }
106 111

  
107
		public void performAction() {
112
        public void performAction() {
108 113

  
109
			myWizardComponents.getFinishButton().setEnabled(false);
110
			SelectAnnotationLayerNameAndField panel1 = (SelectAnnotationLayerNameAndField) myWizardComponents.getWizardPanel(0);
111
			ConfigureLabel panel2 = (ConfigureLabel) myWizardComponents.getWizardPanel(1);
114
            myWizardComponents.getFinishButton().setEnabled(false);
115
            SelectAnnotationLayerNameAndField panel1 = (SelectAnnotationLayerNameAndField) myWizardComponents.getWizardPanel(0);
116
            ConfigureLabel panel2 = (ConfigureLabel) myWizardComponents.getWizardPanel(1);
112 117

  
113 118

  
114
			SelectableDataSource source;
115
			MappingAnnotation mapping=new MappingAnnotation();
119
            SelectableDataSource source;
120
            MappingAnnotation mapping=new MappingAnnotation();
116 121

  
117
			try {
118
				source = this.layerAnnotation.getRecordset();
122
            try {
123
                source = this.layerAnnotation.getRecordset();
119 124

  
120 125

  
121 126

  
122
				mapping.setColumnText(source.getFieldIndexByName(panel1.getField()));
127
                mapping.setColumnText(source.getFieldIndexByName(panel1.getField()));
123 128

  
124
				if (!panel2.getAngleFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
125
					mapping.setColumnRotate(source.getFieldIndexByName(panel2.getAngleFieldName()));
126
				}
129
                if (!panel2.getAngleFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
130
                    mapping.setColumnRotate(source.getFieldIndexByName(panel2.getAngleFieldName()));
131
                }
127 132

  
128
				if (!panel2.getColorFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
129
					mapping.setColumnColor(source.getFieldIndexByName(panel2.getColorFieldName()));
130
				}
133
                if (!panel2.getColorFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
134
                    mapping.setColumnColor(source.getFieldIndexByName(panel2.getColorFieldName()));
135
                }
131 136

  
132
				if (!panel2.getSizeFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
133
					mapping.setColumnHeight(source.getFieldIndexByName(panel2.getSizeFieldName()));
134
				}
135
				this.layerAnnotation.setInPixels(panel2.sizeUnitsInPixels());
137
                if (!panel2.getSizeFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
138
                    mapping.setColumnHeight(source.getFieldIndexByName(panel2.getSizeFieldName()));
139
                }
140
                this.layerAnnotation.setInPixels(panel2.sizeUnitsInPixels());
136 141

  
137
				if (!panel2.getFontFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
138
					mapping.setColumnTypeFont(source.getFieldIndexByName(panel2.getFontFieldName()));
139
				}
140
			} catch (ReadDriverException e) {
141
				e.printStackTrace();
142
				return;
143
			}
142
                if (!panel2.getFontFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
143
                    mapping.setColumnTypeFont(source.getFieldIndexByName(panel2.getFontFieldName()));
144
                }
145
            } catch (ReadDriverException e) {
146
                e.printStackTrace();
147
                return;
148
            }
144 149

  
145 150

  
146
			this.layerAnnotation.setName(panel1.getNewLayerName());
147
			this.layerAnnotation.setMapping(mapping);
151
            this.layerAnnotation.setName(panel1.getNewLayerName());
152
            this.layerAnnotation.setMapping(mapping);
148 153

  
149 154

  
150
        	this.map.getLayers().addLayer(this.layerAnnotation);
151
        	this.map.getLayers().removeLayer(this.layerVectorial);
155
            this.map.getLayers().addLayer(this.layerAnnotation);
156
            this.map.getLayers().removeLayer(this.layerVectorial);
152 157

  
153
        	Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject();
154
        	ArrayList projectTables=project.getDocumentsByType(ProjectTableFactory.registerName);
155
        	for (int i=0;i<projectTables.size();i++){
156
        		ProjectTable pt=(ProjectTable)projectTables.get(i);
157
        		if (pt.getAssociatedTable()!=null && pt.getAssociatedTable().equals(this.layerVectorial)){
158
        			pt.setAssociatedTable(this.layerAnnotation);
159
        		}
160
        	}
158
            Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject();
159
            ArrayList projectTables=project.getDocumentsByType(ProjectTableFactory.registerName);
160
            for (int i=0;i<projectTables.size();i++){
161
                ProjectTable pt=(ProjectTable)projectTables.get(i);
162
                if (pt.getAssociatedTable()!=null && pt.getAssociatedTable().equals(this.layerVectorial)){
163
                    pt.setAssociatedTable(this.layerAnnotation);
164
                }
165
            }
161 166

  
162
        	this.layerAnnotation.setActive(true);
163
        	this.myWizardComponents.getCancelAction().performAction();
164
		}
167
            this.layerAnnotation.setActive(true);
168
            this.myWizardComponents.getCancelAction().performAction();
169
        }
165 170

  
166 171
    }
167 172
    public void execute(String actionCommand) {
168 173
        if ("LAYERTOANNOTATION".equals(actionCommand)) {
169
        	ImageIcon Logo = new javax.swing.ImageIcon(this.getClass().getClassLoader()
170
					.getResource("images/package_graphics.png"));
174
            ImageIcon Logo = new javax.swing.ImageIcon(this.getClass().getClassLoader()
175
                    .getResource("images/package_graphics.png"));
171 176

  
172
        	SimpleWizard wizard = new SimpleWizard(Logo);
177
            SimpleWizard wizard = new SimpleWizard(Logo);
173 178

  
174 179
            FLyrVect lv=(FLyrVect)map.getLayers().getActives()[0];
175 180
            FLyrAnnotation la=new FLyrAnnotation();
176 181
            LayerListener[] layerListeners=lv.getLayerListeners();
177 182
            for (int i=0;i<layerListeners.length;i++) {
178
            	la.addLayerListener(layerListeners[i]);
183
                la.addLayerListener(layerListeners[i]);
179 184
            }
180 185

  
181 186
            la.setSource(lv.getSource());
182 187
            la.setProjection(lv.getProjection());
183 188

  
184
        	SelectAnnotationLayerNameAndField panel1 = new SelectAnnotationLayerNameAndField(wizard.getWizardComponents(),la);
185
        	ConfigureLabel panel2 = new ConfigureLabel(wizard.getWizardComponents(),la);
189
            SelectAnnotationLayerNameAndField panel1 = new SelectAnnotationLayerNameAndField(wizard.getWizardComponents(),la);
190
            ConfigureLabel panel2 = new ConfigureLabel(wizard.getWizardComponents(),la);
186 191

  
187 192

  
188 193

  
189
        	wizard.getWizardComponents().addWizardPanel(panel1);
190
        	wizard.getWizardComponents().addWizardPanel(panel2);
194
            wizard.getWizardComponents().addWizardPanel(panel1);
195
            wizard.getWizardComponents().addWizardPanel(panel2);
191 196

  
192
			wizard.getWizardComponents().setFinishAction(
193
					new MyFinishAction(wizard.getWizardComponents(),
194
							map,lv, la));
197
            wizard.getWizardComponents().setFinishAction(
198
                    new MyFinishAction(wizard.getWizardComponents(),
199
                            map,lv, la));
195 200

  
196
			wizard.getWindowInfo().setWidth(540);
197
			wizard.getWindowInfo().setHeight(380);
198
			wizard.getWindowInfo().setTitle(PluginServices.getText(this,"to_annotation"));
201
            wizard.getWindowInfo().setWidth(540);
202
            wizard.getWindowInfo().setHeight(380);
203
            wizard.getWindowInfo().setTitle(PluginServices.getText(this,"to_annotation"));
199 204

  
200
			PluginServices.getMDIManager().addWindow(wizard);
201
			((ProjectDocument)((View)view).getModel()).setModified(true);
205
            PluginServices.getMDIManager().addWindow(wizard);
206
            ((ProjectDocument)((View)view).getModel()).setModified(true);
202 207

  
203 208

  
204
        	/*
209
            /*
205 210
            FLyrVect lv=(FLyrVect)map.getLayers().getActives()[0];
206 211
            FLyrAnnotation la=new FLyrAnnotation();
207 212
            la.setSource(lv.getSource());
208 213

  
209
			MappingFieldsToAnotation mfta=new MappingFieldsToAnotation(la);
214
            MappingFieldsToAnotation mfta=new MappingFieldsToAnotation(la);
210 215
            PluginServices.getMDIManager().addView(mfta);
211 216

  
212 217
            if (mfta.isOk()){
213
            	map.getLayers().addLayer(la);
214
            	map.getLayers().removeLayer(lv);
218
                map.getLayers().addLayer(la);
219
                map.getLayers().removeLayer(lv);
215 220
            }
216 221
            */
217 222

  
......
222 227
     * @see com.iver.andami.plugins.IExtension#isEnabled()
223 228
     */
224 229
    public boolean isEnabled() {
225
    	IWindow v = PluginServices.getMDIManager().getActiveWindow();
230
        IWindow v = PluginServices.getMDIManager().getActiveWindow();
226 231

  
227 232
        if (v != null && v instanceof com.iver.cit.gvsig.project.documents.view.gui.View) {
228
        	com.iver.cit.gvsig.project.documents.view.gui.View vista=(com.iver.cit.gvsig.project.documents.view.gui.View)v;
229
        	IProjectView model = vista.getModel();
230
    		map = model.getMapContext();
231
    		FLayer[] layers=map.getLayers().getActives();
232
    		if (layers.length==1){
233
    			if (layers[0].isAvailable() && layers[0] instanceof FLyrVect){
234
    				FLyrVect lv=(FLyrVect)layers[0];
235
    				ReadableVectorial src = lv.getSource();
236
    				try {
237
						if (src == null || src.getShapeType()==FShape.POLYGON || src.getShapeType()==FShape.LINE)
238
							return false;
239
						SelectableDataSource sds=lv.getSource().getRecordset();
240
						if (sds.getFieldCount()>0)
241
							return true;
242
					} catch (ReadDriverException e) {
243
						return false;
244
					}
245
    			}
246
    		}
233
            com.iver.cit.gvsig.project.documents.view.gui.View vista=(com.iver.cit.gvsig.project.documents.view.gui.View)v;
234
            IProjectView model = vista.getModel();
235
            map = model.getMapContext();
236
            FLayer[] layers=map.getLayers().getActives();
237
            if (layers.length==1){
238
                if (layers[0].isAvailable() && layers[0] instanceof FLyrVect){
239
                    FLyrVect lv=(FLyrVect)layers[0];
240
                    ReadableVectorial src = lv.getSource();
241
                    try {
242
                        if (src == null || src.getShapeType()==FShape.POLYGON || src.getShapeType()==FShape.LINE)
243
                            return false;
244
                        SelectableDataSource sds=lv.getSource().getRecordset();
245
                        if (sds.getFieldCount()>0)
246
                            return true;
247
                    } catch (ReadDriverException e) {
248
                        return false;
249
                    }
250
                }
251
            }
247 252
        }
248 253
        return false;
249 254
    }

Also available in: Unified diff