📄 awtfileselector.java
字号:
/*
* SSL-Explorer
*
* Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package com.sshtools.ui.awt;
import java.awt.BorderLayout;
import java.awt.Checkbox;
import java.awt.Choice;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Vector;
import com.sshtools.ui.FileFilter;
import com.sshtools.ui.FileSelector;
import com.sshtools.ui.StockIcons;
import com.sshtools.ui.awt.options.Option;
import com.sshtools.ui.awt.options.OptionDialog;
import com.sshtools.util.StringComparator;
import com.sshtools.util.Util;
/**
*
*/
public class AWTFileSelector extends Panel implements FileSelector, ActionListener, ItemListener {
private java.awt.List files;
private File cwd;
private TextField path;
// private Label cwdLabel;
private Choice lookIn;
private ImageButton go;
private ImageButton remove;
private ImageButton newFolder;
private ImageButton home;
private ImageButton parent;
private int type;
private Checkbox showHiddenFiles;
private Choice filterSelect;
private Vector filters;
private FileFilter acceptAllFilter = new FileFilter() {
public String getDescription() {
return "All files (*)";
}
public boolean accept(File f) {
return true;
}
};
public AWTFileSelector() {
super(new BorderLayout());
}
public void init(int type, File cwd, boolean showButtons, boolean showHiddenFilesSwitch, boolean showButtonImages, boolean showButtonText) {
// Initialise
this.cwd = cwd;
this.type = type;
filters = new Vector();
filters.addElement(acceptAllFilter);
if (cwd == null) {
cwd = new File(System.getProperty("user.dir"));
}
// Create the
files = new SelectList() {
public Dimension getPreferredSize() {
return new Dimension(400, 260);
}
public void selected() {
String item = files.getSelectedItem();
if (item != null) {
path.setText(item);
selectFile();
}
}
};
files.addItemListener(this);
// Create the 'Look In' component
lookIn = new Choice();
lookIn.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
AWTFileSelector.this.cwd = new File(lookIn.getSelectedItem());
refresh();
}
});
rebuildLookIn();
// Create the tool bar
Panel z = new Panel(new FlowLayout());
if (showButtons) {
home = new ImageButton(showButtonImages ? UIUtil.getStockImage(StockIcons.STOCK_HOME, AWTFileSelector.class) : null, showButtonText ? "Home" : null, "home");
home.setHoverButton(true);
home.addActionListener(this);
home.setToolTipText("Navigate to your home directory");
z.add(home);
parent = new ImageButton(showButtonImages ? UIUtil.getStockImage(StockIcons.STOCK_UP_FOLDER, AWTFileSelector.class) : null, showButtonText ? "Home" : null, "home");
parent.setHoverButton(true);
parent.addActionListener(this);
parent.setToolTipText("Navigate to the parent folder");
z.add(parent);
newFolder = new ImageButton(showButtonImages ? UIUtil.getStockImage(StockIcons.STOCK_NEW_FOLDER, AWTFileSelector.class) : null, showButtonText ? "New" : null, "newFolder");
newFolder.setHoverButton(true);
newFolder.addActionListener(this);
newFolder.setToolTipText("Create a new folder");
z.add(newFolder);
remove = new ImageButton(showButtonImages ? UIUtil.getStockImage(StockIcons.STOCK_DELETE, AWTFileSelector.class) : null, showButtonText ? "Del." : null, "delete");
remove.setHoverButton(true);
remove.addActionListener(this);
remove.setToolTipText("Remove the selected file");
z.add(remove);
}
if (showHiddenFilesSwitch) {
showHiddenFiles = new Checkbox("Hidden files");
showHiddenFiles.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
refresh();
}
});
}
// Create the top bar
Panel top = new Panel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.anchor = GridBagConstraints.WEST;
gbc.weightx = 1.0;
UIUtil.gridBagAdd(top, lookIn, gbc, GridBagConstraints.RELATIVE);
gbc.weightx = 0.0;
UIUtil.gridBagAdd(top, z, gbc, GridBagConstraints.REMAINDER);
// Create the path panel
Panel pathPanel = new Panel(new GridBagLayout());
GridBagConstraints gbc1 = new GridBagConstraints();
path = new TextField("");
path.addActionListener(this);
gbc1.fill = GridBagConstraints.HORIZONTAL;
gbc1.anchor = GridBagConstraints.WEST;
gbc1.weightx = 0.0;
gbc1.insets = new Insets(2, 2, 2, 2);
UIUtil.gridBagAdd(pathPanel, new Label("File name: "), gbc1, showButtons ? 1 : GridBagConstraints.RELATIVE);
gbc1.weightx = 1.0;
UIUtil.gridBagAdd(pathPanel, path, gbc1, showButtons ? GridBagConstraints.RELATIVE : GridBagConstraints.REMAINDER);
gbc1.weightx = 0.0;
if(showButtons) {
go = new ImageButton(null, "Go", "go");
go.setHoverButton(true);
go.addActionListener(this);
go.setToolTipText("Navigate to the selected folder");
UIUtil.gridBagAdd(pathPanel, go, gbc1, GridBagConstraints.REMAINDER);
}
UIUtil.gridBagAdd(pathPanel, new Label("Files of type: "), gbc1, showButtons ? 1 : GridBagConstraints.RELATIVE);
gbc1.weightx = 1.0;
filterSelect = new Choice();
rebuildFilterSelect();
filterSelect.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
refresh();
}
});
UIUtil.gridBagAdd(pathPanel, filterSelect, gbc1, showButtons ? GridBagConstraints.RELATIVE : GridBagConstraints.REMAINDER);
gbc1.weightx = 0.0;
if(showButtons) {
UIUtil.gridBagAdd(pathPanel, new Label(), gbc1, GridBagConstraints.REMAINDER);
}
// Build the main component
add(top, "North");
add(files, "Center");
add(pathPanel, "South");
refresh();
}
public void setUseAcceptAllFilter(boolean useAcceptAllFilter) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -