KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > pooka > gui > DisplayStyleComboBox


1 package net.suberic.pooka.gui;
2 import java.util.*;
3
4 /**
5  * A ConfigurableComboBox that should remain in sync with the display
6  * style.
7  */

8 public class DisplayStyleComboBox extends net.suberic.util.gui.ConfigurableComboBox {
9   
10   public boolean displayStyle = false;
11   public boolean headerStyle = false;
12
13   /**
14    * This configures the ComboBox using the given buttonID and
15    * VariableBundle.
16    *
17    * As defined in interface net.suberic.util.gui.ConfigurableUI.
18    */

19   public void configureComponent(String JavaDoc key, net.suberic.util.VariableBundle vars) {
20     super.configureComponent(key, vars);
21
22     // set whether this is a header combo, a display combo, or both.
23

24     for (int i = 0; i < getItemCount(); i++) {
25       String JavaDoc cmd = (String JavaDoc) selectionMap.get(getItemAt(i));
26       if (cmd.equalsIgnoreCase("file-open-textdisplay") || cmd.equalsIgnoreCase("file-open-htmldisplay") || cmd.equalsIgnoreCase("file-open-rawdisplay")) {
27     displayStyle = true;
28       } else if (cmd.equalsIgnoreCase("file-open-defaultdisplay") || cmd.equalsIgnoreCase("file-open-fulldisplay")) {
29     headerStyle=true;
30       }
31     }
32
33   }
34
35   /**
36    * Called when either style is updated.
37    */

38   public void styleUpdated(int newDisplayStyle, int newHeaderStyle) {
39     // find out which of the items we have corresponds to the given display
40
// and/or header style.
41

42     for (int i = 0; i < getItemCount(); i++) {
43       String JavaDoc cmd = (String JavaDoc) selectionMap.get(getItemAt(i));
44       if (cmd != null) {
45     javax.swing.Action JavaDoc currentAction = getAction(cmd);
46     while (currentAction instanceof net.suberic.util.thread.ActionWrapper) {
47       currentAction = ((net.suberic.util.thread.ActionWrapper) currentAction).getWrappedAction();
48     }
49     if (currentAction != null && currentAction instanceof MessageProxy.OpenAction) {
50       MessageProxy.OpenAction oa = (MessageProxy.OpenAction) currentAction;
51       if (((displayStyle && (oa.getDisplayModeValue() == newDisplayStyle)) || !displayStyle) && ((headerStyle && (oa.getHeaderModeValue() == newHeaderStyle)) || !headerStyle)) {
52         if (getSelectedIndex() != i) {
53           setSelectedIndex(i);
54         }
55       }
56     }
57       }
58     }
59   }
60
61 }
62
Popular Tags