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