1 14 package wingset; 15 16 import org.wings.*; 17 import org.wings.text.SNumberFormatter; 18 import org.wings.event.SDocumentListener; 19 import org.wings.event.SDocumentEvent; 20 21 import java.awt.event.ActionEvent ; 22 import java.awt.event.ActionListener ; 23 import java.text.NumberFormat ; 24 25 29 public class TextComponentExample 30 extends WingSetPane 31 { 32 private ComponentControls controls; 33 private SLabel documentEvent = new SLabel(); 34 private SLabel actionEvent = new SLabel(); 35 36 SDocumentListener documentListener = new SDocumentListener() { 37 public void insertUpdate(SDocumentEvent e) { 38 documentEvent.setText(((STextComponent) e.getSource()).getName()); 39 actionEvent.setText("button not pressed"); 40 } 41 42 public void removeUpdate(SDocumentEvent e) { 43 documentEvent.setText(((STextComponent) e.getSource()).getName()); 44 actionEvent.setText("button not pressed"); 45 } 46 47 public void changedUpdate(SDocumentEvent e) { 48 if (e.getSource() instanceof STextComponent) { 49 STextComponent component = (STextComponent) e.getSource(); 50 documentEvent.setText(((STextComponent) e.getSource()).getName()); 51 } 52 else { 53 log.debug("e.getSource().getClass() = " + e.getSource().getClass()); 54 } 55 actionEvent.setText("button not pressed"); 56 } 57 }; 58 59 public SComponent createExample() { 60 controls = new ComponentControls(); 61 62 SGridLayout gridLayout = new SGridLayout(2); 63 gridLayout.setHgap(4); 64 gridLayout.setVgap(4); 65 SPanel p = new SPanel(gridLayout); 66 67 SLabel l = new SLabel("STextField: "); 68 l.setVerticalAlignment(SConstants.TOP); 69 p.add(l); 70 STextField textField = new STextField(); 71 textField.setName("textfield"); 72 textField.addDocumentListener(documentListener); 73 p.add(textField); 74 75 l = new SLabel("STextArea: "); 76 l.setVerticalAlignment(SConstants.TOP); 77 p.add(l); 78 STextArea textArea = new STextArea(); 79 textArea.setName("textarea"); 80 textArea.addDocumentListener(documentListener); 81 p.add(textArea); 82 83 l = new SLabel("SFormattedTextField: "); 84 l.setVerticalAlignment(SConstants.TOP); 85 p.add(l); 86 SNumberFormatter formatter = new SNumberFormatter(NumberFormat.getNumberInstance(getSession().getLocale())); 87 SFormattedTextField formattedTextField = new SFormattedTextField(formatter); 88 formattedTextField.setName("formattedTextField"); 89 formattedTextField.addDocumentListener(documentListener); 90 p.add(formattedTextField); 91 92 p.add(new SLabel("DocumentEvent: ")); 93 p.add(documentEvent); 94 95 SButton button = new SButton("Submit"); 96 p.add(button); 97 p.add(actionEvent); 98 99 button.addActionListener(new ActionListener () { 100 public void actionPerformed(ActionEvent e) { 101 actionEvent.setText("Button pressed"); 102 } 103 }); 104 105 SForm f = new SForm(new SBorderLayout()); 106 f.addActionListener(new ActionListener () { 107 public void actionPerformed(ActionEvent e) { 108 actionEvent.setText(actionEvent.getText() + " + form event"); 109 } 110 }); 111 112 controls.addSizable(textField); 113 controls.addSizable(textArea); 114 controls.addSizable(formattedTextField); 115 116 f.add(controls, SBorderLayout.NORTH); 117 f.add(p, SBorderLayout.CENTER); 118 return f; 119 } 120 } 121 122 123 | Popular Tags |