package OperatingSyetem;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.DefaultListSelectionModel;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JMenu;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.awt.datatransfer.*;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragGestureRecognizer;
import java.awt.dnd.DragSource;
import java.awt.dnd.DragSourceDragEvent;
import java.awt.dnd.DragSourceDropEvent;
import java.awt.dnd.DragSourceEvent;
import java.awt.dnd.DragSourceListener;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.awt.dnd.DropTargetListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JSplitPane;
import javax.swing.JTree;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.filechooser.FileSystemView;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import com.sun.org.apache.xml.internal.utils.StringVector;
public class FileSystemUI {
private JFrame frame;
private JTree tree;
private JTable table;
private JPopupMenu tablePopupMenu;
private JPopupMenu popupMenu;
private String nameOfFileToCopy;
private String pathOfFileToCopy;
private String nameOfFileToMove;
private String pathOfFileToMove;
private Icon draggedIcon;
private JScrollPane scrollTablePane;
private JScrollPane scrollTreePane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
FileSystemUI window = new FileSystemUI();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public FileSystemUI() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 714, 438);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar menuBar = new JMenuBar();
frame.setJMenuBar(menuBar);
// frame.setLayout(new
// BoxLayout(frame.getContentPane(),BoxLayout.X_AXIS));
JSplitPane splitPane = new JSplitPane();
splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
scrollTreePane = new JScrollPane();
scrollTreePane
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
// frame.add(scrollTreePane);
scrollTreePane.setBorder(null);
tree = new JTree();
scrollTreePane.getViewport().add(tree);
table = new JTable();
scrollTablePane = new JScrollPane();
scrollTablePane.getViewport().add(table);
// frame.add(scrollTreePane);
splitPane.setLeftComponent(scrollTreePane);
splitPane.setRightComponent(scrollTablePane);
splitPane.setDividerLocation(250);
frame.add(splitPane);
JMenu mnMenu = new JMenu("Menu");
menuBar.add(mnMenu);
ImageIcon icon = new ImageIcon("addFolder.png");
icon.setImage(icon.getImage().getScaledInstance(24, 24, Image.SCALE_DEFAULT));
JMenuItem menuItem = new JMenuItem("新建文件夹",icon);
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
createFolder();
}
});
ImageIcon icon1 = new ImageIcon("addFile.png");
icon1.setImage(icon1.getImage().getScaledInstance(24, 24, Image.SCALE_DEFAULT));
JMenuItem menuItem1 = new JMenuItem("新建文档",icon1);
menuItem1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
try {
createFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
mnMenu.add(menuItem1);
mnMenu.add(menuItem);
tablePopupMenu = new JPopupMenu();
JMenuItem item = new JMenuItem("删除");
JMenuItem item1 = new JMenuItem("拷贝");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
delete();
}
});
item1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
copyFile();
}
});
tablePopupMenu.add(item);
tablePopupMenu.add(item1);
popupMenu = new JPopupMenu();
JMenuItem item3 = new JMenuItem("粘贴");
item3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
pasteFile();
}
});
popupMenu.add(item3);
scrollTablePane.addMouseListener(new MouseListener() {
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
if(e.getButton()==3){
popupMenu.show(scrollTablePane,e.getX(),e.getY());
}
}
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mouseClicked(MouseEvent arg0) {
// TODO Auto-generated method stub
}
});
initData();
}
private void initData() {
tree.setCellRenderer(new MyTreeCellRenderer());
DefaultMutableTreeNode root = new DefaultMutableTreeNode("PC");
((DefaultTreeModel) tree.getModel()).setRoot(root);
DragSource dragSource = DragSource.getDefaultDragSource();
DragGestureRecognizer dgr = dragSource.createDefaultDragGestureRecognizer(table, DnDConstants.ACTION_MOVE, new DragGestureListener() {
public void dragGestureRecognized(DragGestureEvent dge) {
// TODO Auto-generated method stub
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension dim = tk.getBestCursorSize(draggedIcon.getIconWidth(),draggedIcon.getIconHeight());
BufferedImage buff = new BufferedImage(dim.width,dim.height,BufferedImage.TYPE_INT_ARGB);
draggedIcon.paintIcon(table,buff.getGraphics(),0,0);
if(DragSource.isDragImageSupported()) {
Transferable tr = new StringSelection(pathOfFileToMove);
dge.startDrag(DragSource.DefaultMoveDrop,buff,new Point(0,0),tr,new DragSourceListener() {
public void dropActionChanged(DragSourceDragEvent arg0) {
// TODO Auto-generated method stub
}
public void dragOver(DragSourceDragEvent arg0) {
// TODO Auto-generated method stub
}
public void dragExit(DragSourceEvent arg0) {
// TODO Auto-generated method stub
}
public void dragEnter(DragSourceDragEvent arg0) {
// TODO Auto-generated method stub
}
public void dragDropEnd(
用java实现的资源管理器
5星 · 超过95%的资源 需积分: 31 75 浏览量
2015-03-14
22:38:02
上传
评论 8
收藏 34KB ZIP 举报
码农小兴
- 粉丝: 10
- 资源: 4
最新资源
- apk.tw_LineLite_v8a_v.2.17.1_sign.apk
- Elasticsearch实战:构建高效搜索系统的秘诀.zip
- HTML+CSS+JS网页设计:从入门到精通.zip
- 数据库课程设计:从理论到实践的全面指南.zip
- Python闭包:深入理解与应用场景解析.zip
- Win64OpenSSL-3-3-0.exe
- 课高分程设计-基于C++实现的民航飞行与地图简易管理系统-南京航空航天大学
- 航天器遥测数据故障检测系统python源码+文档说明+数据库(课程设计)
- 北京航空航天大学操作系统课设+ppt+实验报告
- 基于Vue+Echarts实现风力发电机中传感器的数据展示监控可视化系统+源代码+文档说明(高分课程设计)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈