1 30 31 32 package org.hsqldb.util; 33 34 import java.util.Vector ; 35 import java.awt.Choice ; 36 import java.awt.Color ; 37 38 45 46 public class ZaurusChoice extends Choice implements ZaurusComponent { 54 55 private static final int MaxLenInZChoice = 15; 56 Vector values; 57 int countChanges; 58 59 public ZaurusChoice() { 60 61 super(); 62 63 values = new Vector (20); 64 countChanges = 0; 65 } 66 67 public void add(String item, String value) { 69 70 int maxChar = MaxLenInZChoice; 71 72 if (item.length() < MaxLenInZChoice) { 73 maxChar = item.length(); 74 } 75 76 super.add(item.substring(0, maxChar)); 77 values.addElement(value); 78 } 79 80 public void clearChanges() { 81 countChanges = 0; 82 } 83 84 public void clearContent() { 85 super.select(0); 86 } 87 88 public String getContent() { 89 return (String ) values.elementAt(super.getSelectedIndex()); 90 } 91 92 public boolean hasChanged() { 93 return countChanges > 0; 94 } 95 96 public void requestFocus() { 97 super.requestFocus(); 98 } 99 100 public void setChanged() { 101 countChanges++; 102 } 103 104 public void setContent(String s) { 106 super.select(this.findValue(s)); 107 } 108 109 public void setEditable(boolean b) { 110 111 super.setEnabled(b); 112 113 if (b) { 114 super.setBackground(Color.white); 115 } else { 116 super.setBackground(Color.lightGray); 117 } } 119 120 private int findValue(String s) { 122 123 for (int i = 0; i < values.size(); i++) { 124 if (s.equals(values.elementAt(i))) { 125 return i; 126 } } 129 return -1; 130 } 131 } 132 | Popular Tags |