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.Color;
19: import java.awt.event.KeyAdapter;
20: import java.awt.event.KeyEvent;
21:
22: import javax.swing.JPanel;
23:
24: import org.tp23.antinstaller.renderer.AIResourceBundle;
25: import org.tp23.antinstaller.renderer.MessageRenderer;
26: import org.tp23.gui.GBCF;
27:
28: public class PasswordTextInputRenderer extends
29: ValidatedTextInputRenderer {
30:
31: private static final AIResourceBundle res = new AIResourceBundle();
32:
33: public PasswordTextInputRenderer() {
34: this .jTextField = new AIPasswordField();
35: origFore = jTextField.getForeground(); // this is lazy there must be a way to shift this line of code to the superclass (is it worth it)
36: }
37:
38: public void renderError() {
39: MessageRenderer mr = ctx.getMessageRenderer();
40: mr.printMessage(getErrorMessage());
41: // fixed BUG:1295944 mr.printMessage("The password is not of the correct format\n\n e.g. "+inputField.getDefaultValue());
42: this .jTextField.requestFocus();
43: this .jTextField.setForeground(Color.red);
44: jTextField.addKeyListener(new KeyAdapter() {
45: public void keyTyped(KeyEvent e) {
46: if (e.getKeyChar() != '\t') {
47: inputField.setEditted(true);
48: }
49: }
50: });
51: }
52:
53: public int addSelf(JPanel content, GBCF cf, int row,
54: boolean overflow) {
55: content.add(fieldLabel, cf.getCell(row, 0));
56: content.add(jTextField, cf.getCell(row, 1));
57: if (overflow) {
58: ((AIPasswordField) jTextField)
59: .setOverflow(SizeConstants.OVERFLOW_FIELD_SIZE);
60: }
61: return ++row;
62: }
63:
64: protected String getErrorMessage() {
65: return res.getString("not.correct.password.format")
66: + "\n\n e.g. " + inputField.getDefaultValue();
67: }
68:
69: }
|