source: AE/installer2/src/net/oni2/aeinstaller/gui/settings/LaFComboModel.java@ 591

Last change on this file since 591 was 591, checked in by alloc, 12 years ago

AEI2-import

File size: 1.9 KB
RevLine 
[591]1package net.oni2.aeinstaller.gui.settings;
2
3import java.util.HashSet;
4import java.util.Vector;
5
6import javax.swing.ComboBoxModel;
7import javax.swing.UIManager;
8import javax.swing.UIManager.LookAndFeelInfo;
9import javax.swing.event.ListDataListener;
10
11import net.oni2.aeinstaller.backend.Settings;
12
13/**
14 * Comboboxmodel for Look and Feel selection
15 *
16 * @author Christian Illy
17 */
18public 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}
Note: See TracBrowser for help on using the repository browser.