[298] | 1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
[626] | 2 | package org.openstreetmap.josm.gui.preferences;
|
---|
| 3 |
|
---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 5 |
|
---|
| 6 | import java.awt.Component;
|
---|
[1165] | 7 | import java.awt.GridBagLayout;
|
---|
[626] | 8 |
|
---|
[1165] | 9 | import javax.swing.BorderFactory;
|
---|
| 10 | import javax.swing.Box;
|
---|
[626] | 11 | import javax.swing.DefaultListCellRenderer;
|
---|
[1165] | 12 | import javax.swing.JCheckBox;
|
---|
[626] | 13 | import javax.swing.JComboBox;
|
---|
| 14 | import javax.swing.JLabel;
|
---|
| 15 | import javax.swing.JList;
|
---|
[1165] | 16 | import javax.swing.JPanel;
|
---|
| 17 | import javax.swing.JScrollPane;
|
---|
[626] | 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 |
|
---|
[1742] | 27 | public static class Factory implements PreferenceSettingFactory {
|
---|
| 28 | public PreferenceSetting createPreferenceSetting() {
|
---|
| 29 | return new LafPreference();
|
---|
| 30 | }
|
---|
| 31 | }
|
---|
| 32 |
|
---|
[1169] | 33 | /**
|
---|
| 34 | * ComboBox with all look and feels.
|
---|
| 35 | */
|
---|
| 36 | private JComboBox lafCombo;
|
---|
[1178] | 37 | public JPanel panel;
|
---|
[1169] | 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"));
|
---|
[1990] | 40 | private JCheckBox showLocalizedName = new JCheckBox(tr("Show localized name in selection lists"));
|
---|
[1405] | 41 | private JCheckBox modeless = new JCheckBox(tr("Modeless working (Potlatch style)"));
|
---|
[4512] | 42 | private JCheckBox expert = new JCheckBox(tr("Expert mode"));
|
---|
| 43 | private JCheckBox dynamicButtons = new JCheckBox(tr("Dynamic buttons in side menus"));
|
---|
[626] | 44 |
|
---|
[2745] | 45 | public void addGui(PreferenceTabbedPane gui) {
|
---|
[1169] | 46 | lafCombo = new JComboBox(UIManager.getInstalledLookAndFeels());
|
---|
[1023] | 47 |
|
---|
[1169] | 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(
|
---|
[1990] | 54 | new UIManager.LookAndFeelInfo(((javax.swing.LookAndFeel)Oquaqua).getName(), "ch.randelshofer.quaqua.QuaquaLookAndFeel")
|
---|
[1169] | 55 | );
|
---|
| 56 | } catch (Exception ex) {
|
---|
| 57 | // just ignore, Quaqua may not even be installed...
|
---|
| 58 | //System.out.println("Failed to load Quaqua: " + ex);
|
---|
| 59 | }
|
---|
[1023] | 60 |
|
---|
[2428] | 61 | String laf = Main.pref.get("laf", Main.platform.getDefaultStyle());
|
---|
[1169] | 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 | }
|
---|
[626] | 68 |
|
---|
[1169] | 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 | });
|
---|
[626] | 75 |
|
---|
[1178] | 76 | panel = new JPanel(new GridBagLayout());
|
---|
[1169] | 77 | panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
[1165] | 78 |
|
---|
[1169] | 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));
|
---|
[1165] | 83 |
|
---|
[4658] | 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 |
|
---|
[4828] | 96 | panel.add(showID, GBC.eop().insets(20, 0, 0, 0));
|
---|
[4658] | 97 | if (Main.pref.getBoolean("expert", false)) {
|
---|
[4512] | 98 | panel.add(showLocalizedName, GBC.eop().insets(20, 0, 0, 0));
|
---|
| 99 | panel.add(modeless, GBC.eop().insets(20, 0, 0, 0));
|
---|
| 100 | }
|
---|
[1405] | 101 |
|
---|
[4512] | 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 |
|
---|
[1169] | 110 | panel.add(Box.createVerticalGlue(), GBC.eol().insets(0, 20, 0, 0));
|
---|
[1165] | 111 |
|
---|
[1169] | 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));
|
---|
[1165] | 115 |
|
---|
[1169] | 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 | }
|
---|
[626] | 120 |
|
---|
[1180] | 121 | public boolean ok() {
|
---|
[4512] | 122 | boolean mod = false;
|
---|
[1169] | 123 | Main.pref.put("draw.splashscreen", showSplashScreen.isSelected());
|
---|
| 124 | Main.pref.put("osm-primitives.showid", showID.isSelected());
|
---|
[1990] | 125 | Main.pref.put("osm-primitives.localize-name", showLocalizedName.isSelected());
|
---|
[1405] | 126 | Main.pref.put("modeless", modeless.isSelected());
|
---|
[4512] | 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;
|
---|
[626] | 133 | }
|
---|
| 134 | }
|
---|