source: release-kits/lirk3/bin/ant-installer/src/org/tp23/antinstaller/renderer/swing/DirectoryInputRenderer.java@ 14982

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

initial import of LiRK3

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