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