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

📄 statusbar.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.ExperimentListener;import edu.udo.cs.yale.operator.ExperimentOperator;import edu.udo.cs.yale.operator.Operator;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.Box;import javax.swing.BoxLayout;import javax.swing.border.Border;import java.awt.Font;import java.awt.FlowLayout;import java.awt.Component;import java.awt.Graphics;import java.awt.Insets;import java.awt.Color;public class StatusBar extends Box implements ExperimentListener {    private JLabel clock    = createLabel(getTime(), true);    private JLabel operator = createLabel("                         ", true);    //private JLabel time     = createLabel("", false);    private Operator currentOperator = null;;    public StatusBar() {	super(BoxLayout.X_AXIS);	operator.setPreferredSize(new java.awt.Dimension(200,8));	//JPanel opPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));	//opPanel.setBorder(createBorder());	//opPanel.add(operator);	//opPanel.add(time);	//add(opPanel);	add(operator);	add(createHorizontalGlue());	add(clock);	new Thread() {		public void run() {		    setPriority(MIN_PRIORITY);		    while (true) {			try {			    clock.setText(getTime());			    if (currentOperator != null) {				long execTime = System.currentTimeMillis() - currentOperator.getStartTime();				if (execTime > 1000)				    operator.setText("["+currentOperator.getApplyCount() + "] "+						     currentOperator.getName()+"  "+(execTime/1000)+" s");				sleep(1000);			    }			} catch (InterruptedException e) {			    e.printStackTrace();			    return;			}		    }		}	    }.start();    }    private static Border createBorder() {	return new Border() {		    public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {			Color highlight = c.getBackground().brighter().brighter();			Color shadow    = c.getBackground().darker().darker();			Color oldColor = g.getColor();			g.translate(x, y);			g.setColor(shadow);			g.drawLine(3,   0,   3,   h-2);			g.drawLine(3,   0,   w-3, 0);			g.setColor(highlight);			g.drawLine(3,   h-2, w-3, h-2);			g.drawLine(w-3, 1,   w-3, h-2);			g.translate(-x, -y);			g.setColor(oldColor);		    }		    public Insets getBorderInsets(Component c) { return new Insets(1, 4, 2, 3); }		    public boolean isBorderOpaque() { return false; }	    };    }    private static JLabel createLabel(String text, boolean border) {	JLabel label = new JLabel(text);	if (border) {	    label.setBorder(createBorder());	}	label.setFont(label.getFont().deriveFont(Font.PLAIN));	return label;    }    private static String getTime() {	return java.text.DateFormat.getTimeInstance().format(new java.util.Date());    }    public void experimentStep(ExperimentOperator op) {	currentOperator = op.getExperiment().getCurrentOperator();	operator.setText("["+currentOperator.getApplyCount() + "] " + currentOperator.getName());    }    public void experimentEnded() {	operator.setText(" ");	currentOperator = null;    }}

⌨️ 快捷键说明

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