1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.gui.preferences;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.GridBagLayout;
|
---|
7 |
|
---|
8 | import javax.swing.BorderFactory;
|
---|
9 | import javax.swing.JCheckBox;
|
---|
10 | import javax.swing.JComboBox;
|
---|
11 | import javax.swing.JLabel;
|
---|
12 | import javax.swing.JPanel;
|
---|
13 | import javax.swing.JScrollPane;
|
---|
14 |
|
---|
15 | import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
|
---|
16 | import org.openstreetmap.josm.Main;
|
---|
17 | import org.openstreetmap.josm.tools.GBC;
|
---|
18 |
|
---|
19 | public class MapPaintPreference implements PreferenceSetting {
|
---|
20 | private StyleSources sources;
|
---|
21 | private JCheckBox enableIconDefault;
|
---|
22 | private JCheckBox enableDefault;
|
---|
23 | private JComboBox styleCombo = new JComboBox();
|
---|
24 |
|
---|
25 | public static class Factory implements PreferenceSettingFactory {
|
---|
26 | public PreferenceSetting createPreferenceSetting() {
|
---|
27 | return new MapPaintPreference();
|
---|
28 | }
|
---|
29 | }
|
---|
30 |
|
---|
31 | public void addGui(final PreferenceDialog gui) {
|
---|
32 | enableDefault = new JCheckBox(tr("Enable built-in defaults"),
|
---|
33 | Main.pref.getBoolean("mappaint.style.enable-defaults", true));
|
---|
34 | enableIconDefault = new JCheckBox(tr("Enable built-in icon defaults"),
|
---|
35 | Main.pref.getBoolean("mappaint.icon.enable-defaults", true));
|
---|
36 |
|
---|
37 | styleCombo.addItem("standard");
|
---|
38 |
|
---|
39 | sources = new StyleSources("mappaint.style.sources", "mappaint.icon.sources",
|
---|
40 | "http://josm.openstreetmap.de/styles", false, tr("Map Paint Styles"));
|
---|
41 |
|
---|
42 | String style = Main.pref.get("mappaint.style", "standard");
|
---|
43 | if(!style.equals("standard"))
|
---|
44 | styleCombo.addItem(style);
|
---|
45 |
|
---|
46 | styleCombo.setEditable(true);
|
---|
47 | for (int i = 0; i < styleCombo.getItemCount(); ++i) {
|
---|
48 | if (((String)styleCombo.getItemAt(i)).equals(style)) {
|
---|
49 | styleCombo.setSelectedIndex(i);
|
---|
50 | break;
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | JPanel panel = new JPanel(new GridBagLayout());
|
---|
55 | JScrollPane scrollpane = new JScrollPane(panel);
|
---|
56 | panel.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 ));
|
---|
57 | panel.add(enableDefault, GBC.std().insets(5,5,5,0));
|
---|
58 | panel.add(enableIconDefault, GBC.eol().insets(5,5,5,0));
|
---|
59 |
|
---|
60 | panel.add(new JLabel(tr("Used style")), GBC.std().insets(5,5,0,5));
|
---|
61 | panel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
|
---|
62 | panel.add(styleCombo, GBC.eop().fill(GBC.HORIZONTAL).insets(0,0,5,0));
|
---|
63 |
|
---|
64 | panel.add(sources, GBC.eol().fill(GBC.BOTH));
|
---|
65 | gui.mapcontent.addTab(tr("Map Paint Styles"), scrollpane);
|
---|
66 | }
|
---|
67 |
|
---|
68 | public boolean ok() {
|
---|
69 | Boolean restart = Main.pref.put("mappaint.style.enable-defaults", enableDefault.getSelectedObjects() != null);
|
---|
70 | if(Main.pref.put("mappaint.icon.enable-defaults", enableIconDefault.getSelectedObjects() != null))
|
---|
71 | restart = true;
|
---|
72 | if(sources.finish())
|
---|
73 | restart = true;
|
---|
74 | Main.pref.put("mappaint.style", styleCombo.getEditor().getItem().toString());
|
---|
75 | return restart;
|
---|
76 | }
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * Initialize the styles
|
---|
80 | */
|
---|
81 | public static void initialize() {
|
---|
82 | MapPaintStyles.readFromPreferences();
|
---|
83 | }
|
---|
84 | }
|
---|