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 outlineOnly = new JCheckBox(tr("Draw only outlines of areas")); 048 049 public void addGui(PreferenceTabbedPane gui) { 050 //gui.display.setPreferredSize(new Dimension(400,600)); 051 gpxPanel = new GPXSettingsPanel(); 052 gui.addValidationListener(gpxPanel); 053 JPanel panel = gpxPanel; 054 055 JScrollPane scrollpane = new JScrollPane(panel); 056 scrollpane.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 )); 057 gui.getDisplayPreference().displaycontent.addTab(tr("GPS Points"), scrollpane); 058 panel = new JPanel(new GridBagLayout()); 059 panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 060 061 // directionHint 062 directionHint.addActionListener(new ActionListener(){ 063 public void actionPerformed(ActionEvent e) { 064 if (directionHint.isSelected()){ 065 headArrow.setSelected(Main.pref.getBoolean("draw.segment.head_only", false)); 066 }else{ 067 headArrow.setSelected(false); 068 } 069 headArrow.setEnabled(directionHint.isSelected()); 070 } 071 }); 072 directionHint.setToolTipText(tr("Draw direction hints for way segments.")); 073 directionHint.setSelected(Main.pref.getBoolean("draw.segment.direction", false)); 074 panel.add(directionHint, GBC.eop().insets(20,0,0,0)); 075 076 // only on the head of a way 077 headArrow.setToolTipText(tr("Only on the head of a way.")); 078 headArrow.setSelected(Main.pref.getBoolean("draw.segment.head_only", false)); 079 headArrow.setEnabled(directionHint.isSelected()); 080 panel.add(headArrow, GBC.eop().insets(40, 0, 0, 0)); 081 082 // draw oneway arrows 083 onewayArrow.setToolTipText(tr("Draw arrows in the direction of oneways and other directed features.")); 084 onewayArrow.setSelected(Main.pref.getBoolean("draw.oneway", true)); 085 panel.add(onewayArrow, GBC.eop().insets(20,0,0,0)); 086 087 // segment order number 088 segmentOrderNumber.setToolTipText(tr("Draw the order numbers of all segments within their way.")); 089 segmentOrderNumber.setSelected(Main.pref.getBoolean("draw.segment.order_number", false)); 090 panel.add(segmentOrderNumber, GBC.eop().insets(20,0,0,0)); 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 panel.add(sourceBounds, GBC.eop().insets(20,0,0,0)); 096 097 // virtual nodes 098 virtualNodes.setToolTipText(tr("Draw virtual nodes in select mode for easy way modification.")); 099 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 }