source: release-kits/shared/ant-installer/src/org/tp23/antinstaller/renderer/swing/DateInputRenderer.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: 2.9 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;
26
27import org.tp23.antinstaller.input.DateInput;
28import org.tp23.antinstaller.input.OutputField;
29import org.tp23.antinstaller.renderer.MessageRenderer;
30import org.tp23.gui.GBCF;
31
32public class DateInputRenderer
33 extends SwingOutputFieldRenderer {
34
35 protected DateInput inputField;
36
37 protected AILabel fieldLabel = new AILabel();
38 protected AITextfield jTextField = new AITextfield();
39 protected Color origFore;
40
41 public DateInputRenderer() {
42 origFore = jTextField.getForeground();
43 }
44
45 public void initComponent(JPanel parent){
46 try {
47 jbInit();
48 }
49 catch(Exception e) {
50 e.printStackTrace();
51 }
52 }
53
54 public void setOutputField(OutputField inputField) {
55 this.inputField = (DateInput)inputField;
56 this.inputField.setValue(this.inputField.getDefaultValue());
57 }
58 public void updateInputField(){
59 inputField.setValue(jTextField.getText());
60 }
61 public void updateDefaultValue(){
62 if(!inputField.isEditted())jTextField.setText(inputField.getDefaultValue());
63 }
64
65 private void jbInit() throws Exception {
66 fieldLabel.setText(inputField.getDisplayText());
67 jTextField.setText(inputField.getDefaultValue());
68 jTextField.addKeyListener(new KeyAdapter() {
69 public void keyTyped(KeyEvent e) {
70 if(e.getKeyChar() != '\t'){
71 inputField.setEditted(true);
72 }
73 }
74 });
75 jTextField.addFocusListener(new FocusAdapter() {
76 public void focusLost(FocusEvent fe){
77 jTextField.setForeground(origFore);
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
91 /**
92 * renderError
93 */
94 public void renderError() {
95 MessageRenderer mr = ctx.getMessageRenderer();
96 mr.printMessage(org.tp23.antinstaller.Installer.langPack.getString("notCorrectFormat") + "\n\n " + inputField.getDateFormat());
97 //fixed BUG1295944 mr.printMessage("The field is not of the correct format\n\n "+inputField.getDateFormat());
98 this.jTextField.requestFocus();
99 this.jTextField.setForeground(Color.red);
100 }
101
102}
Note: See TracBrowser for help on using the repository browser.