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

📄 memorymonitor.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
字号:
/*
 *    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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*
 * Created on 2006/8/7
 *
 * @Author: Xiaojun Chen
 * $Revision$ 1.0
 *
 */

package eti.bi.alphaminer.tools.SystemTools.SystemToolPage;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.border.TitledBorder;
import eti.bi.alphaminer.tools.SystemTools.SystemToolPanel;
import eti.bi.common.Locale.Resource;
import eti.bi.util.MemoryUtil;


public class MemoryMonitor extends SystemToolPanel implements ActionListener{

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPopupMenu menu;
	private JMenuItem start;
	private JMenuItem stop;
	private JMenuItem gc;
	private MemoryMonitorPanel monitor;
	
	public MemoryMonitor() {
		super(Resource.srcStr("MemoryMonitor"));
		setBackground(Color.WHITE);
		monitor = new MemoryMonitorPanel();
		monitor.setPreferredSize(new Dimension(180,300));
		monitor.addMouseListener(this);
		monitor.setMonitorable(true);
		this.add(monitor);
		
		menu = new JPopupMenu();
		start = new JMenuItem(Resource.srcStr("MemoryMonitor_Start"));
		stop = new JMenuItem(Resource.srcStr("MemoryMonitor_Stop"));
		gc = new JMenuItem(Resource.srcStr("MemoryMonitor_Gc"));
		start.addActionListener(this);
		stop.addActionListener(this);
		gc.addActionListener(this);
		
		setBorder(BorderFactory.createTitledBorder(Resource.srcStr("MemoryMonitor")));
	}

	public void mouseClicked(MouseEvent e) {
		if(e.getClickCount()==1&&e.getButton()==MouseEvent.BUTTON3) {
			if(monitor.isMonitoring()) {
				menu.removeAll();
				menu.add(stop);
				menu.add(new JPopupMenu.Separator());
				menu.add(gc);
				menu.show(e.getComponent(), e.getX(), e.getY());
			}
			else {
				menu.removeAll();
				menu.add(start);
				menu.add(new JPopupMenu.Separator());
				menu.add(gc);
				menu.show(e.getComponent(), e.getX(), e.getY());
			}
		}
	}

	public void actionPerformed(ActionEvent e) {
		Object source = e.getSource();
		if(source instanceof JMenuItem) {
			if(source.equals(start)) {
				monitor.monitor(true);
			}
			else if(source.equals(stop)){
				monitor.monitor(false);
			}
			else if(source.equals(gc)) {
				try {
					MemoryUtil.runGC();
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		}
	}

	public void addToolMouseListener(MouseListener l) {
		this.addMouseListener(l);
	}

	public JComponent getTopComponentAt(Point point) {
		return monitor;
	}
	
	public void hideTool() {
		monitor.monitor(false);
		this.setVisible(false);
	}

	public void showTool(){
		monitor.monitor(true);
		this.setVisible(true);
	}
	
	public void resetLocale() {
		this.setName(Resource.srcStr("MemoryMonitor"));
		start.setText(Resource.srcStr("MemoryMonitor_Start"));
		stop.setText(Resource.srcStr("MemoryMonitor_Stop"));
		gc.setText(Resource.srcStr("MemoryMonitor_Gc"));
		((TitledBorder)getBorder()).setTitle(Resource.srcStr("MemoryMonitor"));
	}

	public void dispose() {
		menu = null;
		start = null;
		stop = null;
		monitor.dispose();
	}
}

⌨️ 快捷键说明

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