source: release-kits/shared/ant-installer/src/org/tp23/antinstaller/renderer/swing/ValidatedTextInputRenderer.java@ 17514

Last change on this file since 17514 was 17514, checked in by oranfry, 16 years ago

changes to the way ant-installer loads and reloads the language packs, and a new attribute to the select input which triggers it to change the language to the input value

File size: 3.4 KB
Line 
1/*
2 * Copyright 2005 Paul Hinds
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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 */
16package org.tp23.antinstaller.renderer.swing;
17
18import java.awt.Color;
19import java.awt.event.FocusAdapter;
20import java.awt.event.FocusEvent;
21import java.awt.event.KeyAdapter;
22import java.awt.event.KeyEvent;
23import java.util.ResourceBundle;
24
25import javax.swing.JPanel;
26import javax.swing.JTextField;
27
28import org.tp23.antinstaller.input.OutputField;
29import org.tp23.antinstaller.input.ValidatedTextInput;
30import org.tp23.antinstaller.renderer.MessageRenderer;
31import org.tp23.gui.GBCF;
32
33public class ValidatedTextInputRenderer extends SwingOutputFieldRenderer {
34
35 protected ValidatedTextInput inputField;
36 protected AILabel fieldLabel = new AILabel();
37 protected JTextField jTextField = new AITextfield();
38 protected Color origFore;
39
40 public ValidatedTextInputRenderer() {
41 origFore = jTextField.getForeground();
42 }
43
44 public void initComponent(JPanel parent) {
45 try {
46 jbInit();
47 } catch (Exception e) {
48 ctx.log(e.getMessage());
49 if (ctx.getInstaller().isVerbose()) {
50 ctx.log(e);
51 }
52
53 }
54 }
55
56 public void setOutputField(OutputField inputField) {
57 this.inputField = (ValidatedTextInput) inputField;
58 this.inputField.setValue(this.inputField.getDefaultValue());
59 }
60
61 public void updateInputField() {
62 inputField.setValue(jTextField.getText());
63 }
64
65 public void updateDefaultValue() {
66 if (!inputField.isEditted()) {
67 jTextField.setText(inputField.getDefaultValue());
68 }
69 }
70
71 private void jbInit() throws Exception {
72 fieldLabel.setText(inputField.getDisplayText());
73 jTextField.setText(inputField.getDefaultValue());
74
75 jTextField.addFocusListener(new FocusAdapter() {
76 public void focusLost(FocusEvent fe) {
77 jTextField.setForeground(origFore);
78 }
79 });
80 jTextField.addKeyListener(new KeyAdapter() {
81 public void keyTyped(KeyEvent e) {
82 if (e.getKeyChar() != '\t') {
83 inputField.setEditted(true);
84 }
85 }
86 });
87 }
88
89 public int addSelf(JPanel content, GBCF cf, int row, boolean overflow) {
90 content.add(fieldLabel, cf.getCell(row, 0));
91 content.add(jTextField, cf.getCell(row, 1));
92 if (overflow) {
93 ((AITextfield) jTextField).setOverflow(SizeConstants.OVERFLOW_FIELD_SIZE);
94 }
95 return ++row;
96 }
97
98 /**
99 * renderError
100 */
101 public void renderError() {
102 MessageRenderer mr = ctx.getMessageRenderer();
103 mr.printMessage(org.tp23.antinstaller.Installer.langPack.getString("notCorrectFormat") + "\n\n e.g. "
104 + inputField.getDefaultValue());
105 this.jTextField.requestFocus();
106 this.jTextField.setForeground(Color.red);
107 }
108
109}
Note: See TracBrowser for help on using the repository browser.