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

Last change on this file since 19200 was 19200, checked in by oranfry, 15 years ago

language and ant-installer changes for the installer pages about the admin pages

File size: 3.5 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 java.awt.Dimension;
26import java.awt.Insets;
27import javax.swing.JPanel;
28import javax.swing.JTextField;
29import java.awt.FlowLayout;
30import java.awt.GridLayout;
31import java.awt.BorderLayout;
32
33
34import org.tp23.antinstaller.input.OutputField;
35import org.tp23.antinstaller.input.ValidatedTextInput;
36import org.tp23.antinstaller.renderer.MessageRenderer;
37import org.tp23.gui.GBCF;
38
39public class ValidatedTextInputRenderer extends SwingOutputFieldRenderer {
40
41 protected ValidatedTextInput inputField;
42 protected AILabel fieldLabel = new AILabel();
43 protected JTextField jTextField = new AITextfield();
44 protected Color origFore;
45
46 public ValidatedTextInputRenderer() {
47 origFore = jTextField.getForeground();
48 }
49
50 public void initComponent(JPanel parent) {
51 try {
52 jbInit();
53 } catch (Exception e) {
54 ctx.log(e.getMessage());
55 if (ctx.getInstaller().isVerbose()) {
56 ctx.log(e);
57 }
58
59 }
60 }
61
62 public void setOutputField(OutputField inputField) {
63 this.inputField = (ValidatedTextInput) inputField;
64 this.inputField.setValue(this.inputField.getDefaultValue());
65 }
66
67 public void updateInputField() {
68 inputField.setValue(jTextField.getText());
69 }
70
71 public void updateDefaultValue() {
72 if (!inputField.isEditted()) {
73 jTextField.setText(inputField.getDefaultValue());
74 }
75 }
76
77 private void jbInit() throws Exception {
78 fieldLabel.setText(inputField.getDisplayText());
79 jTextField.setText(inputField.getDefaultValue());
80
81 jTextField.addFocusListener(new FocusAdapter() {
82 public void focusLost(FocusEvent fe) {
83 jTextField.setForeground(origFore);
84 }
85 });
86 jTextField.addKeyListener(new KeyAdapter() {
87 public void keyTyped(KeyEvent e) {
88 if (e.getKeyChar() != '\t') {
89 inputField.setEditted(true);
90 }
91 }
92 });
93 }
94
95 public int addSelf(JPanel content, GBCF cf, int row, boolean overflow) {
96
97 JPanel p;
98
99 //p = new JPanel(new FlowLayout(FlowLayout.LEFT));
100 BorderLayout l = new BorderLayout();
101 p = new JPanel(l);
102 p.add( fieldLabel, BorderLayout.WEST );
103 p.add( jTextField, BorderLayout.CENTER );
104 content.add(p);
105
106 p = new JPanel();
107 p.setMinimumSize( new Dimension(0,1) );
108 content.add(p);
109
110 return ++row;
111 }
112
113 /**
114 * renderError
115 */
116 public void renderError() {
117 MessageRenderer mr = ctx.getMessageRenderer();
118 mr.printMessage( org.tp23.antinstaller.Installer.langPack.getString("notCorrectFormat") );
119 this.jTextField.requestFocus();
120 this.jTextField.setForeground(Color.red);
121 }
122
123}
Note: See TracBrowser for help on using the repository browser.