1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.gui.preferences.display;
|
---|
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.actions.ExpertToggleAction;
|
---|
24 | import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
|
---|
25 | import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
|
---|
26 | import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
|
---|
27 | import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting;
|
---|
28 | import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting;
|
---|
29 | import org.openstreetmap.josm.tools.GBC;
|
---|
30 |
|
---|
31 | public class LafPreference implements SubPreferenceSetting {
|
---|
32 |
|
---|
33 | public static class Factory implements PreferenceSettingFactory {
|
---|
34 | public PreferenceSetting createPreferenceSetting() {
|
---|
35 | return new LafPreference();
|
---|
36 | }
|
---|
37 | }
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * ComboBox with all look and feels.
|
---|
41 | */
|
---|
42 | private JComboBox lafCombo;
|
---|
43 | public JPanel panel;
|
---|
44 | private JCheckBox showSplashScreen = new JCheckBox(tr("Show splash screen at startup"));
|
---|
45 | private JCheckBox showID = new JCheckBox(tr("Show object ID in selection lists"));
|
---|
46 | private JCheckBox showLocalizedName = new JCheckBox(tr("Show localized name in selection lists"));
|
---|
47 | private JCheckBox modeless = new JCheckBox(tr("Modeless working (Potlatch style)"));
|
---|
48 | private JCheckBox dynamicButtons = new JCheckBox(tr("Dynamic buttons in side menus"));
|
---|
49 |
|
---|
50 | public void addGui(PreferenceTabbedPane gui) {
|
---|
51 | lafCombo = new JComboBox(UIManager.getInstalledLookAndFeels());
|
---|
52 |
|
---|
53 | // let's try to load additional LookAndFeels and put them into the list
|
---|
54 | try {
|
---|
55 | Class<?> Cquaqua = Class.forName("ch.randelshofer.quaqua.QuaquaLookAndFeel");
|
---|
56 | Object Oquaqua = Cquaqua.getConstructor((Class[])null).newInstance((Object[])null);
|
---|
57 | // no exception? Then Go!
|
---|
58 | lafCombo.addItem(
|
---|
59 | new UIManager.LookAndFeelInfo(((javax.swing.LookAndFeel)Oquaqua).getName(), "ch.randelshofer.quaqua.QuaquaLookAndFeel")
|
---|
60 | );
|
---|
61 | } catch (Exception ex) {
|
---|
62 | // just ignore, Quaqua may not even be installed...
|
---|
63 | //System.out.println("Failed to load Quaqua: " + ex);
|
---|
64 | }
|
---|
65 |
|
---|
66 | String laf = Main.pref.get("laf", Main.platform.getDefaultStyle());
|
---|
67 | for (int i = 0; i < lafCombo.getItemCount(); ++i) {
|
---|
68 | if (((LookAndFeelInfo)lafCombo.getItemAt(i)).getClassName().equals(laf)) {
|
---|
69 | lafCombo.setSelectedIndex(i);
|
---|
70 | break;
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | final ListCellRenderer oldRenderer = lafCombo.getRenderer();
|
---|
75 | lafCombo.setRenderer(new DefaultListCellRenderer(){
|
---|
76 | @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
---|
77 | return oldRenderer.getListCellRendererComponent(list, ((LookAndFeelInfo)value).getName(), index, isSelected, cellHasFocus);
|
---|
78 | }
|
---|
79 | });
|
---|
80 |
|
---|
81 | panel = new JPanel(new GridBagLayout());
|
---|
82 | panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
83 |
|
---|
84 | // Show splash screen on startup
|
---|
85 | showSplashScreen.setToolTipText(tr("Show splash screen at startup"));
|
---|
86 | showSplashScreen.setSelected(Main.pref.getBoolean("draw.splashscreen", true));
|
---|
87 | panel.add(showSplashScreen, GBC.eop().insets(20, 0, 0, 0));
|
---|
88 |
|
---|
89 | // Show ID in selection
|
---|
90 | showID.setToolTipText(tr("Show object ID in selection lists"));
|
---|
91 | showID.setSelected(Main.pref.getBoolean("osm-primitives.showid", false));
|
---|
92 |
|
---|
93 | // Show localized names
|
---|
94 | showLocalizedName.setToolTipText(tr("Show localized name in selection lists, if available"));
|
---|
95 | showLocalizedName.setSelected(Main.pref.getBoolean("osm-primitives.localize-name", true));
|
---|
96 | ExpertToggleAction.addVisibilitySwitcher(showLocalizedName);
|
---|
97 |
|
---|
98 | modeless.setToolTipText(tr("Do not require to switch modes (potlatch style workflow)"));
|
---|
99 | modeless.setSelected(Main.pref.getBoolean("modeless", false));
|
---|
100 | ExpertToggleAction.addVisibilitySwitcher(modeless);
|
---|
101 |
|
---|
102 | panel.add(showID, GBC.eop().insets(20, 0, 0, 0));
|
---|
103 | panel.add(showLocalizedName, GBC.eop().insets(20, 0, 0, 0));
|
---|
104 | panel.add(modeless, GBC.eop().insets(20, 0, 0, 0));
|
---|
105 |
|
---|
106 | dynamicButtons.setToolTipText(tr("Display buttons in right side menus only when mouse is inside the element"));
|
---|
107 | dynamicButtons.setSelected(Main.pref.getBoolean("dialog.dynamic.buttons", true));
|
---|
108 | panel.add(dynamicButtons, 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.getDisplayPreference().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 | Main.pref.put("dialog.dynamic.buttons", dynamicButtons.isSelected());
|
---|
128 | mod |= Main.pref.put("laf", ((LookAndFeelInfo)lafCombo.getSelectedItem()).getClassName());
|
---|
129 | return mod;
|
---|
130 | }
|
---|
131 |
|
---|
132 | @Override
|
---|
133 | public boolean isExpert() {
|
---|
134 | return false;
|
---|
135 | }
|
---|
136 |
|
---|
137 | @Override
|
---|
138 | public TabPreferenceSetting getTabPreferenceSetting(final PreferenceTabbedPane gui) {
|
---|
139 | return gui.getDisplayPreference();
|
---|
140 | }
|
---|
141 | }
|
---|