1 7 package javax.swing.text; 8 9 import java.io.Serializable ; 10 import java.text.ParseException ; 11 import javax.swing.JFormattedTextField ; 12 13 58 public class DefaultFormatterFactory extends JFormattedTextField.AbstractFormatterFactory implements Serializable { 59 63 private JFormattedTextField.AbstractFormatter defaultFormat; 64 65 68 private JFormattedTextField.AbstractFormatter displayFormat; 69 70 73 private JFormattedTextField.AbstractFormatter editFormat; 74 75 79 private JFormattedTextField.AbstractFormatter nullFormat; 80 81 82 public DefaultFormatterFactory() { 83 } 84 85 94 public DefaultFormatterFactory(JFormattedTextField. 95 AbstractFormatter defaultFormat) { 96 this(defaultFormat, null); 97 } 98 99 110 public DefaultFormatterFactory( 111 JFormattedTextField.AbstractFormatter defaultFormat, 112 JFormattedTextField.AbstractFormatter displayFormat) { 113 this(defaultFormat, displayFormat, null); 114 } 115 116 129 public DefaultFormatterFactory( 130 JFormattedTextField.AbstractFormatter defaultFormat, 131 JFormattedTextField.AbstractFormatter displayFormat, 132 JFormattedTextField.AbstractFormatter editFormat) { 133 this(defaultFormat, displayFormat, editFormat, null); 134 } 135 136 151 public DefaultFormatterFactory( 152 JFormattedTextField.AbstractFormatter defaultFormat, 153 JFormattedTextField.AbstractFormatter displayFormat, 154 JFormattedTextField.AbstractFormatter editFormat, 155 JFormattedTextField.AbstractFormatter nullFormat) { 156 this.defaultFormat = defaultFormat; 157 this.displayFormat = displayFormat; 158 this.editFormat = editFormat; 159 this.nullFormat = nullFormat; 160 } 161 162 171 public void setDefaultFormatter(JFormattedTextField.AbstractFormatter atf){ 172 defaultFormat = atf; 173 } 174 175 184 public JFormattedTextField.AbstractFormatter getDefaultFormatter() { 185 return defaultFormat; 186 } 187 188 197 public void setDisplayFormatter(JFormattedTextField.AbstractFormatter atf){ 198 displayFormat = atf; 199 } 200 201 210 public JFormattedTextField.AbstractFormatter getDisplayFormatter() { 211 return displayFormat; 212 } 213 214 223 public void setEditFormatter(JFormattedTextField.AbstractFormatter atf) { 224 editFormat = atf; 225 } 226 227 236 public JFormattedTextField.AbstractFormatter getEditFormatter() { 237 return editFormat; 238 } 239 240 247 public void setNullFormatter(JFormattedTextField.AbstractFormatter atf) { 248 nullFormat = atf; 249 } 250 251 257 public JFormattedTextField.AbstractFormatter getNullFormatter() { 258 return nullFormat; 259 } 260 261 271 public JFormattedTextField.AbstractFormatter getFormatter( 272 JFormattedTextField source) { 273 JFormattedTextField.AbstractFormatter format = null; 274 275 if (source == null) { 276 return null; 277 } 278 Object value = source.getValue(); 279 280 if (value == null) { 281 format = getNullFormatter(); 282 } 283 if (format == null) { 284 if (source.hasFocus()) { 285 format = getEditFormatter(); 286 } 287 else { 288 format = getDisplayFormatter(); 289 } 290 if (format == null) { 291 format = getDefaultFormatter(); 292 } 293 } 294 return format; 295 } 296 } 297 | Popular Tags |