📄 pathselect.java
字号:
package net.aetherial.gis.publicuse.frame;
import javax.swing.JPanel;
import javax.swing.JFrame;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import net.aetherial.gis.surface.ItemValue;
import javax.swing.JFileChooser;
import java.io.File;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Component;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2004</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class PathSelect
extends JPanel {
public PathSelect() {
try {
jbInit();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
public PathSelect(Component parent) {
this();
this.parent = parent;
}
/**
* 是否是选择文件
* 如果是false,则为路径
*/
private boolean isSelectFile = false;
/**
* 设置 @isSelectFile 是否是选择文件 的值
*/
public void setIsSelectFile(boolean isSelectFile) {
this.isSelectFile = isSelectFile;
}
/**
* 设置 @jLabel 文字 的值
*/
public void setLabelText(String text) {
this.jLabel.setText(text);
}
/**
* 取 @path 路径 的值
*/
public String getPath() {
return this.jTextField.getText();
}
/**
* 设置 @path 路径 的值
*/
public void setPath(String path) {
this.jTextField.setText(path);
this.doParentAction();
}
/**
* 引起parent动作
*/
public void doParentAction() {
/**
* 借助toString()方法传递消息
*/
this.parent.toString();
}
private Component parent = this;
private void selectPath(JTextField jText) {
JFileChooser fileDialog = new JFileChooser();
if (this.isSelectFile) {
fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY);
}
else {
fileDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
}
if (! (ItemValue.fileChoosePath.equals(""))) {
fileDialog.setCurrentDirectory( (new File(ItemValue.fileChoosePath)).
getParentFile());
}
int result = fileDialog.showOpenDialog(parent);
if (result == JFileChooser.APPROVE_OPTION) {
File f = fileDialog.getSelectedFile();
ItemValue.fileChoosePath = f.getAbsolutePath();
jText.setText(f.getAbsolutePath());
}
}
private void jbInit() throws Exception {
this.setLayout(xYLayout1);
jLabel.setText("路径选择:");
xYLayout1.setWidth(430);
xYLayout1.setHeight(37);
jTextField.setText("");
jButton.setText("选择");
jButton.addActionListener(new PathSelect_jButton_actionAdapter(this));
this.add(jTextField, new XYConstraints(101, 6, 247, -1));
this.add(jButton, new XYConstraints(368, 5, -1, -1));
this.add(jLabel, new XYConstraints(8, 9, 92, -1));
}
private XYLayout xYLayout1 = new XYLayout();
private JLabel jLabel = new JLabel();
private JTextField jTextField = new JTextField();
private JButton jButton = new JButton();
public void jButton_actionPerformed(ActionEvent e) {
this.selectPath(jTextField);
if (this.parent != null) {
this.doParentAction();
}
}
}
class PathSelect_jButton_actionAdapter
implements ActionListener {
private PathSelect adaptee;
PathSelect_jButton_actionAdapter(PathSelect adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -