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

📄 messageswindow.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: MessagesWindow.java * * Copyright (c) 2003 Sun Microsystems and Static Free Software * * Electric(tm) 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 3 of the License, or * (at your option) any later version. * * Electric(tm) 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 Electric(tm); see the file COPYING.  If not, write to * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, Mass 02111-1307, USA. */package com.sun.electric.tool.user.ui;import com.sun.electric.database.text.TextUtils;import com.sun.electric.tool.Client;import com.sun.electric.tool.Job;import com.sun.electric.tool.user.User;import com.sun.electric.tool.user.dialogs.EDialog;import java.awt.BorderLayout;import java.awt.Component;import java.awt.Container;import java.awt.Dimension;import java.awt.Font;import java.awt.Frame;import java.awt.GraphicsEnvironment;import java.awt.GridBagConstraints;import java.awt.Point;import java.awt.Rectangle;import java.awt.Toolkit;import java.awt.datatransfer.Clipboard;import java.awt.datatransfer.ClipboardOwner;import java.awt.datatransfer.StringSelection;import java.awt.datatransfer.Transferable;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.util.Observable;import java.util.Observer;import javax.swing.DefaultListModel;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JInternalFrame;import javax.swing.JLabel;import javax.swing.JList;import javax.swing.JMenuItem;import javax.swing.JPopupMenu;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.ListSelectionModel;import javax.swing.SwingUtilities;/** * a console for the Java side of Electric.  Used because the standard * Electric console can't handle multiple threads of printing. * An instance of this class should be set as the PrintStream for System.out, * e.g. System.setOut(new PrintStream(new MessagesWindow())); * In such a situation, there should never be a reason to call any of * the methods of this class directly. */public class MessagesWindow	implements Observer, MouseListener, Runnable, ClipboardOwner{	private static final int STACK_SIZE = Client.isOSMac()?0:8*1024;	private JTextArea info;	private Container contentFrame;	private final Thread ticker = new Thread(null, this, "MessagesTicker", STACK_SIZE);	private boolean dumpInvoked = false;	private StringBuilder buffer = new StringBuilder();	private Container jf;	// -------------------- private and protected methods ------------------------	public MessagesWindow()	{		Dimension scrnSize = TopLevel.getScreenSize();		Dimension msgSize = new Dimension(scrnSize.width/3*2, scrnSize.height/100*15);		Point msgPos = new Point(150, scrnSize.height/100*85);		if (TopLevel.isMDIMode())		{			JInternalFrame jInternalFrame = new JInternalFrame("Electric Messages", true, false, true, true);			jf = jInternalFrame;			contentFrame = jInternalFrame.getContentPane();			jInternalFrame.setFrameIcon(TopLevel.getFrameIcon());			jf.setLocation(msgPos);		} else		{			JFrame jFrame = new JFrame("Electric Messages");			jf = jFrame;			jFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);			contentFrame = jFrame.getContentPane();			jFrame.setIconImage(TopLevel.getFrameIcon().getImage());			Point pt = User.getDefaultMessagesPos();			if (pt == null) pt = msgPos;			jf.setLocation(pt);			Dimension override = User.getDefaultMessagesSize();			if (override != null) jf.setPreferredSize(override);		}		contentFrame.setLayout(new BorderLayout());		info = new JTextArea(20, 110);		info.setLineWrap(false);		info.setFont(new Font("Monospaced", 0, 12));		info.addMouseListener(this);		JScrollPane scrollPane = new JScrollPane(info,			JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,			JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);		scrollPane.setPreferredSize(msgSize);		contentFrame.add(scrollPane, BorderLayout.CENTER);		ticker.start();		if (TopLevel.isMDIMode())		{			((JInternalFrame)jf).pack();			TopLevel.addToDesktop((JInternalFrame)jf);		} else		{			((JFrame)jf).pack();			((JFrame)jf).setVisible(true);		}	}	public Component getComponent()	{		return jf;	}	public boolean isFocusOwner()	{		if (TopLevel.isMDIMode())			return ((JInternalFrame)jf).isSelected();		return jf.isFocusOwner();	}	/**	 * Method to request focus on this window	 */	public void requestFocus() {		if (!SwingUtilities.isEventDispatchThread()) {			SwingUtilities.invokeLater(new Runnable() {				public void run() { requestFocusUnsafe(); }			});			return;		}		requestFocusUnsafe();	}	private void requestFocusUnsafe()	{		if (TopLevel.isMDIMode())		{			((JInternalFrame)jf).toFront();			try {				((JInternalFrame)jf).setSelected(true);			} catch (java.beans.PropertyVetoException e) {}		} else		{			((JFrame)jf).toFront();			jf.requestFocus();		}	}	public Rectangle getMessagesLocation()	{		return jf.getBounds();	}	public int getMessagesCharWidth()	{		return info.getColumns();	}	/**	 * Method to adjust the Messages Window so that it attaches to the current Edit Window.	 */	public void tileWithEdit()	{		// get the location of the edit window		WindowFrame wf = WindowFrame.getCurrentWindowFrame();		if (wf == null) return;		Rectangle eb;		if (TopLevel.isMDIMode()) eb = wf.getInternalFrame().getBounds(); else			eb = wf.getFrame().getBounds();		// get the location of the messages window		Rectangle mb = this.getMessagesLocation();		// adjust the messages window location and size		mb.x = eb.x;		mb.width = eb.width;		mb.y = eb.y + eb.height;		jf.setBounds(mb);	}	/**	 * Method to erase everything in the messages window.	 */	public void clear()	{		info.setText("");	}	public void update(Observable obs, Object str)	{		String mess = (String)str;		appendString(mess);	}	private void appendString(String str)	{		if (str.length() == 0) return;		synchronized (buffer)		{			if (buffer.length() == 0)				buffer.notify();			buffer.append(str);		}	}	public void run()	{		for (;;)		{			synchronized (buffer)			{				try				{					while (dumpInvoked || buffer.length() == 0)						buffer.wait();				} catch (InterruptedException ie) {}				dumpInvoked = true;			}			try			{				Thread.sleep(200);			} catch (InterruptedException ie) {}			SwingUtilities.invokeLater(new Runnable()			{				public void run()				{					String s;					synchronized (buffer)					{						s = buffer.toString();						buffer.setLength(0);						dumpInvoked = false;					}					dump(s);				}			});		}	}	protected void dump(String str)	{		info.append(str);		if (Job.BATCHMODE) return;		try		{			Rectangle r = info.modelToView(info.getDocument().getLength());			info.scrollRectToVisible(r);		} catch (javax.swing.text.BadLocationException ble)		{

⌨️ 快捷键说明

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