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

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

fix #7386 - Major rework of preferences GUI settings in order to speed up preferences dialog startup time. The building of each preferences tab is delayed until this tab is selected. Plugins that use preferences will need to make some (minor) changes.

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