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

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

Allow to access directly to validator preferences from validator dialog with a small preferences button left to pin button.
Generic approach in order to be reused by plugins using dialogs.
This leads to some changes in preferences settings system, but without any break in compatibility.
The only impact is the deprecation of some public JTabbedPane fields, that will be removed mid-2013.

  • Property svn:eol-style set to native
File size: 8.9 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
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
26public class DrawingPreference implements SubPreferenceSetting {
27
28 public static class Factory implements PreferenceSettingFactory {
29 public PreferenceSetting createPreferenceSetting() {
30 return new DrawingPreference();
31 }
32 }
33
34 private GPXSettingsPanel gpxPanel;
35 private JCheckBox directionHint = new JCheckBox(tr("Draw Direction Arrows"));
36 private JCheckBox headArrow = new JCheckBox(tr("Only on the head of a way."));
37 private JCheckBox onewayArrow = new JCheckBox(tr("Draw oneway arrows."));
38 private JCheckBox segmentOrderNumber = new JCheckBox(tr("Draw segment order numbers"));
39 private JCheckBox sourceBounds = new JCheckBox(tr("Draw boundaries of downloaded data"));
40 private JCheckBox virtualNodes = new JCheckBox(tr("Draw virtual nodes in select mode"));
41 private JCheckBox inactive = new JCheckBox(tr("Draw inactive layers in other color"));
42
43 // Options that affect performance
44 private JCheckBox useHighlighting = new JCheckBox(tr("Highlight target ways and nodes"));
45 private JCheckBox drawHelperLine = new JCheckBox(tr("Draw rubber-band helper line"));
46 private JCheckBox useAntialiasing = new JCheckBox(tr("Smooth map graphics (antialiasing)"));
47 private JCheckBox useWireframeAntialiasing = new JCheckBox(tr("Smooth map graphics in wireframe mode (antialiasing)"));
48 private JCheckBox outlineOnly = new JCheckBox(tr("Draw only outlines of areas"));
49
50 public void addGui(PreferenceTabbedPane gui) {
51 //gui.display.setPreferredSize(new Dimension(400,600));
52 gpxPanel = new GPXSettingsPanel();
53 gui.addValidationListener(gpxPanel);
54 JPanel panel = gpxPanel;
55
56 JScrollPane scrollpane = new JScrollPane(panel);
57 scrollpane.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 ));
58 gui.getDisplayPreference().addSubTab(this, tr("GPS Points"), scrollpane);
59 panel = new JPanel(new GridBagLayout());
60 panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
61
62 // directionHint
63 directionHint.addActionListener(new ActionListener(){
64 public void actionPerformed(ActionEvent e) {
65 if (directionHint.isSelected()){
66 headArrow.setSelected(Main.pref.getBoolean("draw.segment.head_only", false));
67 }else{
68 headArrow.setSelected(false);
69 }
70 headArrow.setEnabled(directionHint.isSelected());
71 }
72 });
73 directionHint.setToolTipText(tr("Draw direction hints for way segments."));
74 directionHint.setSelected(Main.pref.getBoolean("draw.segment.direction", false));
75 panel.add(directionHint, GBC.eop().insets(20,0,0,0));
76
77 // only on the head of a way
78 headArrow.setToolTipText(tr("Only on the head of a way."));
79 headArrow.setSelected(Main.pref.getBoolean("draw.segment.head_only", false));
80 headArrow.setEnabled(directionHint.isSelected());
81 panel.add(headArrow, GBC.eop().insets(40, 0, 0, 0));
82
83 // draw oneway arrows
84 onewayArrow.setToolTipText(tr("Draw arrows in the direction of oneways and other directed features."));
85 onewayArrow.setSelected(Main.pref.getBoolean("draw.oneway", true));
86 panel.add(onewayArrow, GBC.eop().insets(20,0,0,0));
87
88 // segment order number
89 segmentOrderNumber.setToolTipText(tr("Draw the order numbers of all segments within their way."));
90 segmentOrderNumber.setSelected(Main.pref.getBoolean("draw.segment.order_number", false));
91 panel.add(segmentOrderNumber, GBC.eop().insets(20,0,0,0));
92
93 // downloaded area
94 sourceBounds.setToolTipText(tr("Draw the boundaries of data loaded from the server."));
95 sourceBounds.setSelected(Main.pref.getBoolean("draw.data.downloaded_area", true));
96 panel.add(sourceBounds, GBC.eop().insets(20,0,0,0));
97
98 // virtual nodes
99 virtualNodes.setToolTipText(tr("Draw virtual nodes in select mode for easy way modification."));
100 virtualNodes.setSelected(Main.pref.getInteger("mappaint.node.virtual-size", 8) != 0);
101 panel.add(virtualNodes, GBC.eop().insets(20,0,0,0));
102
103 // background layers in inactive color
104 inactive.setToolTipText(tr("Draw the inactive data layers in a different color."));
105 inactive.setSelected(Main.pref.getBoolean("draw.data.inactive_color", true));
106 panel.add(inactive, GBC.eop().insets(20,0,0,0));
107
108 // antialiasing
109 useAntialiasing.setToolTipText(tr("Apply antialiasing to the map view resulting in a smoother appearance."));
110 useAntialiasing.setSelected(Main.pref.getBoolean("mappaint.use-antialiasing", true));
111
112 // wireframe mode antialiasing
113 useWireframeAntialiasing.setToolTipText(tr("Apply antialiasing to the map view in wireframe mode resulting in a smoother appearance."));
114 useWireframeAntialiasing.setSelected(Main.pref.getBoolean("mappaint.wireframe.use-antialiasing", false));
115
116 // highlighting
117 useHighlighting.setToolTipText(tr("Hightlight target nodes and ways while drawing or selecting"));
118 useHighlighting.setSelected(Main.pref.getBoolean("draw.target-highlight", true));
119
120 drawHelperLine.setToolTipText(tr("Draw rubber-band helper line"));
121 drawHelperLine.setSelected(Main.pref.getBoolean("draw.helper-line", true));
122 panel.add(drawHelperLine, GBC.eop().insets(20, 0, 0, 0));
123
124 // outlineOnly
125 outlineOnly.setSelected(Main.pref.getBoolean("draw.data.area_outline_only", false));
126 outlineOnly.setToolTipText(tr("This option suppresses the filling of areas, overriding anything specified in the selected style."));
127
128 JLabel performanceLabel = new JLabel(tr("Options that affect drawing performance"));
129 panel.add(performanceLabel, GBC.eop().insets(5,10,0,0));
130 panel.add(useAntialiasing, GBC.eop().insets(20,5,0,0));
131 panel.add(useWireframeAntialiasing, GBC.eop().insets(20, 0, 0, 0));
132 panel.add(useHighlighting, GBC.eop().insets(20,0,0,0));
133 panel.add(outlineOnly, GBC.eol().insets(20,0,0,5));
134
135 ExpertToggleAction.addVisibilitySwitcher(performanceLabel);
136 ExpertToggleAction.addVisibilitySwitcher(useAntialiasing);
137 ExpertToggleAction.addVisibilitySwitcher(useWireframeAntialiasing);
138 ExpertToggleAction.addVisibilitySwitcher(useHighlighting);
139 ExpertToggleAction.addVisibilitySwitcher(outlineOnly);
140
141 panel.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.BOTH));
142 scrollpane = new JScrollPane(panel);
143 scrollpane.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 ));
144 gui.getDisplayPreference().addSubTab(this, tr("OSM Data"), scrollpane);
145 }
146
147 public boolean ok() {
148 gpxPanel.savePreferences();
149 Main.pref.put("draw.data.area_outline_only", outlineOnly.isSelected());
150 Main.pref.put("draw.segment.direction", directionHint.isSelected());
151 Main.pref.put("draw.segment.head_only", headArrow.isSelected());
152 Main.pref.put("draw.oneway", onewayArrow.isSelected());
153 Main.pref.put("draw.segment.order_number", segmentOrderNumber.isSelected());
154 Main.pref.put("draw.data.downloaded_area", sourceBounds.isSelected());
155 Main.pref.put("draw.data.inactive_color", inactive.isSelected());
156 Main.pref.put("mappaint.use-antialiasing", useAntialiasing.isSelected());
157 Main.pref.put("mappaint.wireframe.use-antialiasing", useWireframeAntialiasing.isSelected());
158 Main.pref.put("draw.target-highlight", useHighlighting.isSelected());
159 Main.pref.put("draw.helper-line", drawHelperLine.isSelected());
160 int vn = Main.pref.getInteger("mappaint.node.virtual-size", 8);
161 if (virtualNodes.isSelected()) {
162 if (vn < 1) {
163 vn = 8;
164 }
165 }
166 else {
167 vn = 0;
168 }
169 Main.pref.putInteger("mappaint.node.virtual-size", vn);
170 return false;
171 }
172
173 @Override
174 public boolean isExpert() {
175 return false;
176 }
177
178 @Override
179 public TabPreferenceSetting getTabPreferenceSetting(final PreferenceTabbedPane gui) {
180 return gui.getDisplayPreference();
181 }
182}
Note: See TracBrowser for help on using the repository browser.