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

Last change on this file since 9078 was 9078, checked in by Don-vip, 8 years ago

sonar - Immutable Field

  • Property svn:eol-style set to native
File size: 10.0 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;
7import java.awt.event.ActionEvent;
8import java.awt.event.ActionListener;
9
10import javax.swing.BorderFactory;
11import javax.swing.Box;
12import javax.swing.JCheckBox;
13import javax.swing.JLabel;
14import javax.swing.JPanel;
15import javax.swing.JScrollPane;
16
17import org.openstreetmap.josm.Main;
18import org.openstreetmap.josm.actions.ExpertToggleAction;
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.tools.GBC;
25
26/**
27 * Map drawing preferences.
28 */
29public class DrawingPreference implements SubPreferenceSetting {
30
31 /**
32 * Factory used to create a new {@code DrawingPreference}.
33 */
34 public static class Factory implements PreferenceSettingFactory {
35 @Override
36 public PreferenceSetting createPreferenceSetting() {
37 return new DrawingPreference();
38 }
39 }
40
41 private GPXSettingsPanel gpxPanel;
42 private final JCheckBox directionHint = new JCheckBox(tr("Draw Direction Arrows"));
43 private final JCheckBox headArrow = new JCheckBox(tr("Only on the head of a way."));
44 private final JCheckBox onewayArrow = new JCheckBox(tr("Draw oneway arrows."));
45 private final JCheckBox segmentOrderNumber = new JCheckBox(tr("Draw segment order numbers"));
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 gui.getDisplayPreference().addSubTab(this, tr("GPS Points"), scrollpane);
67 panel = new JPanel(new GridBagLayout());
68 panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
69
70 // directionHint
71 directionHint.addActionListener(new ActionListener() {
72 @Override
73 public void actionPerformed(ActionEvent e) {
74 if (directionHint.isSelected()) {
75 headArrow.setSelected(Main.pref.getBoolean("draw.segment.head_only", false));
76 } else {
77 headArrow.setSelected(false);
78 }
79 headArrow.setEnabled(directionHint.isSelected());
80 }
81 });
82 directionHint.setToolTipText(tr("Draw direction hints for way segments."));
83 directionHint.setSelected(Main.pref.getBoolean("draw.segment.direction", false));
84
85 // only on the head of a way
86 headArrow.setToolTipText(tr("Only on the head of a way."));
87 headArrow.setSelected(Main.pref.getBoolean("draw.segment.head_only", false));
88 headArrow.setEnabled(directionHint.isSelected());
89
90 // draw oneway arrows
91 onewayArrow.setToolTipText(tr("Draw arrows in the direction of oneways and other directed features."));
92 onewayArrow.setSelected(Main.pref.getBoolean("draw.oneway", true));
93
94 // segment order number
95 segmentOrderNumber.setToolTipText(tr("Draw the order numbers of all segments within their way."));
96 segmentOrderNumber.setSelected(Main.pref.getBoolean("draw.segment.order_number", 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
142 panel.add(new JLabel(tr("Select and draw mode options")),
143 GBC.eop().insets(5, 10, 0, 0));
144 panel.add(virtualNodes, GBC.eop().insets(20, 0, 0, 0));
145 panel.add(drawHelperLine, GBC.eop().insets(20, 0, 0, 0));
146
147 panel.add(performanceLabel, GBC.eop().insets(5, 10, 0, 0));
148 panel.add(useAntialiasing, GBC.eop().insets(20, 0, 0, 0));
149 panel.add(useWireframeAntialiasing, GBC.eop().insets(20, 0, 0, 0));
150 panel.add(useHighlighting, GBC.eop().insets(20, 0, 0, 0));
151 panel.add(outlineOnly, GBC.eol().insets(20, 0, 0, 0));
152
153 panel.add(new JLabel(tr("Other options")),
154 GBC.eop().insets(5, 10, 0, 0));
155 panel.add(sourceBounds, GBC.eop().insets(20, 0, 0, 0));
156 panel.add(inactive, GBC.eop().insets(20, 0, 0, 0));
157 panel.add(discardableKeys, GBC.eop().insets(20, 0, 0, 0));
158
159 ExpertToggleAction.addVisibilitySwitcher(performanceLabel);
160 ExpertToggleAction.addVisibilitySwitcher(useAntialiasing);
161 ExpertToggleAction.addVisibilitySwitcher(useWireframeAntialiasing);
162 ExpertToggleAction.addVisibilitySwitcher(useHighlighting);
163 ExpertToggleAction.addVisibilitySwitcher(outlineOnly);
164 ExpertToggleAction.addVisibilitySwitcher(discardableKeys);
165
166 panel.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.BOTH));
167 scrollpane = new JScrollPane(panel);
168 scrollpane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
169 gui.getDisplayPreference().addSubTab(this, tr("OSM Data"), scrollpane);
170 }
171
172 @Override
173 public boolean ok() {
174 boolean restart = gpxPanel.savePreferences();
175 Main.pref.put("draw.data.area_outline_only", outlineOnly.isSelected());
176 Main.pref.put("draw.segment.direction", directionHint.isSelected());
177 Main.pref.put("draw.segment.head_only", headArrow.isSelected());
178 Main.pref.put("draw.oneway", onewayArrow.isSelected());
179 Main.pref.put("draw.segment.order_number", segmentOrderNumber.isSelected());
180 Main.pref.put("draw.data.downloaded_area", sourceBounds.isSelected());
181 Main.pref.put("draw.data.inactive_color", inactive.isSelected());
182 Main.pref.put("mappaint.use-antialiasing", useAntialiasing.isSelected());
183 Main.pref.put("mappaint.wireframe.use-antialiasing", useWireframeAntialiasing.isSelected());
184 Main.pref.put("draw.target-highlight", useHighlighting.isSelected());
185 Main.pref.put("draw.helper-line", drawHelperLine.isSelected());
186 Main.pref.put("display.discardable-keys", discardableKeys.isSelected());
187 int vn = Main.pref.getInteger("mappaint.node.virtual-size", 8);
188 if (virtualNodes.isSelected()) {
189 if (vn < 1) {
190 vn = 8;
191 }
192 } else {
193 vn = 0;
194 }
195 Main.pref.putInteger("mappaint.node.virtual-size", vn);
196 return restart;
197 }
198
199 @Override
200 public boolean isExpert() {
201 return false;
202 }
203
204 @Override
205 public TabPreferenceSetting getTabPreferenceSetting(final PreferenceTabbedPane gui) {
206 return gui.getDisplayPreference();
207 }
208}
Note: See TracBrowser for help on using the repository browser.