1 14 package org.wings; 15 16 import org.wings.plaf.TextFieldCG; 17 18 import javax.swing.event.EventListenerList ; 19 import java.awt.event.ActionEvent ; 20 import java.awt.event.ActionListener ; 21 22 26 public class STextField 27 extends STextComponent { 28 29 32 protected int columns = 12; 33 34 37 protected int maxColumns = -1; 38 39 42 protected String actionCommand; 43 44 private boolean firingActionEvent = false; 46 47 public STextField() { 48 } 49 50 public STextField(String text) { 51 super(text); 52 } 53 54 public void setColumns(int c) { 55 int oldColumns = columns; 56 columns = c; 57 if (columns != oldColumns) 58 reload(); 59 } 60 61 public int getColumns() { 62 return columns; 63 } 64 65 public void setMaxColumns(int mc) { 66 int oldMaxColumns = maxColumns; 67 maxColumns = mc; 68 if (maxColumns != oldMaxColumns) 69 reload(); 70 } 71 72 public int getMaxColumns() { 73 return maxColumns; 74 } 75 76 public void setCG(TextFieldCG cg) { 77 super.setCG(cg); 78 } 79 80 89 public void setActionCommand(String command) { 90 actionCommand = command; 91 } 92 93 100 public String getActionCommand() { 101 if (actionCommand == null) 102 return getText(); 103 return actionCommand; 104 } 105 106 111 public void addActionListener(ActionListener listener) { 112 addEventListener(ActionListener .class, listener); 113 } 114 115 118 public void removeActionListener(ActionListener listener) { 119 removeEventListener(ActionListener .class, listener); 120 } 121 122 129 public ActionListener [] getActionListeners() { 130 return (ActionListener []) (getListeners(ActionListener .class)); 131 } 132 133 138 protected void fireActionPerformed(ActionEvent event) { 139 Object [] listeners = getListenerList(); 141 ActionEvent e = null; 142 for (int i = listeners.length - 2; i >= 0; i -= 2) { 145 if (listeners[i] == ActionListener .class) { 146 if (e == null) { 147 String actionCommand = event.getActionCommand(); 148 if (actionCommand == null) { 149 actionCommand = getActionCommand(); 150 } 151 e = new ActionEvent (this, 152 ActionEvent.ACTION_PERFORMED, 153 actionCommand, 154 event.getWhen(), 155 event.getModifiers()); 156 } 157 ((ActionListener ) listeners[i + 1]).actionPerformed(e); 158 } 159 } 160 } 161 162 168 protected void fireActionEvent() { 169 if (!firingActionEvent) { 170 firingActionEvent = true; 172 173 ActionEvent e = null; 174 175 Object [] listeners = getListenerList(); 177 for (int i = listeners.length - 2; i >= 0; i -= 2) { 180 if (listeners[i] == ActionListener .class) { 181 if (e == null) 182 e = new ActionEvent (this, ActionEvent.ACTION_PERFORMED, 183 getActionCommand()); 184 ((ActionListener ) listeners[i + 1]).actionPerformed(e); 185 } 186 } 187 firingActionEvent = false; 188 } 189 } 190 191 public void fireFinalEvents() { 192 super.fireFinalEvents(); 193 fireActionEvent(); 194 } 195 } 196 197 198 | Popular Tags |