001 // License: GPL. Copyright 2007 by Immanuel Scholz and others 002 package org.openstreetmap.josm.gui.preferences.display; 003 004 import static org.openstreetmap.josm.tools.I18n.tr; 005 006 import java.awt.GridBagLayout; 007 import java.awt.event.ActionEvent; 008 import java.awt.event.ActionListener; 009 010 import javax.swing.BorderFactory; 011 import javax.swing.Box; 012 import javax.swing.JCheckBox; 013 import javax.swing.JLabel; 014 import javax.swing.JPanel; 015 import javax.swing.JScrollPane; 016 017 import org.openstreetmap.josm.Main; 018 import org.openstreetmap.josm.actions.ExpertToggleAction; 019 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 020 import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory; 021 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane; 022 import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting; 023 import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting; 024 import org.openstreetmap.josm.tools.GBC; 025 026 public class DrawingPreference implements SubPreferenceSetting { 027 028 public static class Factory implements PreferenceSettingFactory { 029 public PreferenceSetting createPreferenceSetting() { 030 return new DrawingPreference(); 031 } 032 } 033 034 private GPXSettingsPanel gpxPanel; 035 private JCheckBox directionHint = new JCheckBox(tr("Draw Direction Arrows")); 036 private JCheckBox headArrow = new JCheckBox(tr("Only on the head of a way.")); 037 private JCheckBox onewayArrow = new JCheckBox(tr("Draw oneway arrows.")); 038 private JCheckBox segmentOrderNumber = new JCheckBox(tr("Draw segment order numbers")); 039 private JCheckBox sourceBounds = new JCheckBox(tr("Draw boundaries of downloaded data")); 040 private JCheckBox virtualNodes = new JCheckBox(tr("Draw virtual nodes in select mode")); 041 private JCheckBox inactive = new JCheckBox(tr("Draw inactive layers in other color")); 042 043 // Options that affect performance 044 private JCheckBox useHighlighting = new JCheckBox(tr("Highlight target ways and nodes")); 045 private JCheckBox drawHelperLine = new JCheckBox(tr("Draw rubber-band helper line")); 046 private JCheckBox useAntialiasing = new JCheckBox(tr("Smooth map graphics (antialiasing)")); 047 private JCheckBox useWireframeAntialiasing = new JCheckBox(tr("Smooth map graphics in wireframe mode (antialiasing)")); 048 private JCheckBox outlineOnly = new JCheckBox(tr("Draw only outlines of areas")); 049 050 public void addGui(PreferenceTabbedPane gui) { 051 //gui.display.setPreferredSize(new Dimension(400,600)); 052 gpxPanel = new GPXSettingsPanel(); 053 gui.addValidationListener(gpxPanel); 054 JPanel panel = gpxPanel; 055 056 JScrollPane scrollpane = new JScrollPane(panel); 057 scrollpane.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 )); 058 gui.getDisplayPreference().displaycontent.addTab(tr("GPS Points"), scrollpane); 059 panel = new JPanel(new GridBagLayout()); 060 panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 061 062 // directionHint 063 directionHint.addActionListener(new ActionListener(){ 064 public void actionPerformed(ActionEvent e) { 065 if (directionHint.isSelected()){ 066 headArrow.setSelected(Main.pref.getBoolean("draw.segment.head_only", false)); 067 }else{ 068 headArrow.setSelected(false); 069 } 070 headArrow.setEnabled(directionHint.isSelected()); 071 } 072 }); 073 directionHint.setToolTipText(tr("Draw direction hints for way segments.")); 074 directionHint.setSelected(Main.pref.getBoolean("draw.segment.direction", false)); 075 panel.add(directionHint, GBC.eop().insets(20,0,0,0)); 076 077 // only on the head of a way 078 headArrow.setToolTipText(tr("Only on the head of a way.")); 079 headArrow.setSelected(Main.pref.getBoolean("draw.segment.head_only", false)); 080 headArrow.setEnabled(directionHint.isSelected()); 081 panel.add(headArrow, GBC.eop().insets(40, 0, 0, 0)); 082 083 // draw oneway arrows 084 onewayArrow.setToolTipText(tr("Draw arrows in the direction of oneways and other directed features.")); 085 onewayArrow.setSelected(Main.pref.getBoolean("draw.oneway", true)); 086 panel.add(onewayArrow, GBC.eop().insets(20,0,0,0)); 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 panel.add(segmentOrderNumber, GBC.eop().insets(20,0,0,0)); 092 093 // downloaded area 094 sourceBounds.setToolTipText(tr("Draw the boundaries of data loaded from the server.")); 095 sourceBounds.setSelected(Main.pref.getBoolean("draw.data.downloaded_area", true)); 096 panel.add(sourceBounds, GBC.eop().insets(20,0,0,0)); 097 098 // virtual nodes 099 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().displaycontent.addTab(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 }