[6380] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
[4968] | 2 | package org.openstreetmap.josm.gui.preferences.display;
|
---|
[283] | 3 |
|
---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 5 |
|
---|
[1742] | 6 | import java.awt.GridBagLayout;
|
---|
[283] | 7 |
|
---|
[1165] | 8 | import javax.swing.BorderFactory;
|
---|
[1742] | 9 | import javax.swing.Box;
|
---|
[283] | 10 | import javax.swing.JCheckBox;
|
---|
[4767] | 11 | import javax.swing.JLabel;
|
---|
[1742] | 12 | import javax.swing.JPanel;
|
---|
| 13 | import javax.swing.JScrollPane;
|
---|
[283] | 14 |
|
---|
| 15 | import org.openstreetmap.josm.Main;
|
---|
[4840] | 16 | import org.openstreetmap.josm.actions.ExpertToggleAction;
|
---|
[12400] | 17 | import org.openstreetmap.josm.gui.autofilter.AutoFilterManager;
|
---|
| 18 | import org.openstreetmap.josm.gui.autofilter.AutoFilterRule;
|
---|
[4968] | 19 | import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
|
---|
| 20 | import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
|
---|
| 21 | import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
|
---|
| 22 | import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting;
|
---|
| 23 | import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting;
|
---|
[9778] | 24 | import org.openstreetmap.josm.gui.util.GuiHelper;
|
---|
[12400] | 25 | import org.openstreetmap.josm.gui.widgets.JosmComboBox;
|
---|
[283] | 26 | import org.openstreetmap.josm.tools.GBC;
|
---|
| 27 |
|
---|
[6764] | 28 | /**
|
---|
| 29 | * Map drawing preferences.
|
---|
| 30 | */
|
---|
[4968] | 31 | public class DrawingPreference implements SubPreferenceSetting {
|
---|
[283] | 32 |
|
---|
[6529] | 33 | /**
|
---|
| 34 | * Factory used to create a new {@code DrawingPreference}.
|
---|
| 35 | */
|
---|
[1742] | 36 | public static class Factory implements PreferenceSettingFactory {
|
---|
[6084] | 37 | @Override
|
---|
[1742] | 38 | public PreferenceSetting createPreferenceSetting() {
|
---|
| 39 | return new DrawingPreference();
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 |
|
---|
[4270] | 43 | private GPXSettingsPanel gpxPanel;
|
---|
[9078] | 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"));
|
---|
[11090] | 48 | private final JCheckBox segmentOrderNumberOnSelectedWay = new JCheckBox(tr("Draw segment order numbers on selected way"));
|
---|
[9078] | 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"));
|
---|
[12400] | 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[] {}));
|
---|
[4767] | 57 |
|
---|
| 58 | // Options that affect performance
|
---|
[9078] | 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"));
|
---|
[4840] | 64 |
|
---|
[6084] | 65 | @Override
|
---|
[2745] | 66 | public void addGui(PreferenceTabbedPane gui) {
|
---|
[4270] | 67 | gpxPanel = new GPXSettingsPanel();
|
---|
[4287] | 68 | gui.addValidationListener(gpxPanel);
|
---|
[4270] | 69 | JPanel panel = gpxPanel;
|
---|
[4287] | 70 |
|
---|
[1169] | 71 | JScrollPane scrollpane = new JScrollPane(panel);
|
---|
[8444] | 72 | scrollpane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
|
---|
[9778] | 73 | GuiHelper.setDefaultIncrement(scrollpane);
|
---|
[5631] | 74 | gui.getDisplayPreference().addSubTab(this, tr("GPS Points"), scrollpane);
|
---|
[1169] | 75 | panel = new JPanel(new GridBagLayout());
|
---|
[8510] | 76 | panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
---|
[1169] | 77 |
|
---|
| 78 | // directionHint
|
---|
[10611] | 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);
|
---|
[1169] | 84 | }
|
---|
[10611] | 85 | headArrow.setEnabled(directionHint.isSelected());
|
---|
[1169] | 86 | });
|
---|
| 87 | directionHint.setToolTipText(tr("Draw direction hints for way segments."));
|
---|
[3996] | 88 | directionHint.setSelected(Main.pref.getBoolean("draw.segment.direction", false));
|
---|
[597] | 89 |
|
---|
[1289] | 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 |
|
---|
[3994] | 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 |
|
---|
[1169] | 99 | // segment order number
|
---|
| 100 | segmentOrderNumber.setToolTipText(tr("Draw the order numbers of all segments within their way."));
|
---|
[1222] | 101 | segmentOrderNumber.setSelected(Main.pref.getBoolean("draw.segment.order_number", false));
|
---|
[11090] | 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));
|
---|
[805] | 104 |
|
---|
[1169] | 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));
|
---|
[283] | 108 |
|
---|
[1169] | 109 | // virtual nodes
|
---|
| 110 | virtualNodes.setToolTipText(tr("Draw virtual nodes in select mode for easy way modification."));
|
---|
| 111 | virtualNodes.setSelected(Main.pref.getInteger("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 |
|
---|
[4767] | 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 |
|
---|
[5568] | 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 |
|
---|
[4767] | 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 |
|
---|
[3691] | 132 | // outlineOnly
|
---|
[6314] | 133 | outlineOnly.setToolTipText(tr("This option suppresses the filling of areas, overriding anything specified in the selected style."));
|
---|
[3691] | 134 | outlineOnly.setSelected(Main.pref.getBoolean("draw.data.area_outline_only", false));
|
---|
| 135 |
|
---|
[6314] | 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));
|
---|
[6764] | 139 |
|
---|
[12400] | 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 |
|
---|
[4843] | 150 | JLabel performanceLabel = new JLabel(tr("Options that affect drawing performance"));
|
---|
[5703] | 151 |
|
---|
| 152 | panel.add(new JLabel(tr("Segment drawing options")),
|
---|
[8510] | 153 | GBC.eop().insets(5, 10, 0, 0));
|
---|
| 154 | panel.add(directionHint, GBC.eop().insets(20, 0, 0, 0));
|
---|
[5703] | 155 | panel.add(headArrow, GBC.eop().insets(40, 0, 0, 0));
|
---|
[8510] | 156 | panel.add(onewayArrow, GBC.eop().insets(20, 0, 0, 0));
|
---|
| 157 | panel.add(segmentOrderNumber, GBC.eop().insets(20, 0, 0, 0));
|
---|
[11090] | 158 | panel.add(segmentOrderNumberOnSelectedWay, GBC.eop().insets(20, 0, 0, 0));
|
---|
[6070] | 159 |
|
---|
[5703] | 160 | panel.add(new JLabel(tr("Select and draw mode options")),
|
---|
[8510] | 161 | GBC.eop().insets(5, 10, 0, 0));
|
---|
| 162 | panel.add(virtualNodes, GBC.eop().insets(20, 0, 0, 0));
|
---|
[5703] | 163 | panel.add(drawHelperLine, GBC.eop().insets(20, 0, 0, 0));
|
---|
[6070] | 164 |
|
---|
[8510] | 165 | panel.add(performanceLabel, GBC.eop().insets(5, 10, 0, 0));
|
---|
| 166 | panel.add(useAntialiasing, GBC.eop().insets(20, 0, 0, 0));
|
---|
[5568] | 167 | panel.add(useWireframeAntialiasing, GBC.eop().insets(20, 0, 0, 0));
|
---|
[8510] | 168 | panel.add(useHighlighting, GBC.eop().insets(20, 0, 0, 0));
|
---|
| 169 | panel.add(outlineOnly, GBC.eol().insets(20, 0, 0, 0));
|
---|
[6070] | 170 |
|
---|
[5703] | 171 | panel.add(new JLabel(tr("Other options")),
|
---|
[8510] | 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));
|
---|
[12400] | 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));
|
---|
[6070] | 179 |
|
---|
[4843] | 180 | ExpertToggleAction.addVisibilitySwitcher(performanceLabel);
|
---|
| 181 | ExpertToggleAction.addVisibilitySwitcher(useAntialiasing);
|
---|
[5568] | 182 | ExpertToggleAction.addVisibilitySwitcher(useWireframeAntialiasing);
|
---|
[4843] | 183 | ExpertToggleAction.addVisibilitySwitcher(useHighlighting);
|
---|
| 184 | ExpertToggleAction.addVisibilitySwitcher(outlineOnly);
|
---|
[6314] | 185 | ExpertToggleAction.addVisibilitySwitcher(discardableKeys);
|
---|
[4843] | 186 |
|
---|
[1169] | 187 | panel.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.BOTH));
|
---|
| 188 | scrollpane = new JScrollPane(panel);
|
---|
[8444] | 189 | scrollpane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
|
---|
[9778] | 190 | GuiHelper.setDefaultIncrement(scrollpane);
|
---|
[5631] | 191 | gui.getDisplayPreference().addSubTab(this, tr("OSM Data"), scrollpane);
|
---|
[1169] | 192 | }
|
---|
| 193 |
|
---|
[6084] | 194 | @Override
|
---|
[1180] | 195 | public boolean ok() {
|
---|
[6764] | 196 | boolean restart = gpxPanel.savePreferences();
|
---|
[3691] | 197 | Main.pref.put("draw.data.area_outline_only", outlineOnly.isSelected());
|
---|
[1169] | 198 | Main.pref.put("draw.segment.direction", directionHint.isSelected());
|
---|
[1289] | 199 | Main.pref.put("draw.segment.head_only", headArrow.isSelected());
|
---|
[3994] | 200 | Main.pref.put("draw.oneway", onewayArrow.isSelected());
|
---|
[1169] | 201 | Main.pref.put("draw.segment.order_number", segmentOrderNumber.isSelected());
|
---|
[11090] | 202 | Main.pref.put("draw.segment.order_number.on_selected", segmentOrderNumberOnSelectedWay.isSelected());
|
---|
[1169] | 203 | Main.pref.put("draw.data.downloaded_area", sourceBounds.isSelected());
|
---|
| 204 | Main.pref.put("draw.data.inactive_color", inactive.isSelected());
|
---|
| 205 | Main.pref.put("mappaint.use-antialiasing", useAntialiasing.isSelected());
|
---|
[5568] | 206 | Main.pref.put("mappaint.wireframe.use-antialiasing", useWireframeAntialiasing.isSelected());
|
---|
[4767] | 207 | Main.pref.put("draw.target-highlight", useHighlighting.isSelected());
|
---|
| 208 | Main.pref.put("draw.helper-line", drawHelperLine.isSelected());
|
---|
[6314] | 209 | Main.pref.put("display.discardable-keys", discardableKeys.isSelected());
|
---|
[12400] | 210 | AutoFilterManager.PROP_AUTO_FILTER_ENABLED.put(autoFilters.isSelected());
|
---|
| 211 | AutoFilterManager.PROP_AUTO_FILTER_RULE.put(((AutoFilterRule) autoFilterRules.getSelectedItem()).getKey());
|
---|
[1169] | 212 | int vn = Main.pref.getInteger("mappaint.node.virtual-size", 8);
|
---|
[3396] | 213 | if (virtualNodes.isSelected()) {
|
---|
| 214 | if (vn < 1) {
|
---|
| 215 | vn = 8;
|
---|
| 216 | }
|
---|
[8342] | 217 | } else {
|
---|
[3396] | 218 | vn = 0;
|
---|
| 219 | }
|
---|
[1180] | 220 | Main.pref.putInteger("mappaint.node.virtual-size", vn);
|
---|
[6764] | 221 | return restart;
|
---|
[1169] | 222 | }
|
---|
[4968] | 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 | }
|
---|
[283] | 233 | }
|
---|