⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myownexplorer.java

📁 Eclipse编程技术与实例一书的附CD-ROM光盘
💻 JAVA
字号:
package org.Chapter13;

import java.io.*;
import org.eclipse.jface.viewers.*;
import org.eclipse.jface.window.*;
import org.eclipse.swt.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.widgets.*;

public class MyOwnExplorer extends ApplicationWindow {
	String file_name;

	/*
	 * file为要显示的目录名; 父类的构造函数一定要在最开始就调用。
	 */
	public MyOwnExplorer(String file) {
		super(null);
		this.file_name = file;
	}

	protected Control createContents(Composite parent) {
		SashForm sash_form = new SashForm(parent, SWT.HORIZONTAL | SWT.NULL);
		TreeViewer tv = new TreeViewer(sash_form);
		tv.setContentProvider(new FileTreeContentProvider());
		tv.setLabelProvider(new FileTreeLabelProvider());
		File file = new File(file_name);
		
		if (file == null) {
			System.out.println("the file is null");
			System.exit(1);
		}

		tv.setInput(file);
		final TableViewer tbv = new TableViewer(sash_form, SWT.BORDER);
		tbv.setContentProvider(new FileTableContentProvider());
		tv.addSelectionChangedListener(new ISelectionChangedListener() {
			public void selectionChanged(SelectionChangedEvent event) {
				IStructuredSelection selection = (IStructuredSelection) event
						.getSelection();
				Object selected_file = selection.getFirstElement();
				tbv.setInput(selected_file);
			}
		});
		return sash_form;
	}

	public static void main(String[] args) {
		MyOwnExplorer explorer = new MyOwnExplorer("d:\\");
		explorer.setBlockOnOpen(true);
		explorer.open();
		Display.getCurrent().dispose();
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -