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

Last change on this file since 1971 was 1971, checked in by stoecker, 16 years ago

improved custom style selection box

  • Property svn:eol-style set to native
File size: 3.2 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.JScrollPane;
16
17import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
18import org.openstreetmap.josm.Main;
19import org.openstreetmap.josm.tools.GBC;
20
21public class MapPaintPreference implements PreferenceSetting {
22 private StyleSources sources;
23 private JCheckBox enableIconDefault;
24 private JCheckBox enableDefault;
25 private JComboBox styleCombo = new JComboBox();
26
27 public static class Factory implements PreferenceSettingFactory {
28 public PreferenceSetting createPreferenceSetting() {
29 return new MapPaintPreference();
30 }
31 }
32
33 public void addGui(final PreferenceDialog gui) {
34 enableDefault = new JCheckBox(tr("Enable built-in defaults"),
35 Main.pref.getBoolean("mappaint.style.enable-defaults", true));
36 enableIconDefault = new JCheckBox(tr("Enable built-in icon defaults"),
37 Main.pref.getBoolean("mappaint.icon.enable-defaults", true));
38
39 sources = new StyleSources("mappaint.style.sources", "mappaint.icon.sources",
40 "http://josm.openstreetmap.de/styles", false, tr("Map Paint Styles"));
41
42 Collection<String> styles = new TreeSet<String>(MapPaintStyles.getStyles().getStyleNames());
43 String defstyle = Main.pref.get("mappaint.style", "standard");
44 styles.add(defstyle);
45 for(String style : styles)
46 styleCombo.addItem(style);
47
48 styleCombo.setEditable(true);
49 for (int i = 0; i < styleCombo.getItemCount(); ++i) {
50 if (((String)styleCombo.getItemAt(i)).equals(defstyle)) {
51 styleCombo.setSelectedIndex(i);
52 break;
53 }
54 }
55
56 JPanel panel = new JPanel(new GridBagLayout());
57 JScrollPane scrollpane = new JScrollPane(panel);
58 panel.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 ));
59 panel.add(enableDefault, GBC.std().insets(5,5,5,0));
60 panel.add(enableIconDefault, GBC.eol().insets(5,5,5,0));
61
62 panel.add(new JLabel(tr("Used style")), GBC.std().insets(5,5,0,5));
63 panel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
64 panel.add(styleCombo, GBC.eop().fill(GBC.HORIZONTAL).insets(0,0,5,0));
65
66 panel.add(sources, GBC.eol().fill(GBC.BOTH));
67 gui.mapcontent.addTab(tr("Map Paint Styles"), scrollpane);
68 }
69
70 public boolean ok() {
71 Boolean restart = Main.pref.put("mappaint.style.enable-defaults", enableDefault.getSelectedObjects() != null);
72 if(Main.pref.put("mappaint.icon.enable-defaults", enableIconDefault.getSelectedObjects() != null))
73 restart = true;
74 if(sources.finish())
75 restart = true;
76 Main.pref.put("mappaint.style", styleCombo.getEditor().getItem().toString());
77 return restart;
78 }
79
80 /**
81 * Initialize the styles
82 */
83 public static void initialize() {
84 MapPaintStyles.readFromPreferences();
85 }
86}
Note: See TracBrowser for help on using the repository browser.