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.Component;
|
---|
7 | import java.awt.GridBagLayout;
|
---|
8 |
|
---|
9 | import javax.swing.BorderFactory;
|
---|
10 | import javax.swing.Box;
|
---|
11 | import javax.swing.DefaultListCellRenderer;
|
---|
12 | import javax.swing.JCheckBox;
|
---|
13 | import javax.swing.JComboBox;
|
---|
14 | import javax.swing.JLabel;
|
---|
15 | import javax.swing.JList;
|
---|
16 | import javax.swing.JPanel;
|
---|
17 | import javax.swing.JScrollPane;
|
---|
18 | import javax.swing.ListCellRenderer;
|
---|
19 | import javax.swing.UIManager;
|
---|
20 | import javax.swing.UIManager.LookAndFeelInfo;
|
---|
21 |
|
---|
22 | import org.openstreetmap.josm.Main;
|
---|
23 | import org.openstreetmap.josm.tools.GBC;
|
---|
24 |
|
---|
25 | public class LafPreference implements PreferenceSetting {
|
---|
26 |
|
---|
27 | public static class Factory implements PreferenceSettingFactory {
|
---|
28 | public PreferenceSetting createPreferenceSetting() {
|
---|
29 | return new LafPreference();
|
---|
30 | }
|
---|
31 | }
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * ComboBox with all look and feels.
|
---|
35 | */
|
---|
36 | private JComboBox lafCombo;
|
---|
37 | public JPanel panel;
|
---|
38 | private JCheckBox showSplashScreen = new JCheckBox(tr("Show splash screen at startup"));
|
---|
39 | private JCheckBox showID = new JCheckBox(tr("Show object ID in selection lists"));
|
---|
40 | private JCheckBox showLocalizedName = new JCheckBox(tr("Show localized name in selection lists"));
|
---|
41 | private JCheckBox modeless = new JCheckBox(tr("Modeless working (Potlatch style)"));
|
---|
42 | private JCheckBox expert = new JCheckBox(tr("Expert mode"));
|
---|
43 | private JCheckBox dynamicButtons = new JCheckBox(tr("Dynamic buttons in side menus"));
|
---|
44 |
|
---|
45 | public void addGui(PreferenceTabbedPane gui) {
|
---|
46 | lafCombo = new JComboBox(UIManager.getInstalledLookAndFeels());
|
---|
47 |
|
---|
48 | // let's try to load additional LookAndFeels and put them into the list
|
---|
49 | try {
|
---|
50 | Class<?> Cquaqua = Class.forName("ch.randelshofer.quaqua.QuaquaLookAndFeel");
|
---|
51 | Object Oquaqua = Cquaqua.getConstructor((Class[])null).newInstance((Object[])null);
|
---|
52 | // no exception? Then Go!
|
---|
53 | lafCombo.addItem(
|
---|
54 | new UIManager.LookAndFeelInfo(((javax.swing.LookAndFeel)Oquaqua).getName(), "ch.randelshofer.quaqua.QuaquaLookAndFeel")
|
---|
55 | );
|
---|
56 | } catch (Exception ex) {
|
---|
57 | // just ignore, Quaqua may not even be installed...
|
---|
58 | //System.out.println("Failed to load Quaqua: " + ex);
|
---|
59 | }
|
---|
60 |
|
---|
61 | String laf = Main.pref.get("laf", Main.platform.getDefaultStyle());
|
---|
62 | for (int i = 0; i < lafCombo.getItemCount(); ++i) {
|
---|
63 | if (((LookAndFeelInfo)lafCombo.getItemAt(i)).getClassName().equals(laf)) {
|
---|
64 | lafCombo.setSelectedIndex(i);
|
---|
65 | break;
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | final ListCellRenderer oldRenderer = lafCombo.getRenderer();
|
---|
70 | lafCombo.setRenderer(new DefaultListCellRenderer(){
|
---|
71 | @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
---|
72 | return oldRenderer.getListCellRendererComponent(list, ((LookAndFeelInfo)value).getName(), index, isSelected, cellHasFocus);
|
---|
73 | }
|
---|
74 | });
|
---|
75 |
|
---|
76 | panel = new JPanel(new GridBagLayout());
|
---|
77 | panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
78 |
|
---|
79 | // Show splash screen on startup
|
---|
80 | showSplashScreen.setToolTipText(tr("Show splash screen at startup"));
|
---|
81 | showSplashScreen.setSelected(Main.pref.getBoolean("draw.splashscreen", true));
|
---|
82 | panel.add(showSplashScreen, GBC.eop().insets(20, 0, 0, 0));
|
---|
83 |
|
---|
84 | // Show ID in selection
|
---|
85 | showID.setToolTipText(tr("Show object ID in selection lists"));
|
---|
86 | showID.setSelected(Main.pref.getBoolean("osm-primitives.showid", false));
|
---|
87 |
|
---|
88 | // Show localized names
|
---|
89 | showLocalizedName.setToolTipText(tr("Show localized name in selection lists, if available"));
|
---|
90 | showLocalizedName.setSelected(Main.pref.getBoolean("osm-primitives.localize-name", true));
|
---|
91 |
|
---|
92 |
|
---|
93 | modeless.setToolTipText(tr("Do not require to switch modes (potlatch style workflow)"));
|
---|
94 | modeless.setSelected(Main.pref.getBoolean("modeless", false));
|
---|
95 |
|
---|
96 | if (Main.pref.getBoolean("expert", false)) {
|
---|
97 | panel.add(showID, GBC.eop().insets(20, 0, 0, 0));
|
---|
98 | panel.add(showLocalizedName, GBC.eop().insets(20, 0, 0, 0));
|
---|
99 | panel.add(modeless, GBC.eop().insets(20, 0, 0, 0));
|
---|
100 | }
|
---|
101 |
|
---|
102 | dynamicButtons.setToolTipText(tr("Display buttons in right side menus only when mouse is inside the element"));
|
---|
103 | dynamicButtons.setSelected(Main.pref.getBoolean("dialog.dynamic.buttons", true));
|
---|
104 | panel.add(dynamicButtons, GBC.eop().insets(20, 0, 0, 0));
|
---|
105 |
|
---|
106 | expert.setToolTipText(tr("The expert mode shows a lot of additional settings hidden from normal user"));
|
---|
107 | expert.setSelected(Main.pref.getBoolean("expert", false));
|
---|
108 | panel.add(expert, GBC.eop().insets(20, 0, 0, 0));
|
---|
109 |
|
---|
110 | panel.add(Box.createVerticalGlue(), GBC.eol().insets(0, 20, 0, 0));
|
---|
111 |
|
---|
112 | panel.add(new JLabel(tr("Look and Feel")), GBC.std().insets(20, 0, 0, 0));
|
---|
113 | panel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
|
---|
114 | panel.add(lafCombo, GBC.eol().fill(GBC.HORIZONTAL));
|
---|
115 |
|
---|
116 | JScrollPane scrollpane = new JScrollPane(panel);
|
---|
117 | scrollpane.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 ));
|
---|
118 | gui.displaycontent.addTab(tr("Look and Feel"), scrollpane);
|
---|
119 | }
|
---|
120 |
|
---|
121 | public boolean ok() {
|
---|
122 | boolean mod = false;
|
---|
123 | Main.pref.put("draw.splashscreen", showSplashScreen.isSelected());
|
---|
124 | Main.pref.put("osm-primitives.showid", showID.isSelected());
|
---|
125 | Main.pref.put("osm-primitives.localize-name", showLocalizedName.isSelected());
|
---|
126 | Main.pref.put("modeless", modeless.isSelected());
|
---|
127 | if(Main.pref.put("expert", expert.isSelected()))
|
---|
128 | mod = true;
|
---|
129 | Main.pref.put("dialog.dynamic.buttons", dynamicButtons.isSelected());
|
---|
130 | if(Main.pref.put("laf", ((LookAndFeelInfo)lafCombo.getSelectedItem()).getClassName()))
|
---|
131 | mod = true;
|
---|
132 | return mod;
|
---|
133 | }
|
---|
134 | }
|
---|