source: josm/trunk/src/org/openstreetmap/josm/gui/preferences/LafPreference.java@ 2745

Last change on this file since 2745 was 2745, checked in by Gubaer, 14 years ago

Partial commit due to #4137. Comment to follow in another commit.

  • Property svn:eol-style set to native
File size: 5.3 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.gui.preferences;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Component;
7import java.awt.GridBagLayout;
8
9import javax.swing.BorderFactory;
10import javax.swing.Box;
11import javax.swing.DefaultListCellRenderer;
12import javax.swing.JCheckBox;
13import javax.swing.JComboBox;
14import javax.swing.JLabel;
15import javax.swing.JList;
16import javax.swing.JPanel;
17import javax.swing.JScrollPane;
18import javax.swing.ListCellRenderer;
19import javax.swing.UIManager;
20import javax.swing.UIManager.LookAndFeelInfo;
21
22import org.openstreetmap.josm.Main;
23import org.openstreetmap.josm.tools.GBC;
24
25public 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 drawHelperLine = new JCheckBox(tr("Draw rubber-band helper line"));
42 private JCheckBox modeless = new JCheckBox(tr("Modeless working (Potlatch style)"));
43
44 public void addGui(PreferenceTabbedPane gui) {
45 lafCombo = new JComboBox(UIManager.getInstalledLookAndFeels());
46
47 // let's try to load additional LookAndFeels and put them into the list
48 try {
49 Class<?> Cquaqua = Class.forName("ch.randelshofer.quaqua.QuaquaLookAndFeel");
50 Object Oquaqua = Cquaqua.getConstructor((Class[])null).newInstance((Object[])null);
51 // no exception? Then Go!
52 lafCombo.addItem(
53 new UIManager.LookAndFeelInfo(((javax.swing.LookAndFeel)Oquaqua).getName(), "ch.randelshofer.quaqua.QuaquaLookAndFeel")
54 );
55 } catch (Exception ex) {
56 // just ignore, Quaqua may not even be installed...
57 //System.out.println("Failed to load Quaqua: " + ex);
58 }
59
60 String laf = Main.pref.get("laf", Main.platform.getDefaultStyle());
61 for (int i = 0; i < lafCombo.getItemCount(); ++i) {
62 if (((LookAndFeelInfo)lafCombo.getItemAt(i)).getClassName().equals(laf)) {
63 lafCombo.setSelectedIndex(i);
64 break;
65 }
66 }
67
68 final ListCellRenderer oldRenderer = lafCombo.getRenderer();
69 lafCombo.setRenderer(new DefaultListCellRenderer(){
70 @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
71 return oldRenderer.getListCellRendererComponent(list, ((LookAndFeelInfo)value).getName(), index, isSelected, cellHasFocus);
72 }
73 });
74
75 panel = new JPanel(new GridBagLayout());
76 panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
77
78 // Show splash screen on startup
79 showSplashScreen.setToolTipText(tr("Show splash screen at startup"));
80 showSplashScreen.setSelected(Main.pref.getBoolean("draw.splashscreen", true));
81 panel.add(showSplashScreen, GBC.eop().insets(20, 0, 0, 0));
82
83 // Show ID in selection
84 showID.setToolTipText(tr("Show object ID in selection lists"));
85 showID.setSelected(Main.pref.getBoolean("osm-primitives.showid", false));
86 panel.add(showID, GBC.eop().insets(20, 0, 0, 0));
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 panel.add(showLocalizedName, GBC.eop().insets(20, 0, 0, 0));
92
93 drawHelperLine.setToolTipText(tr("Draw rubber-band helper line"));
94 drawHelperLine.setSelected(Main.pref.getBoolean("draw.helper-line", true));
95 panel.add(drawHelperLine, GBC.eop().insets(20, 0, 0, 0));
96
97 modeless.setToolTipText(tr("Do not require to switch modes (potlatch style workflow)"));
98 modeless.setSelected(Main.pref.getBoolean("modeless", false));
99 panel.add(modeless, GBC.eop().insets(20, 0, 0, 0));
100
101 panel.add(Box.createVerticalGlue(), GBC.eol().insets(0, 20, 0, 0));
102
103 panel.add(new JLabel(tr("Look and Feel")), GBC.std().insets(20, 0, 0, 0));
104 panel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
105 panel.add(lafCombo, GBC.eol().fill(GBC.HORIZONTAL));
106
107 JScrollPane scrollpane = new JScrollPane(panel);
108 scrollpane.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 ));
109 gui.displaycontent.addTab(tr("Look and Feel"), scrollpane);
110 }
111
112 public boolean ok() {
113 Main.pref.put("draw.splashscreen", showSplashScreen.isSelected());
114 Main.pref.put("osm-primitives.showid", showID.isSelected());
115 Main.pref.put("osm-primitives.localize-name", showLocalizedName.isSelected());
116 Main.pref.put("draw.helper-line", drawHelperLine.isSelected());
117 Main.pref.put("modeless", modeless.isSelected());
118 return Main.pref.put("laf", ((LookAndFeelInfo)lafCombo.getSelectedItem()).getClassName());
119 }
120}
Note: See TracBrowser for help on using the repository browser.