1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package org.openoffice.setup.Panel; 25 26 import org.openoffice.setup.InstallData; 27 import org.openoffice.setup.PanelHelper.PanelLabel; 28 import org.openoffice.setup.PanelHelper.PanelTitle; 29 import org.openoffice.setup.ResourceManager; 30 import java.awt.BorderLayout; 31 import java.awt.FlowLayout; 32 import java.awt.GridBagConstraints; 33 import java.awt.GridBagLayout; 34 import java.awt.Insets; 35 import java.awt.event.ActionEvent; 36 import java.awt.event.ActionListener; 37 import java.io.File; 38 import javax.swing.Box; 39 import javax.swing.BoxLayout; 40 import javax.swing.JButton; 41 import javax.swing.JFileChooser; 42 import javax.swing.JPanel; 43 import javax.swing.JTextField; 44 import javax.swing.border.EmptyBorder; 45 46 public class ChooseDirectory extends JPanel implements ActionListener { 47 48 private JFileChooser directoryChooser; 49 private JFileChooser directoryChooserRootdir; 50 private JButton directoryButton; 51 private JButton directoryButtonRootdir; 52 private JTextField directoryField; 53 private JTextField directoryFieldRootdir; 54 private PanelLabel databaseProgress; 55 private PanelTitle titleBox; 56 ChooseDirectory()57 public ChooseDirectory() { 58 59 setLayout(new java.awt.BorderLayout()); 60 setBorder(new EmptyBorder(new Insets(10, 10, 10, 10))); 61 62 String titleText = ResourceManager.getString("String_ChooseDirectory1"); 63 String subtitleText = ResourceManager.getString("String_ChooseDirectory2"); 64 65 titleBox = new PanelTitle(titleText, subtitleText); 66 titleBox.addVerticalStrut(10); 67 add(titleBox, BorderLayout.NORTH); 68 69 Box contentBox = new Box(BoxLayout.Y_AXIS); 70 71 JPanel contentPanel = new JPanel(); 72 contentPanel.setLayout(new GridBagLayout()); 73 74 directoryChooser = new JFileChooser(); 75 directoryChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 76 77 String browseText = ResourceManager.getString("String_ChooseDirectory3"); 78 directoryButton = new JButton(browseText); 79 directoryButton.addActionListener(this); 80 81 directoryField = new JTextField(); 82 83 GridBagConstraints constraints = new GridBagConstraints(); 84 85 constraints.gridx = 0; 86 constraints.gridy = 0; 87 constraints.weightx = 1; 88 constraints.weighty = 0; 89 constraints.fill = GridBagConstraints.HORIZONTAL; 90 91 contentPanel.add(directoryField, constraints); 92 93 constraints.gridx = 1; 94 constraints.gridy = 0; 95 constraints.weightx = 0; 96 constraints.weighty = 0; 97 constraints.fill = GridBagConstraints.HORIZONTAL; 98 99 contentPanel.add(directoryButton, constraints); 100 101 constraints.gridx = 0; 102 constraints.gridy = 1; 103 constraints.weightx = 0; 104 constraints.weighty = 1; 105 constraints.fill = GridBagConstraints.VERTICAL; 106 107 contentPanel.add(new JPanel(), constraints); 108 109 contentBox.add(contentPanel); 110 111 // defining a place for text output 112 databaseProgress = new PanelLabel(""); // planned for database progress 113 contentBox.add(databaseProgress); 114 115 add(contentBox, BorderLayout.CENTER); 116 } 117 setDatabaseText(String s)118 public void setDatabaseText(String s) { 119 databaseProgress.setText(s); 120 } 121 setTitleText(String s)122 public void setTitleText(String s) { 123 titleBox.setTitle(s); 124 } 125 setDirectory(String dir)126 public void setDirectory(String dir) { 127 directoryField.setText(dir); 128 } 129 disableDirectoryField()130 public void disableDirectoryField() { 131 directoryField.setEditable(false) ; 132 } 133 disableBrowseButton()134 public void disableBrowseButton() { 135 directoryButton.setEnabled(false); 136 } 137 enableDirectoryField()138 public void enableDirectoryField() { 139 directoryField.setEditable(true) ; 140 } 141 getDirectory()142 public String getDirectory() { 143 return directoryField.getText(); 144 } 145 setRootDirectory(String dir)146 public void setRootDirectory(String dir) { 147 directoryFieldRootdir.setText(dir); 148 } 149 getRootDirectory()150 public String getRootDirectory() { 151 return directoryFieldRootdir.getText(); 152 } 153 actionPerformed(ActionEvent e)154 public void actionPerformed(ActionEvent e) { 155 156 //Handle open button action. 157 if (e.getSource() == directoryButton) { 158 int ReturnValue = directoryChooser.showOpenDialog(ChooseDirectory.this); 159 160 if (ReturnValue == JFileChooser.APPROVE_OPTION) { 161 File file = directoryChooser.getSelectedFile(); 162 directoryField.setText(file.getAbsolutePath()); 163 } else { 164 // do nothing for now 165 } 166 } 167 168 if (e.getSource() == directoryButtonRootdir) { 169 int ReturnValue = directoryChooserRootdir.showOpenDialog(ChooseDirectory.this); 170 171 if (ReturnValue == JFileChooser.APPROVE_OPTION) { 172 File file = directoryChooserRootdir.getSelectedFile(); 173 directoryFieldRootdir.setText(file.getAbsolutePath()); 174 } else { 175 // do nothing for now 176 } 177 } 178 179 } 180 181 } 182