📄 yalegui.java
字号:
/* * YALE - Yet Another Learning Environment * Copyright (C) 2002, 2003 * Simon Fischer, Ralf Klinkenberg, Ingo Mierswa, * Katharina Morik, Oliver Ritthoff * Artificial Intelligence Unit * Computer Science Department * University of Dortmund * 44221 Dortmund, Germany * email: yale@ls8.cs.uni-dortmund.de * web: http://yale.cs.uni-dortmund.de/ * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA. */package edu.udo.cs.yale.gui;import edu.udo.cs.yale.Yale;import edu.udo.cs.yale.tools.LogService;import edu.udo.cs.yale.tools.ParameterService;import java.awt.event.WindowListener;import java.awt.event.WindowEvent;import java.awt.Dimension;import java.io.File;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import java.io.BufferedReader; import java.io.PrintWriter; import java.io.OutputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.io.FileInputStream; import java.util.LinkedList;import java.util.List;import java.util.Iterator;import java.util.Properties;public class YaleGUI extends Yale { private static final int NUMBER_OF_RECENT_FILES = 8; private static MainFrame mainFrame; private static LinkedList recentFiles = new LinkedList(); private static class ShutdownHook extends Thread { public void run() { LogService.logMessage("Running shutdown sequence.", LogService.INIT); YaleGUI.saveRecentFileList(); YaleGUI.saveGUIProperties(); } } public void run(File file) throws Exception { showLogo(); splashMessage("Initialising operators"); init(); splashMessage("Loading history"); loadRecentFileList(); splashMessage("Creating frame"); mainFrame = new MainFrame(); LogService.setOutputStream(mainFrame.getMessageViewer().outputStream); splashMessage("Ready."); loadGUIProperties(mainFrame); mainFrame.show(); hideLogo(); if (file != null) { mainFrame.open(file); } else { new WelcomeDialog(mainFrame).show(); } } public static MainFrame getMainFrame() { return mainFrame; } public static void main(String[] args) throws Exception { Runtime.getRuntime().addShutdownHook(new ShutdownHook()); File file = null; if (args.length > 0) { if (args.length != 1) { System.out.println("java " + YaleGUI.class.getName() + " [experimentfile]"); return; } file = new File(args[0]); if (!file.exists()) { System.err.println("File '"+args[0]+"' not found."); return; } if (!file.canRead()) { System.err.println("Cannot read file '"+args[0]+"'."); return; } } setInputHandler(new GUIInputHandler()); new YaleGUI().run(file); } public static void useExperimentFile() { File file = getExperiment().getExperimentFile(); file = new File(file.getAbsolutePath()); if (recentFiles.contains(file)) { recentFiles.remove(file); } recentFiles.addFirst(file); while (recentFiles.size() > NUMBER_OF_RECENT_FILES) recentFiles.removeLast(); } public static List getRecentFiles() { return recentFiles; } private static void loadRecentFileList() { try { File file = ParameterService.getUserConfigFile("history"); if (!file.exists()) return; BufferedReader in = new BufferedReader(new FileReader(file)); recentFiles.clear(); String line = null; while ((line = in.readLine()) != null) { recentFiles.add(new File(line)); } in.close(); } catch (IOException e) { SwingTools.showErrorMessage("Cannot read history file", e); } } private static void saveRecentFileList() { try { File file = ParameterService.getUserConfigFile("history"); PrintWriter out = new PrintWriter(new FileWriter(file)); Iterator i = recentFiles.iterator(); while (i.hasNext()) { out.println(((File)i.next()).getAbsolutePath()); } out.close(); } catch (IOException e) { SwingTools.showErrorMessage("Cannot write history file", e); } } private static void saveGUIProperties() { Properties properties = new Properties(); MainFrame mainFrame = getMainFrame(); if (mainFrame != null) { properties.setProperty("yale.gui.geometry.x", ""+(int)mainFrame.getLocation().getX()); properties.setProperty("yale.gui.geometry.y", ""+(int)mainFrame.getLocation().getY()); properties.setProperty("yale.gui.geometry.width", ""+(int)mainFrame.getWidth()); properties.setProperty("yale.gui.geometry.height", ""+(int)mainFrame.getHeight()); properties.setProperty("yale.gui.geometry.divider.h", ""+(int)mainFrame.getHorizontalDividerLocation()); properties.setProperty("yale.gui.geometry.divider.v", ""+(int)mainFrame.getVerticalDividerLocation()); File file = ParameterService.getUserConfigFile("gui.properties"); try { OutputStream out = new FileOutputStream(file); properties.store(out, "Yale GUI properties"); out.close(); } catch (IOException e) { e.printStackTrace(); } } } private static void loadGUIProperties(MainFrame mainFrame) { Properties properties = new Properties(); File file = ParameterService.getUserConfigFile("gui.properties"); if (file.exists()) { try { InputStream in = new FileInputStream(file); properties.load(in); in.close(); } catch (IOException e) { e.printStackTrace(); } try { mainFrame.setLocation(Integer.parseInt(properties.getProperty("yale.gui.geometry.x")), Integer.parseInt(properties.getProperty("yale.gui.geometry.y"))); mainFrame.setSize(new Dimension(Integer.parseInt(properties.getProperty("yale.gui.geometry.width")), Integer.parseInt(properties.getProperty("yale.gui.geometry.height")))); mainFrame.setDividerLocations(Integer.parseInt(properties.getProperty("yale.gui.geometry.divider.h")), Integer.parseInt(properties.getProperty("yale.gui.geometry.divider.v"))); } catch (NumberFormatException e) { e.printStackTrace(); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -