source: josm/trunk/src/org/openstreetmap/josm/gui/preferences/display/DrawingPreference.java @ 12841

Last change on this file since 12841 was 12841, checked in by bastiK, 3 months ago

see #15229 - fix deprecations caused by [12840]

  • Property svn:eol-style set to native
File size: 12.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.preferences.display;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.GridBagLayout;
7
8import javax.swing.BorderFactory;
9import javax.swing.Box;
10import javax.swing.JCheckBox;
11import javax.swing.JLabel;
12import javax.swing.JPanel;
13import javax.swing.JScrollPane;
14
15import org.openstreetmap.josm.Main;
16import org.openstreetmap.josm.actions.ExpertToggleAction;
17import org.openstreetmap.josm.gui.autofilter.AutoFilterManager;
18import org.openstreetmap.josm.gui.autofilter.AutoFilterRule;
19import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
20import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
21import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
22import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting;
23import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting;
24import org.openstreetmap.josm.gui.util.GuiHelper;
25import org.openstreetmap.josm.gui.widgets.JosmComboBox;
26import org.openstreetmap.josm.tools.GBC;
27
28/**
29 * Map drawing preferences.
30 */
31public class DrawingPreference implements SubPreferenceSetting {
32
33    /**
34     * Factory used to create a new {@code DrawingPreference}.
35     */
36    public static class Factory implements PreferenceSettingFactory {
37        @Override
38        public PreferenceSetting createPreferenceSetting() {
39            return new DrawingPreference();
40        }
41    }
42
43    private GPXSettingsPanel gpxPanel;
44    private final JCheckBox directionHint = new JCheckBox(tr("Draw Direction Arrows"));
45    private final JCheckBox headArrow = new JCheckBox(tr("Only on the head of a way."));
46    private final JCheckBox onewayArrow = new JCheckBox(tr("Draw oneway arrows."));
47    private final JCheckBox segmentOrderNumber = new JCheckBox(tr("Draw segment order numbers"));
48    private final JCheckBox segmentOrderNumberOnSelectedWay = new JCheckBox(tr("Draw segment order numbers on selected way"));
49    private final JCheckBox sourceBounds = new JCheckBox(tr("Draw boundaries of downloaded data"));
50    private final JCheckBox virtualNodes = new JCheckBox(tr("Draw virtual nodes in select mode"));
51    private final JCheckBox inactive = new JCheckBox(tr("Draw inactive layers in other color"));
52    private final JCheckBox discardableKeys = new JCheckBox(tr("Display discardable keys"));
53    private final JCheckBox autoFilters = new JCheckBox(tr("Use auto filters"));
54    private final JLabel lblRule = new JLabel(tr("Rule"));
55    private final JosmComboBox<AutoFilterRule> autoFilterRules = new JosmComboBox<>(
56            AutoFilterManager.getInstance().getAutoFilterRules().toArray(new AutoFilterRule[] {}));
57
58    // Options that affect performance
59    private final JCheckBox useHighlighting = new JCheckBox(tr("Highlight target ways and nodes"));
60    private final JCheckBox drawHelperLine = new JCheckBox(tr("Draw rubber-band helper line"));
61    private final JCheckBox useAntialiasing = new JCheckBox(tr("Smooth map graphics (antialiasing)"));
62    private final JCheckBox useWireframeAntialiasing = new JCheckBox(tr("Smooth map graphics in wireframe mode (antialiasing)"));
63    private final JCheckBox outlineOnly = new JCheckBox(tr("Draw only outlines of areas"));
64
65    @Override
66    public void addGui(PreferenceTabbedPane gui) {
67        gpxPanel = new GPXSettingsPanel();
68        gui.addValidationListener(gpxPanel);
69        JPanel panel = gpxPanel;
70
71        JScrollPane scrollpane = new JScrollPane(panel);
72        scrollpane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
73        GuiHelper.setDefaultIncrement(scrollpane);
74        gui.getDisplayPreference().addSubTab(this, tr("GPS Points"), scrollpane);
75        panel = new JPanel(new GridBagLayout());
76        panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
77
78        // directionHint
79        directionHint.addActionListener(e -> {
80            if (directionHint.isSelected()) {
81                headArrow.setSelected(Main.pref.getBoolean("draw.segment.head_only", false));
82            } else {
83                headArrow.setSelected(false);
84            }
85            headArrow.setEnabled(directionHint.isSelected());
86        });
87        directionHint.setToolTipText(tr("Draw direction hints for way segments."));
88        directionHint.setSelected(Main.pref.getBoolean("draw.segment.direction", false));
89
90        // only on the head of a way
91        headArrow.setToolTipText(tr("Only on the head of a way."));
92        headArrow.setSelected(Main.pref.getBoolean("draw.segment.head_only", false));
93        headArrow.setEnabled(directionHint.isSelected());
94
95        // draw oneway arrows
96        onewayArrow.setToolTipText(tr("Draw arrows in the direction of oneways and other directed features."));
97        onewayArrow.setSelected(Main.pref.getBoolean("draw.oneway", true));
98
99        // segment order number
100        segmentOrderNumber.setToolTipText(tr("Draw the order numbers of all segments within their way."));
101        segmentOrderNumber.setSelected(Main.pref.getBoolean("draw.segment.order_number", false));
102        segmentOrderNumberOnSelectedWay.setToolTipText(tr("Draw the order numbers of all segments within their way."));
103        segmentOrderNumberOnSelectedWay.setSelected(Main.pref.getBoolean("draw.segment.order_number.on_selected", false));
104
105        // downloaded area
106        sourceBounds.setToolTipText(tr("Draw the boundaries of data loaded from the server."));
107        sourceBounds.setSelected(Main.pref.getBoolean("draw.data.downloaded_area", true));
108
109        // virtual nodes
110        virtualNodes.setToolTipText(tr("Draw virtual nodes in select mode for easy way modification."));
111        virtualNodes.setSelected(Main.pref.getInt("mappaint.node.virtual-size", 8) != 0);
112
113        // background layers in inactive color
114        inactive.setToolTipText(tr("Draw the inactive data layers in a different color."));
115        inactive.setSelected(Main.pref.getBoolean("draw.data.inactive_color", true));
116
117        // antialiasing
118        useAntialiasing.setToolTipText(tr("Apply antialiasing to the map view resulting in a smoother appearance."));
119        useAntialiasing.setSelected(Main.pref.getBoolean("mappaint.use-antialiasing", true));
120
121        // wireframe mode antialiasing
122        useWireframeAntialiasing.setToolTipText(tr("Apply antialiasing to the map view in wireframe mode resulting in a smoother appearance."));
123        useWireframeAntialiasing.setSelected(Main.pref.getBoolean("mappaint.wireframe.use-antialiasing", false));
124
125        // highlighting
126        useHighlighting.setToolTipText(tr("Hightlight target nodes and ways while drawing or selecting"));
127        useHighlighting.setSelected(Main.pref.getBoolean("draw.target-highlight", true));
128
129        drawHelperLine.setToolTipText(tr("Draw rubber-band helper line"));
130        drawHelperLine.setSelected(Main.pref.getBoolean("draw.helper-line", true));
131
132        // outlineOnly
133        outlineOnly.setToolTipText(tr("This option suppresses the filling of areas, overriding anything specified in the selected style."));
134        outlineOnly.setSelected(Main.pref.getBoolean("draw.data.area_outline_only", false));
135
136        // discardable keys
137        discardableKeys.setToolTipText(tr("Display keys which have been deemed uninteresting to the point that they can be silently removed."));
138        discardableKeys.setSelected(Main.pref.getBoolean("display.discardable-keys", false));
139
140        // auto filters
141        autoFilters.setToolTipText(tr("Display buttons to automatically filter numeric values of a predefined tag"));
142        autoFilters.setSelected(AutoFilterManager.PROP_AUTO_FILTER_ENABLED.get());
143        autoFilters.addActionListener(e -> {
144            lblRule.setEnabled(autoFilters.isSelected());
145            autoFilterRules.setEnabled(autoFilters.isSelected());
146        });
147        autoFilterRules.setToolTipText("Rule defining which tag will provide automatic filters, below a certain zoom level");
148        autoFilterRules.setSelectedItem(AutoFilterManager.getInstance().getAutoFilterRule(AutoFilterManager.PROP_AUTO_FILTER_RULE.get()));
149
150        JLabel performanceLabel = new JLabel(tr("Options that affect drawing performance"));
151
152        panel.add(new JLabel(tr("Segment drawing options")),
153                GBC.eop().insets(5, 10, 0, 0));
154        panel.add(directionHint, GBC.eop().insets(20, 0, 0, 0));
155        panel.add(headArrow, GBC.eop().insets(40, 0, 0, 0));
156        panel.add(onewayArrow, GBC.eop().insets(20, 0, 0, 0));
157        panel.add(segmentOrderNumber, GBC.eop().insets(20, 0, 0, 0));
158        panel.add(segmentOrderNumberOnSelectedWay, GBC.eop().insets(20, 0, 0, 0));
159
160        panel.add(new JLabel(tr("Select and draw mode options")),
161                GBC.eop().insets(5, 10, 0, 0));
162        panel.add(virtualNodes, GBC.eop().insets(20, 0, 0, 0));
163        panel.add(drawHelperLine, GBC.eop().insets(20, 0, 0, 0));
164
165        panel.add(performanceLabel, GBC.eop().insets(5, 10, 0, 0));
166        panel.add(useAntialiasing, GBC.eop().insets(20, 0, 0, 0));
167        panel.add(useWireframeAntialiasing, GBC.eop().insets(20, 0, 0, 0));
168        panel.add(useHighlighting, GBC.eop().insets(20, 0, 0, 0));
169        panel.add(outlineOnly, GBC.eol().insets(20, 0, 0, 0));
170
171        panel.add(new JLabel(tr("Other options")),
172                GBC.eop().insets(5, 10, 0, 0));
173        panel.add(sourceBounds, GBC.eop().insets(20, 0, 0, 0));
174        panel.add(inactive, GBC.eop().insets(20, 0, 0, 0));
175        panel.add(discardableKeys, GBC.eop().insets(20, 0, 0, 0));
176        panel.add(autoFilters, GBC.eop().insets(20, 0, 0, 0));
177        panel.add(lblRule, GBC.std().insets(40, 0, 0, 0));
178        panel.add(autoFilterRules, GBC.eop().fill(GBC.HORIZONTAL).insets(5, 0, 0, 0));
179
180        ExpertToggleAction.addVisibilitySwitcher(performanceLabel);
181        ExpertToggleAction.addVisibilitySwitcher(useAntialiasing);
182        ExpertToggleAction.addVisibilitySwitcher(useWireframeAntialiasing);
183        ExpertToggleAction.addVisibilitySwitcher(useHighlighting);
184        ExpertToggleAction.addVisibilitySwitcher(outlineOnly);
185        ExpertToggleAction.addVisibilitySwitcher(discardableKeys);
186
187        panel.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.BOTH));
188        scrollpane = new JScrollPane(panel);
189        scrollpane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
190        GuiHelper.setDefaultIncrement(scrollpane);
191        gui.getDisplayPreference().addSubTab(this, tr("OSM Data"), scrollpane);
192    }
193
194    @Override
195    public boolean ok() {
196        boolean restart = gpxPanel.savePreferences();
197        Main.pref.putBoolean("draw.data.area_outline_only", outlineOnly.isSelected());
198        Main.pref.putBoolean("draw.segment.direction", directionHint.isSelected());
199        Main.pref.putBoolean("draw.segment.head_only", headArrow.isSelected());
200        Main.pref.putBoolean("draw.oneway", onewayArrow.isSelected());
201        Main.pref.putBoolean("draw.segment.order_number", segmentOrderNumber.isSelected());
202        Main.pref.putBoolean("draw.segment.order_number.on_selected", segmentOrderNumberOnSelectedWay.isSelected());
203        Main.pref.putBoolean("draw.data.downloaded_area", sourceBounds.isSelected());
204        Main.pref.putBoolean("draw.data.inactive_color", inactive.isSelected());
205        Main.pref.putBoolean("mappaint.use-antialiasing", useAntialiasing.isSelected());
206        Main.pref.putBoolean("mappaint.wireframe.use-antialiasing", useWireframeAntialiasing.isSelected());
207        Main.pref.putBoolean("draw.target-highlight", useHighlighting.isSelected());
208        Main.pref.putBoolean("draw.helper-line", drawHelperLine.isSelected());
209        Main.pref.putBoolean("display.discardable-keys", discardableKeys.isSelected());
210        AutoFilterManager.PROP_AUTO_FILTER_ENABLED.put(autoFilters.isSelected());
211        AutoFilterManager.PROP_AUTO_FILTER_RULE.put(((AutoFilterRule) autoFilterRules.getSelectedItem()).getKey());
212        int vn = Main.pref.getInt("mappaint.node.virtual-size", 8);
213        if (virtualNodes.isSelected()) {
214            if (vn < 1) {
215                vn = 8;
216            }
217        } else {
218            vn = 0;
219        }
220        Main.pref.putInt("mappaint.node.virtual-size", vn);
221        return restart;
222    }
223
224    @Override
225    public boolean isExpert() {
226        return false;
227    }
228
229    @Override
230    public TabPreferenceSetting getTabPreferenceSetting(final PreferenceTabbedPane gui) {
231        return gui.getDisplayPreference();
232    }
233}
Note: See TracBrowser for help on using the repository browser.