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 | Vector<LookAndFeelInfo> items;
|
---|
21 | HashSet<ListDataListener> listeners;
|
---|
22 | 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 | String laf = Settings.getInstance().get("lookandfeel",
|
---|
34 | UIManager.getSystemLookAndFeelClassName());
|
---|
35 |
|
---|
36 | if (items.size() > 0)
|
---|
37 | selected = 0;
|
---|
38 | else
|
---|
39 | selected = -1;
|
---|
40 |
|
---|
41 | for (int i = 0; i < items.size(); i++) {
|
---|
42 | String iLaF = items.get(i).getClassName();
|
---|
43 | if (iLaF.equals(laf)) {
|
---|
44 | selected = i;
|
---|
45 | break;
|
---|
46 | }
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override
|
---|
51 | public int getSize() {
|
---|
52 | return items.size();
|
---|
53 | }
|
---|
54 |
|
---|
55 | @Override
|
---|
56 | public Object getElementAt(int index) {
|
---|
57 | return items.get(index).getName();
|
---|
58 | }
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * Get class name for the selected LaF
|
---|
62 | *
|
---|
63 | * @return LaF class name
|
---|
64 | */
|
---|
65 | public String getSelectedClassName() {
|
---|
66 | return items.get(selected).getClassName();
|
---|
67 | }
|
---|
68 |
|
---|
69 | @Override
|
---|
70 | public void addListDataListener(ListDataListener arg0) {
|
---|
71 | listeners.add(arg0);
|
---|
72 | }
|
---|
73 |
|
---|
74 | @Override
|
---|
75 | public void removeListDataListener(ListDataListener arg0) {
|
---|
76 | listeners.remove(arg0);
|
---|
77 | }
|
---|
78 |
|
---|
79 | @Override
|
---|
80 | public Object getSelectedItem() {
|
---|
81 | if (selected >= 0)
|
---|
82 | return getElementAt(selected);
|
---|
83 | else
|
---|
84 | return null;
|
---|
85 | }
|
---|
86 |
|
---|
87 | @Override
|
---|
88 | public void setSelectedItem(Object anItem) {
|
---|
89 | for (int i = 0; i < items.size(); i++) {
|
---|
90 | if (getElementAt(i).equals(anItem)) {
|
---|
91 | selected = i;
|
---|
92 | return;
|
---|
93 | }
|
---|
94 | }
|
---|
95 | selected = -1;
|
---|
96 | }
|
---|
97 | }
|
---|