source: josm/trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/query/OpenAndCloseStateRestrictionPanel.java@ 12846

Last change on this file since 12846 was 12846, checked in by bastiK, 7 years ago

see #15229 - use Config.getPref() wherever possible

  • Property svn:eol-style set to native
File size: 4.1 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;
7import java.awt.GridBagConstraints;
8import java.awt.GridBagLayout;
9
10import javax.swing.BorderFactory;
11import javax.swing.ButtonGroup;
12import javax.swing.JPanel;
13import javax.swing.JRadioButton;
14
15import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
16import org.openstreetmap.josm.io.ChangesetQuery;
17import org.openstreetmap.josm.spi.preferences.Config;
18
19/**
20 * This is the panel for selecting whether the changeset query should be restricted to
21 * open or closed changesets.
22 * @since 11326 (extracted from AdvancedChangesetQueryPanel)
23 */
24public class OpenAndCloseStateRestrictionPanel extends JPanel implements RestrictionPanel {
25
26 private static final String PREF_ROOT = "changeset-query.advanced.open-restrictions";
27 private static final String PREF_QUERY_TYPE = PREF_ROOT + ".query-type";
28
29 private final JRadioButton rbOpenOnly = new JRadioButton();
30 private final JRadioButton rbClosedOnly = new JRadioButton();
31 private final JRadioButton rbBoth = new JRadioButton();
32
33 /**
34 * Constructs a new {@code OpenAndCloseStateRestrictionPanel}.
35 */
36 public OpenAndCloseStateRestrictionPanel() {
37 build();
38 }
39
40 protected void build() {
41 setLayout(new GridBagLayout());
42 setBorder(BorderFactory.createCompoundBorder(
43 BorderFactory.createEmptyBorder(3, 3, 3, 3),
44 BorderFactory.createCompoundBorder(
45 BorderFactory.createLineBorder(Color.GRAY),
46 BorderFactory.createEmptyBorder(5, 5, 5, 5)
47 )
48 ));
49 GridBagConstraints gc = new GridBagConstraints();
50 gc.anchor = GridBagConstraints.NORTHWEST;
51 gc.fill = GridBagConstraints.HORIZONTAL;
52 gc.weightx = 0.0;
53 add(rbOpenOnly, gc);
54
55 gc.gridx = 1;
56 gc.weightx = 1.0;
57 add(new JMultilineLabel(tr("Query open changesets only")), gc);
58
59 gc.gridy = 1;
60 gc.gridx = 0;
61 gc.weightx = 0.0;
62 add(rbClosedOnly, gc);
63
64 gc.gridx = 1;
65 gc.weightx = 1.0;
66 add(new JMultilineLabel(tr("Query closed changesets only")), gc);
67
68 gc.gridy = 2;
69 gc.gridx = 0;
70 gc.weightx = 0.0;
71 add(rbBoth, gc);
72
73 gc.gridx = 1;
74 gc.weightx = 1.0;
75 add(new JMultilineLabel(tr("Query both open and closed changesets")), gc);
76
77 ButtonGroup bgRestrictions = new ButtonGroup();
78 bgRestrictions.add(rbBoth);
79 bgRestrictions.add(rbClosedOnly);
80 bgRestrictions.add(rbOpenOnly);
81 }
82
83 /**
84 * Initializes HMI for user input.
85 */
86 public void startUserInput() {
87 restoreFromSettings();
88 }
89
90 /**
91 * Sets the query restrictions on <code>query</code> for state based restrictions.
92 * @param query the query to fill
93 */
94 @Override
95 public void fillInQuery(ChangesetQuery query) {
96 if (rbBoth.isSelected()) {
97 query.beingClosed(true);
98 query.beingOpen(true);
99 } else if (rbOpenOnly.isSelected()) {
100 query.beingOpen(true);
101 } else if (rbClosedOnly.isSelected()) {
102 query.beingClosed(true);
103 }
104 }
105
106 /**
107 * Remember settings in preferences.
108 */
109 public void rememberSettings() {
110 if (rbBoth.isSelected()) {
111 Config.getPref().put(PREF_QUERY_TYPE, "both");
112 } else if (rbOpenOnly.isSelected()) {
113 Config.getPref().put(PREF_QUERY_TYPE, "open");
114 } else if (rbClosedOnly.isSelected()) {
115 Config.getPref().put(PREF_QUERY_TYPE, "closed");
116 }
117 }
118
119 /**
120 * Restore settings from preferences.
121 */
122 public void restoreFromSettings() {
123 String v = Config.getPref().get(PREF_QUERY_TYPE, "open");
124 rbBoth.setSelected("both".equals(v));
125 rbOpenOnly.setSelected("open".equals(v));
126 rbClosedOnly.setSelected("closed".equals(v));
127 }
128
129 @Override
130 public boolean isValidChangesetQuery() {
131 return true;
132 }
133
134 @Override
135 public void displayMessageIfInvalid() {
136 // Do nothing
137 }
138}
Note: See TracBrowser for help on using the repository browser.