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

📄 sharedtab.java

📁 JMule是一个基于Java开发
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* *  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.swing.maintabs.shared;import java.awt.BorderLayout;import java.awt.Component;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Insets;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.io.File;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.concurrent.CopyOnWriteArrayList;import javax.swing.AbstractListModel;import javax.swing.JButton;import javax.swing.JFileChooser;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JList;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JSplitPane;import javax.swing.ListCellRenderer;import javax.swing.SwingUtilities;import javax.swing.border.TitledBorder;import javax.swing.filechooser.FileSystemView;import org.apache.commons.io.FileUtils;import org.jmule.core.JMThread;import org.jmule.core.JMuleCore;import org.jmule.core.JMuleCoreFactory;import org.jmule.core.configmanager.ConfigurationAdapter;import org.jmule.core.configmanager.ConfigurationManager;import org.jmule.core.sharingmanager.PartialFile;import org.jmule.core.sharingmanager.SharedFile;import org.jmule.core.sharingmanager.SharingManager;import org.jmule.ui.swing.ImgRep;import org.jmule.ui.swing.Refreshable;import org.jmule.ui.swing.SwingGUIUpdater;import org.jmule.ui.swing.maintabs.AbstractTab;import org.jmule.ui.swing.tables.SharedFilesTable;import org.jmule.ui.swing.wizards.ChosenFolders;import org.jmule.ui.swing.wizards.ExistedFoldersDialog;import org.jmule.ui.utils.NumberFormatter;/** *  * @author javajox * @version $$Revision: 1.1 $$ * Last changed by $$Author: javajox $$ on $$Date: 2008/10/16 17:35:15 $$ */public class SharedTab extends AbstractTab {	JMuleCore _core = JMuleCoreFactory.getSingleton();	SharingManager _sharing_manager = _core.getSharingManager();	ConfigurationManager _config_manager = _core.getConfigurationManager();	SwingGUIUpdater _updater = SwingGUIUpdater.getInstance(); 		private enum FilesCategory {		INCOMING_FILES { public String toString() { return "Incoming files"; } },		INCOMPLETE_FILES { public String toString() { return "Incomplete files"; } },		ALL_FILES { public String toString() { return "All files"; } }	}		class SharedFoldersListModel extends AbstractListModel {				public SharedFoldersListModel() {			_config_manager.addConfigurationListener(new ConfigurationAdapter() {				public void sharedDirectoriesChanged(List<File> sharedDirs) {					fireContentsChanged(this,2,sharedDirs.size()-1);				}			});		}				public Object getElementAt(int index) {            if(index == 0) return FilesCategory.INCOMING_FILES;            if(index == 1) return FilesCategory.INCOMPLETE_FILES;            if(index == 2) return FilesCategory.ALL_FILES;			return _config_manager.getSharedFolders().get(index-3);		}		public int getSize() {			if(_config_manager.getSharedFolders() == null) return 3;			return _config_manager.getSharedFolders().size() + 3;		}			}		class SharedFoldersListCellRenderer extends JLabel implements ListCellRenderer {		public Component getListCellRendererComponent(JList list, Object value,				int index, boolean isSelected, boolean cellHasFocus) {			if(value instanceof String) this.setText((String)value);			else if(value instanceof File) {				this.setFont(new java.awt.Font("Dialog", 0, 12));				this.setText(((File)value).getAbsolutePath());			} else if(value instanceof FilesCategory) {				FilesCategory files_category = (FilesCategory)value;				this.setFont(new java.awt.Font("Dialog", 1, 12));				this.setText(files_category.toString());			}			setEnabled(list.isEnabled());			//setFont(list.getFont());		    setOpaque(true);			if (isSelected) {		         setBackground(list.getSelectionBackground());			     setForeground(list.getSelectionForeground());			} else {			  	// if ( (index % 2) == 0 )			    //  this.setBackground(new Color(255,255,255));			   //  else			   //    this.setBackground(new Color(240,240,240));			       setBackground(list.getBackground());			       setForeground(list.getForeground());			}			return this;		}			}		class TopPanel extends JPanel {				private JButton add_button = new JButton("Add");		private JButton remove_button = new JButton("Remove");		private JButton rescan_button = new JButton("Rescan");		private JButton clear_button = new JButton("Clear");				public TopPanel() {			init();		}				private void init() {			GridBagLayout thisLayout = new GridBagLayout();			this.setPreferredSize(new java.awt.Dimension(467, 56));			thisLayout.rowWeights = new double[] {0.1};			thisLayout.rowHeights = new int[] {7};			thisLayout.columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};			thisLayout.columnWidths = new int[] {6, 107, 108, 107, 122, 7};			this.setLayout(thisLayout);			this.add(add_button, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 0, 10), 0, 0));            this.add(remove_button, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 0, 10), 0, 0));            this.add(clear_button, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 0, 10), 0, 0));            this.add(rescan_button, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 0, 10), 0, 0));            add_button.setIcon(ImgRep.getIcon("add.png"));            remove_button.setIcon(ImgRep.getIcon("remove.png"));            clear_button.setIcon(ImgRep.getIcon("remove_all.png"));            rescan_button.setIcon(ImgRep.getIcon("refresh.png"));		}				public JButton getAddButton() {						return add_button;		}				public JButton getRemoveButton() {						return remove_button;		}				public JButton getClearButton() {						return clear_button;		}				public JButton getRescanButton() {						return rescan_button;		}	}		private JSplitPane split_pane;	private TopPanel top_panel;	private JScrollPane shared_folders_scroll_pane;	private JScrollPane shared_files_scroll_pane;	private JList shared_folders_list;	private TitledBorder shared_folders_border;	private TitledBorder shared_files_border;	private SharedFoldersListModel shared_folders_list_model;	private SharedFilesTable shared_files_table;	    private JFileChooser file_chooser;    private FileSystemView file_system_view;     // current chosen folders     private File[] current_chosen_folders;    // all folders chosen during this session    private ChosenFolders chosen_folders;	//private JDialog parent;		public SharedTab(final JFrame parent) {		super(parent);		init();

⌨️ 快捷键说明

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