1
16package org.tp23.antinstaller.renderer.swing;
17
18import java.awt.event.ActionEvent;
19import java.awt.event.ActionListener;
20import java.awt.event.KeyAdapter;
21import java.awt.event.KeyEvent;
22
23import javax.swing.JPanel;
24
25import org.tp23.antinstaller.input.OutputField;
26import org.tp23.antinstaller.input.UnvalidatedTextInput;
27import org.tp23.gui.GBCF;
28
29public class UnvalidatedTextInputRenderer
30 extends SwingOutputFieldRenderer {
31
32 protected UnvalidatedTextInput inputField;
33
34 protected AILabel fieldLabel = new AILabel();
35 protected AITextfield jTextField = new AITextfield();
36
37 public UnvalidatedTextInputRenderer() {
38 }
39
40 public void initComponent(JPanel parent){
41 try {
42 jbInit();
43 }
44 catch(Exception e) {
45 ctx.log(e.getMessage());
46 if(ctx.getInstaller().isVerbose()) {
47 ctx.log(e);
48 }
49
50 }
51 }
52
53 public void setOutputField(OutputField inputField) {
54 this.inputField=(UnvalidatedTextInput)inputField;
55 this.inputField.setValue(this.inputField.getDefaultValue());
56 }
57 public void updateInputField(){
58 inputField.setValue(jTextField.getText());
59 }
60 public void updateDefaultValue(){
61 if(!inputField.isEditted())jTextField.setText(inputField.getDefaultValue());
62 }
63
64 private void jbInit() throws Exception {
65 fieldLabel.setText(inputField.getDisplayText());
66 jTextField.setText(inputField.getDefaultValue());
67 jTextField.addActionListener(new ActionListener() {
68 public void actionPerformed(ActionEvent e) {
69 updateInputField();
70 }
71 });
72 jTextField.addKeyListener(new KeyAdapter() {
73 public void keyTyped(KeyEvent e) {
74 if (e.getKeyChar() != '\t') {
75 inputField.setEditted(true);
76 }
77 }
78 });
79
80 }
81 public int addSelf(JPanel content,GBCF cf, int row,boolean overflow) {
82 content.add(fieldLabel,cf.getCell(row,0));
83 content.add(jTextField,cf.getCell(row,1));
84 if(overflow){
85 jTextField.setOverflow(SizeConstants.OVERFLOW_FIELD_SIZE);
86 }
87 return ++row;
88 }
89
90
93 public void renderError() {
94 }
95}
96