svn-gvsig-desktop / branches / v2_0_0_prep / libraries / org.gvsig.exportto / org.gvsig.exportto.swing / org.gvsig.exportto.swing.impl / src / main / java / org / gvsig / exportto / swing / impl / panel / ExportFilterPanel.java @ 34981
History | View | Annotate | Download (9 KB)
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.exportto.swing.impl.panel; |
23 |
|
24 |
import java.awt.GridBagConstraints; |
25 |
import java.awt.GridBagLayout; |
26 |
import java.awt.Insets; |
27 |
import java.awt.event.ItemEvent; |
28 |
import java.awt.event.ItemListener; |
29 |
|
30 |
import javax.swing.ButtonGroup; |
31 |
import javax.swing.JList; |
32 |
import javax.swing.JPanel; |
33 |
import javax.swing.JRadioButton; |
34 |
import javax.swing.JScrollPane; |
35 |
import javax.swing.JTextArea; |
36 |
import javax.swing.border.TitledBorder; |
37 |
import javax.swing.event.ChangeEvent; |
38 |
import javax.swing.event.ListSelectionEvent; |
39 |
import javax.swing.event.ListSelectionListener; |
40 |
|
41 |
import org.gvsig.exportto.ExporttoLocator; |
42 |
import org.gvsig.exportto.ExporttoManager; |
43 |
import org.gvsig.exportto.swing.impl.DefaultJExporttoServicePanel; |
44 |
import org.gvsig.exportto.swing.impl.panel.ExportFiltersListModel.Filter; |
45 |
|
46 |
|
47 |
/**
|
48 |
* @author gvSIG Team
|
49 |
* @version $Id$
|
50 |
*
|
51 |
*/
|
52 |
public class ExportFilterPanel extends AbstractExporttoPanel implements ListSelectionListener, ItemListener{ |
53 |
private static final long serialVersionUID = -7108159123965667106L; |
54 |
|
55 |
private static final ExporttoManager EXPORTTO_MANAGER = ExporttoLocator.getManager(); |
56 |
|
57 |
private ButtonGroup selectionButtonGroup; |
58 |
private JRadioButton allLayerRadioButton; |
59 |
private JRadioButton selectedFeaturesRabioButton; |
60 |
private JRadioButton personalizedFilterRabioButton; |
61 |
|
62 |
private JPanel filterPanel; |
63 |
|
64 |
private JPanel predefinedFilterPanel; |
65 |
private JScrollPane predefinedFilterScrollPane; |
66 |
private JList predefinedFilterList; |
67 |
|
68 |
private JPanel freeFilterPanel; |
69 |
private JScrollPane freeFilterScrollPane; |
70 |
private JTextArea freeFilterTextArea; |
71 |
|
72 |
public ExportFilterPanel(DefaultJExporttoServicePanel exporttoServicePanel) {
|
73 |
super(exporttoServicePanel);
|
74 |
initializeComponents(); |
75 |
} |
76 |
|
77 |
private void initializeComponents() { |
78 |
GridBagConstraints gridBagConstraints;
|
79 |
setLayout(new GridBagLayout()); |
80 |
|
81 |
//Adding the radio buttons to the button group
|
82 |
allLayerRadioButton = new JRadioButton(); |
83 |
allLayerRadioButton.setSelected(true);
|
84 |
selectedFeaturesRabioButton = new JRadioButton(); |
85 |
personalizedFilterRabioButton = new JRadioButton(); |
86 |
|
87 |
allLayerRadioButton.addItemListener(this);
|
88 |
selectedFeaturesRabioButton.addItemListener(this);
|
89 |
personalizedFilterRabioButton.addItemListener(this);
|
90 |
|
91 |
selectionButtonGroup = new ButtonGroup(); |
92 |
selectionButtonGroup.add(allLayerRadioButton); |
93 |
selectionButtonGroup.add(selectedFeaturesRabioButton); |
94 |
selectionButtonGroup.add(personalizedFilterRabioButton); |
95 |
|
96 |
allLayerRadioButton.setText(exporttoServicePanel.getExporttoSwingManager().getTranslation("all_layer"));
|
97 |
gridBagConstraints = new GridBagConstraints(); |
98 |
gridBagConstraints.gridx = 0;
|
99 |
gridBagConstraints.gridy = 0;
|
100 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
101 |
gridBagConstraints.anchor = GridBagConstraints.WEST;
|
102 |
gridBagConstraints.weightx = 1.0;
|
103 |
add(allLayerRadioButton, gridBagConstraints); |
104 |
|
105 |
selectedFeaturesRabioButton.setText(exporttoServicePanel.getExporttoSwingManager().getTranslation("selected_features"));
|
106 |
gridBagConstraints = new GridBagConstraints(); |
107 |
gridBagConstraints.gridx = 0;
|
108 |
gridBagConstraints.gridy = 1;
|
109 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
110 |
gridBagConstraints.anchor = GridBagConstraints.WEST;
|
111 |
gridBagConstraints.weightx = 1.0;
|
112 |
add(selectedFeaturesRabioButton, gridBagConstraints); |
113 |
|
114 |
personalizedFilterRabioButton.setText(exporttoServicePanel.getExporttoSwingManager().getTranslation("filter"));
|
115 |
gridBagConstraints = new GridBagConstraints(); |
116 |
gridBagConstraints.gridx = 0;
|
117 |
gridBagConstraints.gridy = 2;
|
118 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
119 |
gridBagConstraints.anchor = GridBagConstraints.WEST;
|
120 |
gridBagConstraints.weightx = 1.0;
|
121 |
add(personalizedFilterRabioButton, gridBagConstraints); |
122 |
|
123 |
//Create the filter panel
|
124 |
filterPanel = new JPanel(); |
125 |
filterPanel.setLayout(new GridBagLayout()); |
126 |
|
127 |
//Create the predefined filter panel
|
128 |
predefinedFilterPanel = new JPanel(); |
129 |
predefinedFilterScrollPane = new JScrollPane(); |
130 |
predefinedFilterPanel.setBorder(new TitledBorder(exporttoServicePanel.getExporttoSwingManager().getTranslation("predefined_filters"))); |
131 |
predefinedFilterList = new JList(); |
132 |
predefinedFilterList.setModel(new ExportFiltersListModel(exporttoServicePanel));
|
133 |
predefinedFilterList.addListSelectionListener(this);
|
134 |
|
135 |
predefinedFilterPanel.setLayout(new GridBagLayout()); |
136 |
predefinedFilterScrollPane.setViewportView(predefinedFilterList); |
137 |
|
138 |
gridBagConstraints = new GridBagConstraints(); |
139 |
gridBagConstraints.gridx = 0;
|
140 |
gridBagConstraints.gridy = 0;
|
141 |
gridBagConstraints.fill = GridBagConstraints.BOTH;
|
142 |
gridBagConstraints.weightx = 1.0;
|
143 |
gridBagConstraints.weighty = 1.0;
|
144 |
predefinedFilterPanel.add(predefinedFilterScrollPane, gridBagConstraints); |
145 |
|
146 |
gridBagConstraints = new GridBagConstraints(); |
147 |
gridBagConstraints.gridx = 0;
|
148 |
gridBagConstraints.gridy = 0;
|
149 |
gridBagConstraints.fill = GridBagConstraints.BOTH;
|
150 |
gridBagConstraints.weightx = 1.0;
|
151 |
gridBagConstraints.weighty = 1.0;
|
152 |
filterPanel.add(predefinedFilterPanel, gridBagConstraints); |
153 |
|
154 |
//Create the free filter panel
|
155 |
freeFilterPanel = new JPanel(); |
156 |
freeFilterScrollPane = new JScrollPane(); |
157 |
freeFilterPanel.setBorder(new TitledBorder(exporttoServicePanel.getExporttoSwingManager().getTranslation("free_filter"))); |
158 |
freeFilterTextArea = new JTextArea(); |
159 |
|
160 |
freeFilterPanel.setLayout(new GridBagLayout()); |
161 |
freeFilterScrollPane.setViewportView(freeFilterTextArea); |
162 |
|
163 |
gridBagConstraints = new GridBagConstraints(); |
164 |
gridBagConstraints.gridx = 0;
|
165 |
gridBagConstraints.gridy = 0;
|
166 |
gridBagConstraints.fill = GridBagConstraints.BOTH;
|
167 |
gridBagConstraints.weightx = 1.0;
|
168 |
gridBagConstraints.weighty = 1.0;
|
169 |
freeFilterPanel.add(freeFilterScrollPane, gridBagConstraints); |
170 |
|
171 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
172 |
gridBagConstraints.gridx = 0;
|
173 |
gridBagConstraints.gridy = 1;
|
174 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
175 |
gridBagConstraints.weightx = 1.0;
|
176 |
gridBagConstraints.weighty = 1.0;
|
177 |
filterPanel.add(freeFilterPanel, gridBagConstraints); |
178 |
|
179 |
//Add the filter panel
|
180 |
gridBagConstraints = new GridBagConstraints(); |
181 |
gridBagConstraints.gridx = 0;
|
182 |
gridBagConstraints.gridy = 3;
|
183 |
gridBagConstraints.fill = GridBagConstraints.BOTH;
|
184 |
gridBagConstraints.insets = new Insets(0, 20, 0, 0); |
185 |
gridBagConstraints.weightx = 1.0;
|
186 |
gridBagConstraints.weighty = 1.0;
|
187 |
add(filterPanel, gridBagConstraints); |
188 |
|
189 |
} |
190 |
|
191 |
public boolean isFullLayerSelected(){ |
192 |
return allLayerRadioButton.isSelected();
|
193 |
} |
194 |
|
195 |
public boolean isSelectedFeaturesSelected(){ |
196 |
return selectedFeaturesRabioButton.isSelected();
|
197 |
} |
198 |
|
199 |
public boolean isPersonalizedFilterSelected(){ |
200 |
return personalizedFilterRabioButton.isSelected();
|
201 |
} |
202 |
|
203 |
public String getFreeFilter(){ |
204 |
if ((freeFilterTextArea.getText() != null) && (!freeFilterTextArea.getText().equals(""))){ |
205 |
return freeFilterTextArea.getText();
|
206 |
} |
207 |
return null; |
208 |
} |
209 |
|
210 |
public void valueChanged(ListSelectionEvent e) { |
211 |
Object obj = predefinedFilterList.getSelectedValue();
|
212 |
if (obj != null){ |
213 |
Filter filter = (Filter)obj; |
214 |
this.freeFilterTextArea.setText(EXPORTTO_MANAGER.getFilter(filter.getFilterKey()));
|
215 |
} |
216 |
} |
217 |
|
218 |
public void stateChanged(ChangeEvent e) { |
219 |
// TODO Auto-generated method stub
|
220 |
|
221 |
} |
222 |
|
223 |
public void itemStateChanged(ItemEvent e) { |
224 |
predefinedFilterList.setEnabled(isPersonalizedFilterSelected()); |
225 |
freeFilterTextArea.setEnabled(isPersonalizedFilterSelected()); |
226 |
} |
227 |
} |