1 | // License: GPL. For details, see LICENSE file.
|
---|
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.JLabel;
|
---|
14 | import javax.swing.JList;
|
---|
15 | import javax.swing.JPanel;
|
---|
16 | import javax.swing.JScrollPane;
|
---|
17 | import javax.swing.ListCellRenderer;
|
---|
18 | import javax.swing.LookAndFeel;
|
---|
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.dialogs.ToggleDialog;
|
---|
25 | import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
|
---|
26 | import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
|
---|
27 | import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
|
---|
28 | import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting;
|
---|
29 | import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting;
|
---|
30 | import org.openstreetmap.josm.gui.widgets.JosmComboBox;
|
---|
31 | import org.openstreetmap.josm.tools.GBC;
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Look-and-feel preferences.
|
---|
35 | */
|
---|
36 | public class LafPreference implements SubPreferenceSetting {
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * Factory used to create a new {@code LafPreference}.
|
---|
40 | */
|
---|
41 | public static class Factory implements PreferenceSettingFactory {
|
---|
42 | @Override
|
---|
43 | public PreferenceSetting createPreferenceSetting() {
|
---|
44 | return new LafPreference();
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * ComboBox with all look and feels.
|
---|
50 | */
|
---|
51 | private JosmComboBox lafCombo;
|
---|
52 | JPanel panel;
|
---|
53 | private JCheckBox showSplashScreen = new JCheckBox(tr("Show splash screen at startup"));
|
---|
54 | private JCheckBox showID = new JCheckBox(tr("Show object ID in selection lists"));
|
---|
55 | private JCheckBox showLocalizedName = new JCheckBox(tr("Show localized name in selection lists"));
|
---|
56 | private JCheckBox modeless = new JCheckBox(tr("Modeless working (Potlatch style)"));
|
---|
57 | private JCheckBox dynamicButtons = new JCheckBox(tr("Dynamic buttons in side menus"));
|
---|
58 |
|
---|
59 | @Override
|
---|
60 | public void addGui(PreferenceTabbedPane gui) {
|
---|
61 | lafCombo = new JosmComboBox(UIManager.getInstalledLookAndFeels());
|
---|
62 |
|
---|
63 | // let's try to load additional LookAndFeels and put them into the list
|
---|
64 | if (Main.isPlatformOsx()) {
|
---|
65 | try {
|
---|
66 | Class<?> Cquaqua = Class.forName("ch.randelshofer.quaqua.QuaquaLookAndFeel");
|
---|
67 | Object Oquaqua = Cquaqua.getConstructor((Class[])null).newInstance((Object[])null);
|
---|
68 | // no exception? Then Go!
|
---|
69 | lafCombo.addItem(
|
---|
70 | new UIManager.LookAndFeelInfo(((LookAndFeel)Oquaqua).getName(), "ch.randelshofer.quaqua.QuaquaLookAndFeel")
|
---|
71 | );
|
---|
72 | } catch (Exception ex) {
|
---|
73 | // just debug, Quaqua may not even be installed...
|
---|
74 | Main.debug(ex.getMessage());
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | String laf = Main.pref.get("laf", Main.platform.getDefaultStyle());
|
---|
79 | for (int i = 0; i < lafCombo.getItemCount(); ++i) {
|
---|
80 | if (((LookAndFeelInfo)lafCombo.getItemAt(i)).getClassName().equals(laf)) {
|
---|
81 | lafCombo.setSelectedIndex(i);
|
---|
82 | break;
|
---|
83 | }
|
---|
84 | }
|
---|
85 |
|
---|
86 | final ListCellRenderer oldRenderer = lafCombo.getRenderer();
|
---|
87 | lafCombo.setRenderer(new DefaultListCellRenderer(){
|
---|
88 | @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
---|
89 | return oldRenderer.getListCellRendererComponent(list, ((LookAndFeelInfo)value).getName(), index, isSelected, cellHasFocus);
|
---|
90 | }
|
---|
91 | });
|
---|
92 |
|
---|
93 | panel = new JPanel(new GridBagLayout());
|
---|
94 | panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
95 |
|
---|
96 | // Show splash screen on startup
|
---|
97 | showSplashScreen.setToolTipText(tr("Show splash screen at startup"));
|
---|
98 | showSplashScreen.setSelected(Main.pref.getBoolean("draw.splashscreen", true));
|
---|
99 | panel.add(showSplashScreen, GBC.eop().insets(20, 0, 0, 0));
|
---|
100 |
|
---|
101 | // Show ID in selection
|
---|
102 | showID.setToolTipText(tr("Show object ID in selection lists"));
|
---|
103 | showID.setSelected(Main.pref.getBoolean("osm-primitives.showid", false));
|
---|
104 |
|
---|
105 | // Show localized names
|
---|
106 | showLocalizedName.setToolTipText(tr("Show localized name in selection lists, if available"));
|
---|
107 | showLocalizedName.setSelected(Main.pref.getBoolean("osm-primitives.localize-name", true));
|
---|
108 | ExpertToggleAction.addVisibilitySwitcher(showLocalizedName);
|
---|
109 |
|
---|
110 | modeless.setToolTipText(tr("Do not require to switch modes (potlatch style workflow)"));
|
---|
111 | modeless.setSelected(Main.pref.getBoolean("modeless", false));
|
---|
112 | ExpertToggleAction.addVisibilitySwitcher(modeless);
|
---|
113 |
|
---|
114 | panel.add(showID, GBC.eop().insets(20, 0, 0, 0));
|
---|
115 | panel.add(showLocalizedName, GBC.eop().insets(20, 0, 0, 0));
|
---|
116 | panel.add(modeless, GBC.eop().insets(20, 0, 0, 0));
|
---|
117 |
|
---|
118 | dynamicButtons.setToolTipText(tr("Display buttons in right side menus only when mouse is inside the element"));
|
---|
119 | dynamicButtons.setSelected(ToggleDialog.PROP_DYNAMIC_BUTTONS.get());
|
---|
120 | panel.add(dynamicButtons, GBC.eop().insets(20, 0, 0, 0));
|
---|
121 |
|
---|
122 | panel.add(Box.createVerticalGlue(), GBC.eol().insets(0, 20, 0, 0));
|
---|
123 |
|
---|
124 | panel.add(new JLabel(tr("Look and Feel")), GBC.std().insets(20, 0, 0, 0));
|
---|
125 | panel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
|
---|
126 | panel.add(lafCombo, GBC.eol().fill(GBC.HORIZONTAL));
|
---|
127 |
|
---|
128 | JScrollPane scrollpane = new JScrollPane(panel);
|
---|
129 | scrollpane.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 ));
|
---|
130 | gui.getDisplayPreference().addSubTab(this, tr("Look and Feel"), scrollpane);
|
---|
131 | }
|
---|
132 |
|
---|
133 | @Override
|
---|
134 | public boolean ok() {
|
---|
135 | boolean mod = false;
|
---|
136 | Main.pref.put("draw.splashscreen", showSplashScreen.isSelected());
|
---|
137 | Main.pref.put("osm-primitives.showid", showID.isSelected());
|
---|
138 | Main.pref.put("osm-primitives.localize-name", showLocalizedName.isSelected());
|
---|
139 | Main.pref.put("modeless", modeless.isSelected());
|
---|
140 | Main.pref.put(ToggleDialog.PROP_DYNAMIC_BUTTONS.getKey(), dynamicButtons.isSelected());
|
---|
141 | mod |= Main.pref.put("laf", ((LookAndFeelInfo)lafCombo.getSelectedItem()).getClassName());
|
---|
142 | return mod;
|
---|
143 | }
|
---|
144 |
|
---|
145 | @Override
|
---|
146 | public boolean isExpert() {
|
---|
147 | return false;
|
---|
148 | }
|
---|
149 |
|
---|
150 | @Override
|
---|
151 | public TabPreferenceSetting getTabPreferenceSetting(final PreferenceTabbedPane gui) {
|
---|
152 | return gui.getDisplayPreference();
|
---|
153 | }
|
---|
154 | }
|
---|