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

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

fixed page title bug once and for all (touch wood)

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