📄 statisticstab.java
字号:
/* * JMule - Java file sharing client * Copyright (C) 2007-2008 JMule team ( jmule@jmule.org / http://jmule.org ) * * Any parts of this program derived from other projects, or contributed * by third-party developers are copyrighted by their respective authors. * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */package org.jmule.ui.swt.maintabs.statistics;import java.lang.management.MemoryMXBean;import java.lang.management.MemoryUsage;import java.lang.management.RuntimeMXBean;import java.lang.management.ThreadMXBean;import java.util.HashSet;import java.util.Hashtable;import java.util.Map;import java.util.Set;import org.eclipse.swt.SWT;import org.eclipse.swt.custom.CTabFolder;import org.eclipse.swt.custom.CTabItem;import org.eclipse.swt.layout.FillLayout;import org.eclipse.swt.layout.GridData;import org.eclipse.swt.layout.GridLayout;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Group;import org.eclipse.swt.widgets.Label;import org.jmule.core.statistics.JMuleCoreStats;import org.jmule.ui.JMuleUIManager;import org.jmule.ui.localizer._;import org.jmule.ui.swt.GUIUpdater;import org.jmule.ui.swt.Refreshable;import org.jmule.ui.swt.maintabs.AbstractTab;import org.jmule.ui.swt.skin.SWTSkin;import org.jmule.ui.utils.FileFormatter;import org.jmule.ui.utils.TimeFormatter;import sun.management.ManagementFactory;/** * * @author binary256 * @version $$Revision: 1.2 $$ * Last changed by $$Author: binary256_ $$ on $$Date: 2008/10/02 06:11:28 $$ */public class StatisticsTab extends AbstractTab{ private Refreshable refreshable; private Map<String,Label> stats_fields = new Hashtable<String,Label>(); private Set<String> types = new HashSet<String>(); private Set<String> filesize_formatter = new HashSet<String>(); private RuntimeMXBean runtime_bean = ManagementFactory.getRuntimeMXBean(); private MemoryMXBean memory_bean = ManagementFactory.getMemoryMXBean(); private MemoryUsage heap_memory = memory_bean.getHeapMemoryUsage(); private MemoryUsage nonheap_memory = memory_bean.getNonHeapMemoryUsage(); private ThreadMXBean thread_bean = ManagementFactory.getThreadMXBean(); private Label heapmemory_init, heapmemory_used, heapmemory_max, nonheapmemory_init,jvm_uptime, nonheapmemory_used, nonheapmemory_max, thread_count,daemon_thread_count,peak_thread_count, total_thread_count; public StatisticsTab(Composite shell) { super(shell); types.add(JMuleCoreStats.ST_NET_SESSION_DOWNLOAD_BYTES); types.add(JMuleCoreStats.ST_NET_SESSION_UPLOAD_BYTES); types.add(JMuleCoreStats.ST_NET_SESSION_DOWNLOAD_COUNT); types.add(JMuleCoreStats.ST_NET_SESSION_UPLOAD_COUNT); types.add(JMuleCoreStats.ST_NET_PEERS_COUNT); types.add(JMuleCoreStats.ST_NET_PEERS_DOWNLOAD_COUNT); types.add(JMuleCoreStats.ST_NET_PEERS_UPLOAD_COUNT); types.add(JMuleCoreStats.ST_NET_SERVERS_COUNT); types.add(JMuleCoreStats.ST_NET_SERVERS_DEAD_COUNT); types.add(JMuleCoreStats.ST_NET_SERVERS_ALIVE_COUNT); types.add(JMuleCoreStats.ST_DISK_SHARED_FILES_COUNT); types.add(JMuleCoreStats.ST_DISK_SHARED_FILES_PARTIAL_COUNT); types.add(JMuleCoreStats.ST_DISK_SHARED_FILES_COMPLETE_COUNT); types.add(JMuleCoreStats.ST_DISK_SHARED_FILES_BYTES); types.add(JMuleCoreStats.ST_DISK_SHARED_FILES_PARTIAL_BYTES); types.add(JMuleCoreStats.ST_DISK_SHARED_FILES_COMPLETE_BYTES); types.add(JMuleCoreStats.SEARCHES_COUNT); filesize_formatter.add(JMuleCoreStats.ST_NET_SESSION_DOWNLOAD_BYTES); filesize_formatter.add(JMuleCoreStats.ST_NET_SESSION_UPLOAD_BYTES); filesize_formatter.add(JMuleCoreStats.ST_DISK_SHARED_FILES_BYTES); filesize_formatter.add(JMuleCoreStats.ST_DISK_SHARED_FILES_PARTIAL_BYTES); filesize_formatter.add(JMuleCoreStats.ST_DISK_SHARED_FILES_COMPLETE_BYTES); refreshable = new Refreshable() { public void refresh() { Map<String,Object> stats = JMuleCoreStats.getStats(types); for(String key : stats.keySet()) { Number value = (Number)stats.get(key); Label label = stats_fields.get(key); String str = value+""; if (filesize_formatter.contains(key)) str = FileFormatter.formatFileSize((Long) value); label.setText(str); } jvm_uptime.setText(TimeFormatter.formatColon(runtime_bean.getUptime()/1000)+""); heapmemory_init.setText(FileFormatter.formatFileSize(heap_memory.getInit())); heapmemory_used.setText(FileFormatter.formatFileSize(heap_memory.getUsed())); heapmemory_max.setText(FileFormatter.formatFileSize(heap_memory.getMax())); nonheapmemory_init.setText(FileFormatter.formatFileSize(nonheap_memory.getInit())); nonheapmemory_used.setText(FileFormatter.formatFileSize(nonheap_memory.getUsed())); nonheapmemory_max.setText(FileFormatter.formatFileSize(nonheap_memory.getMax())); thread_count.setText(thread_bean.getThreadCount()+""); daemon_thread_count.setText(thread_bean.getDaemonThreadCount()+""); peak_thread_count.setText(thread_bean.getPeakThreadCount()+""); total_thread_count.setText(thread_bean.getTotalStartedThreadCount()+""); } }; SWTSkin skin = null; try { skin = (SWTSkin) JMuleUIManager.getJMuleUI().getSkin(); }catch(Throwable t) {} Composite content; GridData layout_data; GridLayout layout; Label label; setLayout(new FillLayout()); CTabFolder stats_tabs = new CTabFolder(this,SWT.BORDER); stats_tabs.setLayout(new FillLayout()); stats_tabs.setSimple(false); CTabItem network_stats = new CTabItem(stats_tabs,SWT.NONE); network_stats.setText(_._("mainwindow.statisticstab.tab.general")); content = new Composite(stats_tabs,SWT.NONE); network_stats.setControl(content); content.setLayout(new GridLayout(2,true)); Group sessions_stats = new Group(content,SWT.NONE); sessions_stats.setText(_._("mainwindow.statisticstab.tab.general.group.sessions")); layout_data = new GridData(GridData.FILL_HORIZONTAL); sessions_stats.setLayoutData(layout_data); layout = new GridLayout(2,false); sessions_stats.setLayout(layout); label = new Label(sessions_stats,SWT.NONE); label.setFont(skin.getLabelFont()); label.setText(_._("mainwindow.statisticstab.tab.general.label.session_downloaded") + " : "); label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); Label download_session_bytes = new Label(sessions_stats,SWT.NONE); download_session_bytes.setFont(skin.getLabelFont()); download_session_bytes.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); stats_fields.put(JMuleCoreStats.ST_NET_SESSION_DOWNLOAD_BYTES, download_session_bytes); label = new Label(sessions_stats,SWT.NONE); label.setFont(skin.getLabelFont()); label.setText(_._("mainwindow.statisticstab.tab.general.label.session_uploaded") + " : "); label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); Label upload_session_bytes = new Label(sessions_stats,SWT.NONE); upload_session_bytes.setFont(skin.getLabelFont()); upload_session_bytes.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); stats_fields.put(JMuleCoreStats.ST_NET_SESSION_UPLOAD_BYTES, upload_session_bytes); label = new Label(sessions_stats,SWT.NONE); label.setFont(skin.getLabelFont()); label.setText(_._("mainwindow.statisticstab.tab.general.label.session_download_count") + " : "); label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); Label download_session_count = new Label(sessions_stats,SWT.NONE); download_session_count.setFont(skin.getLabelFont()); download_session_count.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); stats_fields.put(JMuleCoreStats.ST_NET_SESSION_DOWNLOAD_COUNT, download_session_count); label = new Label(sessions_stats,SWT.NONE); label.setFont(skin.getLabelFont()); label.setText(_._("mainwindow.statisticstab.tab.general.label.session_upload_count") + " : "); label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); Label upload_session_count = new Label(sessions_stats,SWT.NONE); upload_session_count.setFont(skin.getLabelFont()); upload_session_count.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); stats_fields.put(JMuleCoreStats.ST_NET_SESSION_UPLOAD_COUNT, upload_session_count); Group peers_stats = new Group(content,SWT.NONE); peers_stats.setText(_._("mainwindow.statisticstab.tab.general.group.peers")); layout_data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING ); peers_stats.setLayoutData(layout_data); layout = new GridLayout(2,false); peers_stats.setLayout(layout); label = new Label(peers_stats,SWT.NONE); label.setFont(skin.getLabelFont()); label.setText(_._("mainwindow.statisticstab.tab.general.label.peer_count") + " : "); label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); Label peer_count = new Label(peers_stats,SWT.NONE); peer_count.setFont(skin.getLabelFont()); peer_count.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); stats_fields.put(JMuleCoreStats.ST_NET_PEERS_COUNT, peer_count); label = new Label(peers_stats,SWT.NONE); label.setFont(skin.getLabelFont()); label.setText(_._("mainwindow.statisticstab.tab.general.label.download_peers") + " : "); label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); Label download_peers = new Label(peers_stats,SWT.NONE); download_peers.setFont(skin.getLabelFont()); download_peers.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); stats_fields.put(JMuleCoreStats.ST_NET_PEERS_DOWNLOAD_COUNT, download_peers); label = new Label(peers_stats,SWT.NONE); label.setFont(skin.getLabelFont()); label.setText(_._("mainwindow.statisticstab.tab.general.label.upload_peers") + " : "); label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); Label upload_peers = new Label(peers_stats,SWT.NONE); upload_peers.setFont(skin.getLabelFont()); upload_peers.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); stats_fields.put(JMuleCoreStats.ST_NET_PEERS_UPLOAD_COUNT, upload_peers); new Label(peers_stats,SWT.NONE); Group sesvers_stats = new Group(content,SWT.NONE); sesvers_stats.setText(_._("mainwindow.statisticstab.tab.general.group.servers")); layout_data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING ); sesvers_stats.setLayoutData(layout_data); layout = new GridLayout(2,false); sesvers_stats.setLayout(layout); label = new Label(sesvers_stats,SWT.NONE); label.setFont(skin.getLabelFont()); label.setText(_._("mainwindow.statisticstab.tab.general.label.server_count") + " : "); label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); Label server_count = new Label(sesvers_stats,SWT.NONE); server_count.setFont(skin.getLabelFont()); server_count.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); stats_fields.put(JMuleCoreStats.ST_NET_SERVERS_COUNT, server_count); label = new Label(sesvers_stats,SWT.NONE); label.setFont(skin.getLabelFont()); label.setText(_._("mainwindow.statisticstab.tab.general.label.server_alive_count") + " : "); label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); Label server_alive_count = new Label(sesvers_stats,SWT.NONE); server_alive_count.setFont(skin.getLabelFont()); server_alive_count.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); stats_fields.put(JMuleCoreStats.ST_NET_SERVERS_ALIVE_COUNT, server_alive_count);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -