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

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

Lots of changes to the installer. Now only look in LanguagePack resource bundle for strings.

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