001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.preferences.display; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005 006import java.awt.GridBagLayout; 007import java.awt.event.ActionEvent; 008import java.awt.event.ActionListener; 009 010import javax.swing.BorderFactory; 011import javax.swing.Box; 012import javax.swing.JCheckBox; 013import javax.swing.JLabel; 014import javax.swing.JPanel; 015import javax.swing.JScrollPane; 016 017import org.openstreetmap.josm.Main; 018import org.openstreetmap.josm.actions.ExpertToggleAction; 019import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 020import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory; 021import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane; 022import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting; 023import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting; 024import org.openstreetmap.josm.tools.GBC; 025 026public class DrawingPreference implements SubPreferenceSetting { 027 028 public static class Factory implements PreferenceSettingFactory { 029 @Override 030 public PreferenceSetting createPreferenceSetting() { 031 return new DrawingPreference(); 032 } 033 } 034 035 private GPXSettingsPanel gpxPanel; 036 private JCheckBox directionHint = new JCheckBox(tr("Draw Direction Arrows")); 037 private JCheckBox headArrow = new JCheckBox(tr("Only on the head of a way.")); 038 private JCheckBox onewayArrow = new JCheckBox(tr("Draw oneway arrows.")); 039 private JCheckBox segmentOrderNumber = new JCheckBox(tr("Draw segment order numbers")); 040 private JCheckBox sourceBounds = new JCheckBox(tr("Draw boundaries of downloaded data")); 041 private JCheckBox virtualNodes = new JCheckBox(tr("Draw virtual nodes in select mode")); 042 private JCheckBox inactive = new JCheckBox(tr("Draw inactive layers in other color")); 043 private JCheckBox discardableKeys = new JCheckBox(tr("Display discardable keys")); 044 045 // Options that affect performance 046 private JCheckBox useHighlighting = new JCheckBox(tr("Highlight target ways and nodes")); 047 private JCheckBox drawHelperLine = new JCheckBox(tr("Draw rubber-band helper line")); 048 private JCheckBox useAntialiasing = new JCheckBox(tr("Smooth map graphics (antialiasing)")); 049 private JCheckBox useWireframeAntialiasing = new JCheckBox(tr("Smooth map graphics in wireframe mode (antialiasing)")); 050 private JCheckBox outlineOnly = new JCheckBox(tr("Draw only outlines of areas")); 051 052 @Override 053 public void addGui(PreferenceTabbedPane gui) { 054 gpxPanel = new GPXSettingsPanel(); 055 gui.addValidationListener(gpxPanel); 056 JPanel panel = gpxPanel; 057 058 JScrollPane scrollpane = new JScrollPane(panel); 059 scrollpane.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 )); 060 gui.getDisplayPreference().addSubTab(this, tr("GPS Points"), scrollpane); 061 panel = new JPanel(new GridBagLayout()); 062 panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 063 064 // directionHint 065 directionHint.addActionListener(new ActionListener(){ 066 @Override 067 public void actionPerformed(ActionEvent e) { 068 if (directionHint.isSelected()){ 069 headArrow.setSelected(Main.pref.getBoolean("draw.segment.head_only", false)); 070 }else{ 071 headArrow.setSelected(false); 072 } 073 headArrow.setEnabled(directionHint.isSelected()); 074 } 075 }); 076 directionHint.setToolTipText(tr("Draw direction hints for way segments.")); 077 directionHint.setSelected(Main.pref.getBoolean("draw.segment.direction", false)); 078 079 // only on the head of a way 080 headArrow.setToolTipText(tr("Only on the head of a way.")); 081 headArrow.setSelected(Main.pref.getBoolean("draw.segment.head_only", false)); 082 headArrow.setEnabled(directionHint.isSelected()); 083 084 // draw oneway arrows 085 onewayArrow.setToolTipText(tr("Draw arrows in the direction of oneways and other directed features.")); 086 onewayArrow.setSelected(Main.pref.getBoolean("draw.oneway", true)); 087 088 // segment order number 089 segmentOrderNumber.setToolTipText(tr("Draw the order numbers of all segments within their way.")); 090 segmentOrderNumber.setSelected(Main.pref.getBoolean("draw.segment.order_number", false)); 091 092 // downloaded area 093 sourceBounds.setToolTipText(tr("Draw the boundaries of data loaded from the server.")); 094 sourceBounds.setSelected(Main.pref.getBoolean("draw.data.downloaded_area", true)); 095 096 // virtual nodes 097 virtualNodes.setToolTipText(tr("Draw virtual nodes in select mode for easy way modification.")); 098 virtualNodes.setSelected(Main.pref.getInteger("mappaint.node.virtual-size", 8) != 0); 099 100 // background layers in inactive color 101 inactive.setToolTipText(tr("Draw the inactive data layers in a different color.")); 102 inactive.setSelected(Main.pref.getBoolean("draw.data.inactive_color", true)); 103 104 // antialiasing 105 useAntialiasing.setToolTipText(tr("Apply antialiasing to the map view resulting in a smoother appearance.")); 106 useAntialiasing.setSelected(Main.pref.getBoolean("mappaint.use-antialiasing", true)); 107 108 // wireframe mode antialiasing 109 useWireframeAntialiasing.setToolTipText(tr("Apply antialiasing to the map view in wireframe mode resulting in a smoother appearance.")); 110 useWireframeAntialiasing.setSelected(Main.pref.getBoolean("mappaint.wireframe.use-antialiasing", false)); 111 112 // highlighting 113 useHighlighting.setToolTipText(tr("Hightlight target nodes and ways while drawing or selecting")); 114 useHighlighting.setSelected(Main.pref.getBoolean("draw.target-highlight", true)); 115 116 drawHelperLine.setToolTipText(tr("Draw rubber-band helper line")); 117 drawHelperLine.setSelected(Main.pref.getBoolean("draw.helper-line", true)); 118 119 // outlineOnly 120 outlineOnly.setToolTipText(tr("This option suppresses the filling of areas, overriding anything specified in the selected style.")); 121 outlineOnly.setSelected(Main.pref.getBoolean("draw.data.area_outline_only", false)); 122 123 // discardable keys 124 discardableKeys.setToolTipText(tr("Display keys which have been deemed uninteresting to the point that they can be silently removed.")); 125 discardableKeys.setSelected(Main.pref.getBoolean("display.discardable-keys", false)); 126 127 JLabel performanceLabel = new JLabel(tr("Options that affect drawing performance")); 128 129 panel.add(new JLabel(tr("Segment drawing options")), 130 GBC.eop().insets(5,10,0,0)); 131 panel.add(directionHint, GBC.eop().insets(20,0,0,0)); 132 panel.add(headArrow, GBC.eop().insets(40, 0, 0, 0)); 133 panel.add(onewayArrow, GBC.eop().insets(20,0,0,0)); 134 panel.add(segmentOrderNumber, GBC.eop().insets(20,0,0,0)); 135 136 panel.add(new JLabel(tr("Select and draw mode options")), 137 GBC.eop().insets(5,10,0,0)); 138 panel.add(virtualNodes, GBC.eop().insets(20,0,0,0)); 139 panel.add(drawHelperLine, GBC.eop().insets(20, 0, 0, 0)); 140 141 panel.add(performanceLabel, GBC.eop().insets(5,10,0,0)); 142 panel.add(useAntialiasing, GBC.eop().insets(20,0,0,0)); 143 panel.add(useWireframeAntialiasing, GBC.eop().insets(20, 0, 0, 0)); 144 panel.add(useHighlighting, GBC.eop().insets(20,0,0,0)); 145 panel.add(outlineOnly, GBC.eol().insets(20,0,0,0)); 146 147 panel.add(new JLabel(tr("Other options")), 148 GBC.eop().insets(5,10,0,0)); 149 panel.add(sourceBounds, GBC.eop().insets(20,0,0,0)); 150 panel.add(inactive, GBC.eop().insets(20,0,0,0)); 151 panel.add(discardableKeys, GBC.eop().insets(20,0,0,0)); 152 153 ExpertToggleAction.addVisibilitySwitcher(performanceLabel); 154 ExpertToggleAction.addVisibilitySwitcher(useAntialiasing); 155 ExpertToggleAction.addVisibilitySwitcher(useWireframeAntialiasing); 156 ExpertToggleAction.addVisibilitySwitcher(useHighlighting); 157 ExpertToggleAction.addVisibilitySwitcher(outlineOnly); 158 ExpertToggleAction.addVisibilitySwitcher(discardableKeys); 159 160 panel.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.BOTH)); 161 scrollpane = new JScrollPane(panel); 162 scrollpane.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 )); 163 gui.getDisplayPreference().addSubTab(this, tr("OSM Data"), scrollpane); 164 } 165 166 @Override 167 public boolean ok() { 168 gpxPanel.savePreferences(); 169 Main.pref.put("draw.data.area_outline_only", outlineOnly.isSelected()); 170 Main.pref.put("draw.segment.direction", directionHint.isSelected()); 171 Main.pref.put("draw.segment.head_only", headArrow.isSelected()); 172 Main.pref.put("draw.oneway", onewayArrow.isSelected()); 173 Main.pref.put("draw.segment.order_number", segmentOrderNumber.isSelected()); 174 Main.pref.put("draw.data.downloaded_area", sourceBounds.isSelected()); 175 Main.pref.put("draw.data.inactive_color", inactive.isSelected()); 176 Main.pref.put("mappaint.use-antialiasing", useAntialiasing.isSelected()); 177 Main.pref.put("mappaint.wireframe.use-antialiasing", useWireframeAntialiasing.isSelected()); 178 Main.pref.put("draw.target-highlight", useHighlighting.isSelected()); 179 Main.pref.put("draw.helper-line", drawHelperLine.isSelected()); 180 Main.pref.put("display.discardable-keys", discardableKeys.isSelected()); 181 int vn = Main.pref.getInteger("mappaint.node.virtual-size", 8); 182 if (virtualNodes.isSelected()) { 183 if (vn < 1) { 184 vn = 8; 185 } 186 } 187 else { 188 vn = 0; 189 } 190 Main.pref.putInteger("mappaint.node.virtual-size", vn); 191 return false; 192 } 193 194 @Override 195 public boolean isExpert() { 196 return false; 197 } 198 199 @Override 200 public TabPreferenceSetting getTabPreferenceSetting(final PreferenceTabbedPane gui) { 201 return gui.getDisplayPreference(); 202 } 203}