source: josm/trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/query/BBoxRestrictionPanel.java

Last change on this file was 11326, checked in by Don-vip, 10 years ago

code refactorization, javadoc

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs.changeset.query;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Color;
7
8import javax.swing.BorderFactory;
9import javax.swing.JOptionPane;
10
11import org.openstreetmap.josm.gui.HelpAwareOptionPane;
12import org.openstreetmap.josm.gui.help.HelpUtil;
13import org.openstreetmap.josm.gui.widgets.BoundingBoxSelectionPanel;
14import org.openstreetmap.josm.io.ChangesetQuery;
15
16/**
17 * This is the panel for selecting whether the query should be restricted to a specific bounding box.
18 * @since 11326 (extracted from AdvancedChangesetQueryPanel)
19 */
20public class BBoxRestrictionPanel extends BoundingBoxSelectionPanel implements RestrictionPanel {
21
22 /**
23 * Constructs a new {@code BBoxRestrictionPanel}.
24 */
25 public BBoxRestrictionPanel() {
26 setBorder(BorderFactory.createCompoundBorder(
27 BorderFactory.createEmptyBorder(3, 3, 3, 3),
28 BorderFactory.createCompoundBorder(
29 BorderFactory.createLineBorder(Color.GRAY),
30 BorderFactory.createEmptyBorder(5, 5, 5, 5)
31 )
32 ));
33 }
34
35 /**
36 * Determines if the changeset query bbox is valid.
37 * @return {@code true} if the changeset query bbox is defined.
38 */
39 @Override
40 public boolean isValidChangesetQuery() {
41 return getBoundingBox() != null;
42 }
43
44 /**
45 * Sets the query restrictions on <code>query</code> for bbox based restrictions.
46 * @param query query to fill
47 */
48 @Override
49 public void fillInQuery(ChangesetQuery query) {
50 if (!isValidChangesetQuery())
51 throw new IllegalStateException(tr("Cannot restrict the changeset query to a specific bounding box. The input is invalid."));
52 query.inBbox(getBoundingBox());
53 }
54
55 @Override
56 public void displayMessageIfInvalid() {
57 if (isValidChangesetQuery())
58 return;
59 HelpAwareOptionPane.showOptionDialog(
60 this,
61 tr(
62 "<html>Please enter valid longitude/latitude values to restrict<br>" +
63 "the changeset query to a specific bounding box.</html>"
64 ),
65 tr("Invalid bounding box"),
66 JOptionPane.ERROR_MESSAGE,
67 HelpUtil.ht("/Dialog/ChangesetQueryDialog#InvalidBoundingBox")
68 );
69 }
70}
Note: See TracBrowser for help on using the repository browser.