Revision 1261

View differences:

org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.merge/src/main/java/org/gvsig/geoprocess/algorithm/merge/MergeParametersPanel.java
54 54

  
55 55
/**
56 56
 * Panel for merge algorithm
57
 *
57 58
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
58 59
 */
59 60
public class MergeParametersPanel extends GeoAlgorithmParametersPanel implements ActionListener {
60
	private static final long                serialVersionUID   = 1L;
61
	private GeoAlgorithm                     m_Algorithm        = null;
62
	private JComboBox                        fieldsCombo        = null;
63
	private JCheckBox                        allLayers          = null;
64
	//private AlgorithmOutputPanel             output             = null;
65
	private final String[]                   columnNames        = { GeoProcessLocator.getGeoProcessManager().getTranslation("Selected"),
66
																	GeoProcessLocator.getGeoProcessManager().getTranslation("Layer") };
67
	private final int[]                      columnWidths       = { 35, 334 };
68
	private TableContainer                   table              = null;
69
	private ObjectAndDescription[]           layerList          = null;
70
	private AlgorithmOutputPanel             algorithmOutputPanel  = null;
71
	private OutputChannelSelectionPanel      outputChannelSelectionPanelPol;
72
	private OutputChannelSelectionPanel      outputChannelSelectionPanelLine;
73
	private OutputChannelSelectionPanel      outputChannelSelectionPanelPoint;
74
	private JPanel                           outputPanel;
75 61

  
76
	public MergeParametersPanel() {
77
		super();
78
	}
62
    private static final long serialVersionUID = 1L;
63
    private GeoAlgorithm m_Algorithm = null;
64
    private JComboBox fieldsCombo = null;
65
    private JCheckBox allLayers = null;
66
    //private AlgorithmOutputPanel             output             = null;
67
    private final String[] columnNames = {GeoProcessLocator.getGeoProcessManager().getTranslation("Selected"),
68
        GeoProcessLocator.getGeoProcessManager().getTranslation("Layer")};
69
    private final int[] columnWidths = {35, 334};
70
    private TableContainer table = null;
71
    private ObjectAndDescription[] layerList = null;
72
    private AlgorithmOutputPanel algorithmOutputPanel = null;
73
    private OutputChannelSelectionPanel outputChannelSelectionPanelPol;
74
    private OutputChannelSelectionPanel outputChannelSelectionPanelLine;
75
    private OutputChannelSelectionPanel outputChannelSelectionPanelPoint;
76
    private JPanel outputPanel;
79 77

  
78
    public MergeParametersPanel() {
79
        super();
80
    }
81

  
80 82
    public void init(GeoAlgorithm algorithm) {
81
    	m_Algorithm = algorithm;
82
    	initGUI();
83
        m_Algorithm = algorithm;
84
        initGUI();
83 85
    }
84 86

  
85
	private void initGUI() {
86
		GridBagLayout gbl = new GridBagLayout();
87
		this.setLayout(gbl);
87
    private void initGUI() {
88
        GridBagLayout gbl = new GridBagLayout();
89
        this.setLayout(gbl);
88 90

  
89
		GridBagConstraints gbc = new GridBagConstraints();
90
		gbc.fill = GridBagConstraints.HORIZONTAL;
91
		gbc.weightx = 1.0;
92
		gbc.gridx = 0;
93
		gbc.gridy = 0;
94
		gbc.insets = new Insets(5, 5, 8, 5);
95
		this.add(getAllLayersCheck(), gbc);
91
        GridBagConstraints gbc = new GridBagConstraints();
92
        gbc.fill = GridBagConstraints.HORIZONTAL;
93
        gbc.weightx = 1.0;
94
        gbc.gridx = 0;
95
        gbc.gridy = 0;
96
        gbc.insets = new Insets(5, 5, 8, 5);
97
        this.add(getAllLayersCheck(), gbc);
96 98

  
97
		gbc.gridy = 1;
98
		gbc.fill = GridBagConstraints.BOTH;
99
		gbc.insets = new Insets(0, 0, 12, 0);
100
		gbc.weighty = 1.0;
101
		this.add(getCheckBoxTable(), gbc);
99
        gbc.gridy = 1;
100
        gbc.fill = GridBagConstraints.BOTH;
101
        gbc.insets = new Insets(0, 0, 12, 0);
102
        gbc.weighty = 1.0;
103
        this.add(getCheckBoxTable(), gbc);
102 104

  
103
		gbc.gridy = 2;
104
		gbc.fill = GridBagConstraints.HORIZONTAL;
105
		gbc.insets = new Insets(5, 5, 8, 5);
106
		gbc.weightx = 1.0;
107
		gbc.weighty = 0;
108
		this.add(getFieldsComboPanel(GeoProcessLocator.getGeoProcessManager().getTranslation("use_fields_from_layer"), getFieldsCombo()), gbc);
105
        gbc.gridy = 2;
106
        gbc.fill = GridBagConstraints.HORIZONTAL;
107
        gbc.insets = new Insets(5, 5, 8, 5);
108
        gbc.weightx = 1.0;
109
        gbc.weighty = 0;
110
        this.add(getFieldsComboPanel(GeoProcessLocator.getGeoProcessManager().getTranslation("use_fields_from_layer"), getFieldsCombo()), gbc);
109 111

  
110
		gbc.gridy = 3;
111
		this.add(getOutputChannelSelectionPanel(), gbc);
112
        gbc.gridy = 3;
113
        this.add(getOutputChannelSelectionPanel(), gbc);
112 114

  
113
		initTable();
114
	}
115
        initTable();
116
    }
115 117

  
116
	/**
117
	 * Gets the output panel (SEXTANTE)
118
	 * @return
119
	 */
120
	private JPanel getOutputChannelSelectionPanel() {
121
		if(outputPanel == null) {
122
			try {
123
				outputPanel = new JPanel();
124
				outputPanel.setLayout(new GridBagLayout());
125
				final OutputObjectsSet ooSet = m_Algorithm.getOutputObjects();
126
				final Output out_pol = ooSet.getOutput(MergeAlgorithm.RESULT_POL);
127
				final Output out_line = ooSet.getOutput(MergeAlgorithm.RESULT_LINE);
128
				final Output out_point = ooSet.getOutput(MergeAlgorithm.RESULT_POINT);
118
    /**
119
     * Gets the output panel (SEXTANTE)
120
     *
121
     * @return
122
     */
123
    private JPanel getOutputChannelSelectionPanel() {
124
        if (outputPanel == null) {
125
            try {
126
                outputPanel = new JPanel();
127
                outputPanel.setLayout(new GridBagLayout());
128
                final OutputObjectsSet ooSet = m_Algorithm.getOutputObjects();
129
                final Output out_pol = ooSet.getOutput(MergeAlgorithm.RESULT_POL);
130
                final Output out_line = ooSet.getOutput(MergeAlgorithm.RESULT_LINE);
131
                final Output out_point = ooSet.getOutput(MergeAlgorithm.RESULT_POINT);
129 132

  
130
				outputChannelSelectionPanelPol = new OutputChannelSelectionPanel(out_pol, m_Algorithm.getParameters());
131
				outputChannelSelectionPanelLine = new OutputChannelSelectionPanel(out_line, m_Algorithm.getParameters());
132
				outputChannelSelectionPanelPoint = new OutputChannelSelectionPanel(out_point, m_Algorithm.getParameters());
133
                outputChannelSelectionPanelPol = new OutputChannelSelectionPanel(out_pol, m_Algorithm.getParameters());
134
                outputChannelSelectionPanelLine = new OutputChannelSelectionPanel(out_line, m_Algorithm.getParameters());
135
                outputChannelSelectionPanelPoint = new OutputChannelSelectionPanel(out_point, m_Algorithm.getParameters());
133 136

  
134
				String label = GeoProcessLocator.getGeoProcessManager().getTranslation("Merge");
137
                String label = GeoProcessLocator.getGeoProcessManager().getTranslation("Merge");
135 138

  
136
				GridBagConstraints gbc = new GridBagConstraints();
137
				gbc.fill = GridBagConstraints.HORIZONTAL;
138
				gbc.insets = new Insets(0, 0, 4, 0);
139
				gbc.weightx = 1;
140
				gbc.gridx = 0;
141
				gbc.gridy = 0;
142
				outputPanel.add(new JLabel(" " + label + " [" +
143
						GeoProcessLocator.getGeoProcessManager().getTranslation("Polygon") + "]               "), gbc);
139
                GridBagConstraints gbc = new GridBagConstraints();
140
                gbc.fill = GridBagConstraints.HORIZONTAL;
141
                gbc.insets = new Insets(0, 0, 4, 0);
142
                gbc.weightx = 1;
143
                gbc.gridx = 0;
144
                gbc.gridy = 0;
145
                outputPanel.add(new JLabel(" " + label + " ["
146
                        + GeoProcessLocator.getGeoProcessManager().getTranslation("Polygon") + "]               "), gbc);
144 147

  
145
				gbc.gridx = 0;
146
				gbc.gridy = 1;
147
				outputPanel.add(new JLabel(" " + label + " [" +
148
						GeoProcessLocator.getGeoProcessManager().getTranslation("Line") + "]               "), gbc);
148
                gbc.gridx = 0;
149
                gbc.gridy = 1;
150
                outputPanel.add(new JLabel(" " + label + " ["
151
                        + GeoProcessLocator.getGeoProcessManager().getTranslation("Line") + "]               "), gbc);
149 152

  
150
				gbc.gridx = 0;
151
				gbc.gridy = 2;
152
				outputPanel.add(new JLabel(" " + label + " [" +
153
						GeoProcessLocator.getGeoProcessManager().getTranslation("Point") + "]               "), gbc);
153
                gbc.gridx = 0;
154
                gbc.gridy = 2;
155
                outputPanel.add(new JLabel(" " + label + " ["
156
                        + GeoProcessLocator.getGeoProcessManager().getTranslation("Point") + "]               "), gbc);
154 157

  
155
				gbc.fill = GridBagConstraints.HORIZONTAL;
156
				gbc.weightx = 1;
157
				gbc.gridx = 1;
158
				gbc.gridy = 0;
159
				outputPanel.add(outputChannelSelectionPanelPol, gbc);
158
                gbc.fill = GridBagConstraints.HORIZONTAL;
159
                gbc.weightx = 1;
160
                gbc.gridx = 1;
161
                gbc.gridy = 0;
162
                outputPanel.add(outputChannelSelectionPanelPol, gbc);
160 163

  
161
				gbc.gridx = 1;
162
				gbc.gridy = 1;
163
				outputPanel.add(outputChannelSelectionPanelLine, gbc);
164
                gbc.gridx = 1;
165
                gbc.gridy = 1;
166
                outputPanel.add(outputChannelSelectionPanelLine, gbc);
164 167

  
165
				gbc.gridx = 1;
166
				gbc.gridy = 2;
167
				outputPanel.add(outputChannelSelectionPanelPoint, gbc);
168
			} catch (final Exception e) {
169
				Sextante.addErrorToLog(e);
170
			}
171
		}
172
		return outputPanel;
173
	}
168
                gbc.gridx = 1;
169
                gbc.gridy = 2;
170
                outputPanel.add(outputChannelSelectionPanelPoint, gbc);
171
            } catch (final Exception e) {
172
                Sextante.addErrorToLog(e);
173
            }
174
        }
175
        return outputPanel;
176
    }
174 177

  
175
	/**
176
	 * Gets the output panel (DAL)
177
	 * @return
178
	 */
179
	@SuppressWarnings("unused")
180
	private AlgorithmOutputPanel getAlgorithmOutputPanel() {
181
		if(algorithmOutputPanel == null)
182
		    algorithmOutputPanel = new AlgorithmOutputPanel();
183
		return algorithmOutputPanel;
184
	}
178
    /**
179
     * Gets the output panel (DAL)
180
     *
181
     * @return
182
     */
183
    @SuppressWarnings("unused")
184
    private AlgorithmOutputPanel getAlgorithmOutputPanel() {
185
        if (algorithmOutputPanel == null) {
186
            algorithmOutputPanel = new AlgorithmOutputPanel();
187
        }
188
        return algorithmOutputPanel;
189
    }
185 190

  
186
	/**
187
	 * Gets a new JPanel with the text and JComboBox
188
	 * @param text
189
	 * @param combo
190
	 * @return
191
	 */
192
	public JPanel getFieldsComboPanel(String text, JComboBox combo) {
193
		JPanel panel = new JPanel();
194
		GridBagLayout gbl = new GridBagLayout();
195
		panel.setLayout(gbl);
191
    /**
192
     * Gets a new JPanel with the text and JComboBox
193
     *
194
     * @param text
195
     * @param combo
196
     * @return
197
     */
198
    public JPanel getFieldsComboPanel(String text, JComboBox combo) {
199
        JPanel panel = new JPanel();
200
        GridBagLayout gbl = new GridBagLayout();
201
        panel.setLayout(gbl);
196 202

  
197
		GridBagConstraints gbc = new GridBagConstraints();
198
		gbc.fill = GridBagConstraints.HORIZONTAL;
199
		gbc.weightx = 1.0;
200
		gbc.gridx = 0;
201
		gbc.insets = new Insets(0, 0, 4, 0);
202
		JLabel label = new JLabel(text);
203
        GridBagConstraints gbc = new GridBagConstraints();
204
        gbc.fill = GridBagConstraints.HORIZONTAL;
205
        gbc.weightx = 1.0;
206
        gbc.gridx = 0;
207
        gbc.insets = new Insets(0, 0, 4, 0);
208
        JLabel label = new JLabel(text);
203 209
//		label.setPreferredSize(new Dimension(80, 18));
204
		panel.add(label, gbc);
210
        panel.add(label, gbc);
205 211

  
206
		gbc.fill = GridBagConstraints.HORIZONTAL;
207
		gbc.weightx = 1.0;
208
		gbc.gridx = 1;
212
        gbc.fill = GridBagConstraints.HORIZONTAL;
213
        gbc.weightx = 1.0;
214
        gbc.gridx = 1;
209 215
//		gbc.anchor = GridBagConstraints.EAST;
210
		gbc.insets = new Insets(0, 0, 4, 0);
211
		panel.add(combo, gbc);
212
		return panel;
213
	}
216
        gbc.insets = new Insets(0, 0, 4, 0);
217
        panel.add(combo, gbc);
218
        return panel;
219
    }
214 220

  
215
	/**
216
	 * Gets a ComboBox
217
	 * @return
218
	 */
219
	public JComboBox getFieldsCombo() {
220
		if(fieldsCombo == null) {
221
			fieldsCombo = new JComboBox();
221
    /**
222
     * Gets a ComboBox
223
     *
224
     * @return
225
     */
226
    public JComboBox getFieldsCombo() {
227
        if (fieldsCombo == null) {
228
            fieldsCombo = new JComboBox();
222 229
//			fieldsCombo.setPreferredSize(new Dimension(0, 18));
223
			ObjectAndDescription[] fieldList = getLayerList();
224
			fieldsCombo.removeAllItems();
225
			for (int i = 0; i < fieldList.length; i++)
226
				fieldsCombo.addItem(fieldList[i]);
227
		}
228
		return fieldsCombo;
229
	}
230
            ObjectAndDescription[] fieldList = getLayerList();
231
            fieldsCombo.removeAllItems();
232
            for (int i = 0; i < fieldList.length; i++) {
233
                fieldsCombo.addItem(fieldList[i]);
234
            }
235
        }
236
        return fieldsCombo;
237
    }
230 238

  
231
	/**
232
	 * Gets a CheckBox
233
	 * @return
234
	 */
235
	public JCheckBox getAllLayersCheck() {
236
		if(allLayers == null) {
237
			allLayers = new JCheckBox(GeoProcessLocator.getGeoProcessManager().getTranslation("select_all_layers"));
238
			allLayers.addActionListener(this);
239
		}
240
		return allLayers;
241
	}
239
    /**
240
     * Gets a CheckBox
241
     *
242
     * @return
243
     */
244
    public JCheckBox getAllLayersCheck() {
245
        if (allLayers == null) {
246
            allLayers = new JCheckBox(GeoProcessLocator.getGeoProcessManager().getTranslation("select_all_layers"));
247
            allLayers.addActionListener(this);
248
        }
249
        return allLayers;
250
    }
242 251

  
243
	/**
244
	 * Gets the summary table
245
	 * @return TableContainer
246
	 */
247
	public TableContainer getCheckBoxTable() {
248
		if (table == null) {
249
			table = new TableContainer(columnNames, columnWidths, null);
250
			table.setModel("CheckBoxModel");
251
			table.setControlVisible(false);
252
			table.initialize();
253
		}
254
		return table;
255
	}
252
    /**
253
     * Gets the summary table
254
     *
255
     * @return TableContainer
256
     */
257
    public TableContainer getCheckBoxTable() {
258
        if (table == null) {
259
            table = new TableContainer(columnNames, columnWidths, null);
260
            table.setModel("CheckBoxModel");
261
            table.setControlVisible(false);
262
            table.initialize();
263
        }
264
        return table;
265
    }
256 266

  
257
	//------------------------------------------------------------
267
    //------------------------------------------------------------
258 268

  
259
	/*
269
    /*
260 270
	 * (non-Javadoc)
261 271
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
262
	 */
263
	public void actionPerformed(ActionEvent e) {
264
		if(e.getSource() == getAllLayersCheck()) {
265
			//Selecci?n de todas las capas de la tabla
266
			try {
267
				for (int i = 0; i < getCheckBoxTable().getRowCount(); i++) {
268
					if(getAllLayersCheck().isSelected())
269
						getCheckBoxTable().getModel().setValueAt(new Boolean(true), i, 0);
270
					else
271
						getCheckBoxTable().getModel().setValueAt(new Boolean(false), i, 0);
272
				}
273
			} catch (NotInitializeException e1) {
274
				Sextante.addErrorToLog(e1);
275
			}
276
		}
277
	}
272
     */
273
    public void actionPerformed(ActionEvent e) {
274
        if (e.getSource() == getAllLayersCheck()) {
275
            //Selecci?n de todas las capas de la tabla
276
            try {
277
                for (int i = 0; i < getCheckBoxTable().getRowCount(); i++) {
278
                    if (getAllLayersCheck().isSelected()) {
279
                        getCheckBoxTable().getModel().setValueAt(new Boolean(true), i, 0);
280
                    } else {
281
                        getCheckBoxTable().getModel().setValueAt(new Boolean(false), i, 0);
282
                    }
283
                }
284
            } catch (NotInitializeException e1) {
285
                Sextante.addErrorToLog(e1);
286
            }
287
        }
288
    }
278 289

  
279
	/**
280
	 * Adds to the table one entry for each field
281
	 */
282
	private void initTable() {
283
		try {
284
			getCheckBoxTable().removeAllRows();
285
			ObjectAndDescription[] layerList = getLayerList();
286
			for (int i = 0; i < layerList.length; i++)
287
				addTableRow(layerList[i].getDescription());
288
		} catch (NotInitializeException e) {
289
			Sextante.addErrorToLog(e);
290
		}
291
	}
290
    /**
291
     * Adds to the table one entry for each field
292
     */
293
    private void initTable() {
294
        try {
295
            getCheckBoxTable().removeAllRows();
296
            ObjectAndDescription[] layerList = getLayerList();
297
            for (int i = 0; i < layerList.length; i++) {
298
                addTableRow(layerList[i].getDescription());
299
            }
300
        } catch (NotInitializeException e) {
301
            Sextante.addErrorToLog(e);
302
        }
303
    }
292 304

  
293
	/**
294
	 * Adds one entry to the table
295
	 * @param layerName
296
	 *        Layer name
297
	 * @throws NotInitializeException
298
	 */
299
	private void addTableRow(String layerName) throws NotInitializeException {
300
		Object[] row = {	new Boolean(false),
301
							layerName };
302
		getCheckBoxTable().addRow(row);
303
	}
305
    /**
306
     * Adds one entry to the table
307
     *
308
     * @param layerName Layer name
309
     * @throws NotInitializeException
310
     */
311
    private void addTableRow(String layerName) throws NotInitializeException {
312
        Object[] row = {new Boolean(false),
313
            layerName};
314
        getCheckBoxTable().addRow(row);
315
    }
304 316

  
305
	@Override
317
    @Override
306 318
    public void assignParameters() {
307
		try {
308
			ParametersSet params = m_Algorithm.getParameters();
309
			params.getParameter(MergeAlgorithm.FIELDLAYER).setParameterValue(getSelectedVectorLayer());
310
			params.getParameter(MergeAlgorithm.LAYERS).setParameterValue(getSelectedLayerList());
319
        try {
320
            ParametersSet params = m_Algorithm.getParameters();
321
            params.getParameter(MergeAlgorithm.FIELDLAYER).setParameterValue(getSelectedVectorLayer());
322
            params.getParameter(MergeAlgorithm.LAYERS).setParameterValue(getSelectedLayerList());
311 323

  
312
			OutputObjectsSet ooSet = m_Algorithm.getOutputObjects();
313
			Output outPol = ooSet.getOutput(MergeAlgorithm.RESULT_POL);
314
			Output outLine = ooSet.getOutput(MergeAlgorithm.RESULT_LINE);
315
			Output outPoint = ooSet.getOutput(MergeAlgorithm.RESULT_POINT);
324
            OutputObjectsSet ooSet = m_Algorithm.getOutputObjects();
325
            Output outPol = ooSet.getOutput(MergeAlgorithm.RESULT_POL);
326
            Output outLine = ooSet.getOutput(MergeAlgorithm.RESULT_LINE);
327
            Output outPoint = ooSet.getOutput(MergeAlgorithm.RESULT_POINT);
316 328

  
317
			//Reponer estas l?neas para cambiar el panel de salida y comentar la siguiente
318
			//AlgorithmOutputPanel fsp = getAlgorithmOutputPanel();
319
			//out.setOutputChannel(new CompositeSourceOutputChannel(fsp.getOutputParameters()));
320
			outPol.setOutputChannel(outputChannelSelectionPanelPol.getOutputChannel());
321
			outLine.setOutputChannel(outputChannelSelectionPanelLine.getOutputChannel());
322
			outPoint.setOutputChannel(outputChannelSelectionPanelPoint.getOutputChannel());
323
		} catch (Exception e) {
324
			Sextante.addErrorToLog(e);
325
		}
326
	}
329
            //Reponer estas l?neas para cambiar el panel de salida y comentar la siguiente
330
            //AlgorithmOutputPanel fsp = getAlgorithmOutputPanel();
331
            //out.setOutputChannel(new CompositeSourceOutputChannel(fsp.getOutputParameters()));
332
            outPol.setOutputChannel(outputChannelSelectionPanelPol.getOutputChannel());
333
            outLine.setOutputChannel(outputChannelSelectionPanelLine.getOutputChannel());
334
            outPoint.setOutputChannel(outputChannelSelectionPanelPoint.getOutputChannel());
335
        } catch (Exception e) {
336
            Sextante.addErrorToLog(e);
337
        }
338
    }
327 339

  
328
	@Override
329
	public void setOutputValue(String arg0, String arg1) {
340
    @Override
341
    public void setOutputValue(String arg0, String arg1) {
330 342

  
331
	}
343
    }
332 344

  
333
	@Override
334
	public void setParameterValue(String arg0, String arg1) {
345
    @Override
346
    public void setParameterValue(String arg0, String arg1) {
335 347

  
336
	}
348
    }
337 349

  
338
	/**
339
	 * Gets the input layer list
340
	 * @return
341
	 */
342
	private ObjectAndDescription[] getLayerList() {
343
		if(layerList == null) {
344
			IVectorLayer[] layers = SextanteGUI.getInputFactory()
345
			.getVectorLayers(IVectorLayer.SHAPE_TYPE_WRONG);
346
			layerList = new ObjectAndDescription[layers.length];
347
			for (int i = 0; i < layers.length; i++)
348
				layerList[i] = new ObjectAndDescription(layers[i].getName(), layers[i]);
349
		}
350
		return layerList;
351
	}
350
    /**
351
     * Gets the input layer list
352
     *
353
     * @return
354
     */
355
    private ObjectAndDescription[] getLayerList() {
356
        if (layerList == null) {
357
            IVectorLayer[] layers = SextanteGUI.getInputFactory()
358
                    .getVectorLayers(IVectorLayer.SHAPE_TYPE_WRONG);
359
            layerList = new ObjectAndDescription[layers.length];
360
            for (int i = 0; i < layers.length; i++) {
361
                layerList[i] = new ObjectAndDescription(layers[i].getName(), layers[i]);
362
            }
363
        }
364
        return layerList;
365
    }
352 366

  
353
	/**
354
	 * Gets the list of selected layers
355
	 * @return
356
	 */
357
	private ArrayList<IVectorLayer> getSelectedLayerList() {
358
		ObjectAndDescription[] layerList = getLayerList();
359
		ArrayList<IVectorLayer> vLayer = new ArrayList<IVectorLayer>();
360
		for (int i = 0; i < layerList.length; i++) {
361
			Boolean check = (Boolean)getCheckBoxTable().getModel().getValueAt(i, 0);
362
			if(check.booleanValue())
363
				vLayer.add((IVectorLayer)layerList[i].getObject());
364
		}
365
		return vLayer;
366
	}
367
    /**
368
     * Gets the list of selected layers
369
     *
370
     * @return
371
     */
372
    private ArrayList<IVectorLayer> getSelectedLayerList() {
373
        ObjectAndDescription[] layerList = getLayerList();
374
        ArrayList<IVectorLayer> vLayer = new ArrayList<IVectorLayer>();
375
        for (int i = 0; i < layerList.length; i++) {
376
            Boolean check = (Boolean) getCheckBoxTable().getModel().getValueAt(i, 0);
377
            if (check.booleanValue()) {
378
                vLayer.add((IVectorLayer) layerList[i].getObject());
379
            }
380
        }
381
        return vLayer;
382
    }
367 383

  
368
	/**
369
	 * Gets the selected vector layer in the JComboBox
370
	 * @return
371
	 */
372
	private IVectorLayer getSelectedVectorLayer() {
373
		if(getFieldsCombo().getSelectedItem() != null)
374
			return (IVectorLayer)((ObjectAndDescription)getFieldsCombo().getSelectedItem()).getObject();
375
		return null;
376
	}
384
    /**
385
     * Gets the selected vector layer in the JComboBox
386
     *
387
     * @return
388
     */
389
    private IVectorLayer getSelectedVectorLayer() {
390
        if (getFieldsCombo().getSelectedItem() != null) {
391
            return (IVectorLayer) ((ObjectAndDescription) getFieldsCombo().getSelectedItem()).getObject();
392
        }
393
        return null;
394
    }
377 395

  
378 396
}
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.merge/src/main/java/org/gvsig/geoprocess/algorithm/merge/MergeLibrary.java
29 29

  
30 30
/**
31 31
 * Initialization of MergeLibrary library.
32
 * 
32
 *
33 33
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
34 34
 */
35 35
public class MergeLibrary extends AlgorithmAbstractLibrary {
......
42 42
    @Override
43 43
    protected void doPostInitialize() throws LibraryException {
44 44
        Messages.addResourceFamily(
45
            "org.gvsig.geoprocess.algorithm.merge.merge", MergeLibrary.class
46
                .getClassLoader(), MergeLibrary.class.getClass().getName());
45
                "org.gvsig.geoprocess.algorithm.merge.merge", MergeLibrary.class
46
                        .getClassLoader(), MergeLibrary.class.getClass().getName());
47 47
        registerGeoProcess(new MergeAlgorithm());
48 48
    }
49 49

  
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.merge/src/main/java/org/gvsig/geoprocess/algorithm/merge/MergeAlgorithm.java
45 45

  
46 46
/**
47 47
 * Merge algorithm
48
 *
48 49
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
49 50
 */
50 51
public class MergeAlgorithm extends AbstractSextanteGeoProcess {
51
	public static final String        RESULT_POL        = "RESULT_POL";
52
	public static final String        RESULT_POINT      = "RESULT_POINT";
53
	public static final String        RESULT_LINE       = "RESULT_LINE";
54
	public static final String        LAYERS            = "LAYERS";
55
	public static final String        FIELDLAYER        = "LAYER";
56
	
57
	/*
52

  
53
    public static final String RESULT_POL = "RESULT_POL";
54
    public static final String RESULT_POINT = "RESULT_POINT";
55
    public static final String RESULT_LINE = "RESULT_LINE";
56
    public static final String LAYERS = "LAYERS";
57
    public static final String FIELDLAYER = "LAYER";
58

  
59
    /*
58 60
	 * (non-Javadoc)
59 61
	 * @see es.unex.sextante.core.GeoAlgorithm#defineCharacteristics()
60
	 */
61
	public void defineCharacteristics() {
62
     */
63
    public void defineCharacteristics() {
62 64
        setName(getTranslation("Merge"));
63 65
        setGroup(getTranslation("basic_vect_algorithms"));
64 66
        // setGeneratesUserDefinedRasterOutput(false);
65
		
66
		try {
67
			m_Parameters.addMultipleInput(LAYERS, 
68
                getTranslation("Input_layers"),
69
											AdditionalInfoMultipleInput.DATA_TYPE_VECTOR_ANY, 
70
											true);
71
			m_Parameters.addInputVectorLayer(FIELDLAYER, 
72
                getTranslation("Fields"),
73
											IVectorLayer.SHAPE_TYPE_WRONG, 
74
											true);
75
			
76
			addOutputVectorLayer(RESULT_POL, getTranslation("Merge_polygon"),
77
					OutputVectorLayer.SHAPE_TYPE_POLYGON);
78
			addOutputVectorLayer(RESULT_LINE, getTranslation("Merge_line"),
79
					OutputVectorLayer.SHAPE_TYPE_LINE);
80
			addOutputVectorLayer(RESULT_POINT, getTranslation("Merge_point"),
81
					OutputVectorLayer.SHAPE_TYPE_POINT);
82
			
83
		} catch (RepeatedParameterNameException e) {
84
			Sextante.addErrorToLog(e);
85
		}
86
	}
87
	
88
	/*
67

  
68
        try {
69
            m_Parameters.addMultipleInput(LAYERS,
70
                    getTranslation("Input_layers"),
71
                    AdditionalInfoMultipleInput.DATA_TYPE_VECTOR_ANY,
72
                    true);
73
            m_Parameters.addInputVectorLayer(FIELDLAYER,
74
                    getTranslation("Fields"),
75
                    IVectorLayer.SHAPE_TYPE_WRONG,
76
                    true);
77

  
78
            addOutputVectorLayer(RESULT_POL, getTranslation("Merge_polygon"),
79
                    OutputVectorLayer.SHAPE_TYPE_POLYGON);
80
            addOutputVectorLayer(RESULT_LINE, getTranslation("Merge_line"),
81
                    OutputVectorLayer.SHAPE_TYPE_LINE);
82
            addOutputVectorLayer(RESULT_POINT, getTranslation("Merge_point"),
83
                    OutputVectorLayer.SHAPE_TYPE_POINT);
84

  
85
        } catch (RepeatedParameterNameException e) {
86
            Sextante.addErrorToLog(e);
87
        }
88
    }
89

  
90
    /*
89 91
	 * (non-Javadoc)
90 92
	 * @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm()
91
	 */
92
	@SuppressWarnings("unchecked")
93
	public boolean processAlgorithm() throws GeoAlgorithmExecutionException {
94
		if(existsOutPutFile(RESULT_POL, 0) || 
95
			existsOutPutFile(RESULT_LINE, 0) ||
96
			existsOutPutFile(RESULT_POINT, 0)) {
97
    		throw new GeoAlgorithmExecutionException(getTranslation("file_exists"));
98
    	}
99
		IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(FIELDLAYER);
100
		ArrayList<IVectorLayer> layers = m_Parameters.getParameterValueAsArrayList(LAYERS);
101
		
102
		FeatureStore storeLayer = null;
103
		if(layer instanceof FlyrVectIVectorLayer)
104
			storeLayer = ((FlyrVectIVectorLayer)layer).getFeatureStore();
105
		else
106
			return false;
107
		
108
		try {
109
			//Gets the list of FeatureStore
110
			ArrayList<FeatureStore> featureStoreList = new ArrayList<FeatureStore>();
111
			for (int i = 0; i < layers.size(); i++) {
112
				IVectorLayer lyr = layers.get(i);
113
				if(lyr instanceof FlyrVectIVectorLayer && layer.getShapeType() == lyr.getShapeType())
114
					featureStoreList.add(((FlyrVectIVectorLayer)lyr).getFeatureStore());
115
				else {
116
					JOptionPane.showMessageDialog(null,
117
                        getTranslation("layers_type_are_different"),
118
							"Error",
119
							JOptionPane.WARNING_MESSAGE);
120
					return false;
121
				}
122
			}
123
			
124
			//Builds the output FeatureStore
125
			FeatureSet features = null;
126
			features = storeLayer.getFeatureSet();
127
			FeatureType featureType = features.getDefaultFeatureType();
128
           /* FeatureStore outFeatStore =
93
     */
94
    @SuppressWarnings("unchecked")
95
    public boolean processAlgorithm() throws GeoAlgorithmExecutionException {
96
        if (existsOutPutFile(RESULT_POL, 0)
97
                || existsOutPutFile(RESULT_LINE, 0)
98
                || existsOutPutFile(RESULT_POINT, 0)) {
99
            throw new GeoAlgorithmExecutionException(getTranslation("file_exists"));
100
        }
101
        IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(FIELDLAYER);
102
        ArrayList<IVectorLayer> layers = m_Parameters.getParameterValueAsArrayList(LAYERS);
103

  
104
        FeatureStore storeLayer = null;
105
        if (layer instanceof FlyrVectIVectorLayer) {
106
            storeLayer = ((FlyrVectIVectorLayer) layer).getFeatureStore();
107
        } else {
108
            return false;
109
        }
110

  
111
        try {
112
            //Gets the list of FeatureStore
113
            ArrayList<FeatureStore> featureStoreList = new ArrayList<FeatureStore>();
114
            for (int i = 0; i < layers.size(); i++) {
115
                IVectorLayer lyr = layers.get(i);
116
                if (lyr instanceof FlyrVectIVectorLayer && layer.getShapeType() == lyr.getShapeType()) {
117
                    featureStoreList.add(((FlyrVectIVectorLayer) lyr).getFeatureStore());
118
                } else {
119
                    JOptionPane.showMessageDialog(null,
120
                            getTranslation("layers_type_are_different"),
121
                            "Error",
122
                            JOptionPane.WARNING_MESSAGE);
123
                    return false;
124
                }
125
            }
126

  
127
            //Builds the output FeatureStore
128
            FeatureSet features = null;
129
            features = storeLayer.getFeatureSet();
130
            FeatureType featureType = features.getDefaultFeatureType();
131
            /* FeatureStore outFeatStore =
129 132
                buildOutPutStore(featureType, layer.getShapeType(),
130 133
                    getTranslation("Merge"), RESULT);
131 134

  
......
133 136
			GeometryOperation operation = new MergeOperation(layer, this);
134 137
            operation.setTaskStatus(getStatus());
135 138
			operation.computesGeometryOperationInAList(featureStoreList, outFeatStore, attrNames, false, true);
136
			*/
137
			GeometryOperation operation = new MergeOperation(layer, this);
139
             */
140
            GeometryOperation operation = new MergeOperation(layer, this);
138 141
            operation.setTaskStatus(getStatus());
139
            
140
			if (isPolygon(storeLayer) || isUndefined(storeLayer)) {
141
				FeatureStore outFeatStore =
142
					buildOutPutStore(featureType, IVectorLayer.SHAPE_TYPE_POLYGON,
143
							getTranslation("Merge_polygon"), RESULT_POL);
144 142

  
145
				operation.computesGeometryOperationInAList(featureStoreList, outFeatStore, attrNames, 
146
						false, false, true);
147
			} else {
148
				buildOutPutStore(featureType, IVectorLayer.SHAPE_TYPE_POLYGON,
149
						getTranslation("Null_polygon"), RESULT_POL);
150
			}
151
			
152
			if (isLine(storeLayer) || isUndefined(storeLayer)) {
153
				FeatureStore outFeatStore =
154
					buildOutPutStore(featureType, IVectorLayer.SHAPE_TYPE_LINE,
155
							getTranslation("Merge_line"), RESULT_LINE);
143
            if (isPolygon(storeLayer) || isUndefined(storeLayer)) {
144
                FeatureStore outFeatStore
145
                        = buildOutPutStore(featureType, IVectorLayer.SHAPE_TYPE_POLYGON,
146
                                getTranslation("Merge_polygon"), RESULT_POL);
156 147

  
157
				operation.computesGeometryOperationInAList(featureStoreList, outFeatStore, attrNames, 
158
						false, false, true);
159
			} else {
160
				buildOutPutStore(featureType.getCopy(), IVectorLayer.SHAPE_TYPE_LINE,
161
						getTranslation("Null_line"), RESULT_LINE);
162
			}
163
			
164
			if (isPoint(storeLayer) || isUndefined(storeLayer)) {
165
				FeatureStore outFeatStore =
166
					buildOutPutStore(featureType.getCopy(), IVectorLayer.SHAPE_TYPE_POINT,
167
							getTranslation("Merge_point"), RESULT_POINT);
148
                operation.computesGeometryOperationInAList(featureStoreList, outFeatStore, attrNames,
149
                        false, false, true);
150
            } else {
151
                buildOutPutStore(featureType, IVectorLayer.SHAPE_TYPE_POLYGON,
152
                        getTranslation("Null_polygon"), RESULT_POL);
153
            }
168 154

  
169
				operation.computesGeometryOperationInAList(featureStoreList, outFeatStore, attrNames, 
170
						false, false, true);
171
			} else {
172
				buildOutPutStore(featureType.getCopy(), IVectorLayer.SHAPE_TYPE_POINT,
173
						getTranslation("Null_point"), RESULT_POINT);
174
			}
175
			
176
		} catch (DataException e) {
177
			Sextante.addErrorToLog(e);
178
			return false;
179
		}
180
		
181
		if(getTaskMonitor().isCanceled())
182
			return false;
183
		
184
		return true;
185
	}
155
            if (isLine(storeLayer) || isUndefined(storeLayer)) {
156
                FeatureStore outFeatStore
157
                        = buildOutPutStore(featureType, IVectorLayer.SHAPE_TYPE_LINE,
158
                                getTranslation("Merge_line"), RESULT_LINE);
186 159

  
160
                operation.computesGeometryOperationInAList(featureStoreList, outFeatStore, attrNames,
161
                        false, false, true);
162
            } else {
163
                buildOutPutStore(featureType.getCopy(), IVectorLayer.SHAPE_TYPE_LINE,
164
                        getTranslation("Null_line"), RESULT_LINE);
165
            }
166

  
167
            if (isPoint(storeLayer) || isUndefined(storeLayer)) {
168
                FeatureStore outFeatStore
169
                        = buildOutPutStore(featureType.getCopy(), IVectorLayer.SHAPE_TYPE_POINT,
170
                                getTranslation("Merge_point"), RESULT_POINT);
171

  
172
                operation.computesGeometryOperationInAList(featureStoreList, outFeatStore, attrNames,
173
                        false, false, true);
174
            } else {
175
                buildOutPutStore(featureType.getCopy(), IVectorLayer.SHAPE_TYPE_POINT,
176
                        getTranslation("Null_point"), RESULT_POINT);
177
            }
178

  
179
        } catch (DataException e) {
180
            Sextante.addErrorToLog(e);
181
            return false;
182
        }
183

  
184
        if (getTaskMonitor().isCanceled()) {
185
            return false;
186
        }
187

  
188
        return true;
189
    }
190

  
187 191
    @Override
188 192
    public Class<? extends GeoAlgorithmParametersPanel> getCustomParametersPanelClass() {
189 193
        return MergeParametersPanel.class;
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.merge/src/main/java/org/gvsig/geoprocess/algorithm/merge/MergeOperation.java
36 36

  
37 37
/**
38 38
 * Builds a geometry with the intersection between two layers
39
 * 
39
 *
40 40
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
41 41
 */
42 42
public class MergeOperation extends GeometryOperation {
43
	private IVectorLayer                     layer            = null;
44 43

  
45
	public MergeOperation(IVectorLayer layer, AbstractSextanteGeoProcess p) {
46
		super(p);
47
		this.layer = layer;
48
	}
44
    private IVectorLayer layer = null;
49 45

  
50
	/**
51
	 * Computes intersection between the geometry and the overlay layer. The fields of the
52
	 * intersected features will be added.
53
	 * @param g
54
	 * @param featureInput
55
	 * @return
56
	 */
57
	public EditableFeature invoke(org.gvsig.fmap.geom.Geometry g, Feature featureInput) {
58
		if(g == null)
59
			return lastEditFeature;
60
		
61
		try {
62
			if(inFeatureStore == ((FlyrVectIVectorLayer)layer).getFeatureStore())
63
				lastEditFeature = persister.addFeature(featureInput, g);
64
			else
65
				lastEditFeature = persister.addDifferentFieldFeature(featureInput, g);
66
		} catch (CreateGeometryException e) {
67
			Sextante.addErrorToLog(e);
68
		} catch (DataException e) {
69
			Sextante.addErrorToLog(e);
70
		}
71
		
72
		return lastEditFeature;
73
	}
74
	
75
	/**
76
	 * clips feature's geometry with the clipping geometry, preserving
77
	 * feature's original attributes.
78
	 * If feature's geometry doesn't touch clipping geometry, it will be
79
	 * ignored.
80
	 */
81
	public void invoke(org.gvsig.fmap.geom.Geometry g, EditableFeature featureInput) {
82
		try {
83
			lastEditFeature = persister.addGeometryToExistingFeature(featureInput, g);
84
		} catch (CreateGeometryException e) {
85
			Sextante.addErrorToLog(e);
86
		} catch (DataException e) {
87
			Sextante.addErrorToLog(e);
88
		}
89
	}
46
    public MergeOperation(IVectorLayer layer, AbstractSextanteGeoProcess p) {
47
        super(p);
48
        this.layer = layer;
49
    }
50

  
51
    /**
52
     * Computes intersection between the geometry and the overlay layer. The
53
     * fields of the intersected features will be added.
54
     *
55
     * @param g
56
     * @param featureInput
57
     * @return
58
     */
59
    public EditableFeature invoke(org.gvsig.fmap.geom.Geometry g, Feature featureInput) {
60
        if (g == null) {
61
            return lastEditFeature;
62
        }
63

  
64
        try {
65
            if (inFeatureStore == ((FlyrVectIVectorLayer) layer).getFeatureStore()) {
66
                lastEditFeature = persister.addFeature(featureInput, g);
67
            } else {
68
                lastEditFeature = persister.addDifferentFieldFeature(featureInput, g);
69
            }
70
        } catch (CreateGeometryException e) {
71
            Sextante.addErrorToLog(e);
72
        } catch (DataException e) {
73
            Sextante.addErrorToLog(e);
74
        }
75

  
76
        return lastEditFeature;
77
    }
78

  
79
    /**
80
     * clips feature's geometry with the clipping geometry, preserving feature's
81
     * original attributes. If feature's geometry doesn't touch clipping
82
     * geometry, it will be ignored.
83
     */
84
    public void invoke(org.gvsig.fmap.geom.Geometry g, EditableFeature featureInput) {
85
        try {
86
            lastEditFeature = persister.addGeometryToExistingFeature(featureInput, g);
87
        } catch (CreateGeometryException e) {
88
            Sextante.addErrorToLog(e);
89
        } catch (DataException e) {
90
            Sextante.addErrorToLog(e);
91
        }
92
    }
90 93
}
91

  

Also available in: Unified diff