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

📄 browsermdiframe.java

📁 Java Bytecode Editor 是一个 JAVA 的字节码反汇编和修改器。它可以很方便的修改已经编译成 Class 文件的 JAVA 文件。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 This library 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.
 */

package ee.ioc.cs.jbe.browser;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Event;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.beans.PropertyVetoException;
import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.HashSet;
import java.util.prefs.Preferences;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.tree.TreePath;

import ee.ioc.cs.jbe.browser.config.classpath.ClasspathArchiveEntry;
import ee.ioc.cs.jbe.browser.config.classpath.ClasspathBrowser;
import ee.ioc.cs.jbe.browser.config.classpath.ClasspathSetupDialog;
import ee.ioc.cs.jbe.browser.config.classpath.FindResult;
import ee.ioc.cs.jbe.browser.config.window.WindowState;

import org.gjt.jclasslib.mdi.BasicDesktopManager;
import org.gjt.jclasslib.mdi.BasicFileFilter;
import org.gjt.jclasslib.mdi.BasicMDIFrame;
import org.gjt.jclasslib.structures.ClassFile;
import org.gjt.jclasslib.structures.InvalidByteCodeException;
import org.gjt.jclasslib.util.FileUtils;
import org.gjt.jclasslib.util.GUIHelper;

import ee.ioc.cs.jbe.browser.codeedit.VerifierDisplay;
import ee.ioc.cs.jbe.browser.config.BrowserConfig;
import ee.ioc.cs.jbe.browser.detail.attributes.code.CodeEditArea;
import ee.ioc.cs.jbe.browser.detail.attributes.code.CodeEditPane;


/**
 * MDI Frame and entry point for the class file browser application.
 * 
 * @author <a href="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>
 *         Modified by Ando Saabas
 * @version $Revision: 1.1 $ $Date: 2006/09/25 16:00:58 $
 */
public class BrowserMDIFrame extends BasicMDIFrame{

	static final ImageIcon ICON_APPLICATION = loadIcon("jbe.png");

	private static final String SETTINGS_WORKSPACE_CHOOSER_PATH = "workspaceChooserPath";

	private static final String SETTINGS_CLASSES_CHOOSER_PATH = "classesChooserPath";

	private static final ImageIcon ICON_OPEN_CLASS_FILE = loadIcon("open_small.png");

	private static final ImageIcon ICON_OPEN_CLASS_FILE_LARGE = loadIcon("open_large.png");

	private static final ImageIcon ICON_BACKWARD = loadIcon("browser_backward_small.png");

	private static final ImageIcon ICON_BACKWARD_LARGE = loadIcon("browser_backward_large.png");

	private static final ImageIcon ICON_FORWARD = loadIcon("browser_forward_small.png");

	private static final ImageIcon ICON_FORWARD_LARGE = loadIcon("browser_forward_large.png");

	private static final ImageIcon ICON_RELOAD = loadIcon("reload_small.png");

	private static final ImageIcon ICON_RELOAD_LARGE = loadIcon("reload_large.png");

	private static final ImageIcon ICON_WEB = loadIcon("web_small.png");

//	private static final ImageIcon ICON_WEB_LARGE = loadIcon("web_large.png");

//	private static final ImageIcon ICON_BROWSE_CLASSPATH = loadIcon("tree_small.png");

//	private static final ImageIcon ICON_BROWSE_CLASSPATH_LARGE = loadIcon("tree_large.png");

	private static final ImageIcon ICON_HELP = loadIcon("help.png");

	private static final ImageIcon ICON_VERIFY_SMALL = loadIcon("verify_small.png");

	private static final ImageIcon ICON_VERIFY_LARGE = loadIcon("verify_large.png");

	private static final ImageIcon ICON_REVERT_SMALL = loadIcon("revert.png");

	private static final ImageIcon ICON_REVERT_LARGE = loadIcon("revert.png");
	
	private static final ImageIcon ICON_UNDO_SMALL = loadIcon("undo_small.png");

	private static final ImageIcon ICON_REDO_SMALL = loadIcon("redo_small.png");

	
	/**
	 * Load an icon from the <tt>images</tt> directory.
	 * 
	 * @param fileName
	 *            the file name for the icon
	 * @return the icon
	 */
	public static ImageIcon loadIcon(String fileName) {

		URL imageURL = BrowserMDIFrame.class.getResource("images/" + fileName);
		return new ImageIcon(imageURL);
	}

	private Action actionOpenClassFile;

	private Action actionBrowseClasspath;

	private Action actionSetupClasspath;

	private Action actionNewWorkspace;

	//private Action actionOpenWorkspace;

	//private Action actionSaveWorkspace;

	private Action actionSaveWorkspaceAs;

	private Action actionQuit;

	private Action actionShowHomepage;

	//private Action actionShowEJT;

	private Action actionBackward;

	private Action actionForward;

	private Action actionReload;

	private Action actionShowHelp;

	private Action actionAbout;

	private Action actionVerifyClass;
	
	private Action actionRevertClass;

	public UndoAction actionUndo;

	public RedoAction actionRedo;

	private File workspaceFile;

	private String workspaceChooserPath = "";

	private String classesChooserPath = "";

	private BrowserConfig config;

	// Visual Components

	//private JFileChooser workspaceFileChooser;

	private JFileChooser classesFileChooser;

	private RecentMenu recentMenu;

	private ClasspathSetupDialog classpathSetupDialog;

	private ClasspathBrowser classpathBrowser;

	private ClasspathBrowser jarBrowser;

	private HashSet<String> tempFiles = new HashSet<String>();

	/**
	 * Constructor.
	 */
	public BrowserMDIFrame() {

		doNewWorkspace();

		recentMenu = new RecentMenu(this);
		loadSettings();
		setupActions();
		setupMenu();
		setupFrame();

	}

	/**
	 * Get the current browser config.
	 * 
	 * @return the browser config
	 */
	public BrowserConfig getConfig() {
		return config;
	}

	public void setVisible(boolean visible) {
		super.setVisible(visible);
		if (visible) {
			desktopManager.showAll();
		}
	}

	/**
	 * Get the action for displaying the classpath setup dialog.
	 * 
	 * @return the action
	 */
	public Action getActionSetupClasspath() {
		return actionSetupClasspath;
	}

	/**
	 * Get the action for going backward in the navigation history.
	 * 
	 * @return the action
	 */
	public Action getActionBackward() {
		return actionBackward;
	}

	/**
	 * Get the action for going forward in the navigation history.
	 * 
	 * @return the action
	 */
	public Action getActionForward() {
		return actionForward;
	}

	/**
	 * Get the action for reloading the current frame.
	 * 
	 * @return the action
	 */
	public Action getActionReload() {
		return actionReload;
	}

	/**
	 * Get the last path for the classes file chooser.
	 * 
	 * @return the path
	 */
	public String getClassesChooserPath() {
		return classesChooserPath;
	}

	/**
	 * Set the last path for the classes file chooser.
	 * 
	 * @param classesChooserPath
	 *            the path
	 */
	public void setClassesChooserPath(String classesChooserPath) {
		this.classesChooserPath = classesChooserPath;
	}

	/**
	 * Open an internal frame for a given file.
	 * 
	 * @param file
	 *            the file
	 * @return the created internal frame
	 */
	public BrowserInternalFrame openClassFromFile(File file) {

		BrowserInternalFrame frame = new BrowserInternalFrame(desktopManager,
				new WindowState(file.getPath()));

		ClassFile classFile = frame.getClassFile();

		if (classFile != null) {
			try {
				String className = classFile.getThisClassName();
				String[] pathComponents = className.split("/");
				File currentDirectory = file.getParentFile();
				boolean validClasspathEntry = true;
				for (int i = pathComponents.length - 2; i >= 0; i--) {
					String pathComponent = pathComponents[i];
					if (!currentDirectory.getName().equals(pathComponent)) {
						validClasspathEntry = false;
						break;
					}
					currentDirectory = currentDirectory.getParentFile();
				}
				if (validClasspathEntry) {
					config.addClasspathDirectory(currentDirectory.getPath());
				}
			} catch (InvalidByteCodeException e) {
			}
		}
		actionVerifyClass.setEnabled(true);
		actionRevertClass.setEnabled(true);
		return frame;
	}

	protected void doQuit() {
		saveSettings();
		removeTempFiles();
		super.doQuit();
	}

	protected BasicDesktopManager createDesktopManager() {
		return new BrowserDesktopManager(this);
	}

	protected Class[] getFrameConstructorArguments(Class frameClass) {
		return BrowserInternalFrame.CONSTRUCTOR_ARGUMENTS;
	}

	private void setupActions() {

		actionOpenClassFile = new DefaultAction("Open class file",
				ICON_OPEN_CLASS_FILE);
		actionOpenClassFile.putValue(Action.SHORT_DESCRIPTION,
				"Open a class file");

		//actionBrowseClasspath = new DefaultAction("Browse classpath",
		//		ICON_BROWSE_CLASSPATH);
		//actionBrowseClasspath.putValue(Action.SHORT_DESCRIPTION,
		//		"Browse the current classpath to open a class file");

		//actionSetupClasspath = new DefaultAction("Setup classpath",
		//		GUIHelper.ICON_EMPTY);
		//actionSetupClasspath.putValue(Action.SHORT_DESCRIPTION,
		//		"Configure the classpath");

		// actionNewWorkspace = new DefaultAction("New workspace",
		// GUIHelper.ICON_EMPTY);
		// actionNewWorkspace.putValue(Action.SHORT_DESCRIPTION, "Close all
		// frames and open a new workspace");

		// actionOpenWorkspace = new DefaultAction("Open workspace",
		// ICON_OPEN_WORKSPACE);
		// actionOpenWorkspace.putValue(Action.SHORT_DESCRIPTION, "Open
		// workspace from disk");

		// actionSaveWorkspace = new DefaultAction("Save workspace",
		// ICON_SAVE_WORKSPACE);
		// actionSaveWorkspace.putValue(Action.SHORT_DESCRIPTION, "Save current
		// workspace to disk");

		// actionSaveWorkspaceAs = new DefaultAction("Save workspace as",
		// GUIHelper.ICON_EMPTY);
		// actionSaveWorkspaceAs.putValue(Action.SHORT_DESCRIPTION, "Save
		// current workspace to a different file");
		// actionSaveWorkspaceAs.setEnabled(false);

		actionQuit = new DefaultAction("Quit", GUIHelper.ICON_EMPTY);

		actionBackward = new DefaultAction("Backward", ICON_BACKWARD);
		actionBackward.putValue(Action.SHORT_DESCRIPTION,
				"Move backward in the navigation history");
		actionBackward.setEnabled(false);

		actionForward = new DefaultAction("Forward", ICON_FORWARD);
		actionForward.putValue(Action.SHORT_DESCRIPTION,
				"Move forward in the navigation history");
		actionForward.setEnabled(false);

		actionReload = new DefaultAction("Reload", ICON_RELOAD);
		actionReload.putValue(Action.SHORT_DESCRIPTION, "Reload class file");
		actionReload.setEnabled(false);

		actionVerifyClass = new DefaultAction("Verify class file",
				ICON_VERIFY_SMALL);
		actionVerifyClass.putValue(Action.SHORT_DESCRIPTION,
				"Verify class file");
		actionVerifyClass.setEnabled(false);

		
		actionRevertClass = new DefaultAction("Revert to original class file",
				ICON_REVERT_SMALL);
		actionRevertClass.putValue(Action.SHORT_DESCRIPTION,
				"Revert to original class file");
		actionRevertClass.setEnabled(false);
		
		
		actionShowHomepage = new DefaultAction("JBE webpage", ICON_WEB);
		actionShowHomepage.putValue(Action.SHORT_DESCRIPTION,
				"Visit jclasslib on the web");


		actionShowHelp = new DefaultAction("Show help", ICON_HELP);
		actionShowHelp.putValue(Action.SHORT_DESCRIPTION,
				"Show the JBE documentation");

		actionAbout = new DefaultAction("About Java Bytecode Editor",
				GUIHelper.ICON_EMPTY);
		actionAbout.putValue(Action.SHORT_DESCRIPTION,
				"About Java Bytecode Editor");

		actionUndo = new UndoAction("Undo typing", ICON_UNDO_SMALL);
		actionUndo.putValue(Action.SHORT_DESCRIPTION, "Undo text typing");

		actionRedo = new RedoAction("Redo typing", ICON_REDO_SMALL);
		actionRedo.putValue(Action.SHORT_DESCRIPTION, "Redo text typing");
	}

	private void setupMenu() {

		JMenuItem menuItem;
		JMenuBar menuBar = new JMenuBar();

		JMenu menuFile = new JMenu("File");
		menuFile.add(actionOpenClassFile);
		menuFile.add(actionVerifyClass);
		menuFile.addSeparator();
		// menuFile.add(actionNewWorkspace);
		// menuFile.add(actionOpenWorkspace);
		// menuFile.add(recentMenu);
		// menuFile.addSeparator();
		// menuFile.add(actionSaveWorkspace);
		// menuFile.add(actionSaveWorkspaceAs);
		// menuFile.addSeparator();
		menuFile.add(actionRevertClass);
		menuFile.addSeparator();
		menuFile.add(actionShowHomepage);
		menuFile.addSeparator();
		menuFile.add(actionQuit);

		JMenu menuEdit = new JMenu("Edit");
		menuItem = menuEdit.add(actionUndo);
		actionUndo.setEnabled(false);
		menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z,
				Event.CTRL_MASK));
		menuItem = menuEdit.add(actionRedo);
		actionRedo.setEnabled(false);

		menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y,
				Event.CTRL_MASK));

		//JMenu menuClasspath = new JMenu("Classpath");
		//menuClasspath.add(actionBrowseClasspath);
		//menuClasspath.add(actionSetupClasspath);

		JMenu menuBrowse = new JMenu("Browse");
		menuItem = menuBrowse.add(actionBackward);
		menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT,
				Event.ALT_MASK));
		menuItem = menuBrowse.add(actionForward);
		menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT,
				Event.ALT_MASK));

		menuBrowse.addSeparator();
		menuItem = menuBrowse.add(actionReload);
		menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R,
				Event.CTRL_MASK));

		JMenu menuHelp = new JMenu("Help");
		menuItem = menuHelp.add(actionShowHelp);
		menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
		menuHelp.add(actionAbout);

		menuBar.add(menuFile);
		menuBar.add(menuEdit);
		//menuBar.add(menuClasspath);
		menuBar.add(menuBrowse);
		menuBar.add(menuWindow);
		menuBar.add(menuHelp);
		setJMenuBar(menuBar);

	}

	private void setupFrame() {

		Container contentPane = getContentPane();

		contentPane.add(buildToolbar(), BorderLayout.NORTH);
		setIconImage(ICON_APPLICATION.getImage());
	}

⌨️ 快捷键说明

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