Revision 39360

View differences:

tags/v2_0_0_Build_2060/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_2060/libraries/libFMap_controls/src/org/gvsig/fmap/IconThemeHelper.java
1
package org.gvsig.fmap;
2

  
3
import java.awt.Image;
4

  
5
import javax.swing.ImageIcon;
6

  
7
import org.gvsig.tools.swing.api.ToolsSwingLocator;
8
import org.gvsig.tools.swing.icontheme.IconTheme;
9
import org.slf4j.Logger;
10
import org.slf4j.LoggerFactory;
11

  
12
public class IconThemeHelper {
13

  
14
	private static Logger logger = LoggerFactory.getLogger(IconThemeHelper.class);
15
	
16
	public static void registerIcon(String group, String name, Object obj) {
17
		String resourceName;
18
		ClassLoader loader;
19
		IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
20
		if( group == null || group.trim().length()==0 ) {
21
			resourceName = "images/"+name+".png";
22
		} else {
23
			resourceName = "images/"+group+"/"+name+".png";
24
		}
25
		if( obj instanceof Class ) {
26
			loader = ((Class) obj).getClassLoader();
27
		} else {
28
			loader = obj.getClass().getClassLoader();
29
		}
30
		try {
31
			iconTheme.registerDefault("mapcontrol", group, name, null, loader.getResource(resourceName));
32
		} catch( Throwable e) {
33
			logger.info(e.getMessage());
34
		}
35
	}
36

  
37
	public static ImageIcon getImageIcon(String iconName) {
38
		IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
39
		return iconTheme.get(iconName);
40
	}
41
	
42
	public static Image getImage(String iconName) {
43
		IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
44
		return iconTheme.get(iconName).getImage();
45
	}
46
}
0 47

  
tags/v2_0_0_Build_2060/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_2060/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_2060/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.gvsig.fmap.dal.DALLocator;
37
import org.gvsig.fmap.dal.DataManager;
38
import org.gvsig.fmap.dal.DataServerExplorer;
39
import org.gvsig.fmap.dal.DataServerExplorerParameters;
40
import org.gvsig.fmap.dal.NewDataStoreParameters;
41
import org.gvsig.fmap.dal.exception.InitializeException;
42
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
43
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
44
import org.gvsig.fmap.mapcontrol.swing.dynobject.DynObjectEditor;
45
import org.gvsig.tools.service.ServiceException;
46
import org.slf4j.Logger;
47
import org.slf4j.LoggerFactory;
48

  
49

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

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

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

  
63
    private static final int FORM_HEIGTH = 18;
64

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

  
68
    private NewDataStoreParameters dataStoreParameters = null;
69

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

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

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

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

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

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

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

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

  
110
        setLayout(new GridBagLayout());
111

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  
tags/v2_0_0_Build_2060/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.gvsig.fmap.dal.exception.DataException;
35
import org.gvsig.fmap.dal.feature.Feature;
36
import org.gvsig.fmap.dal.feature.FeatureSelection;
37
import org.gvsig.fmap.dal.feature.FeatureStore;
38
import org.gvsig.fmap.dal.feature.FeatureStoreNotification;
39
import org.gvsig.fmap.dal.feature.exception.ConcurrentDataModificationException;
40
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.FeatureTableModel;
41
import org.gvsig.tools.observer.Observable;
42
import org.gvsig.tools.observer.Observer;
43
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
45

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

  
55
	private final FeatureTableModel featureTableModel;
56

  
57
	private int selectionMode = SINGLE_INTERVAL_SELECTION;
58

  
59
	private boolean isAdjusting = false;
60

  
61
	private int anchor = -1;
62

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  
290
		FeatureSelection selection = getFeatureSelection();
291

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

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

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

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

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

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

  
354
	private interface FeatureSelectionOperation {
355
		void doWithSelection(FeatureSelection selection, int first, int last)
356
				throws DataException;
357
	}
358
}
tags/v2_0_0_Build_2060/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_2060/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));
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff