svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.geocoding.extension / src / org / gvsig / geocoding / gui / settings / SettingsPanel.java @ 32526
History | View | Annotate | Download (6.38 KB)
1 |
/*
|
---|---|
2 |
* To change this template, choose Tools | Templates
|
3 |
* and open the template in the editor.
|
4 |
*/
|
5 |
|
6 |
/*
|
7 |
* SettingsPanel.java
|
8 |
*
|
9 |
* Created on 16-mar-2009, 12:41:50
|
10 |
*/
|
11 |
|
12 |
package org.gvsig.geocoding.gui.settings; |
13 |
|
14 |
import java.awt.event.KeyEvent; |
15 |
import java.awt.event.KeyListener; |
16 |
|
17 |
import javax.swing.JLabel; |
18 |
import javax.swing.JPanel; |
19 |
import javax.swing.JSlider; |
20 |
import javax.swing.JTextField; |
21 |
|
22 |
import org.gvsig.geocoding.extension.GeocodingController; |
23 |
|
24 |
import org.gvsig.andami.PluginServices; |
25 |
|
26 |
/**
|
27 |
*
|
28 |
* @author vsanjaime
|
29 |
*/
|
30 |
public class SettingsPanel extends JPanel implements KeyListener { |
31 |
|
32 |
private static final int MAXRESULTS = 10; |
33 |
|
34 |
private static final long serialVersionUID = 1L; |
35 |
|
36 |
private GeocodingController control = null; |
37 |
|
38 |
private JLabel jLabMaxResults; |
39 |
private JLabel jLabScore; |
40 |
private JLabel jLabScorePercent; |
41 |
private JPanel jPanMaxResults; |
42 |
private JPanel jPanScore; |
43 |
private JSlider jSliderScore; |
44 |
private JTextField jTextMaxResults; |
45 |
|
46 |
/**
|
47 |
* Constructor
|
48 |
*/
|
49 |
public SettingsPanel(GeocodingController control) {
|
50 |
initComponents(); |
51 |
this.control = control;
|
52 |
|
53 |
setMesages(); |
54 |
} |
55 |
|
56 |
/**
|
57 |
* Initialize components
|
58 |
*/
|
59 |
private void initComponents() { |
60 |
java.awt.GridBagConstraints gridBagConstraints; |
61 |
|
62 |
jPanMaxResults = new javax.swing.JPanel();
|
63 |
jLabMaxResults = new javax.swing.JLabel();
|
64 |
jTextMaxResults = new javax.swing.JTextField();
|
65 |
jPanScore = new javax.swing.JPanel();
|
66 |
jLabScore = new javax.swing.JLabel();
|
67 |
jSliderScore = new javax.swing.JSlider();
|
68 |
jLabScorePercent = new javax.swing.JLabel();
|
69 |
|
70 |
setLayout(new java.awt.GridBagLayout());
|
71 |
|
72 |
jPanMaxResults.setLayout(new java.awt.GridBagLayout());
|
73 |
|
74 |
jLabMaxResults.setText("max");
|
75 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
76 |
gridBagConstraints.gridx = 0;
|
77 |
gridBagConstraints.gridy = 0;
|
78 |
gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5); |
79 |
jPanMaxResults.add(jLabMaxResults, gridBagConstraints); |
80 |
|
81 |
jTextMaxResults.setHorizontalAlignment(javax.swing.JTextField.RIGHT); |
82 |
jTextMaxResults.setMinimumSize(new java.awt.Dimension(30, 20)); |
83 |
jTextMaxResults.setPreferredSize(new java.awt.Dimension(60, 20)); |
84 |
jTextMaxResults.addKeyListener(this);
|
85 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
86 |
gridBagConstraints.gridx = 1;
|
87 |
gridBagConstraints.gridy = 0;
|
88 |
jPanMaxResults.add(jTextMaxResults, gridBagConstraints); |
89 |
|
90 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
91 |
gridBagConstraints.gridx = 0;
|
92 |
gridBagConstraints.gridy = 0;
|
93 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
94 |
gridBagConstraints.weightx = 1.0;
|
95 |
gridBagConstraints.insets = new java.awt.Insets(2, 10, 2, 10); |
96 |
add(jPanMaxResults, gridBagConstraints); |
97 |
|
98 |
jPanScore.setLayout(new java.awt.GridBagLayout());
|
99 |
|
100 |
jLabScore.setText("score");
|
101 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
102 |
gridBagConstraints.gridx = 0;
|
103 |
gridBagConstraints.gridy = 0;
|
104 |
gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5); |
105 |
jPanScore.add(jLabScore, gridBagConstraints); |
106 |
|
107 |
jSliderScore.setMajorTickSpacing(10);
|
108 |
jSliderScore.setMinorTickSpacing(10);
|
109 |
jSliderScore.setPaintTicks(false);
|
110 |
jSliderScore.setSnapToTicks(true);
|
111 |
jSliderScore.setValue(80);
|
112 |
jSliderScore.setMinimumSize(new java.awt.Dimension(120, 25)); |
113 |
jSliderScore.setPreferredSize(new java.awt.Dimension(120, 25)); |
114 |
jSliderScore.addChangeListener(new javax.swing.event.ChangeListener() {
|
115 |
public void stateChanged(javax.swing.event.ChangeEvent evt) { |
116 |
evChangeScore(evt); |
117 |
} |
118 |
}); |
119 |
jPanScore.add(jSliderScore, new java.awt.GridBagConstraints());
|
120 |
|
121 |
jLabScorePercent.setText("80");
|
122 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
123 |
gridBagConstraints.gridx = 2;
|
124 |
gridBagConstraints.gridy = 0;
|
125 |
jPanScore.add(jLabScorePercent, gridBagConstraints); |
126 |
|
127 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
128 |
gridBagConstraints.gridx = 1;
|
129 |
gridBagConstraints.gridy = 0;
|
130 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
131 |
gridBagConstraints.weightx = 1.0;
|
132 |
add(jPanScore, gridBagConstraints); |
133 |
} |
134 |
|
135 |
/**
|
136 |
* change score value event
|
137 |
*
|
138 |
* @param evt
|
139 |
*/
|
140 |
private void evChangeScore(javax.swing.event.ChangeEvent evt) { |
141 |
double score = (double) jSliderScore.getValue(); |
142 |
jLabScorePercent.setText(Integer.toString((int) score)); |
143 |
if (control.getPattern() != null) { |
144 |
control.getPattern().getSettings().setMinScore(score); |
145 |
} |
146 |
} |
147 |
|
148 |
/**
|
149 |
* get internationalizated strings
|
150 |
*/
|
151 |
private void setMesages() { |
152 |
PluginServices ps = PluginServices.getPluginServices(this);
|
153 |
if (ps != null) { |
154 |
this.jLabMaxResults.setText(ps.getText("maxresults")); |
155 |
this.jLabScore.setText(ps.getText("score")); |
156 |
jTextMaxResults.setToolTipText(ps.getText("maxresultstip"));
|
157 |
jSliderScore.setToolTipText(ps.getText("scoretip"));
|
158 |
} |
159 |
} |
160 |
|
161 |
/**
|
162 |
* Set maximum results in the panel
|
163 |
*
|
164 |
* @param result
|
165 |
*/
|
166 |
public void setMaxResults(int result) { |
167 |
jTextMaxResults.setText(Integer.toString(result));
|
168 |
} |
169 |
|
170 |
/**
|
171 |
* Set threshold score
|
172 |
*
|
173 |
* @param result
|
174 |
*/
|
175 |
public void setScore(double score) { |
176 |
jSliderScore.setValue((int) score);
|
177 |
jLabScorePercent.setText(Integer.toString((int) score)); |
178 |
} |
179 |
|
180 |
/**
|
181 |
* swich on and off components
|
182 |
*
|
183 |
* @param active
|
184 |
*/
|
185 |
public void activateComponents(boolean active) { |
186 |
jLabMaxResults.setEnabled(active); |
187 |
jLabScore.setEnabled(active); |
188 |
jLabScorePercent.setEnabled(active); |
189 |
jSliderScore.setEnabled(active); |
190 |
jTextMaxResults.setEnabled(active); |
191 |
} |
192 |
|
193 |
/**
|
194 |
* get new pattern maximum results
|
195 |
*
|
196 |
* @return
|
197 |
*/
|
198 |
public int getMaxResults() { |
199 |
return Integer.parseInt(jTextMaxResults.getText()); |
200 |
} |
201 |
|
202 |
/**
|
203 |
* get new pattern minimum score
|
204 |
*
|
205 |
* @return
|
206 |
*/
|
207 |
public double getScore() { |
208 |
return (double) jSliderScore.getValue(); |
209 |
} |
210 |
|
211 |
/**
|
212 |
* key pressed event
|
213 |
*
|
214 |
* @param e
|
215 |
*/
|
216 |
public void keyPressed(KeyEvent e) { |
217 |
// nothing to do
|
218 |
|
219 |
} |
220 |
|
221 |
/**
|
222 |
* key released event
|
223 |
*
|
224 |
* @param e
|
225 |
*/
|
226 |
public void keyReleased(KeyEvent e) { |
227 |
String max = jTextMaxResults.getText().trim();
|
228 |
int maxresults;
|
229 |
try {
|
230 |
maxresults = Integer.parseInt(max);
|
231 |
if (maxresults < 1) { |
232 |
maxresults = 1;
|
233 |
jTextMaxResults.setText(Integer.toString(maxresults));
|
234 |
control.getPattern().getSettings().setMaxResultsNumber(maxresults); |
235 |
} else {
|
236 |
control.getPattern().getSettings().setMaxResultsNumber(maxresults); |
237 |
} |
238 |
} catch (Exception ex) { |
239 |
jTextMaxResults.setText(Integer.toString(MAXRESULTS));
|
240 |
jTextMaxResults.requestFocus(); |
241 |
} |
242 |
|
243 |
} |
244 |
|
245 |
/**
|
246 |
* key typed event
|
247 |
*
|
248 |
* @param e
|
249 |
*/
|
250 |
public void keyTyped(KeyEvent e) { |
251 |
// TODO nothing to do
|
252 |
|
253 |
} |
254 |
|
255 |
} |