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

📄 swingtools.java

📁 著名的开源仿真软件yale
💻 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.tools.Tools;import edu.udo.cs.yale.tools.ParameterService;import edu.udo.cs.yale.operator.UserError;import edu.udo.cs.yale.Yale;import java.io.File;import java.awt.Color;import java.awt.Component;import java.awt.GradientPaint;import java.awt.FlowLayout;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;import java.awt.GridBagLayout;import java.awt.GridBagConstraints;import java.awt.Insets;import javax.swing.JOptionPane;import javax.swing.JDialog;import javax.swing.Box;import javax.swing.BoxLayout;import javax.swing.BorderFactory;import javax.swing.JFileChooser;import javax.swing.JTextArea;import javax.swing.JScrollPane;import javax.swing.JPanel;import javax.swing.JButton;import javax.swing.JEditorPane;import javax.swing.JLabel;public class SwingTools {    public static final Color DARK_YELLOW  = new Color(180, 164, 148);     public static final Color LIGHT_YELLOW = new Color(206, 184, 163);    public static final Color DARK_BLUE  = new Color(153, 153, 204);    public static final Color LIGHT_BLUE = new Color(204, 204, 255);    public static GradientPaint makeBluePaint(double width, double height) {	return new GradientPaint(0f, 0f, DARK_BLUE, 				 (float)width/2, (float)height/2, LIGHT_BLUE,				 true);    }    public static GradientPaint makeYellowPaint(double width, double height) {	return new GradientPaint(0f, 0f, DARK_YELLOW, 				 (float)width/2, (float)height/2, LIGHT_YELLOW,				 true);    }    public static void showSimpleErrorMessage(String message, Throwable e) {	JOptionPane.showMessageDialog(YaleGUI.getMainFrame(), 				      message + "\n"+				      Tools.classNameWOPackage(e.getClass())+" caught:\n"+				      e.getMessage(),				      "Exception",				      JOptionPane.ERROR_MESSAGE);    }    public static void showErrorMessage(String message, Throwable e) {	JDialog dialog =  ErrorDialog.create(message, e);	dialog.setLocationRelativeTo(YaleGUI.getMainFrame());	dialog.show();    }    /** Opens a file chooser with a reasonable start directory. */    public static File chooseFile(Component parent, File file, boolean open) {	return chooseFile(parent, file, open, false);    }    /** Opens a file chooser with a reasonable start directory.  */    public static File chooseFile(Component parent, File file, boolean open, boolean onlyDirs) {	return chooseFile(parent, file, open, onlyDirs, null, null);    }    /** Opens a file chooser with a reasonable start directory. onlyDirs indidcates if only files or only      *  can be selected.      *  @param file The initially selected value of the file chooser dialog     *  @param open Open or save dialog?     *  @param onlyDirs Only allow directories to be selected     *  @param filter Array of Strings, e.g. file extensions     *  @param filterDescr Human readable description of the filter */    public static File chooseFile(Component parent, File file, boolean open, boolean onlyDirs,				  final String filter[], final String filterDescr) {	if (parent == null) parent = YaleGUI.getMainFrame();	File directory = null;	if (file != null) {	    if (file.isDirectory()) {		directory = file;	    } else {		directory = file.getAbsoluteFile().getParentFile();	    }	} else {	    File experimentFile = (Yale.getExperiment() != null) ? 		Yale.getExperiment().getExperimentFile() : 		null;	    if (experimentFile != null) {		directory = experimentFile.getAbsoluteFile().getParentFile();	    } else {		directory = new File(System.getProperty("user.dir"));	    }	}	JFileChooser fileChooser = new JFileChooser(directory);	if (onlyDirs)	    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);	if (filter != null) {	    fileChooser.setFileFilter(new javax.swing.filechooser.FileFilter() {		    public String getDescription() { return filterDescr; }		    public boolean accept(File f) {			if (f.isDirectory()) return true;			for (int i = 0; i < filter.length; i++)			    if (f.getName().endsWith(filter[i]))				return true;			return false;		    }		});	}	if (file != null) fileChooser.setSelectedFile(file);		int returnValue = open ? fileChooser.showOpenDialog(parent) : fileChooser.showSaveDialog(parent);	switch (returnValue) {	case JFileChooser.APPROVE_OPTION:	    return fileChooser.getSelectedFile();	default:	    return null;	}    }}

⌨️ 快捷键说明

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