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