| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
package org.geotoolkit.gui.swing.referencing; |
| 19 | |
|
| 20 | |
import java.util.Date; |
| 21 | |
import java.util.Arrays; |
| 22 | |
import java.util.Locale; |
| 23 | |
import java.util.TimeZone; |
| 24 | |
import java.util.Calendar; |
| 25 | |
import java.util.EventListener; |
| 26 | |
|
| 27 | |
import java.awt.Component; |
| 28 | |
import java.awt.GridBagLayout; |
| 29 | |
import java.awt.GridBagConstraints; |
| 30 | |
import java.awt.geom.Dimension2D; |
| 31 | |
import java.awt.geom.Rectangle2D; |
| 32 | |
import java.awt.event.ActionEvent; |
| 33 | |
import java.awt.event.ActionListener; |
| 34 | |
|
| 35 | |
import javax.swing.JComponent; |
| 36 | |
import javax.swing.JPanel; |
| 37 | |
import javax.swing.JLabel; |
| 38 | |
import javax.swing.JComboBox; |
| 39 | |
import javax.swing.ButtonGroup; |
| 40 | |
import javax.swing.JRadioButton; |
| 41 | |
import javax.swing.BorderFactory; |
| 42 | |
import javax.swing.AbstractButton; |
| 43 | |
import javax.swing.JSpinner; |
| 44 | |
import javax.swing.SpinnerModel; |
| 45 | |
import javax.swing.SpinnerDateModel; |
| 46 | |
import javax.swing.SpinnerNumberModel; |
| 47 | |
import javax.swing.AbstractSpinnerModel; |
| 48 | |
import javax.swing.JFormattedTextField; |
| 49 | |
import javax.swing.text.InternationalFormatter; |
| 50 | |
import javax.swing.event.ChangeEvent; |
| 51 | |
import javax.swing.event.ChangeListener; |
| 52 | |
|
| 53 | |
import java.text.Format; |
| 54 | |
import java.text.DateFormat; |
| 55 | |
import java.text.NumberFormat; |
| 56 | |
import java.text.ParseException; |
| 57 | |
|
| 58 | |
import org.geotoolkit.measure.Angle; |
| 59 | |
import org.geotoolkit.measure.Latitude; |
| 60 | |
import org.geotoolkit.measure.Longitude; |
| 61 | |
import org.geotoolkit.measure.AngleFormat; |
| 62 | |
|
| 63 | |
import org.geotoolkit.resources.Errors; |
| 64 | |
import org.geotoolkit.resources.Vocabulary; |
| 65 | |
import org.geotoolkit.internal.swing.SwingUtilities; |
| 66 | |
import org.geotoolkit.display.shape.DoubleDimension2D; |
| 67 | |
import org.geotoolkit.gui.swing.Dialog; |
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
@SuppressWarnings("serial") |
| 95 | 0 | public class CoordinateChooser extends JComponent implements Dialog { |
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
private static final double RESOLUTION_FACTOR = 60; |
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
public static final int GEOGRAPHIC_AREA = 1; |
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
public static final int TIME_RANGE = 2; |
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
public static final int RESOLUTION = 4; |
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
private final JComponent areaPanel, timePanel, resoPanel; |
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
private final JComboBox timezone; |
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
private final JSpinner tmin, tmax; |
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
private final JSpinner xmin, xmax, ymin, ymax; |
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | |
|
| 170 | |
private final JSpinner xres, yres; |
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
|
| 175 | |
private final AbstractButton radioBestRes; |
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
private final AbstractButton radioPrefRes; |
| 181 | |
|
| 182 | |
|
| 183 | |
|
| 184 | |
|
| 185 | |
private JComponent accessory; |
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | |
|
| 190 | |
|
| 191 | |
|
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
private final class Listeners implements ActionListener, ChangeListener { |
| 197 | |
|
| 198 | |
|
| 199 | |
|
| 200 | |
private final JComponent[] toggle; |
| 201 | |
|
| 202 | |
|
| 203 | |
|
| 204 | |
|
| 205 | 1 | public Listeners(final JComponent[] toggle) { |
| 206 | 1 | this.toggle=toggle; |
| 207 | 1 | } |
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | |
@Override |
| 213 | |
public void actionPerformed(final ActionEvent event) { |
| 214 | 0 | update(getTimeZone()); |
| 215 | 0 | } |
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
|
| 220 | |
|
| 221 | |
@Override |
| 222 | |
public void stateChanged(final ChangeEvent event) { |
| 223 | 0 | setEnabled(radioPrefRes.isSelected()); |
| 224 | 0 | } |
| 225 | |
|
| 226 | |
|
| 227 | |
|
| 228 | |
|
| 229 | |
final void setEnabled(final boolean state) { |
| 230 | 5 | for (int i=0; i<toggle.length; i++) { |
| 231 | 4 | toggle[i].setEnabled(state); |
| 232 | |
} |
| 233 | 1 | } |
| 234 | |
} |
| 235 | |
|
| 236 | |
|
| 237 | |
|
| 238 | |
|
| 239 | |
|
| 240 | |
public CoordinateChooser() { |
| 241 | 1 | this(new Date(0), new Date()); |
| 242 | 1 | } |
| 243 | |
|
| 244 | |
|
| 245 | |
|
| 246 | |
|
| 247 | |
|
| 248 | |
|
| 249 | |
|
| 250 | |
|
| 251 | |
|
| 252 | |
|
| 253 | |
|
| 254 | 1 | public CoordinateChooser(final Date minTime, final Date maxTime) { |
| 255 | 1 | setLayout(new GridBagLayout()); |
| 256 | 1 | final Locale locale = getDefaultLocale(); |
| 257 | |
final int timeField = Calendar.DAY_OF_YEAR; |
| 258 | 1 | final Vocabulary resources = Vocabulary.getResources(locale); |
| 259 | |
|
| 260 | 1 | radioBestRes = new JRadioButton(resources.getString(Vocabulary.Keys.USE_BEST_RESOLUTION), true); |
| 261 | 1 | radioPrefRes = new JRadioButton(resources.getString(Vocabulary.Keys.SET_PREFERRED_RESOLUTION)); |
| 262 | |
|
| 263 | 1 | tmin = new JSpinner(new SpinnerDateModel(minTime, minTime, maxTime, timeField)); |
| 264 | 1 | tmax = new JSpinner(new SpinnerDateModel(maxTime, minTime, maxTime, timeField)); |
| 265 | 1 | xmin = new JSpinner(new SpinnerAngleModel(new Longitude(Longitude.MIN_VALUE))); |
| 266 | 1 | xmax = new JSpinner(new SpinnerAngleModel(new Longitude(Longitude.MAX_VALUE))); |
| 267 | 1 | ymin = new JSpinner(new SpinnerAngleModel(new Latitude( Latitude.MIN_VALUE))); |
| 268 | 1 | ymax = new JSpinner(new SpinnerAngleModel(new Latitude( Latitude.MAX_VALUE))); |
| 269 | 1 | xres = new JSpinner(new SpinnerNumberModel(1d, 0d, 360d*60, 1d)); |
| 270 | 1 | yres = new JSpinner(new SpinnerNumberModel(1d, 0d, 180d*60, 1d)); |
| 271 | |
|
| 272 | 1 | final AngleFormat angleFormat = AngleFormat.getInstance(locale); |
| 273 | 1 | final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale); |
| 274 | 1 | final NumberFormat numberFormat = NumberFormat.getNumberInstance(locale); |
| 275 | 1 | xmin.setEditor(new SpinnerAngleModel.Editor(xmin, angleFormat)); |
| 276 | 1 | xmax.setEditor(new SpinnerAngleModel.Editor(xmax, angleFormat)); |
| 277 | 1 | ymin.setEditor(new SpinnerAngleModel.Editor(ymin, angleFormat)); |
| 278 | 1 | ymax.setEditor(new SpinnerAngleModel.Editor(ymax, angleFormat)); |
| 279 | |
|
| 280 | 1 | setup(tmin, 10, dateFormat); |
| 281 | 1 | setup(tmax, 10, dateFormat); |
| 282 | 1 | setup(xmin, 7, null); |
| 283 | 1 | setup(xmax, 7, null); |
| 284 | 1 | setup(ymin, 7, null); |
| 285 | 1 | setup(ymax, 7, null); |
| 286 | 1 | setup(xres, 3, numberFormat); |
| 287 | 1 | setup(yres, 3, numberFormat); |
| 288 | |
|
| 289 | 1 | final String[] timezones = TimeZone.getAvailableIDs(); |
| 290 | 1 | Arrays.sort(timezones); |
| 291 | 1 | timezone = new JComboBox(timezones); |
| 292 | 1 | timezone.setSelectedItem(dateFormat.getTimeZone().getID()); |
| 293 | |
|
| 294 | 1 | final JLabel labelSize1 = new JLabel(resources.getLabel(Vocabulary.Keys.SIZE_IN_MINUTES)); |
| 295 | 1 | final JLabel labelSize2 = new JLabel("\u00D7" ); |
| 296 | 1 | final ButtonGroup group = new ButtonGroup(); |
| 297 | 1 | group.add(radioBestRes); |
| 298 | 1 | group.add(radioPrefRes); |
| 299 | |
|
| 300 | 1 | final Listeners listeners = new Listeners(new JComponent[] { |
| 301 | |
labelSize1, labelSize2, xres, yres}); |
| 302 | 1 | listeners .setEnabled(false); |
| 303 | 1 | timezone .addActionListener(listeners); |
| 304 | 1 | radioPrefRes.addChangeListener(listeners); |
| 305 | |
|
| 306 | 1 | areaPanel = getPanel(resources.getString(Vocabulary.Keys.GEOGRAPHIC_COORDINATES)); |
| 307 | 1 | timePanel = getPanel(resources.getString(Vocabulary.Keys.TIME_RANGE )); |
| 308 | 1 | resoPanel = getPanel(resources.getString(Vocabulary.Keys.PREFERRED_RESOLUTION )); |
| 309 | 1 | final GridBagConstraints c = new GridBagConstraints(); |
| 310 | |
|
| 311 | 1 | c.weightx=1; |
| 312 | 1 | c.gridx=1; c.gridy=0; areaPanel.add(ymax, c); |
| 313 | 1 | c.gridx=0; c.gridy=1; areaPanel.add(xmin, c); |
| 314 | 1 | c.gridx=2; c.gridy=1; areaPanel.add(xmax, c); |
| 315 | 1 | c.gridx=1; c.gridy=2; areaPanel.add(ymin, c); |
| 316 | |
|
| 317 | |
JLabel label; |
| 318 | 1 | c.gridx=0; c.anchor=GridBagConstraints.WEST; c.insets.right=3; c.weightx=0; |
| 319 | 1 | c.gridy=0; timePanel.add(label=new JLabel(resources.getLabel(Vocabulary.Keys.START_TIME)), c); label.setLabelFor(tmin); |
| 320 | 1 | c.gridy=1; timePanel.add(label=new JLabel(resources.getLabel(Vocabulary.Keys.END_TIME )), c); label.setLabelFor(tmax); |
| 321 | 1 | c.gridy=2; timePanel.add(label=new JLabel(resources.getLabel(Vocabulary.Keys.TIME_ZONE )), c); label.setLabelFor(timezone); c.gridwidth=4; |
| 322 | 1 | c.gridy=0; resoPanel.add(radioBestRes, c); |
| 323 | 1 | c.gridy=1; resoPanel.add(radioPrefRes, c); |
| 324 | 1 | c.gridy=2; c.gridwidth=1; c.anchor=GridBagConstraints.EAST; c.insets.right=c.insets.left=1; c.weightx=1; |
| 325 | 1 | c.gridx=0; resoPanel.add(labelSize1, c); labelSize1.setLabelFor(xres); c.weightx=0; |
| 326 | 1 | c.gridx=1; resoPanel.add(xres, c); |
| 327 | 1 | c.gridx=2; resoPanel.add(labelSize2, c); labelSize2.setLabelFor(yres); |
| 328 | 1 | c.gridx=3; resoPanel.add(yres, c); |
| 329 | |
|
| 330 | 1 | c.gridx=1; c.fill=GridBagConstraints.HORIZONTAL; c.insets.right=c.insets.left=0; c.weightx=1; |
| 331 | 1 | c.gridy=0; timePanel.add(tmin, c); |
| 332 | 1 | c.gridy=1; timePanel.add(tmax, c); |
| 333 | 1 | c.gridy=2; timePanel.add(timezone, c); |
| 334 | |
|
| 335 | 1 | c.insets.right=c.insets.left=c.insets.top=c.insets.bottom=3; |
| 336 | 1 | c.gridx=0; c.anchor=GridBagConstraints.CENTER; c.fill=GridBagConstraints.BOTH; c.weighty=1; |
| 337 | 1 | c.gridy=0; add(areaPanel, c); |
| 338 | 1 | c.gridy=1; add(timePanel, c); |
| 339 | 1 | c.gridy=2; add(resoPanel, c); |
| 340 | 1 | } |
| 341 | |
|
| 342 | |
|
| 343 | |
|
| 344 | |
|
| 345 | |
private static JPanel getPanel(final String title) { |
| 346 | 3 | final JPanel panel = new JPanel(new GridBagLayout()); |
| 347 | 3 | panel.setBorder(BorderFactory.createCompoundBorder( |
| 348 | |
BorderFactory.createTitledBorder(title), |
| 349 | |
BorderFactory.createEmptyBorder(6,6,6,6))); |
| 350 | 3 | panel.setOpaque(false); |
| 351 | 3 | return panel; |
| 352 | |
} |
| 353 | |
|
| 354 | |
|
| 355 | |
|
| 356 | |
|
| 357 | |
|
| 358 | |
private static void setup(final JSpinner spinner, final int width, final Format format) { |
| 359 | 8 | final JFormattedTextField field = ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField(); |
| 360 | 8 | field.setColumns(width); |
| 361 | 8 | if (format != null) { |
| 362 | 4 | ((InternationalFormatter)field.getFormatter()).setFormat(format); |
| 363 | |
} |
| 364 | 8 | } |
| 365 | |
|
| 366 | |
|
| 367 | |
|
| 368 | |
|
| 369 | |
|
| 370 | |
|
| 371 | |
|
| 372 | |
|
| 373 | |
|
| 374 | |
|
| 375 | |
|
| 376 | |
|
| 377 | |
|
| 378 | |
public boolean isSelectorVisible(final int selector) { |
| 379 | 0 | switch (selector) { |
| 380 | 0 | case GEOGRAPHIC_AREA: return areaPanel.isVisible(); |
| 381 | 0 | case TIME_RANGE: return timePanel.isVisible(); |
| 382 | 0 | case RESOLUTION: return resoPanel.isVisible(); |
| 383 | 0 | default: throw new IllegalArgumentException(); |
| 384 | |
|
| 385 | |
} |
| 386 | |
} |
| 387 | |
|
| 388 | |
|
| 389 | |
|
| 390 | |
|
| 391 | |
|
| 392 | |
|
| 393 | |
|
| 394 | |
|
| 395 | |
|
| 396 | |
|
| 397 | |
public void setSelectorVisible(final int selectors, final boolean visible) { |
| 398 | 0 | ensureValidSelectors(selectors); |
| 399 | 0 | if ((selectors & GEOGRAPHIC_AREA) != 0) areaPanel.setVisible(visible); |
| 400 | 0 | if ((selectors & TIME_RANGE ) != 0) timePanel.setVisible(visible); |
| 401 | 0 | if ((selectors & RESOLUTION ) != 0) resoPanel.setVisible(visible); |
| 402 | 0 | } |
| 403 | |
|
| 404 | |
|
| 405 | |
|
| 406 | |
|
| 407 | |
|
| 408 | |
|
| 409 | |
|
| 410 | |
|
| 411 | |
|
| 412 | |
|
| 413 | |
private static void ensureValidSelectors(final int selectors) throws IllegalArgumentException { |
| 414 | 0 | if ((selectors & ~(GEOGRAPHIC_AREA | TIME_RANGE | RESOLUTION)) != 0) { |
| 415 | 0 | throw new IllegalArgumentException(String.valueOf(selectors)); |
| 416 | |
} |
| 417 | 0 | } |
| 418 | |
|
| 419 | |
|
| 420 | |
|
| 421 | |
|
| 422 | |
|
| 423 | |
private static double min(final double ceil, final double value) { |
| 424 | 0 | return (value < ceil) ? value : ceil; |
| 425 | |
} |
| 426 | |
|
| 427 | |
|
| 428 | |
|
| 429 | |
|
| 430 | |
|
| 431 | |
private static double max(final double floor, final double value) { |
| 432 | 0 | return (value > floor) ? value : floor; |
| 433 | |
} |
| 434 | |
|
| 435 | |
|
| 436 | |
|
| 437 | |
|
| 438 | |
private static double doubleValue(final JSpinner spinner) { |
| 439 | 0 | final Object value = spinner.getValue(); |
| 440 | 0 | return (value instanceof Number) ? ((Number) value).doubleValue() : Double.NaN; |
| 441 | |
} |
| 442 | |
|
| 443 | |
|
| 444 | |
|
| 445 | |
|
| 446 | |
private static double degrees(final JSpinner spinner, final boolean expectLatitude) { |
| 447 | 0 | final Object value = spinner.getValue(); |
| 448 | 0 | if (value instanceof Angle) { |
| 449 | 0 | if (expectLatitude ? (value instanceof Longitude) : (value instanceof Latitude)) { |
| 450 | 0 | return Double.NaN; |
| 451 | |
} |
| 452 | 0 | return ((Angle) value).degrees(); |
| 453 | |
} |
| 454 | 0 | return Double.NaN; |
| 455 | |
} |
| 456 | |
|
| 457 | |
|
| 458 | |
|
| 459 | |
|
| 460 | |
|
| 461 | |
|
| 462 | |
public Rectangle2D getGeographicArea() { |
| 463 | 0 | final double xmin = degrees(this.xmin, false); |
| 464 | 0 | final double ymin = degrees(this.ymin, true); |
| 465 | 0 | final double xmax = degrees(this.xmax, false); |
| 466 | 0 | final double ymax = degrees(this.ymax, true); |
| 467 | 0 | return new Rectangle2D.Double( |
| 468 | |
Math.min(xmin, xmax), Math.min(ymin, ymax), |
| 469 | |
Math.abs(xmax - xmin), Math.abs(ymax - ymin)); |
| 470 | |
} |
| 471 | |
|
| 472 | |
|
| 473 | |
|
| 474 | |
|
| 475 | |
|
| 476 | |
|
| 477 | |
public void setGeographicArea(final Rectangle2D area) { |
| 478 | |
|
| 479 | 0 | xmin.setValue(new Longitude(max(2*Longitude.MIN_VALUE, area.getMinX()))); |
| 480 | 0 | xmax.setValue(new Longitude(min(2*Longitude.MAX_VALUE, area.getMaxX()))); |
| 481 | 0 | ymin.setValue(new Latitude(max( Latitude.MIN_VALUE, area.getMinY()))); |
| 482 | 0 | ymax.setValue(new Latitude(min( Latitude.MAX_VALUE, area.getMaxY()))); |
| 483 | 0 | } |
| 484 | |
|
| 485 | |
|
| 486 | |
|
| 487 | |
|
| 488 | |
|
| 489 | |
|
| 490 | |
|
| 491 | |
public Dimension2D getPreferredResolution() { |
| 492 | 0 | if (radioPrefRes.isSelected()) { |
| 493 | 0 | return new DoubleDimension2D( |
| 494 | |
doubleValue(xres) / RESOLUTION_FACTOR, |
| 495 | |
doubleValue(yres) / RESOLUTION_FACTOR); |
| 496 | |
} |
| 497 | 0 | return null; |
| 498 | |
} |
| 499 | |
|
| 500 | |
|
| 501 | |
|
| 502 | |
|
| 503 | |
|
| 504 | |
|
| 505 | |
|
| 506 | |
public void setPreferredResolution(final Dimension2D resolution) { |
| 507 | 0 | if (resolution != null) { |
| 508 | 0 | xres.setValue(Double.valueOf(max(0, resolution.getWidth () * RESOLUTION_FACTOR))); |
| 509 | 0 | yres.setValue(Double.valueOf(max(0, resolution.getHeight() * RESOLUTION_FACTOR))); |
| 510 | 0 | radioPrefRes.setSelected(true); |
| 511 | |
} else { |
| 512 | 0 | radioBestRes.setSelected(true); |
| 513 | |
} |
| 514 | 0 | } |
| 515 | |
|
| 516 | |
|
| 517 | |
|
| 518 | |
|
| 519 | |
|
| 520 | |
|
| 521 | |
public TimeZone getTimeZone() { |
| 522 | 0 | return TimeZone.getTimeZone(timezone.getSelectedItem().toString()); |
| 523 | |
} |
| 524 | |
|
| 525 | |
|
| 526 | |
|
| 527 | |
|
| 528 | |
|
| 529 | |
|
| 530 | |
|
| 531 | |
public void setTimeZone(final TimeZone timezone) { |
| 532 | 0 | this.timezone.setSelectedItem(timezone.getID()); |
| 533 | 0 | } |
| 534 | |
|
| 535 | |
|
| 536 | |
|
| 537 | |
|
| 538 | |
|
| 539 | |
|
| 540 | |
private void update(final TimeZone timezone) { |
| 541 | 0 | boolean refresh=true; |
| 542 | |
try { |
| 543 | 0 | tmin.commitEdit(); |
| 544 | 0 | tmax.commitEdit(); |
| 545 | 0 | } catch (ParseException exception) { |
| 546 | 0 | refresh = false; |
| 547 | 0 | } |
| 548 | 0 | ((JSpinner.DateEditor)tmin.getEditor()).getFormat().setTimeZone(timezone); |
| 549 | 0 | ((JSpinner.DateEditor)tmax.getEditor()).getFormat().setTimeZone(timezone); |
| 550 | 0 | if (refresh) { |
| 551 | |
|
| 552 | 0 | fireStateChanged((AbstractSpinnerModel)tmin.getModel()); |
| 553 | 0 | fireStateChanged((AbstractSpinnerModel)tmax.getModel()); |
| 554 | |
} |
| 555 | 0 | } |
| 556 | |
|
| 557 | |
|
| 558 | |
|
| 559 | |
|
| 560 | |
private static void fireStateChanged(final AbstractSpinnerModel model) { |
| 561 | 0 | final ChangeEvent changeEvent = new ChangeEvent(model); |
| 562 | 0 | final EventListener[] listeners = model.getListeners(ChangeListener.class); |
| 563 | 0 | for (int i=listeners.length; --i>=0;) { |
| 564 | 0 | ((ChangeListener)listeners[i]).stateChanged(changeEvent); |
| 565 | |
} |
| 566 | 0 | } |
| 567 | |
|
| 568 | |
|
| 569 | |
|
| 570 | |
|
| 571 | |
|
| 572 | |
|
| 573 | |
public Date getStartTime() { |
| 574 | 0 | return (Date) tmin.getValue(); |
| 575 | |
} |
| 576 | |
|
| 577 | |
|
| 578 | |
|
| 579 | |
|
| 580 | |
|
| 581 | |
|
| 582 | |
public Date getEndTime() { |
| 583 | 0 | return (Date) tmax.getValue(); |
| 584 | |
} |
| 585 | |
|
| 586 | |
|
| 587 | |
|
| 588 | |
|
| 589 | |
|
| 590 | |
|
| 591 | |
|
| 592 | |
|
| 593 | |
|
| 594 | |
|
| 595 | |
public void setTimeRange(final Date startTime, final Date endTime) { |
| 596 | 0 | tmin.setValue(startTime); |
| 597 | 0 | tmax.setValue( endTime); |
| 598 | 0 | } |
| 599 | |
|
| 600 | |
|
| 601 | |
|
| 602 | |
|
| 603 | |
|
| 604 | |
|
| 605 | |
public JComponent getAccessory() { |
| 606 | 0 | return accessory; |
| 607 | |
} |
| 608 | |
|
| 609 | |
|
| 610 | |
|
| 611 | |
|
| 612 | |
|
| 613 | |
|
| 614 | |
|
| 615 | |
|
| 616 | |
|
| 617 | |
|
| 618 | |
|
| 619 | |
public void setAccessory(final JComponent accessory) { |
| 620 | 0 | synchronized (getTreeLock()) { |
| 621 | 0 | if (this.accessory!=null) { |
| 622 | 0 | remove(this.accessory); |
| 623 | |
} |
| 624 | 0 | this.accessory = accessory; |
| 625 | 0 | if (accessory != null) { |
| 626 | 0 | final GridBagConstraints c = new GridBagConstraints(); |
| 627 | 0 | c.insets.right=c.insets.left=c.insets.top=c.insets.bottom=3; |
| 628 | 0 | c.gridx=1; c.weightx=1; c.gridwidth=1; |
| 629 | 0 | c.gridy=0; c.weighty=1; c.gridheight=3; |
| 630 | 0 | c.anchor=GridBagConstraints.CENTER; c.fill=GridBagConstraints.BOTH; |
| 631 | 0 | add(accessory, c); |
| 632 | |
} |
| 633 | 0 | validate(); |
| 634 | 0 | } |
| 635 | 0 | } |
| 636 | |
|
| 637 | |
|
| 638 | |
|
| 639 | |
|
| 640 | |
private void checkAngle(final JSpinner field, final boolean expectLatitude) throws ParseException { |
| 641 | 0 | final Object angle=field.getValue(); |
| 642 | 0 | if (expectLatitude ? (angle instanceof Longitude) : (angle instanceof Latitude)) { |
| 643 | 0 | throw new ParseException(Errors.getResources(getLocale()).getString( |
| 644 | |
Errors.Keys.ILLEGAL_COORDINATE_$1, angle), 0); |
| 645 | |
} |
| 646 | 0 | } |
| 647 | |
|
| 648 | |
|
| 649 | |
|
| 650 | |
|
| 651 | |
@Override |
| 652 | |
public void commitEdit() throws ParseException { |
| 653 | 0 | JSpinner focus = null; |
| 654 | |
try { |
| 655 | 0 | (focus = tmin).commitEdit(); |
| 656 | 0 | (focus = tmax).commitEdit(); |
| 657 | 0 | (focus = xmin).commitEdit(); |
| 658 | 0 | (focus = xmax).commitEdit(); |
| 659 | 0 | (focus = ymin).commitEdit(); |
| 660 | 0 | (focus = ymax).commitEdit(); |
| 661 | 0 | (focus = xres).commitEdit(); |
| 662 | 0 | (focus = yres).commitEdit(); |
| 663 | |
|
| 664 | 0 | checkAngle(focus = xmin, false); |
| 665 | 0 | checkAngle(focus = xmax, false); |
| 666 | 0 | checkAngle(focus = ymin, true); |
| 667 | 0 | checkAngle(focus = ymax, true); |
| 668 | 0 | } catch (ParseException exception) { |
| 669 | 0 | focus.requestFocus(); |
| 670 | 0 | throw exception; |
| 671 | 0 | } |
| 672 | 0 | } |
| 673 | |
|
| 674 | |
|
| 675 | |
|
| 676 | |
|
| 677 | |
|
| 678 | |
|
| 679 | |
|
| 680 | |
|
| 681 | |
|
| 682 | |
|
| 683 | |
|
| 684 | |
|
| 685 | |
|
| 686 | |
|
| 687 | |
|
| 688 | |
|
| 689 | |
|
| 690 | |
|
| 691 | |
|
| 692 | |
|
| 693 | |
|
| 694 | |
public void addChangeListener(final int selectors, final ChangeListener listener) { |
| 695 | 0 | ensureValidSelectors(selectors); |
| 696 | 0 | if ((selectors & GEOGRAPHIC_AREA) != 0) { |
| 697 | 0 | xmin.getModel().addChangeListener(listener); |
| 698 | 0 | xmax.getModel().addChangeListener(listener); |
| 699 | 0 | ymin.getModel().addChangeListener(listener); |
| 700 | 0 | ymax.getModel().addChangeListener(listener); |
| 701 | |
} |
| 702 | 0 | if ((selectors & TIME_RANGE) != 0) { |
| 703 | 0 | tmin.getModel().addChangeListener(listener); |
| 704 | 0 | tmax.getModel().addChangeListener(listener); |
| 705 | |
} |
| 706 | 0 | if ((selectors & RESOLUTION) != 0) { |
| 707 | 0 | xres.getModel().addChangeListener(listener); |
| 708 | 0 | yres.getModel().addChangeListener(listener); |
| 709 | 0 | radioPrefRes.getModel().addChangeListener(listener); |
| 710 | |
} |
| 711 | 0 | } |
| 712 | |
|
| 713 | |
|
| 714 | |
|
| 715 | |
|
| 716 | |
|
| 717 | |
|
| 718 | |
|
| 719 | |
|
| 720 | |
|
| 721 | |
|
| 722 | |
|
| 723 | |
public void removeChangeListener(final int selectors, final ChangeListener listener) { |
| 724 | 0 | ensureValidSelectors(selectors); |
| 725 | 0 | if ((selectors & GEOGRAPHIC_AREA) != 0) { |
| 726 | 0 | xmin.getModel().removeChangeListener(listener); |
| 727 | 0 | xmax.getModel().removeChangeListener(listener); |
| 728 | 0 | ymin.getModel().removeChangeListener(listener); |
| 729 | 0 | ymax.getModel().removeChangeListener(listener); |
| 730 | |
} |
| 731 | 0 | if ((selectors & TIME_RANGE) != 0) { |
| 732 | 0 | tmin.getModel().removeChangeListener(listener); |
| 733 | 0 | tmax.getModel().removeChangeListener(listener); |
| 734 | |
} |
| 735 | 0 | if ((selectors & RESOLUTION) != 0) { |
| 736 | 0 | xres.getModel().removeChangeListener(listener); |
| 737 | 0 | yres.getModel().removeChangeListener(listener); |
| 738 | 0 | radioPrefRes.getModel().removeChangeListener(listener); |
| 739 | |
} |
| 740 | 0 | } |
| 741 | |
|
| 742 | |
|
| 743 | |
|
| 744 | |
|
| 745 | |
|
| 746 | |
|
| 747 | |
|
| 748 | |
|
| 749 | |
|
| 750 | |
|
| 751 | |
|
| 752 | |
|
| 753 | |
public boolean showDialog(final Component owner) { |
| 754 | 0 | return showDialog(owner, Vocabulary.getResources(getLocale()). |
| 755 | |
getString(Vocabulary.Keys.COORDINATES_SELECTION)); |
| 756 | |
} |
| 757 | |
|
| 758 | |
|
| 759 | |
|
| 760 | |
|
| 761 | |
@Override |
| 762 | |
public boolean showDialog(final Component owner, final String title) { |
| 763 | 0 | return SwingUtilities.showDialog(owner, this, title); |
| 764 | |
} |
| 765 | |
} |