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

📄 ui.java

📁 生物物种进化历程的演示
💻 JAVA
字号:
/* * Created on 2003-10-22 * User Interface part of code for TreeJuxtaposer  * To change the template for this generated file go to * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments */package TreeJuxtaposer;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;/** * @author jeffrey *  * To change the template for this generated type comment go to * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments */public class UI implements WindowListener, ActionListener{	Frame mainFrame;	String title;	StateFrame stateFrame;	SettingsFrame settingsFrame;	IncrementalSearch searchFrame;	DebugFrame debugFrame;	ButterflyFrame butterflyFrame;	JPanel controlPanel;	Panel drawPanel;	GridLayout drawLayout;	Toolkit toolkit = Toolkit.getDefaultToolkit();	Dimension screendim = toolkit.getScreenSize();	JFileChooser fc = new JFileChooser();	boolean firstTime = true;	/* Variables and constants for the menu bar */	MenuBar menuBar;	MenuItem menuItem[][];	static final String MENUFONTTYPE = "Helvetica";	static final int MENUFONTSTYLE = Font.BOLD;	static final int MENUFONTSIZE = 10;	/* top-level menu bar constants */	static final String menuHeader[] = { "File", "Find", "Tools", "Help" };	static final int FILEMENU = 0;	static final int FINDMENU = 1;	static final int TOOLMENU = 2;	static final int HELPMENU = 3;	static final Menu menu[] = { new Menu(menuHeader[FILEMENU]),			new Menu(menuHeader[FINDMENU]), new Menu(menuHeader[TOOLMENU]),			new Menu(menuHeader[HELPMENU]), };	/* component-level menu bar constants	 * string to describe the menu options, null is for a separator	 * boolean to describe whether menu option is active	 * integer for enumerating menu options	 */	static final String fileMenu[] = { "Open", "Delete", null, "Quit" };	static final boolean fileActive[] = { true, true, false, true };	static final int OPENOPT = 0;	static final int DELETEOPT = 1;	static final int QUITOPT = 3;	static final String findMenu[] = { "Find" };	static final boolean findActive[] = { true };	static final int FINDOPT = 0;	static final String toolMenu[] = { "Groups", "Settings", "Debug", null,			"Windows" };	static final boolean toolActive[] = { true, true, true, false, true };	static final int GROUPOPT = 0;	static final int SETTINGOPT = 1;	static final int DEBUGOPT = 2;	static final int DRAWBUTTERFLYOPT = 4;	static final String helpMenu[] = { "About" };	static final boolean helpActive[] = { true };	static final int ABOUTOPT = 0;	// over-declared to make construction shorter	static final String allMenu[][] = { fileMenu, findMenu, toolMenu, helpMenu };	static final boolean allActive[][] = { fileActive, findActive, toolActive,			helpActive };	File[] files;	TreeJuxtaposer tj;	public UI(TreeJuxtaposer tj, String title) {		this.tj = tj;		mainFrame = new Frame(title);		mainFrame.setLocation(10, 30);		mainFrame.setLayout(new BorderLayout());		controlPanel = new JPanel();		drawPanel = new Panel();		drawLayout = new GridLayout(1, 0, 8, 0);		drawPanel.setLayout(drawLayout);		//mainFrame.getContentPane().add(controlPanel, BorderLayout.NORTH);		mainFrame.add(drawPanel, BorderLayout.CENTER);		fc.addChoosableFileFilter(new NexusFilter());		fc.addChoosableFileFilter(new NewickFilter());		fc.setMultiSelectionEnabled(true);		//fc.setAcceptAllFileFilterUsed(true);		mainFrame.addWindowListener(this);		stateFrame = new StateFrame(tj);		settingsFrame = new SettingsFrame(tj);		searchFrame = new IncrementalSearch(tj);		debugFrame = new DebugFrame(tj);		butterflyFrame = new ButterflyFrame(tj);		addMenuBar();		menuBar.setFont(new Font(MENUFONTTYPE, MENUFONTSTYLE, MENUFONTSIZE));	}	public void windowClosing(WindowEvent event) {		System.exit(0);	}	public void windowClosed(WindowEvent event) {		System.exit(0);	}	public void windowActivated(WindowEvent event) {	}	public void windowDeiconified(WindowEvent event) {		tj.requestRedrawAll();	}	public void windowOpened(WindowEvent event) {		tj.requestRedrawAll();	}	public void windowDeactivated(WindowEvent event) {	}	public void windowIconified(WindowEvent event) {	}	private void addMenuBar()	{		JPopupMenu.setDefaultLightWeightPopupEnabled(false);		menuBar = new MenuBar();		menuItem = new MenuItem[menuHeader.length][];		for (int i = 0; i < menuHeader.length; i++) {			menuItem[i] = new MenuItem[allMenu[i].length];			for (int j = 0; j < allMenu[i].length; j++) {				if (allMenu[i][j] == null)					menu[i].addSeparator();				else				{					menuItem[i][j] = new MenuItem(allMenu[i][j]);					menuItem[i][j].setEnabled(allActive[i][j]);					menuItem[i][j].addActionListener(this);					menu[i].add(menuItem[i][j]);				}			}			menuBar.add(menu[i]);		}		mainFrame.setMenuBar((MenuBar) menuBar);	}	protected Frame getMainFrame() {		return mainFrame;	}	protected Panel getDrawPanel() {		return drawPanel;	}	protected JPanel getControlPanel() {		return controlPanel;	}	protected GridLayout getDrawLayout() {		return drawLayout;	}	protected IncrementalSearch getSearchFrame() {		return searchFrame;	}	protected SettingsFrame getSettingsFrame() {		return settingsFrame;	}	protected DebugFrame getDebugFrame() {		return debugFrame;	}	protected StateFrame getStateFrame() {		return stateFrame;	}	protected ButterflyFrame getButterflyFrame() {		return butterflyFrame;	}	protected void addAction() {		//fc.setCurrentDirectory(new File(System.getProperty("user.dir")));		if (firstTime) {			fc.setCurrentDirectory(new File("."));			firstTime = false;		}		int returnVal = fc.showOpenDialog(mainFrame);		AccordionDrawer.AccordionDrawer.loaded = false;		if (returnVal == JFileChooser.APPROVE_OPTION) {			//				File file = fc.getSelectedFile();			//				File[] files = fc.getSelectedFiles();			files = fc.getSelectedFiles();			for (int i = 0; i < files.length; i++) {				boolean nexus_file;				String s = null;				// It would be better to rely on the parser to				// figure out the format of the file. The one				// implemented here is an ad-hoc solution.				//if(fc.getFileFilter().accept(files[i])) 				if (fc.getFileFilter().getDescription().equals(						Utils.nexus_file_description))					nexus_file = true;				else					nexus_file = false;				try {					//				s = file.getCanonicalPath();					s = files[i].getCanonicalPath();					System.out							.println("YZ File.getCanonicalPath() fname: " + s);					if (!nexus_file) {						System.out.println("Load newick file " + s);						tj.loadNewickTree(s);					} else {						System.out.println("Load nexus file " + s);						tj.loadNexusTree(s, null);					}				} catch (Exception ex) {					System.out.println("File not found: " + s);				}			}		}		AccordionDrawer.AccordionDrawer.loaded = true;		tj.mainFrame.setVisible(true);	}	protected void deleteAction() {		TreeRemovalPanel trp = new TreeRemovalPanel(tj);		trp.pack();		trp.setLocation(500, 0);		trp.show();	}	protected void quitAction() {		// add other actions if needed when the quit menu option is selected		System.exit(0);	}	/* (non-Javadoc)	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)	 */	public void actionPerformed(ActionEvent e) {		Object obj = e.getSource();		if (obj == menuItem[FILEMENU][OPENOPT]) {			tj.addAction();		} else if (obj == menuItem[FILEMENU][DELETEOPT]) {			deleteAction();		} else if (obj == menuItem[FILEMENU][QUITOPT]) {			tj.quitAction();		} else if (obj == menuItem[FINDMENU][FINDOPT]) {			searchFrame.setLocation(screendim.width - searchFrame.getWidth()					- 10, 30);			searchFrame.show();		} else if (obj == menuItem[TOOLMENU][GROUPOPT]) {			stateFrame.prepareToShow();			if (mainFrame.getLocation().y + mainFrame.getHeight() + 30					+ stateFrame.getHeight() < screendim.height)				stateFrame.setLocation(10, mainFrame.getLocation().y						+ mainFrame.getHeight() + 30);			else				stateFrame.setLocation(10, screendim.height						- stateFrame.getHeight());			stateFrame.show();		} else if (obj == menuItem[TOOLMENU][SETTINGOPT]) {			settingsFrame.prepareToShow();			if (stateFrame.getLocation().y == 30) // default loaction for stateFrame				settingsFrame.setLocation(10, screendim.height						- settingsFrame.getHeight() - 30);			else if ((screendim.height < mainFrame.getHeight()					+ stateFrame.getHeight() + settingsFrame.getHeight())					|| (screendim.height < stateFrame.getLocation().y							+ stateFrame.getHeight()							+ settingsFrame.getHeight()))				settingsFrame.setLocation(20 + stateFrame.getWidth(),						stateFrame.getLocation().y);			else				settingsFrame.setLocation(10, stateFrame.getLocation().y						+ stateFrame.getHeight());			settingsFrame.show();		} else if (obj == menuItem[TOOLMENU][DEBUGOPT]) {			if (settingsFrame.getLocation().y == 30)				debugFrame.setLocation(10 + settingsFrame.getWidth(),						screendim.height - debugFrame.getHeight() - 30);			else if (screendim.width < settingsFrame.getLocation().x					+ settingsFrame.getWidth() + debugFrame.getWidth())				debugFrame.setLocation(settingsFrame.getLocation().x,						settingsFrame.getLocation().y - debugFrame.getHeight());			else				debugFrame.setLocation(10 + settingsFrame.getLocation().x						+ settingsFrame.getWidth(),						settingsFrame.getLocation().y);			debugFrame.show();		} else if (obj == menuItem[TOOLMENU][DRAWBUTTERFLYOPT]) {			butterflyFrame.setLocation(520, 30);			butterflyFrame.show();		} else if (obj == menuItem[HELPMENU][ABOUTOPT]) {			new Help().showAboutFrame();		} else			System.out.println("unknown action performed: " + obj);	}}

⌨️ 快捷键说明

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