source: release-kits/shared/ant-installer/src/org/tp23/antinstaller/renderer/swing/DirectoryInputRenderer.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: 4.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.BorderLayout;
19import java.awt.FlowLayout;
20import javax.swing.BoxLayout;
21import java.awt.Dimension;
22import java.awt.event.ActionEvent;
23import java.awt.event.ActionListener;
24import java.awt.Insets;
25import java.io.File;
26import java.util.ResourceBundle;
27
28import javax.swing.JFileChooser;
29import javax.swing.JPanel;
30import javax.swing.JLabel;
31
32import org.tp23.antinstaller.input.DirectoryInput;
33import org.tp23.antinstaller.input.OutputField;
34import org.tp23.gui.GBCF;
35import org.tp23.gui.widget.DefaultingDirectoryChooser;
36
37public class DirectoryInputRenderer
38 extends SwingOutputFieldRenderer {
39
40 private static final String EMPTY_STRING = "";
41 protected DirectoryInput inputField;
42 private boolean createMode;
43 private DefaultingDirectoryChooser chooser = null;
44
45 protected JLabel fieldLabel = new AILabel();
46 protected AIShortTextField jTextField = new AIShortTextField();
47 protected AIButton browseButton = new AIButton();
48 protected JPanel browsePanel = new JPanel();
49 private JPanel parent;
50
51 public DirectoryInputRenderer() {
52 }
53 public void initComponent(JPanel parent){
54 this.parent = parent;
55 try {
56 jbInit();
57 }
58 catch(Exception e) {
59 e.printStackTrace();
60 }
61 }
62
63 public void setOutputField(OutputField inputField) {
64 this.inputField = (DirectoryInput)inputField;
65 this.inputField.setValue(this.inputField.getDefaultValue(true));
66 this.createMode = OutputField.isTrue(this.inputField.getCreate());
67
68 }
69 public void updateInputField(){
70 if( !inputField.getDefaultValue(true).equals(jTextField.getText()) ){
71 inputField.setEditted(true);
72 }
73 inputField.setValue(jTextField.getText());
74 }
75 public void updateDefaultValue(){
76 if(!inputField.isEditted())jTextField.setText(inputField.getDefaultValue(true));
77 }
78
79 private void jbInit() throws Exception {
80 BorderLayout bl = new BorderLayout();
81 //bl.setHgap(3);
82 browsePanel.setLayout(bl);
83 fieldLabel.setText(inputField.getDisplayText());
84 jTextField.setText(inputField.getDefaultValue(true));
85 browsePanel.add(jTextField, BorderLayout.CENTER);
86 browsePanel.add(browseButton, BorderLayout.EAST);
87 browseButton.addActionListener(new ActionListener() {
88 public void actionPerformed(ActionEvent e) {
89 File selectedFile = null;
90 if(chooser==null){
91 chooser = new DefaultingDirectoryChooser(createMode);
92 chooser.setFileHidingEnabled(false);
93 }
94
95 //PR 1468823 - if input is cleared, dialogue won't be displayed
96 String dirPath = jTextField.getText();
97 if( dirPath == null ) {
98 dirPath = EMPTY_STRING;
99 }
100 dirPath = dirPath.trim();
101
102 if( dirPath.length() == 0 ) {
103 dirPath = inputField.getDefaultValue(true);
104 jTextField.setText(dirPath);
105 }
106 chooser.setDefaultDirectory(new File(dirPath));
107
108 int returnVal = chooser.showDialog(parent, e.getActionCommand());
109 if (returnVal == JFileChooser.APPROVE_OPTION) {
110 selectedFile = chooser.getSelectedFile();
111 }
112 if (selectedFile != null) {
113 jTextField.setText(selectedFile.getAbsolutePath());
114 inputField.setValue(selectedFile.getAbsolutePath());
115 inputField.setEditted(true);
116 }
117 }
118 });
119 browseButton.setText(org.tp23.antinstaller.Installer.langPack.getString("selectFolder"));
120 browseButton.setPreferredSize(new Dimension(150, SizeConstants.FIELD_HEIGHT));
121
122 jTextField.addActionListener(new ActionListener() {
123 public void actionPerformed(ActionEvent e) {
124 updateInputField();
125 }
126 });
127
128 }
129 public int addSelf(JPanel content,GBCF cf, int row, boolean overflow) {
130 FlowLayout l = new FlowLayout(FlowLayout.LEFT);
131 JPanel p = new JPanel(l);
132 p.add(fieldLabel);
133 content.add(p);
134 content.add(browsePanel);
135 if(overflow){
136 jTextField.setOverflow(SizeConstants.OVERFLOW_SHORT_FIELD_SIZE);
137 }
138 return ++row;
139 }
140
141
142 /**
143 * renderError
144 */
145 public void renderError() {
146 jTextField.requestFocus();
147 }
148}
Note: See TracBrowser for help on using the repository browser.