KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > rero > gui > windows > ListBoxOptions


1 package rero.gui.windows;
2
3 import java.awt.*;
4 import javax.swing.*;
5
6 import rero.config.*;
7
8 public class ListBoxOptions implements ClientStateListener
9 {
10    protected JComponent container;
11    protected JComponent listbox;
12
13    public ListBoxOptions(JComponent c, JComponent l)
14    {
15       container = c;
16       listbox = l;
17
18       ClientState.getClientState().addClientStateListener("listbox.position", this);
19       ClientState.getClientState().addClientStateListener("listbox.enabled", this);
20
21       rehash();
22    }
23
24    public void rehash()
25    {
26       synchronized (listbox)
27       {
28          container.remove(listbox);
29
30          boolean enabled = ClientState.getClientState().isOption("listbox.enabled", true);
31          int position = ClientState.getClientState().getInteger("listbox.position", 1); // default to right...
32

33          if (enabled)
34          {
35             if (position == 0)
36             {
37                container.add(listbox, BorderLayout.WEST);
38             }
39             else
40             {
41                container.add(listbox, BorderLayout.EAST);
42             }
43          }
44       }
45    }
46
47    public void propertyChanged(String JavaDoc key, String JavaDoc value)
48    {
49       SwingUtilities.invokeLater(new Runnable JavaDoc()
50       {
51          public void run()
52          {
53             rehash();
54             container.revalidate();
55          }
56       });
57    }
58 }
59
60
Popular Tags