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

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

HCI changes to the installer

File size: 4.7 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
87 JPanel browseButtonWrapper = new JPanel( new BorderLayout() );
88 browseButtonWrapper.add( browseButton, BorderLayout.EAST );
89 browsePanel.add(browseButtonWrapper, BorderLayout.SOUTH);
90 browseButton.addActionListener(new ActionListener() {
91 public void actionPerformed(ActionEvent e) {
92 File selectedFile = null;
93 if(chooser==null){
94 chooser = new DefaultingDirectoryChooser(createMode);
95 chooser.setFileHidingEnabled(false);
96 }
97
98 //PR 1468823 - if input is cleared, dialogue won't be displayed
99 String dirPath = jTextField.getText();
100 if( dirPath == null ) {
101 dirPath = EMPTY_STRING;
102 }
103 dirPath = dirPath.trim();
104
105 if( dirPath.length() == 0 ) {
106 dirPath = inputField.getDefaultValue(true);
107 jTextField.setText(dirPath);
108 }
109 chooser.setDefaultDirectory(new File(dirPath));
110
111 int returnVal = chooser.showDialog(parent, org.tp23.antinstaller.Installer.langPack.getString("selectFolder") );
112 if (returnVal == JFileChooser.APPROVE_OPTION) {
113 selectedFile = chooser.getSelectedFile();
114 }
115 if (selectedFile != null) {
116 jTextField.setText(selectedFile.getAbsolutePath());
117 inputField.setValue(selectedFile.getAbsolutePath());
118 inputField.setEditted(true);
119 }
120 }
121 });
122 browseButton.setText(org.tp23.antinstaller.Installer.langPack.getString("browseDotDotDot"));
123 browseButton.setPreferredSize(new Dimension(150, SizeConstants.FIELD_HEIGHT));
124
125 jTextField.addActionListener(new ActionListener() {
126 public void actionPerformed(ActionEvent e) {
127 updateInputField();
128 }
129 });
130
131 }
132 public int addSelf(JPanel content,GBCF cf, int row, boolean overflow) {
133 FlowLayout l = new FlowLayout(FlowLayout.LEFT);
134 JPanel p = new JPanel(l);
135 p.add(fieldLabel);
136 content.add(p);
137 content.add(browsePanel);
138 if(overflow){
139 jTextField.setOverflow(SizeConstants.OVERFLOW_SHORT_FIELD_SIZE);
140 }
141 return ++row;
142 }
143
144
145 /**
146 * renderError
147 */
148 public void renderError() {
149 jTextField.requestFocus();
150 }
151}
Note: See TracBrowser for help on using the repository browser.