sharedfilepropertieswindow.java

来自「JMule是一个基于Java开发」· Java 代码 · 共 211 行

JAVA
211
字号
/* *  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.shared;import org.eclipse.swt.SWT;import org.eclipse.swt.events.SelectionAdapter;import org.eclipse.swt.events.SelectionEvent;import org.eclipse.swt.graphics.Cursor;import org.eclipse.swt.layout.GridData;import org.eclipse.swt.layout.GridLayout;import org.eclipse.swt.widgets.Button;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Event;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.widgets.Listener;import org.eclipse.swt.widgets.Shell;import org.jmule.core.sharingmanager.PartialFile;import org.jmule.core.sharingmanager.SharedFile;import org.jmule.ui.JMuleUIComponent;import org.jmule.ui.JMuleUIManager;import org.jmule.ui.localizer.Localizer;import org.jmule.ui.localizer._;import org.jmule.ui.swt.GUIUpdater;import org.jmule.ui.swt.Refreshable;import org.jmule.ui.swt.SWTImageRepository;import org.jmule.ui.swt.SWTThread;import org.jmule.ui.swt.Utils;import org.jmule.ui.swt.skin.SWTSkin;import org.jmule.ui.utils.FileFormatter;/** * Created on Aug 18, 2008 * @author binary256 * @version $Revision: 1.2 $ * Last changed by $Author: binary256_ $ on $Date: 2008/10/02 06:11:28 $ */public class SharedFilePropertiesWindow implements JMuleUIComponent {	private Shell shell;	private SharedFile shared_file;	private Label completed;	private Refreshable refresher = null;		public SharedFilePropertiesWindow(SharedFile sharedFile) {		shared_file = sharedFile;		}		public void getCoreComponents() {		SWTSkin skin = null;		try {		    skin = (SWTSkin) JMuleUIManager.getJMuleUI().getSkin();		}catch(Throwable t) {		}				final Shell shell1=new Shell(SWTThread.getDisplay(),SWT.ON_TOP);		shell=new Shell(shell1,SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE);				shell.setText(_._("sharedfilepropertieswindow.title"));		shell.setImage(SWTImageRepository.getImage("info.png"));				shell.setSize(500, 310);				Utils.centreWindow(shell);				shell.setLayout(new GridLayout(1,false));		Composite shared_file_fields = new Composite(shell,SWT.BORDER);		shared_file_fields.setLayout(new GridLayout(2,false));		shared_file_fields.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.FILL_BOTH));		Label label;				label = new Label(shared_file_fields,SWT.NONE);		label.setFont(skin.getLabelFont());		label.setText(_._("sharedfilepropertieswindow.label.filename")+" : ");		label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));		label = new Label(shared_file_fields,SWT.NONE);		label.setFont(skin.getLabelFont());		label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));		label.setText(shared_file.getSharingName());				label = new Label(shared_file_fields,SWT.NONE);		label.setFont(skin.getLabelFont());		label.setText(_._("sharedfilepropertieswindow.label.filesize")+" : ");		label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));		label = new Label(shared_file_fields,SWT.NONE);		label.setFont(skin.getLabelFont());		label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));		label.setText(FileFormatter.formatFileSize(shared_file.length()));				label = new Label(shared_file_fields,SWT.NONE);		label.setFont(skin.getLabelFont());		label.setText(_._("sharedfilepropertieswindow.label.filepath")+" : ");		label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));		label = new Label(shared_file_fields,SWT.NONE);		label.setFont(skin.getLabelFont());		label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));		label.setText(shared_file.getAbsolutePath());		label.setToolTipText(shared_file.getAbsolutePath());				label = new Label(shared_file_fields,SWT.NONE);		label.setFont(skin.getLabelFont());		label.setText(_._("sharedfilepropertieswindow.label.filestype")+" : ");		label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));		label = new Label(shared_file_fields,SWT.NONE);		label.setFont(skin.getLabelFont());		label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));		label.setText(FileFormatter.formatMimeType(shared_file.getMimeType()));				label = new Label(shared_file_fields,SWT.NONE);		label.setFont(skin.getLabelFont());		label.setText(_._("sharedfilepropertieswindow.label.file_hash")+" : ");		label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));		label = new Label(shared_file_fields,SWT.NONE);		label.setFont(skin.getLabelFont());		label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));		label.setText(shared_file.getFileHash().getAsString());		label.setForeground(SWTThread.getDisplay().getSystemColor(SWT.COLOR_BLUE));				label = new Label(shared_file_fields,SWT.NONE);		label.setFont(skin.getLabelFont());		label.setText(_._("sharedfilepropertieswindow.label.completed")+" : ");		label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));						completed = new Label(shared_file_fields,SWT.NONE);		completed.setFont(skin.getLabelFont());		completed.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));		if (shared_file instanceof PartialFile) {			refresher = new Refreshable(){				public void refresh() {					PartialFile p_file = (PartialFile) shared_file;					completed.setText(FileFormatter.formatProgress(p_file.getPercentCompleted()));				}							};			GUIUpdater.getInstance().addRefreshable(refresher);		}else			completed.setText("100%");				label = new Label(shared_file_fields,SWT.NONE);		label.setFont(skin.getLabelFont());		label.setText(Localizer._("sharedfilepropertieswindow.label.ed2k_link") + " : ");		label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));		label = new Label(shared_file_fields,SWT.NONE);		label.setFont(skin.getDefaultFont());		label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));		label.setText(shared_file.getED2KLink().getAsString());		label.setToolTipText(_._("sharedfilepropertieswindow.label.ed2k_link.tooltip"));		label.setForeground(SWTThread.getDisplay().getSystemColor(SWT.COLOR_BLUE));		label.setCursor(new Cursor(SWTThread.getDisplay(),SWT.CURSOR_HAND));		label.addListener(SWT.MouseUp, new Listener() {			public void handleEvent(Event arg0) {				Utils.setClipBoardText(shared_file.getED2KLink().getAsString());			}		});						Composite button_bar = new Composite(shell,SWT.NONE);		button_bar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));				GridLayout layout = new GridLayout(2,false);		button_bar.setLayout(layout);						Button button = new Button(button_bar,SWT.NONE);		button.setFont(skin.getButtonFont());		button.setText(_._("sharedfilepropertieswindow.button.close"));				GridData grid_data = new GridData();		grid_data.horizontalAlignment = GridData.END;		grid_data.widthHint = 60;		grid_data.grabExcessHorizontalSpace = true;		button.setLayoutData(grid_data);				button.addSelectionListener(new SelectionAdapter() {			public void widgetSelected(final SelectionEvent e) {				if (refresher != null) {					GUIUpdater.getInstance().removeRefreshable(refresher);				}				shell.close();			}		});	}	public void initUIComponents() {		shell.open();	}}

⌨️ 快捷键说明

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