source: josm/trunk/src/org/openstreetmap/josm/gui/preferences/MapPaintPreference.java@ 3466

Last change on this file since 3466 was 3466, checked in by stoecker, 15 years ago

see #5372 - fix missing style switch

  • Property svn:eol-style set to native
File size: 3.9 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.gui.preferences;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.GridBagLayout;
7import java.util.Collection;
8import java.util.TreeSet;
9
10import javax.swing.BorderFactory;
11import javax.swing.JCheckBox;
12import javax.swing.JComboBox;
13import javax.swing.JLabel;
14import javax.swing.JPanel;
15import javax.swing.event.ChangeEvent;
16import javax.swing.event.ChangeListener;
17
18import org.openstreetmap.josm.Main;
19import org.openstreetmap.josm.data.osm.OsmPrimitive;
20import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
21import org.openstreetmap.josm.tools.GBC;
22
23public class MapPaintPreference implements PreferenceSetting {
24 private StyleSourceEditor sources;
25 private JCheckBox enableIconDefault;
26 private JCheckBox enableDefault;
27 private JComboBox styleCombo = new JComboBox();
28
29 public static class Factory implements PreferenceSettingFactory {
30 public PreferenceSetting createPreferenceSetting() {
31 return new MapPaintPreference();
32 }
33 }
34
35 public void addGui(final PreferenceTabbedPane gui) {
36 enableDefault = new JCheckBox(tr("Enable built-in defaults"),
37 Main.pref.getBoolean("mappaint.style.enable-defaults", true));
38 enableIconDefault = new JCheckBox(tr("Enable built-in icon defaults"),
39 Main.pref.getBoolean("mappaint.icon.enable-defaults", true));
40
41 sources = new StyleSourceEditor("mappaint.style.sources", "mappaint.icon.sources",
42 "http://josm.openstreetmap.de/styles");
43
44 Collection<String> styles = new TreeSet<String>(MapPaintStyles.getStyles().getStyleNames());
45 String defstyle = Main.pref.get("mappaint.style", "standard");
46 styles.add(defstyle);
47 for(String style : styles) {
48 styleCombo.addItem(style);
49 }
50
51 styleCombo.setEditable(true);
52 for (int i = 0; i < styleCombo.getItemCount(); ++i) {
53 if (((String)styleCombo.getItemAt(i)).equals(defstyle)) {
54 styleCombo.setSelectedIndex(i);
55 break;
56 }
57 }
58
59 final JPanel panel = new JPanel(new GridBagLayout());
60 panel.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 ));
61 panel.add(enableDefault, GBC.std().insets(5,5,5,0));
62 panel.add(enableIconDefault, GBC.eol().insets(5,5,5,0));
63
64 panel.add(new JLabel(tr("Used style")), GBC.std().insets(5,5,0,5));
65 panel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
66 panel.add(styleCombo, GBC.eop().fill(GBC.HORIZONTAL).insets(0,0,5,0));
67
68 panel.add(sources, GBC.eol().fill(GBC.BOTH));
69 gui.mapcontent.addTab(tr("Map Paint Styles"), panel);
70
71 // this defers loading of style sources to the first time the tab
72 // with the map paint preferences is selected by the user
73 //
74 gui.mapcontent.addChangeListener(
75 new ChangeListener() {
76 public void stateChanged(ChangeEvent e) {
77 if (gui.mapcontent.getSelectedComponent() == panel) {
78 sources.initiallyLoadAvailableStyles();
79 }
80 }
81 }
82 );
83 }
84
85 public boolean ok() {
86 Boolean restart = Main.pref.put("mappaint.style.enable-defaults", enableDefault.isSelected());
87 if(Main.pref.put("mappaint.icon.enable-defaults", enableIconDefault.isSelected())) {
88 restart = true;
89 }
90 if(sources.finish()) {
91 restart = true;
92 }
93 if(Main.pref.put("mappaint.style", styleCombo.getEditor().getItem().toString()))
94 {
95 for(OsmPrimitive osm : Main.main.getCurrentDataSet().allPrimitives())
96 {
97 osm.clearCached();
98 }
99 }
100 return restart;
101 }
102
103 /**
104 * Initialize the styles
105 */
106 public static void initialize() {
107 MapPaintStyles.readFromPreferences();
108 }
109}
Note: See TracBrowser for help on using the repository browser.