1 21 22 package com.izforge.izpack.panels; 23 24 import java.awt.Dimension ; 25 import java.awt.GridBagConstraints ; 26 import java.awt.GridBagLayout ; 27 import java.awt.Insets ; 28 import java.awt.event.ActionEvent ; 29 import java.awt.event.ActionListener ; 30 import java.io.File ; 31 32 import javax.swing.JButton ; 33 import javax.swing.JFileChooser ; 34 import javax.swing.JPanel ; 35 import javax.swing.JTextField ; 36 37 import com.izforge.izpack.gui.ButtonFactory; 38 import com.izforge.izpack.gui.IzPanelConstraints; 39 import com.izforge.izpack.gui.IzPanelLayout; 40 import com.izforge.izpack.gui.LayoutConstants; 41 import com.izforge.izpack.installer.InstallData; 42 import com.izforge.izpack.installer.IzPanel; 43 import com.izforge.izpack.installer.LayoutHelper; 44 45 56 public class PathSelectionPanel extends JPanel implements ActionListener , LayoutConstants 57 { 58 59 62 private static final long serialVersionUID = 3618700794577105718L; 63 64 65 private JTextField textField; 66 67 68 private JButton browseButton; 69 70 71 private IzPanel parent; 72 73 76 private InstallData idata; 77 78 84 public PathSelectionPanel(IzPanel parent, InstallData idata) 85 { 86 super(); 87 this.parent = parent; 88 this.idata = idata; 89 createLayout(); 90 } 91 92 95 protected void createLayout() 96 { 97 LayoutHelper layoutHelper = new LayoutHelper(this); 103 layoutHelper.startLayout(new IzPanelLayout()); 105 IzPanelConstraints ipc = IzPanelLayout.getDefaultConstraint(TEXT_CONSTRAINT); 107 ipc.setXStretch(1.0); 109 textField = new JTextField (idata.getInstallPath(), 10); 110 textField.addActionListener(this); 111 parent.setInitialFocus(textField); 112 add(textField,ipc); 113 add(IzPanelLayout.createHorizontalFiller(3)); 115 browseButton = ButtonFactory.createButton(parent.getInstallerFrame().langpack 118 .getString("TargetPanel.browse"), parent.getInstallerFrame().icons 119 .getImageIcon("open"), idata.buttonsHColor); 120 browseButton.addActionListener(this); 121 add(browseButton); 122 } 123 124 127 public Dimension getMinimumSize() 128 { 129 Dimension ss = super.getPreferredSize(); 130 Dimension retval = parent.getSize(); 131 retval.height = ss.height; 132 return (retval); 133 } 134 135 140 public void actionPerformed(ActionEvent e) 141 { 142 Object source = e.getSource(); 143 144 if (source == browseButton) 145 { 146 148 JFileChooser fc = new JFileChooser (); 150 fc.setCurrentDirectory(new File (textField.getText())); 151 fc.setMultiSelectionEnabled(false); 152 fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 153 fc.addChoosableFileFilter(fc.getAcceptAllFileFilter()); 154 155 if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) 157 { 158 String path = fc.getSelectedFile().getAbsolutePath(); 159 textField.setText(path); 160 } 161 162 } 163 else 164 { 165 if (parent instanceof ActionListener ) ((ActionListener ) parent).actionPerformed(e); 166 } 167 } 168 169 174 public String getPath() 175 { 176 return (textField.getText()); 177 } 178 179 184 public void setPath(String path) 185 { 186 textField.setText(path); 187 } 188 189 195 public JTextField getPathInputField() 196 { 197 return textField; 198 } 199 200 205 public JButton getBrowseButton() 206 { 207 return browseButton; 208 } 209 210 } 211 | Popular Tags |