1 | package net.oni2.aeinstaller.gui.settings;
|
---|
2 |
|
---|
3 | import java.util.HashSet;
|
---|
4 | import java.util.Vector;
|
---|
5 |
|
---|
6 | import javax.swing.ComboBoxModel;
|
---|
7 | import javax.swing.UIManager;
|
---|
8 | import javax.swing.UIManager.LookAndFeelInfo;
|
---|
9 | import javax.swing.event.ListDataListener;
|
---|
10 |
|
---|
11 | import net.oni2.aeinstaller.backend.Settings;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * Comboboxmodel for Look and Feel selection
|
---|
15 | *
|
---|
16 | * @author Christian Illy
|
---|
17 | */
|
---|
18 | public class LaFComboModel implements ComboBoxModel {
|
---|
19 |
|
---|
20 | private Vector<LookAndFeelInfo> items;
|
---|
21 | private HashSet<ListDataListener> listeners;
|
---|
22 | private int selected;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Create a new LaF model
|
---|
26 | */
|
---|
27 | public LaFComboModel() {
|
---|
28 | listeners = new HashSet<ListDataListener>();
|
---|
29 | items = new Vector<LookAndFeelInfo>();
|
---|
30 | for (LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels())
|
---|
31 | items.add(laf);
|
---|
32 |
|
---|
33 |
|
---|
34 | String laf = Settings.getInstance().get("lookandfeel",
|
---|
35 | UIManager.getLookAndFeel().getClass().getName());
|
---|
36 |
|
---|
37 | if (items.size() > 0)
|
---|
38 | selected = 0;
|
---|
39 | else
|
---|
40 | selected = -1;
|
---|
41 |
|
---|
42 | for (int i = 0; i < items.size(); i++) {
|
---|
43 | String iLaF = items.get(i).getClassName();
|
---|
44 | if (iLaF.equals(laf)) {
|
---|
45 | selected = i;
|
---|
46 | break;
|
---|
47 | }
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | @Override
|
---|
52 | public int getSize() {
|
---|
53 | return items.size();
|
---|
54 | }
|
---|
55 |
|
---|
56 | @Override
|
---|
57 | public Object getElementAt(int index) {
|
---|
58 | return items.get(index).getName();
|
---|
59 | }
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Get class name for the selected LaF
|
---|
63 | *
|
---|
64 | * @return LaF class name
|
---|
65 | */
|
---|
66 | public String getSelectedClassName() {
|
---|
67 | return items.get(selected).getClassName();
|
---|
68 | }
|
---|
69 |
|
---|
70 | @Override
|
---|
71 | public void addListDataListener(ListDataListener arg0) {
|
---|
72 | listeners.add(arg0);
|
---|
73 | }
|
---|
74 |
|
---|
75 | @Override
|
---|
76 | public void removeListDataListener(ListDataListener arg0) {
|
---|
77 | listeners.remove(arg0);
|
---|
78 | }
|
---|
79 |
|
---|
80 | @Override
|
---|
81 | public Object getSelectedItem() {
|
---|
82 | if (selected >= 0)
|
---|
83 | return getElementAt(selected);
|
---|
84 | else
|
---|
85 | return null;
|
---|
86 | }
|
---|
87 |
|
---|
88 | @Override
|
---|
89 | public void setSelectedItem(Object anItem) {
|
---|
90 | for (int i = 0; i < items.size(); i++) {
|
---|
91 | if (getElementAt(i).equals(anItem)) {
|
---|
92 | selected = i;
|
---|
93 | return;
|
---|
94 | }
|
---|
95 | }
|
---|
96 | selected = -1;
|
---|
97 | }
|
---|
98 | }
|
---|