[2801] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.gui.dialogs.changeset.query;
|
---|
| 3 |
|
---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 5 |
|
---|
| 6 | import java.awt.BorderLayout;
|
---|
| 7 | import java.awt.GridBagConstraints;
|
---|
| 8 | import java.awt.GridBagLayout;
|
---|
| 9 | import java.awt.event.ItemEvent;
|
---|
| 10 | import java.awt.event.ItemListener;
|
---|
| 11 |
|
---|
| 12 | import javax.swing.BorderFactory;
|
---|
| 13 | import javax.swing.JCheckBox;
|
---|
| 14 | import javax.swing.JPanel;
|
---|
| 15 | import javax.swing.JScrollPane;
|
---|
| 16 |
|
---|
| 17 | import org.openstreetmap.josm.Main;
|
---|
[6666] | 18 | import org.openstreetmap.josm.gui.util.GuiHelper;
|
---|
[6340] | 19 | import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
|
---|
[2801] | 20 | import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
|
---|
| 21 | import org.openstreetmap.josm.io.ChangesetQuery;
|
---|
| 22 |
|
---|
| 23 | /**
|
---|
| 24 | * This panel allows to specify a changeset query
|
---|
[10179] | 25 | * @since 2689
|
---|
[2801] | 26 | */
|
---|
| 27 | public class AdvancedChangesetQueryPanel extends JPanel {
|
---|
| 28 |
|
---|
[10179] | 29 | private final JCheckBox cbUserRestriction = new JCheckBox();
|
---|
| 30 | private final JCheckBox cbOpenAndCloseRestrictions = new JCheckBox();
|
---|
| 31 | private final JCheckBox cbTimeRestrictions = new JCheckBox();
|
---|
| 32 | private final JCheckBox cbBoundingBoxRestriction = new JCheckBox();
|
---|
| 33 | private final UserRestrictionPanel pnlUserRestriction = new UserRestrictionPanel();
|
---|
| 34 | private final OpenAndCloseStateRestrictionPanel pnlOpenAndCloseRestriction = new OpenAndCloseStateRestrictionPanel();
|
---|
| 35 | private final TimeRestrictionPanel pnlTimeRestriction = new TimeRestrictionPanel();
|
---|
| 36 | private final BBoxRestrictionPanel pnlBoundingBoxRestriction = new BBoxRestrictionPanel();
|
---|
[2801] | 37 |
|
---|
[10179] | 38 | /**
|
---|
| 39 | * Constructs a new {@code AdvancedChangesetQueryPanel}.
|
---|
| 40 | */
|
---|
| 41 | public AdvancedChangesetQueryPanel() {
|
---|
| 42 | build();
|
---|
| 43 | }
|
---|
| 44 |
|
---|
[2801] | 45 | protected JPanel buildQueryPanel() {
|
---|
| 46 | ItemListener stateChangeHandler = new RestrictionGroupStateChangeHandler();
|
---|
[10378] | 47 | JPanel pnl = new VerticallyScrollablePanel(new GridBagLayout());
|
---|
[8510] | 48 | pnl.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
---|
[2801] | 49 | GridBagConstraints gc = new GridBagConstraints();
|
---|
| 50 |
|
---|
| 51 | // -- select changesets by a specific user
|
---|
| 52 | //
|
---|
| 53 | gc.anchor = GridBagConstraints.NORTHWEST;
|
---|
| 54 | gc.weightx = 0.0;
|
---|
| 55 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
[10179] | 56 | pnl.add(cbUserRestriction, gc);
|
---|
[2801] | 57 | cbUserRestriction.addItemListener(stateChangeHandler);
|
---|
| 58 |
|
---|
| 59 | gc.gridx = 1;
|
---|
| 60 | gc.weightx = 1.0;
|
---|
[8510] | 61 | pnl.add(new JMultilineLabel(tr("Select changesets owned by specific users")), gc);
|
---|
[2801] | 62 |
|
---|
| 63 | gc.gridy = 1;
|
---|
| 64 | gc.gridx = 1;
|
---|
| 65 | gc.weightx = 1.0;
|
---|
[10179] | 66 | pnl.add(pnlUserRestriction, gc);
|
---|
[2801] | 67 |
|
---|
| 68 | // -- restricting the query to open and closed changesets
|
---|
| 69 | //
|
---|
| 70 | gc.gridy = 2;
|
---|
| 71 | gc.gridx = 0;
|
---|
| 72 | gc.anchor = GridBagConstraints.NORTHWEST;
|
---|
| 73 | gc.weightx = 0.0;
|
---|
| 74 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
[10179] | 75 | pnl.add(cbOpenAndCloseRestrictions, gc);
|
---|
[2801] | 76 | cbOpenAndCloseRestrictions.addItemListener(stateChangeHandler);
|
---|
| 77 |
|
---|
| 78 | gc.gridx = 1;
|
---|
| 79 | gc.weightx = 1.0;
|
---|
[8510] | 80 | pnl.add(new JMultilineLabel(tr("Select changesets depending on whether they are open or closed")), gc);
|
---|
[2801] | 81 |
|
---|
| 82 | gc.gridy = 3;
|
---|
| 83 | gc.gridx = 1;
|
---|
| 84 | gc.weightx = 1.0;
|
---|
[10179] | 85 | pnl.add(pnlOpenAndCloseRestriction, gc);
|
---|
[2801] | 86 |
|
---|
| 87 | // -- restricting the query to a specific time
|
---|
| 88 | //
|
---|
| 89 | gc.gridy = 4;
|
---|
| 90 | gc.gridx = 0;
|
---|
| 91 | gc.anchor = GridBagConstraints.NORTHWEST;
|
---|
| 92 | gc.weightx = 0.0;
|
---|
| 93 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
[10179] | 94 | pnl.add(cbTimeRestrictions, gc);
|
---|
[2801] | 95 | cbTimeRestrictions.addItemListener(stateChangeHandler);
|
---|
| 96 |
|
---|
| 97 | gc.gridx = 1;
|
---|
| 98 | gc.weightx = 1.0;
|
---|
[8510] | 99 | pnl.add(new JMultilineLabel(tr("Select changesets based on the date/time they have been created or closed")), gc);
|
---|
[2801] | 100 |
|
---|
| 101 | gc.gridy = 5;
|
---|
| 102 | gc.gridx = 1;
|
---|
| 103 | gc.weightx = 1.0;
|
---|
[10179] | 104 | pnl.add(pnlTimeRestriction, gc);
|
---|
[2801] | 105 |
|
---|
| 106 |
|
---|
| 107 | // -- restricting the query to a specific bounding box
|
---|
| 108 | //
|
---|
| 109 | gc.gridy = 6;
|
---|
| 110 | gc.gridx = 0;
|
---|
| 111 | gc.anchor = GridBagConstraints.NORTHWEST;
|
---|
| 112 | gc.weightx = 0.0;
|
---|
| 113 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
[10179] | 114 | pnl.add(cbBoundingBoxRestriction, gc);
|
---|
[2801] | 115 | cbBoundingBoxRestriction.addItemListener(stateChangeHandler);
|
---|
| 116 |
|
---|
| 117 | gc.gridx = 1;
|
---|
| 118 | gc.weightx = 1.0;
|
---|
[8510] | 119 | pnl.add(new JMultilineLabel(tr("Select only changesets related to a specific bounding box")), gc);
|
---|
[2801] | 120 |
|
---|
| 121 | gc.gridy = 7;
|
---|
| 122 | gc.gridx = 1;
|
---|
| 123 | gc.weightx = 1.0;
|
---|
[10179] | 124 | pnl.add(pnlBoundingBoxRestriction, gc);
|
---|
[2801] | 125 |
|
---|
| 126 |
|
---|
| 127 | gc.gridy = 8;
|
---|
| 128 | gc.gridx = 0;
|
---|
| 129 | gc.gridwidth = 2;
|
---|
[8510] | 130 | gc.fill = GridBagConstraints.BOTH;
|
---|
[2801] | 131 | gc.weightx = 1.0;
|
---|
| 132 | gc.weighty = 1.0;
|
---|
| 133 | pnl.add(new JPanel(), gc);
|
---|
| 134 |
|
---|
| 135 | return pnl;
|
---|
| 136 | }
|
---|
| 137 |
|
---|
[6890] | 138 | protected final void build() {
|
---|
[2801] | 139 | setLayout(new BorderLayout());
|
---|
[6666] | 140 | JScrollPane spQueryPanel = GuiHelper.embedInVerticalScrollPane(buildQueryPanel());
|
---|
[2801] | 141 | add(spQueryPanel, BorderLayout.CENTER);
|
---|
| 142 | }
|
---|
| 143 |
|
---|
[11326] | 144 | /**
|
---|
| 145 | * Initializes HMI for user input.
|
---|
| 146 | */
|
---|
[2801] | 147 | public void startUserInput() {
|
---|
| 148 | restoreFromSettings();
|
---|
| 149 | pnlBoundingBoxRestriction.setVisible(cbBoundingBoxRestriction.isSelected());
|
---|
| 150 | pnlOpenAndCloseRestriction.setVisible(cbOpenAndCloseRestrictions.isSelected());
|
---|
| 151 | pnlTimeRestriction.setVisible(cbTimeRestrictions.isSelected());
|
---|
| 152 | pnlUserRestriction.setVisible(cbUserRestriction.isSelected());
|
---|
| 153 | pnlOpenAndCloseRestriction.startUserInput();
|
---|
| 154 | pnlUserRestriction.startUserInput();
|
---|
| 155 | pnlTimeRestriction.startUserInput();
|
---|
| 156 | }
|
---|
| 157 |
|
---|
[11326] | 158 | /**
|
---|
| 159 | * Display error message if a field is invalid.
|
---|
| 160 | */
|
---|
[2801] | 161 | public void displayMessageIfInvalid() {
|
---|
| 162 | if (cbUserRestriction.isSelected()) {
|
---|
[8444] | 163 | if (!pnlUserRestriction.isValidChangesetQuery()) {
|
---|
[2801] | 164 | pnlUserRestriction.displayMessageIfInvalid();
|
---|
| 165 | }
|
---|
| 166 | } else if (cbTimeRestrictions.isSelected()) {
|
---|
| 167 | if (!pnlTimeRestriction.isValidChangesetQuery()) {
|
---|
| 168 | pnlTimeRestriction.displayMessageIfInvalid();
|
---|
| 169 | }
|
---|
| 170 | } else if (cbBoundingBoxRestriction.isSelected()) {
|
---|
| 171 | if (!pnlBoundingBoxRestriction.isValidChangesetQuery()) {
|
---|
| 172 | pnlBoundingBoxRestriction.displayMessageIfInvalid();
|
---|
| 173 | }
|
---|
| 174 | }
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | /**
|
---|
| 178 | * Builds the changeset query based on the data entered in the form.
|
---|
[3530] | 179 | *
|
---|
[2801] | 180 | * @return the changeset query. null, if the data entered doesn't represent
|
---|
| 181 | * a valid changeset query.
|
---|
| 182 | */
|
---|
| 183 | public ChangesetQuery buildChangesetQuery() {
|
---|
| 184 | ChangesetQuery query = new ChangesetQuery();
|
---|
| 185 | if (cbUserRestriction.isSelected()) {
|
---|
[8444] | 186 | if (!pnlUserRestriction.isValidChangesetQuery())
|
---|
[2801] | 187 | return null;
|
---|
| 188 | pnlUserRestriction.fillInQuery(query);
|
---|
| 189 | }
|
---|
| 190 | if (cbOpenAndCloseRestrictions.isSelected()) {
|
---|
| 191 | // don't have to check whether it's valid. It always is.
|
---|
| 192 | pnlOpenAndCloseRestriction.fillInQuery(query);
|
---|
| 193 | }
|
---|
| 194 | if (cbBoundingBoxRestriction.isSelected()) {
|
---|
| 195 | if (!pnlBoundingBoxRestriction.isValidChangesetQuery())
|
---|
| 196 | return null;
|
---|
| 197 | pnlBoundingBoxRestriction.fillInQuery(query);
|
---|
| 198 | }
|
---|
| 199 | if (cbTimeRestrictions.isSelected()) {
|
---|
| 200 | if (!pnlTimeRestriction.isValidChangesetQuery())
|
---|
| 201 | return null;
|
---|
| 202 | pnlTimeRestriction.fillInQuery(query);
|
---|
| 203 | }
|
---|
| 204 | return query;
|
---|
| 205 | }
|
---|
| 206 |
|
---|
[11326] | 207 | /**
|
---|
| 208 | * Remember settings in preferences.
|
---|
| 209 | */
|
---|
[2801] | 210 | public void rememberSettings() {
|
---|
[12841] | 211 | Main.pref.putBoolean("changeset-query.advanced.user-restrictions", cbUserRestriction.isSelected());
|
---|
| 212 | Main.pref.putBoolean("changeset-query.advanced.open-restrictions", cbOpenAndCloseRestrictions.isSelected());
|
---|
| 213 | Main.pref.putBoolean("changeset-query.advanced.time-restrictions", cbTimeRestrictions.isSelected());
|
---|
| 214 | Main.pref.putBoolean("changeset-query.advanced.bbox-restrictions", cbBoundingBoxRestriction.isSelected());
|
---|
[2801] | 215 |
|
---|
| 216 | pnlUserRestriction.rememberSettings();
|
---|
| 217 | pnlOpenAndCloseRestriction.rememberSettings();
|
---|
| 218 | pnlTimeRestriction.rememberSettings();
|
---|
| 219 | }
|
---|
| 220 |
|
---|
[11326] | 221 | /**
|
---|
| 222 | * Restore settings from preferences.
|
---|
| 223 | */
|
---|
[2801] | 224 | public void restoreFromSettings() {
|
---|
| 225 | cbUserRestriction.setSelected(Main.pref.getBoolean("changeset-query.advanced.user-restrictions", false));
|
---|
| 226 | cbOpenAndCloseRestrictions.setSelected(Main.pref.getBoolean("changeset-query.advanced.open-restrictions", false));
|
---|
| 227 | cbTimeRestrictions.setSelected(Main.pref.getBoolean("changeset-query.advanced.time-restrictions", false));
|
---|
| 228 | cbBoundingBoxRestriction.setSelected(Main.pref.getBoolean("changeset-query.advanced.bbox-restrictions", false));
|
---|
| 229 | }
|
---|
| 230 |
|
---|
| 231 | class RestrictionGroupStateChangeHandler implements ItemListener {
|
---|
| 232 | protected void userRestrictionStateChanged() {
|
---|
[10179] | 233 | if (pnlUserRestriction == null)
|
---|
| 234 | return;
|
---|
[2801] | 235 | pnlUserRestriction.setVisible(cbUserRestriction.isSelected());
|
---|
| 236 | }
|
---|
| 237 |
|
---|
| 238 | protected void openCloseRestrictionStateChanged() {
|
---|
[10179] | 239 | if (pnlOpenAndCloseRestriction == null)
|
---|
| 240 | return;
|
---|
[2801] | 241 | pnlOpenAndCloseRestriction.setVisible(cbOpenAndCloseRestrictions.isSelected());
|
---|
| 242 | }
|
---|
| 243 |
|
---|
| 244 | protected void timeRestrictionsStateChanged() {
|
---|
[10179] | 245 | if (pnlTimeRestriction == null)
|
---|
| 246 | return;
|
---|
[2801] | 247 | pnlTimeRestriction.setVisible(cbTimeRestrictions.isSelected());
|
---|
| 248 | }
|
---|
| 249 |
|
---|
| 250 | protected void boundingBoxRestrictionChanged() {
|
---|
[10179] | 251 | if (pnlBoundingBoxRestriction == null)
|
---|
| 252 | return;
|
---|
[2801] | 253 | pnlBoundingBoxRestriction.setVisible(cbBoundingBoxRestriction.isSelected());
|
---|
| 254 | }
|
---|
| 255 |
|
---|
[6084] | 256 | @Override
|
---|
[2801] | 257 | public void itemStateChanged(ItemEvent e) {
|
---|
| 258 | if (e.getSource() == cbUserRestriction) {
|
---|
| 259 | userRestrictionStateChanged();
|
---|
| 260 | } else if (e.getSource() == cbOpenAndCloseRestrictions) {
|
---|
| 261 | openCloseRestrictionStateChanged();
|
---|
| 262 | } else if (e.getSource() == cbTimeRestrictions) {
|
---|
| 263 | timeRestrictionsStateChanged();
|
---|
| 264 | } else if (e.getSource() == cbBoundingBoxRestriction) {
|
---|
| 265 | boundingBoxRestrictionChanged();
|
---|
| 266 | }
|
---|
| 267 | validate();
|
---|
| 268 | repaint();
|
---|
| 269 | }
|
---|
| 270 | }
|
---|
| 271 | }
|
---|