01: /*
02: * Copyright 2005 Paul Hinds
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.tp23.antinstaller.renderer.swing;
17:
18: import java.awt.event.ActionEvent;
19: import java.awt.event.ActionListener;
20: import java.awt.event.KeyAdapter;
21: import java.awt.event.KeyEvent;
22:
23: import javax.swing.JPanel;
24:
25: import org.tp23.antinstaller.input.OutputField;
26: import org.tp23.antinstaller.input.UnvalidatedTextInput;
27: import org.tp23.gui.GBCF;
28:
29: public class UnvalidatedTextInputRenderer extends
30: 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: } catch (Exception e) {
44: ctx.log(e.getMessage());
45: if (ctx.getInstaller().isVerbose()) {
46: ctx.log(e);
47: }
48:
49: }
50: }
51:
52: public void setOutputField(OutputField inputField) {
53: this .inputField = (UnvalidatedTextInput) inputField;
54: this .inputField.setValue(this .inputField.getDefaultValue());
55: }
56:
57: public void updateInputField() {
58: inputField.setValue(jTextField.getText());
59: }
60:
61: public void updateDefaultValue() {
62: if (!inputField.isEditted())
63: jTextField.setText(inputField.getDefaultValue());
64: }
65:
66: private void jbInit() throws Exception {
67: fieldLabel.setText(inputField.getDisplayText());
68: jTextField.setText(inputField.getDefaultValue());
69: jTextField.addActionListener(new ActionListener() {
70: public void actionPerformed(ActionEvent e) {
71: updateInputField();
72: }
73: });
74: jTextField.addKeyListener(new KeyAdapter() {
75: public void keyTyped(KeyEvent e) {
76: if (e.getKeyChar() != '\t') {
77: inputField.setEditted(true);
78: }
79: }
80: });
81:
82: }
83:
84: public int addSelf(JPanel content, GBCF cf, int row,
85: boolean overflow) {
86: content.add(fieldLabel, cf.getCell(row, 0));
87: content.add(jTextField, cf.getCell(row, 1));
88: if (overflow) {
89: jTextField.setOverflow(SizeConstants.OVERFLOW_FIELD_SIZE);
90: }
91: return ++row;
92: }
93:
94: /**
95: * renderError
96: */
97: public void renderError() {
98: }
99: }
|