Revision 38283

View differences:

tags/v2_0_0_Build_2047/libraries/libFMap_controls/src-test/org/gvsig/fmap/mapcontrol/tools/AreaListenerTest.java
1
package org.gvsig.fmap.mapcontrol.tools;
2

  
3
import java.awt.geom.Point2D;
4

  
5
import org.cresques.cts.IProjection;
6
import org.gvsig.fmap.crs.CRSFactory;
7
import org.gvsig.fmap.mapcontext.MapContext;
8
import org.gvsig.fmap.mapcontext.ViewPort;
9
import org.gvsig.fmap.mapcontrol.MapControl;
10
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
11

  
12

  
13
public class AreaListenerTest extends AbstractLibraryAutoInitTestCase {
14
	private IProjection projectionUTM = CRSFactory.getCRS("EPSG:23030");
15
	private IProjection projectionGeo = CRSFactory.getCRS("EPSG:4230");
16
		
17
	@Override
18
	protected void doSetUp() throws Exception {
19
		// Nothing to do	
20
	}
21

  
22
	public void test1() {
23
		AreaListenerImpl areaListenerUTM=new AreaListenerImpl(newMapControlUTM());
24
		AreaListenerImpl areaListenerGeo=new AreaListenerImpl(newMapControlGeo());
25
		Double[] xsUTM=new Double[] {new Double(731292),new Double(731901),new Double(730138)};
26
		Double[] ysUTM=new Double[] {new Double(4351223),new Double(4350768),new Double(4349232)};
27
		double areaUTM=areaListenerUTM.returnCoordsArea(xsUTM,ysUTM,new Point2D.Double(730138,4349232));
28
		Double[] xsGeo=new Double[] {new Double(-0.31888183),new Double(-0.31173131),new Double(-0.33268401)};
29
		Double[] ysGeo=new Double[] {new Double(39.27871741),new Double(39.27464327),new Double(39.26117368)};
30
		double areaGeo=areaListenerGeo.returnGeoCArea(xsGeo,ysGeo,new Point2D.Double(-0.33268401,39.26117368));
31
		assertTrue("Area UTM igual a Geo",areaUTM<(areaGeo+1000)&& areaUTM>(areaGeo-1000));
32
	}
33
	private MapControl newMapControlUTM() {
34
		ViewPort vp = new ViewPort(projectionUTM);
35
		MapControl mc=new MapControl();
36
		mc.setMapContext(new MapContext(vp));
37
		return mc;
38
	}
39
	private MapControl newMapControlGeo() {
40
		ViewPort vp = new ViewPort(projectionGeo);
41
		MapControl mc=new MapControl();
42
		mc.setMapContext(new MapContext(vp));
43
		return mc;
44
	}
45
}
tags/v2_0_0_Build_2047/libraries/libFMap_controls/src/org/gvsig/app/gui/JComboBoxUnits.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 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 org.gvsig.app.gui;
42

  
43
import org.gvsig.fmap.mapcontext.MapContext;
44
import org.gvsig.i18n.Messages;
45
import org.gvsig.utils.swing.JComboBox;
46

  
47

  
48
/**
49
 * <p>Class representing a JComboBox with the measure units handled by the application.
50
 * It takes values from Attributes.NAMES and Attributes.CHANGE static fields. So, to
51
 * add more measure units, you must edit Attributes class and change will be automatically
52
 * reflected in the combo box.</p>
53
 *
54
 * <p>The internatiolanization of the field is automatically handled by the system</p>
55
 * @author jaume dominguez faus - jaume.dominguez@iver.es
56
 */
57
public class JComboBoxUnits extends JComboBox {
58
	private static final long serialVersionUID = 8015263853737441433L;
59

  
60
	/**
61
	 * Creates a new instance of JUnitComboBox including "pixel" units and
62
	 * setting them as automatically pre-selected.
63
	 */
64
	public JComboBoxUnits() {
65
		this(true);
66
	}
67

  
68
	/**
69
	 *
70
	 * Creates a new instance of JUnitComboBox. If includePixel is true
71
	 * then pixel units are included in the list and they are automatically
72
	 * pre-selected. Otherwise, meters are preselected.
73
	 *
74
	 */
75
	public JComboBoxUnits(boolean includePixel) {
76
		super();
77
		String[] names=MapContext.getDistanceNames();
78

  
79
		for (int i = 0; i < names.length; i++) {
80
			super.addItem(Messages.getText(names[i]));
81
		}
82
		if (includePixel) {
83
			super.addItem(Messages.getText("pixels"));
84
			setSelectedItem(Messages.getText("pixels"));
85
		} else {
86
			setSelectedIndex(1);
87
		}
88
		setMaximumRowCount(10);
89
	}
90

  
91

  
92
	/**
93
	 * Returns the conversion factor from the <b>unit selected in the combo box</b>
94
	 * to <b>meters</b> or <b>0</b> if pixels have been selected as the size unit.
95
	 * @return
96
	 */
97
	public double getUnitConversionFactor() {
98
			double unitFactor;
99
			try {
100
				unitFactor = MapContext.getDistanceTrans2Meter()[getSelectedIndex()];
101
			} catch (ArrayIndexOutOfBoundsException aioobEx) { //jijiji
102
				unitFactor = 0; // which represents size in pixel
103
			}
104
			return unitFactor;
105

  
106
	}
107

  
108
	/**
109
	 * the use of this method is not allowed in this combo box.
110
	 * @deprecated
111
	 */
112
	public void addItem(Object anObject) {
113
		throw new Error("Operation not allowed");
114
	}
115

  
116
	/**
117
	 * the use of this method is not allowed for this combo box.
118
	 * @deprecated
119
	 */
120
	public void removeAllItems() {
121
		throw new Error("Operation not allowed");
122
	}
123

  
124
	public int getSelectedUnitIndex() {
125
		int i = getSelectedIndex();
126
		if (i>MapContext.getDistanceNames().length-1)
127
			return -1;
128
		else return i;
129
	}
130

  
131
	public void setSelectedUnitIndex(int unitIndex) {
132
		if (unitIndex == -1) {
133
			setSelectedIndex(getItemCount()-1);
134
		} else {
135
			setSelectedIndex(unitIndex);
136
		}
137
	}
138

  
139

  
140

  
141
}
0 142

  
tags/v2_0_0_Build_2047/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/PrimitivesDrawer.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.fmap.mapcontrol;
29

  
30
import java.awt.Color;
31
import java.awt.Graphics;
32

  
33
/**
34
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
35
 */
36
public interface PrimitivesDrawer {
37
	
38
	/**
39
	 * This method is used to start a drawing process that needs to 
40
	 * be synchronized.
41
	 * @param obj
42
	 * The object that locks the resource.
43
	 * @throws InterruptedException
44
	 */
45
	public void startDrawing(Object obj) throws InterruptedException;
46
	
47
	/**
48
	 * This method is used to finish a drawing process that needs to 
49
	 * be synchronized. 
50
	 * @param obj
51
	 * The object that has locked the resource.
52
	 */
53
	public void stopDrawing(Object obj);
54
	
55
	/**
56
	 * This method sets the <code>Graphics</code> where the 
57
	 * <code>Drawer</code> has to draw all the objects. 
58
	 * @param graphics
59
	 * The component where the new objects has to be drawn. 
60
	 */
61
	public void setGraphics(Graphics graphics);
62
	
63
	/**
64
	 * Sets the color that is used to draw the objects that don't 
65
	 * have a symbol.
66
	 * @param color
67
	 * The color to use on the drawing operations.
68
	 */
69
	public void setColor(Color color);
70
		
71
	/**
72
	 * It draws a rectangle on the map using the color 
73
	 * specified using the {@link #setColor(Color)} method. 
74
	 * @param x
75
	 * The minimum X coordinate.
76
	 * @param y
77
	 * The minimum Y coordinate.
78
	 * @param width
79
	 * The rectangle width.
80
	 * @param height
81
	 * The rectangle height.
82
	 */
83
	public void drawRect(int x, int y, int width, int height);
84
		
85
	/**
86
	 * It fills a rectangle on the map using the color 
87
	 * specified using the {@link #setColor(Color)} method. 
88
	 * @param x
89
	 * The minimum X coordinate.
90
	 * @param y
91
	 * The minimum Y coordinate.
92
	 * @param width
93
	 * The rectangle width.
94
	 * @param height
95
	 * The rectangle height.
96
	 */
97
	public void fillRect(int x, int y, int width, int height);
98
	
99
	public void drawOval(int i, int j, int sizePixels, int sizePixels2);
100

  
101
	public void drawLine(int x1, int y1, int x3, int y12);
102
}
0 103

  
tags/v2_0_0_Build_2047/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/dal/swing/datastore/DataStoreParametersCreationPanel.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.fmap.mapcontrol.dal.swing.datastore;
23

  
24
import javax.swing.JPanel;
25

  
26
import org.gvsig.fmap.dal.DataServerExplorer;
27
import org.gvsig.fmap.dal.NewDataStoreParameters;
28

  
29

  
30
/**
31
 * @author gvSIG Team
32
 * @version $Id$
33
 *
34
 */
35
public abstract class DataStoreParametersCreationPanel extends JPanel {
36
    private static final long serialVersionUID = 5265923639970241325L;
37

  
38
    public abstract NewDataStoreParameters getDataStoreParameters();
39
    
40
    public abstract DataServerExplorer getDataServerExplorer();
41
}
0 42

  
tags/v2_0_0_Build_2047/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/dal/swing/datastore/DefaultDataStoreParametersCreationPanel.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.fmap.mapcontrol.dal.swing.datastore;
23

  
24
import java.awt.Dimension;
25
import java.awt.GridBagConstraints;
26
import java.awt.GridBagLayout;
27
import java.awt.Insets;
28
import java.awt.event.ActionEvent;
29
import java.awt.event.ActionListener;
30
import java.util.Iterator;
31
import java.util.List;
32

  
33
import javax.swing.JButton;
34
import javax.swing.JComboBox;
35

  
36
import org.slf4j.Logger;
37
import org.slf4j.LoggerFactory;
38

  
39
import org.gvsig.fmap.dal.DALLocator;
40
import org.gvsig.fmap.dal.DataManager;
41
import org.gvsig.fmap.dal.DataServerExplorer;
42
import org.gvsig.fmap.dal.DataServerExplorerParameters;
43
import org.gvsig.fmap.dal.NewDataStoreParameters;
44
import org.gvsig.fmap.dal.exception.InitializeException;
45
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
46
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
47
import org.gvsig.fmap.mapcontrol.swing.dynobject.DynObjectEditor;
48
import org.gvsig.tools.service.ServiceException;
49

  
50

  
51
/**
52
 * @author gvSIG Team
53
 * @version $Id$
54
 *
55
 */
56
public class DefaultDataStoreParametersCreationPanel extends DataStoreParametersCreationPanel implements ActionListener{   
57
    private static final long serialVersionUID = -1453149638996485029L;
58

  
59
    private static final Logger LOG =
60
        LoggerFactory.getLogger(DefaultDataStoreParametersCreationPanel.class);
61

  
62
    private static final DataManager DATA_MANAGER = DALLocator.getDataManager();
63

  
64
    private static final int FORM_HEIGTH = 18;
65

  
66
    private DataServerExplorer dataServerExplorer = null;
67
    private DataServerExplorerParameters dataServerExplorerParameters = null;
68

  
69
    private NewDataStoreParameters dataStoreParameters = null;
70

  
71
    private JButton explorersButton;
72
    private JComboBox explorersComboBox;
73
    private JButton providersButton;
74
    private JComboBox providersComboBox;
75

  
76
    public DefaultDataStoreParametersCreationPanel() {
77
        super(); 
78
        initComponents();
79
        populateExplorerCombo();
80
        initListeners();
81
        enableExplorerControls(false);
82
    }     
83

  
84
    private void initListeners() {
85
        this.explorersComboBox.addActionListener(this);
86
        this.explorersButton.addActionListener(this);
87
        this.providersComboBox.addActionListener(this);
88
        this.providersButton.addActionListener(this);        
89
    }
90

  
91
    @SuppressWarnings("rawtypes")
92
    private void populateExplorerCombo(){
93
        explorersComboBox.addItem(null);
94

  
95
        Iterator it = DATA_MANAGER.getExplorerProviders().iterator();
96

  
97
        while(it.hasNext()) {
98
            String explorer = (String)it.next();
99
            explorersComboBox.addItem(explorer);            
100
        }
101
    }   
102

  
103
    private void initComponents() {
104
        GridBagConstraints gridBagConstraints;
105

  
106
        explorersComboBox = new JComboBox();
107
        providersComboBox = new JComboBox();
108
        explorersButton = new JButton();
109
        providersButton = new JButton();
110

  
111
        setLayout(new GridBagLayout());
112

  
113
        explorersComboBox.setPreferredSize(new Dimension(0, FORM_HEIGTH));
114
        gridBagConstraints = new GridBagConstraints();
115
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
116
        gridBagConstraints.weightx = 1.0;
117
        gridBagConstraints.insets = new Insets(0, 2, 0, 2);
118
        add(explorersComboBox, gridBagConstraints);
119

  
120
        explorersButton.setText("...");
121
        explorersButton.setPreferredSize(new Dimension(25, FORM_HEIGTH));
122
        gridBagConstraints = new GridBagConstraints();
123
        gridBagConstraints.gridx = 1;
124
        gridBagConstraints.gridy = 0;
125
        gridBagConstraints.insets = new Insets(0, 2, 0, 2);
126
        add(explorersButton, gridBagConstraints);
127

  
128
        providersComboBox.setPreferredSize(new Dimension(0, FORM_HEIGTH));
129
        gridBagConstraints = new GridBagConstraints();
130
        gridBagConstraints.gridx = 2;
131
        gridBagConstraints.gridy = 0;
132
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
133
        gridBagConstraints.weightx = 1.0;
134
        gridBagConstraints.insets = new Insets(0, 2, 0, 2);
135
        add(providersComboBox, gridBagConstraints);      
136

  
137
        providersButton.setText("...");
138
        providersButton.setPreferredSize(new Dimension(25, FORM_HEIGTH));
139
        gridBagConstraints = new GridBagConstraints();
140
        gridBagConstraints.gridx = 3;
141
        gridBagConstraints.gridy = 0;
142
        gridBagConstraints.insets = new Insets(0, 2, 0, 2);
143
        add(providersButton, gridBagConstraints);
144
    }
145

  
146
    @Override
147
    public NewDataStoreParameters getDataStoreParameters(){       
148
        return dataStoreParameters;
149
    }
150

  
151
    @Override
152
    public DataServerExplorer getDataServerExplorer() {       
153
        return dataServerExplorer;
154
    }
155

  
156
    public void actionPerformed(ActionEvent e) {       
157
        if (e.getSource().equals(explorersButton)) {           
158
            explorersButtonClicked();
159
        }else if (e.getSource().equals(providersButton)) {
160
            providersButtonClicked();
161
        }else if (e.getSource().equals(explorersComboBox)) {           
162
            explorersComboSelectionChanged();
163
        }else if (e.getSource().equals(providersComboBox)) {
164
            providersComboSelectionChanged();
165
        }
166
    }  
167

  
168
    private void explorersComboSelectionChanged(){        
169
        String explorerName = (String)explorersComboBox.getSelectedItem();
170
        if (explorerName == null){
171
            dataServerExplorerParameters = null;
172
            dataServerExplorer = null;
173
            removeProvidersCombo();
174
            enableExplorerControls(false);
175
        }else{
176
            //Only update the explorer if the selection is different
177
            if ((dataServerExplorer == null) || (!explorerName.equals(dataServerExplorer.getProviderName()))){        
178
                dataServerExplorerParameters = null;
179

  
180
                //Remove all the previous providers
181
                removeProvidersCombo(); 
182

  
183
                //Disable all the components and enable the explorer button
184
                this.enableExplorerControls(false);
185
                this.explorersButton.setEnabled(true);       
186
                //Sometimes is possible to create an explorer without parameters (e.g: filesystem explorer"
187
                try {                    
188
                    dataServerExplorerParameters =
189
                        DATA_MANAGER.createServerExplorerParameters(explorerName);
190
                    dataServerExplorer = 
191
                        DATA_MANAGER.openServerExplorer(explorerName, dataServerExplorerParameters);
192
                    populateProvidersCombo();  
193
                    this.providersComboBox.setEnabled(true);     
194
                } catch (InitializeException e) {
195
                    LOG.error("Error creating the explorer parameters", e);                    
196
                } catch (ProviderNotRegisteredException e) {
197
                    LOG.error("The explorer has not been registeger", e);                    
198
                } catch (ValidateDataParametersException e) {
199
                    LOG.error("Error creating the explorer", e);                  
200
                }                
201
            }
202
        }
203
    }
204

  
205
    private void enableExplorerControls(boolean isEnabled){        
206
        this.explorersButton.setEnabled(isEnabled);  
207
        this.providersComboBox.setEnabled(isEnabled);    
208
        this.providersButton.setEnabled(isEnabled);
209
    }
210

  
211
    private void enableProviderControls(boolean isEnabled){       
212
        this.providersButton.setEnabled(isEnabled);  
213
    }
214

  
215
    private void explorersButtonClicked(){
216
        dataServerExplorer = null;
217
        String explorerName = (String)explorersComboBox.getSelectedItem();
218
        if (explorerName != null){
219
            try {
220
                if ((dataServerExplorerParameters == null) || (!dataServerExplorerParameters.getExplorerName().equals(explorerName))){
221
                    dataServerExplorerParameters =
222
                        DATA_MANAGER.createServerExplorerParameters(explorerName);
223
                }
224
                DynObjectEditor dynObjectEditor = new DynObjectEditor(dataServerExplorerParameters);
225
                dynObjectEditor.editObject(true);               
226
                dataServerExplorer = 
227
                    DATA_MANAGER.openServerExplorer(explorerName, dataServerExplorerParameters);
228
                //Remove all the previous providers
229
                removeProvidersCombo(); 
230
                populateProvidersCombo();
231
                this.providersComboBox.setEnabled(true);  
232
            } catch (InitializeException e) {
233
                LOG.error("Error creating the explorer parameters", e);
234
            } catch (ProviderNotRegisteredException e) {
235
                LOG.error("The explorer has not been registered", e);
236
            } catch (ServiceException e) {
237
                LOG.error("Error creating the explorer panel", e);
238
            } catch (ValidateDataParametersException e) {
239
                LOG.error("Error creating the explorer", e);
240
            }    
241
        }
242
    }
243

  
244
    @SuppressWarnings("rawtypes")
245
    private void populateProvidersCombo(){       
246
        providersComboBox.addItem(null);
247
        if (dataServerExplorer != null){
248
            List providerNames = dataServerExplorer.getDataStoreProviderNames();
249
            for (int i=0 ; i<providerNames.size() ; i++){
250
                providersComboBox.addItem(providerNames.get(i));         
251
            }
252
        }
253
    }
254

  
255
    private void removeProvidersCombo(){
256
        providersComboBox.removeAllItems();
257
    }
258

  
259
    private void providersComboSelectionChanged(){
260
        dataStoreParameters = null;
261
        String providerName = (String)providersComboBox.getSelectedItem();   
262
        if ((dataServerExplorer != null) && (providerName != null)){
263
            enableProviderControls(true);
264
        }else{
265
            enableProviderControls(false);
266
        }
267
    }
268

  
269
    private void providersButtonClicked(){
270
        String providerName = (String)providersComboBox.getSelectedItem();       
271
        if ((dataServerExplorer != null) && (providerName != null)){
272
            try {
273
                if ((dataStoreParameters == null) || (!dataStoreParameters.getDataStoreName().equals(providerName))){
274
                    dataStoreParameters = 
275
                        DATA_MANAGER.createNewStoreParameters(dataServerExplorer.getProviderName(), providerName);
276
                }
277
                DynObjectEditor dynObjectEditor = new DynObjectEditor(dataStoreParameters);
278
                dynObjectEditor.editObject(true);             
279
            } catch (InitializeException e) {
280
                LOG.error("Error creating the store parameters", e);
281
            } catch (ProviderNotRegisteredException e) {
282
                LOG.error("The provider has not been registered", e);
283
            } catch (ServiceException e) {
284
                LOG.error("Error creating the store panel", e);
285
            }
286
        }
287
    }  
288
}
0 289

  
tags/v2_0_0_Build_2047/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/dal/feature/swing/FeatureSelectionModel.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2010 {}  {{Task}}
26
 */
27
package org.gvsig.fmap.mapcontrol.dal.feature.swing;
28

  
29
import javax.swing.ListSelectionModel;
30
import javax.swing.event.EventListenerList;
31
import javax.swing.event.ListSelectionEvent;
32
import javax.swing.event.ListSelectionListener;
33

  
34
import org.slf4j.Logger;
35
import org.slf4j.LoggerFactory;
36

  
37
import org.gvsig.fmap.dal.exception.DataException;
38
import org.gvsig.fmap.dal.feature.Feature;
39
import org.gvsig.fmap.dal.feature.FeatureSelection;
40
import org.gvsig.fmap.dal.feature.FeatureStore;
41
import org.gvsig.fmap.dal.feature.FeatureStoreNotification;
42
import org.gvsig.fmap.dal.feature.exception.ConcurrentDataModificationException;
43
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.FeatureTableModel;
44
import org.gvsig.tools.observer.Observable;
45
import org.gvsig.tools.observer.Observer;
46

  
47
/**
48
 * @author 2010- C?sar Ordi?ana - gvSIG team
49
 */
50
public class FeatureSelectionModel implements ListSelectionModel, Observer {
51
    private static Logger LOG = 
52
        LoggerFactory.getLogger(FeatureSelectionModel.class);
53
    
54
	protected EventListenerList listenerList = new EventListenerList();
55

  
56
	private final FeatureTableModel featureTableModel;
57

  
58
	private int selectionMode = SINGLE_INTERVAL_SELECTION;
59

  
60
	private boolean isAdjusting = false;
61

  
62
	private int anchor = -1;
63

  
64
	private int lead = -1;
65
	
66
	private int currentFirst = -1;
67
	private int currentLast = -1;
68

  
69
	/**
70
	 * Creates a new {@link FeatureSelectionModel} with a
71
	 * {@link FeatureTableModel} used to get the {@link Feature}s by position in
72
	 * the table.
73
	 * 
74
	 * @param featureTableModel
75
	 *            to get Features from
76
	 * @throws DataException
77
	 *             if there is an error getting the store selection
78
	 */
79
	public FeatureSelectionModel(FeatureTableModel featureTableModel)
80
			throws DataException {
81
		this.featureTableModel = featureTableModel;
82
		this.featureTableModel.getFeatureStore().addObserver(this);
83
	}
84

  
85
	public int getAnchorSelectionIndex() {
86
		return anchor;
87
	}
88

  
89
	public int getLeadSelectionIndex() {
90
		return lead;
91
	}
92

  
93
	public int getMaxSelectionIndex() {
94
		FeatureSelection selection = getFeatureSelection();
95
		try {
96
			if (!selection.isEmpty()) {
97
				for (int i = featureTableModel.getRowCount() - 1; i >= 0; i--) {
98
					if (selection.isSelected(featureTableModel.getFeatureAt(i))) {
99
						return i;
100
					}
101
				}
102
			}
103
		} catch (DataException e) {
104
			throw new SelectionChangeException(e);
105
		}
106
		return -1;
107
	}
108

  
109
	public int getMinSelectionIndex() {
110
		FeatureSelection selection = getFeatureSelection();
111
		try {
112
			if (!selection.isEmpty()) {
113
				for (int i = 0; i < featureTableModel.getRowCount(); i++) {
114
					if (selection.isSelected(featureTableModel.getFeatureAt(i))) {
115
						return i;
116
					}
117
				}
118
			}
119
		} catch (DataException e) {
120
			throw new SelectionChangeException(e);
121
		}
122
		return -1;
123
	}
124

  
125
	public void insertIndexInterval(int index, int length, boolean before) {
126
		// Nothing to do
127
	}
128

  
129
	public void removeIndexInterval(int index0, int index1) {
130
		// Nothing to do
131
	}
132

  
133
	public void setAnchorSelectionIndex(int index) {
134
		this.anchor = index;
135
	}
136

  
137
	public void setLeadSelectionIndex(int index) {
138
		this.lead = index;
139
	}
140

  
141
	public void addSelectionInterval(int index0, int index1) {
142
		doWithSelection(new FeatureSelectionOperation() {
143

  
144
			public void doWithSelection(FeatureSelection selection, int first,
145
					int last) throws DataException {
146
				for (int i = first; i <= last; i++) {
147
					Feature feature = getFeature(i);
148
					if (!selection.isSelected(feature)) {
149
						selection.select(feature);
150
					}
151
				}
152
			}
153

  
154
		}, index0, index1, true);
155
	}
156

  
157
	public void setSelectionInterval(int index0, int index1) {
158
		doWithSelection(new FeatureSelectionOperation() {
159

  
160
			public void doWithSelection(FeatureSelection selection, int first,
161
					int last) throws DataException {
162
				selection.deselectAll();
163
				for (int i = first; i <= last; i++) {
164
					Feature feature = getFeature(i);
165
					selection.select(feature);
166
				}
167
			}
168

  
169
		}, index0, index1, true);
170
	}
171

  
172
	public void removeSelectionInterval(int index0, int index1) {
173
		doWithSelection(new FeatureSelectionOperation() {
174

  
175
			public void doWithSelection(FeatureSelection selection, int first,
176
					int last) throws DataException {
177
				for (int i = first; i <= last; i++) {
178
					Feature feature = getFeature(i);
179
					if (selection.isSelected(feature)) {
180
						selection.deselect(feature);
181
					}
182
				}
183
			}
184

  
185
		}, index0, index1, false);
186
	}
187

  
188
	public void clearSelection() {
189
		try {
190
			getFeatureSelection().deselectAll();
191
		} catch (DataException e) {
192
			throw new SelectionChangeException(e);
193
		}
194
	}
195

  
196
	public boolean isSelectedIndex(int index) {
197
		if (index == -1) {
198
			return false;
199
		}
200
		Feature feature = featureTableModel.getFeatureAt(index);
201
		return getFeatureSelection().isSelected(feature);
202
	}
203

  
204
	public boolean isSelectionEmpty() {
205
		try {
206
			return getFeatureSelection().isEmpty();
207
		} catch (DataException ex) {
208
			throw new SelectionChangeException(ex);
209
		}
210
	}
211

  
212
	public boolean getValueIsAdjusting() {
213
		return isAdjusting;
214
	}
215

  
216
	public void setValueIsAdjusting(boolean valueIsAdjusting) {
217
		if (this.isAdjusting != valueIsAdjusting) {
218
			this.isAdjusting = valueIsAdjusting;
219
			if (this.isAdjusting) {
220
				getFeatureSelection().beginComplexNotification();
221
			} else {
222
				getFeatureSelection().endComplexNotification();
223
			}
224
		}
225
	}
226

  
227
	public int getSelectionMode() {
228
		return selectionMode;
229
	}
230

  
231
	public void setSelectionMode(int selectionMode) {
232
		this.selectionMode = selectionMode;
233
	}
234

  
235
	public void addListSelectionListener(ListSelectionListener listener) {
236
		listenerList.add(ListSelectionListener.class, listener);
237
	}
238

  
239
	public void removeListSelectionListener(ListSelectionListener listener) {
240
		listenerList.remove(ListSelectionListener.class, listener);
241
	}
242

  
243
	public void update(Observable observable, Object notification) {
244
		if (notification instanceof FeatureStoreNotification) {
245
			FeatureStoreNotification fnotification =
246
					(FeatureStoreNotification) notification;
247
			if (!fnotification.getSource().equals(getFeatureStore())) {
248
				return;
249
			}
250
			if (FeatureStoreNotification.SELECTION_CHANGE.equals(fnotification.getType())) {
251
				try{
252
				    fireValueChanged(-1, -1, false);
253
				}catch(ConcurrentDataModificationException e){
254
				    LOG.warn("The store has been updated and the selection can not be refreshed", e);
255
				}
256
			}
257
		}
258
	}
259

  
260
	private FeatureSelection getFeatureSelection() {
261
		try {
262
			return (FeatureSelection) getFeatureStore().getSelection();
263
		} catch (DataException ex) {
264
			throw new SelectionChangeException(ex);
265
		}
266
	}
267

  
268
	/**
269
	 * @param operation
270
	 * @param index0
271
	 * @param index1
272
	 */
273
	private void doWithSelection(FeatureSelectionOperation operation,
274
			int index0, int index1, boolean select) {
275
		// Set the anchor and lead
276
		anchor = index0;
277
		lead = index1;
278

  
279
		// As index0 <= index1 is no guaranteed, calculate the first and second
280
		// values
281
		int first = (index0 <= index1) ? index0 : index1;
282
		int last = (index0 <= index1) ? index1 : index0;
283
		
284
		//If the new selection is not updated don't continue
285
		if ((currentFirst == first) && (currentLast == last)){
286
		    return;
287
		}
288
		currentFirst = first;
289
		currentLast = last;
290

  
291
		FeatureSelection selection = getFeatureSelection();
292

  
293
		// Perform the selection operation into a complex notification
294
		selection.beginComplexNotification();
295
		try {
296
			// Is a full select or deselect
297
			if (first == 00 && last == featureTableModel.getRowCount() - 1) {
298
				if (select) {
299
					selection.selectAll();
300
				} else {
301
					selection.deselectAll();
302
				}
303
			} else {
304
				operation.doWithSelection(selection, first, last);
305
			}
306
		} catch (DataException e) {
307
			throw new SelectionChangeException(e);
308
		} finally {
309
			selection.endComplexNotification();
310
		}
311

  
312
		fireValueChanged(first, last, isAdjusting);
313
	}
314

  
315
	/**
316
	 * Returns a Feature by table row position.
317
	 */
318
	private Feature getFeature(int index) {
319
		return featureTableModel.getFeatureAt(index);
320
	}
321

  
322
	/**
323
	 * Returns the FeatureStore.
324
	 */
325
	private FeatureStore getFeatureStore() {
326
		return featureTableModel.getFeatureStore();
327
	}
328

  
329
	/**
330
	 * @param firstIndex
331
	 *            the first index in the interval
332
	 * @param lastIndex
333
	 *            the last index in the interval
334
	 * @param isAdjusting
335
	 *            true if this is the final change in a series of adjustments
336
	 * @see EventListenerList
337
	 */
338
	protected void fireValueChanged(int firstIndex, int lastIndex,
339
			boolean isAdjusting) {
340
		Object[] listeners = listenerList.getListenerList();
341
		ListSelectionEvent e = null;
342

  
343
		for (int i = listeners.length - 2; i >= 0; i -= 2) {
344
			if (listeners[i] == ListSelectionListener.class) {
345
				if (e == null) {
346
					e =
347
							new ListSelectionEvent(this, firstIndex, lastIndex,
348
									isAdjusting);
349
				}
350
				((ListSelectionListener) listeners[i + 1]).valueChanged(e);
351
			}
352
		}
353
	}
354

  
355
	private interface FeatureSelectionOperation {
356
		void doWithSelection(FeatureSelection selection, int first, int last)
357
				throws DataException;
358
	}
359
}
tags/v2_0_0_Build_2047/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/dal/feature/swing/FeatureTable.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 {DiSiD Technologies}  {Create a Table component for Features}
26
 */
27
package org.gvsig.fmap.mapcontrol.dal.feature.swing;
28

  
29
import java.awt.Color;
30
import java.awt.Component;
31

  
32
import javax.swing.JTable;
33
import javax.swing.event.TableModelEvent;
34
import javax.swing.table.TableCellRenderer;
35
import javax.swing.table.TableColumn;
36
import javax.swing.table.TableColumnModel;
37
import javax.swing.table.TableModel;
38

  
39
import org.gvsig.fmap.dal.exception.DataException;
40
import org.gvsig.fmap.dal.feature.Feature;
41
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
42
import org.gvsig.fmap.dal.feature.FeatureStoreNotification;
43
import org.gvsig.fmap.geom.Geometry;
44
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.FeatureCellRenderer;
45
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.FeatureTableModel;
46
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.GeometryWKTCellEditor;
47
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.GeometryWKTCellRenderer;
48
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.JToggleButtonHeaderCellRenderer;
49
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.notification.ColumnHeaderSelectionChangeNotification;
50
import org.gvsig.tools.observer.Observable;
51
import org.gvsig.tools.observer.Observer;
52

  
53
/**
54
 * Table extension to show Feature values.
55
 *
56
 * It's based on the usage of a FeatureTableModel, and adds renderers for
57
 * Geometry and Feature cell values.
58
 *
59
 * Observers are notified about column header selection changes, with a
60
 * {@link ColumnHeaderSelectionChangeNotification}.
61
 *
62
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
63
 */
64
public class FeatureTable extends JTable implements Observer, Observable {
65

  
66
    /**
67
     * Generated Serial UID
68
     */
69
    private static final long serialVersionUID = -6139395189283163964L;
70
    private final FeatureTableModel featureTableModel;
71
    private JToggleButtonHeaderCellRenderer headerCellRenderer;
72

  
73
	private static final int COLUMN_HEADER_MARGIN = 8;
74

  
75
	private static final int COLUMN_HEADER_MIN_WIDTH = 50;
76

  
77
    /**
78
     * Creates a new FeatureTable with a {@link FeatureTableModel}.
79
     *
80
     * @param featureTableModel
81
     *            the table model to get data to be shown on the table
82
     * @throws DataException
83
     *             if there is an error while loading the Features to show
84
     * @see JTable#JTable(TableModel)
85
     */
86
    public FeatureTable(FeatureTableModel featureTableModel)
87
            throws DataException {
88
        super(featureTableModel);
89
        this.featureTableModel = featureTableModel;
90
        init();
91
    }
92

  
93
    /**
94
     * Creates a new FeatureTable with a {@link FeatureTableModel}.
95
     *
96
     * @param featureTableModel
97
     *            the table model to get data to be shown on the table
98
     * @param cm
99
     *            the table column model to use
100
     * @throws DataException
101
     *             if there is an error while loading the Features to show
102
     * @see JTable#JTable(TableModel, TableColumnModel)
103
     */
104
    public FeatureTable(FeatureTableModel featureTableModel, TableColumnModel cm)
105
            throws DataException {
106
        super(featureTableModel, cm);
107
        this.featureTableModel = featureTableModel;
108
        init();
109
    }
110

  
111
    public void update(Observable observable, Object notification) {
112
        if (notification instanceof FeatureStoreNotification) {
113
            FeatureStoreNotification fsNotification = (FeatureStoreNotification) notification;
114
            String type = fsNotification.getType();
115
            // If the selection has changed, repaint the table to show the new
116
            // selected rows
117
            if (FeatureStoreNotification.SELECTION_CHANGE.equals(type)) {
118
                repaint();
119
            }
120
        }
121
    }
122

  
123
    /**
124
     * Returns the FeatureAttributeDescriptor related to the selected columns.
125
     *
126
     * @return an array of FeatureAttributeDescriptor
127
     *
128
     * @see org.gvsig.fmap.mapcontrol.dal.feature.swing.table.JToggleButtonHeaderCellRenderer#getSelectedColumns()
129
     */
130
    public FeatureAttributeDescriptor[] getSelectedColumnsAttributeDescriptor() {
131
        int[] columns = headerCellRenderer.getSelectedColumns();
132
        FeatureAttributeDescriptor[] descriptors = new FeatureAttributeDescriptor[columns.length];
133

  
134
        for (int i = 0; i < descriptors.length; i++) {
135
            descriptors[i] = featureTableModel
136
                    .getDescriptorForColumn(columns[i]);
137
        }
138

  
139
        return descriptors;
140
    }
141

  
142
    public void addObserver(Observer observer) {
143
        headerCellRenderer.addObserver(observer);
144
    }
145

  
146
    public void deleteObserver(Observer observer) {
147
        headerCellRenderer.deleteObserver(observer);
148
    }
149

  
150
    public void deleteObservers() {
151
        headerCellRenderer.deleteObservers();
152
    }
153

  
154
	/**
155
	 * Sets that the selected Features to be viewed first.
156
	 */
157
	public void setSelectionUp(boolean selectionUp) {
158
		((FeatureTableModel) getModel()).setSelectionUp(selectionUp);
159
		scrollRectToVisible(getCellRect(0, 0, true));
160
	}
161

  
162
    // @Override
163
    // public void tableChanged(TableModelEvent e) {
164
    // super.tableChanged(e);
165
    // if (headerCellRenderer != null) {
166
    // headerCellRenderer.deselectAll();
167
    // }
168
    // }
169

  
170
    @Override
171
    protected void initializeLocalVars() {
172
        super.initializeLocalVars();
173
        // Add a cell renderer for Geometries and Features
174
        setDefaultRenderer(Geometry.class, new GeometryWKTCellRenderer());
175
        setDefaultEditor(Geometry.class, new GeometryWKTCellEditor());
176
        setDefaultRenderer(Feature.class, new FeatureCellRenderer());
177

  
178
        // Set the selected row colors
179
        setSelectionForeground(Color.blue);
180
        setSelectionBackground(Color.yellow);
181
    }
182

  
183
    /**
184
     * Initializes the table GUI.
185
     */
186
    private void init() throws DataException {
187
		setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
188

  
189
        featureTableModel.getFeatureStore().addObserver(this);
190
        // Change the selection model to link with the FeatureStore selection
191
        // through the FeatureTableModel
192
        setRowSelectionAllowed(true);
193
        setColumnSelectionAllowed(false);
194
		setSelectionModel(new FeatureSelectionModel(featureTableModel));		
195

  
196
		headerCellRenderer = new JToggleButtonHeaderCellRenderer(this);
197
		getTableHeader().setDefaultRenderer(headerCellRenderer);
198

  
199
		TableColumnModel tcmodel = getColumnModel();
200
		for (int i = 0; i < tcmodel.getColumnCount(); i++) {
201
			TableColumn col = tcmodel.getColumn(i);
202
			// Get width of column header
203
			TableCellRenderer renderer = col.getHeaderRenderer();
204
			if (renderer == null) {
205
				renderer = getTableHeader().getDefaultRenderer();
206
			}
207
			Component comp =
208
					renderer.getTableCellRendererComponent(this,
209
							col.getHeaderValue(), false, false, 0, i);
210
			int width = comp.getPreferredSize().width;
211
			width =
212
					width < COLUMN_HEADER_MIN_WIDTH ? COLUMN_HEADER_MIN_WIDTH
213
							: width;
214
			col.setPreferredWidth(width + 2 * COLUMN_HEADER_MARGIN);
215
		}
216
    }
217

  
218
    /**
219
     * Returns the number of selected columns.
220
     *
221
     * @return the number of selected columns, 0 if no columns are selected
222
     */
223
    public int getSelectedColumnCount() {
224
        return headerCellRenderer.getSelectedColumns().length;
225
    }
226
    
227
    public void tableChanged(TableModelEvent e) {
228
        // Clear the header selection
229
        if (e != null && e.getFirstRow() == TableModelEvent.HEADER_ROW
230
            && headerCellRenderer != null) {
231
            headerCellRenderer.deselectAll();
232
        }
233
        super.tableChanged(e);
234
    }
235
}
0 236

  
tags/v2_0_0_Build_2047/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/dal/feature/swing/FeatureTablePanel.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 {DiSiD Technologies}  {Create a Table component for Features}
26
 */
27
package org.gvsig.fmap.mapcontrol.dal.feature.swing;
28

  
29
import java.awt.BorderLayout;
30

  
31
import javax.swing.JLabel;
32
import javax.swing.JPanel;
33
import javax.swing.JScrollPane;
34

  
35
import org.gvsig.fmap.dal.DataStoreNotification;
36
import org.gvsig.fmap.dal.exception.DataException;
37
import org.gvsig.fmap.dal.feature.Feature;
38
import org.gvsig.fmap.dal.feature.FeatureQuery;
39
import org.gvsig.fmap.dal.feature.FeatureStore;
40
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.ConfigurableFeatureTableModel;
41
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.FeatureTableConfigurationPanel;
42
import org.gvsig.i18n.Messages;
43
import org.gvsig.tools.exception.BaseException;
44
import org.gvsig.tools.observer.Observable;
45
import org.gvsig.tools.observer.Observer;
46

  
47
/**
48
 * Panel to show a table of Feature data.
49
 * 
50
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
51
 */
52
public class FeatureTablePanel extends JPanel implements Observer {
53

  
54
    private static final long serialVersionUID = -9199073063283531216L;
55

  
56
    private ConfigurableFeatureTableModel tableModel;
57

  
58
    private JScrollPane jScrollPane = null;
59

  
60
    private FeatureTable table = null;
61
    private JPanel selectionPanel;
62
    private JLabel selectionLabel;
63

  
64
    /**
65
     * Constructs a Panel to show a table with the features of a FeatureStore.
66
     * 
67
     * @param featureStore
68
     *            to extract the features from
69
     * @throws BaseException
70
     *             if there is an error reading data from the FeatureStore
71
     */
72
    public FeatureTablePanel(FeatureStore featureStore) throws BaseException {
73
        this(featureStore, true);
74
    }
75

  
76
    /**
77
     * Constructs a Panel to show a table with the features of a FeatureStore.
78
     * 
79
     * @param featureStore
80
     *            to extract the features from
81
     * @param isDoubleBuffered
82
     *            a boolean, true for double-buffering, which uses additional
83
     *            memory space to achieve fast, flicker-free updates
84
     * @throws BaseException
85
     *             if there is an error reading data from the FeatureStore
86
     */
87
    public FeatureTablePanel(FeatureStore featureStore, boolean isDoubleBuffered)
88
        throws BaseException {
89
        this(featureStore, null, isDoubleBuffered);
90
    }
91

  
92
    /**
93
     * @throws BaseException
94
     * 
95
     */
96
    public FeatureTablePanel(FeatureStore featureStore,
97
        FeatureQuery featureQuery) throws BaseException {
98
        this(featureStore, featureQuery, true);
99
    }
100

  
101
    /**
102
     * @param isDoubleBuffered
103
     * @throws BaseException
104
     */
105
    public FeatureTablePanel(FeatureStore featureStore,
106
        FeatureQuery featureQuery, boolean isDoubleBuffered)
107
        throws BaseException {
108
        this(createModel(featureStore, featureQuery));
109
    }
110

  
111
    public FeatureTablePanel(ConfigurableFeatureTableModel tableModel)
112
        throws DataException {
113
        this(tableModel, true);
114
    }
115

  
116
    public FeatureTablePanel(ConfigurableFeatureTableModel tableModel,
117
        boolean isDoubleBuffered) throws DataException {
118
        super(isDoubleBuffered);
119
        this.tableModel = tableModel;
120
        this.setLayout(new BorderLayout());
121
        this.add(getJScrollPane(), BorderLayout.CENTER);
122
        this.add(getSelectionPanel(), BorderLayout.SOUTH);
123
        tableModel.getFeatureStore().addObserver(this);
124
    }
125

  
126
    private JPanel getSelectionPanel() {
127
        if (selectionPanel == null) {
128
            selectionLabel = new JLabel();
129
            selectionLabel.setText(getFeatureSelectionSize() + " / "
130
                + getTableModel().getHelper().getTotalSize() + " "
131
                + Messages.getText("registros_seleccionados_total") + ".");
132
            selectionPanel = new JPanel();
133

  
134
            selectionPanel.add(selectionLabel, BorderLayout.EAST);
135
        }
136
        return selectionPanel;
137
    }
138

  
139
    private void updateSelection() {
140
        selectionLabel.setText(getFeatureSelectionSize() + " / "
141
            + getTableModel().getRowCount() + " "
142
            + Messages.getText("registros_seleccionados_total") + ".");
143
    }
144

  
145
    private long getFeatureSelectionSize() {
146
        try {
147
            return getFeatureStore().getFeatureSelection().getSize();
148
        } catch (DataException e) {
149
            throw new RuntimeException("Error updating selection information",
150
                e);
151
        }
152
    }
153

  
154
    public JPanel createConfigurationPanel() {
155
        return new FeatureTableConfigurationPanel(tableModel);
156
    }
157

  
158
    /**
159
     * Returns the internal Table Model for the Features of the FeatureStore.
160
     * 
161
     * @return the internal Table Model
162
     */
163
    public ConfigurableFeatureTableModel getTableModel() {
164
        return tableModel;
165
    }
166

  
167
    /**
168
     * Returns the {@link FeatureStore} of the {@link Feature}s being shown in
169
     * the table.
170
     * 
171
     * @return the store of the features
172
     */
173
    public FeatureStore getFeatureStore() {
174
        return getTableModel().getFeatureStore();
175
    }
176

  
177
    /**
178
     * Returns the FeatureQuery used to get the Features.
179
     * 
180
     * @return the FeatureQuery
181
     */
182
    public FeatureQuery getFeatureQuery() {
183
        return getTableModel().getFeatureQuery();
184
    }
185

  
186
    /**
187
     * Sets that the selected Features to be viewed first.
188
     */
189
    public void setSelectionUp(boolean selectionUp) {
190
        try {
191
            getTable().setSelectionUp(selectionUp);
192
        } catch (DataException e) {
193
            throw new RuntimeException("Error setting the selection up", e);
194
        }
195
    }
196

  
197
    private static ConfigurableFeatureTableModel createModel(
198
        FeatureStore featureStore, FeatureQuery featureQuery)
199
        throws BaseException {
200
        FeatureQuery query =
201
            featureQuery == null ? featureStore.createFeatureQuery()
202
                : featureQuery;
203

  
204
        return new ConfigurableFeatureTableModel(featureStore, query);
205
    }
206

  
207
    public FeatureTable getTable() throws DataException {
208
        if (table == null) {
209
            table = new FeatureTable(tableModel);
210
            // Change the selection model to link with the FeatureStore
211
            // selection
212
            // through the FeatureTableModel
213
            table.setRowSelectionAllowed(true);
214
            table.setColumnSelectionAllowed(false);
215
            // table.setSelectionModel(new FeatureSelectionModel(tableModel));
216
        }
217
        return table;
218
    }
219

  
220
    /**
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff