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

📄 downloadstable.java

📁 JMule是一个基于Java开发
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
				 });				 cancel_download = new JMenuItem("Cancel download");				 cancel_download.setIcon(ImgRep.getIcon("cancel.png"));				 cancel_download.addActionListener(new ActionListener() {					public void actionPerformed(ActionEvent e) {						for(DownloadSession session : getSelectedDownloadSessions())							_download_manager.removeDownload(session.getFileHash());					}				 });				 paste_ed2k_links = new JMenuItem("Paste ed2k link(s)");				 paste_ed2k_links.setIcon(ImgRep.getIcon("ed2k_link_paste.png"));				 paste_ed2k_links.addActionListener(new ActionListener() {					   public void actionPerformed(ActionEvent event) {						      (new JMThread(new JMRunnable() {						    	   public void JMRun() {						    		 try {  						    		   Object clipboard_contents = clipboard.getData(DataFlavor.stringFlavor);						    		   List<ED2KFileLink> clipboard_file_links = ED2KFileLink.extractLinks(clipboard_contents.toString());									   if( clipboard_file_links.size() != 0 )  										 for(ED2KFileLink file_link : clipboard_file_links) {  	                                        _download_manager.addDownload(file_link); 										  }						    		 }catch(Throwable t) {						    			 t.printStackTrace();						    		 }								   }						      })).start();					   }				   });				 copy_ed2k_links = new JMenuItem("Copy ed2k link(s)");				 copy_ed2k_links.setIcon(ImgRep.getIcon("ed2k_link.png"));				 copy_ed2k_links.addActionListener(new ActionListener() {					public void actionPerformed(ActionEvent e) {						clipboard.setContents(new Transferable() {							public Object getTransferData(DataFlavor flavor)									throws UnsupportedFlavorException,									IOException {								String ed2k_links = "";								DownloadSession[] download_sessions = getSelectedDownloadSessions();								for(DownloadSession session : download_sessions) {									ed2k_links += session.getED2KLink().getAsString() + System.getProperty("line.separator");								}								return ed2k_links;							}							public DataFlavor[] getTransferDataFlavors() {								DataFlavor[] data_flavours = new DataFlavor[1];								data_flavours[0] = DataFlavor.stringFlavor;								return data_flavours;							}							public boolean isDataFlavorSupported(									DataFlavor flavor) {							    return flavor.isFlavorTextType();							}													}, new ClipboardOwner() {							public void lostOwnership(Clipboard clipboard, Transferable contents) {															}													});					}				 });				 column_setup = new JMenuItem("Column setup");				 column_setup.setIcon(ImgRep.getIcon("columns_setup.png"));				 column_setup.addActionListener(new ActionListener() {					public void actionPerformed(ActionEvent e) {						System.out.println("Column setup performed");					}				 });				 properties = new JMenuItem("Properties");				 properties.setIcon(ImgRep.getIcon("info.png"));				 properties.addActionListener(new ActionListener() {					public void actionPerformed(ActionEvent e) {						DownloadSession sessions[] = getSelectedDownloadSessions();						DownloadDetailsDialog ddd = new DownloadDetailsDialog(parent, sessions[0]);						SwingUtils.setWindowLocationRelativeTo(ddd, parent);						ddd.setVisible(true);					}				 });			}						public void mousePressed(MouseEvent e) {				showPopup(e);			}						public void mouseReleased(MouseEvent e) {				showPopup(e);			}						private void showPopup(MouseEvent e) {				 				 if (e.isPopupTrigger()) {					 					 JPopupMenu popup_menu = null;					 					 switch( whichCondition() ) {					 					     case A  :  popup_menu = new JPopupMenu();					                popup_menu.add(stop_download);					                popup_menu.add(cancel_download);					                popup_menu.addSeparator();					                popup_menu.add(copy_ed2k_links);					                popup_menu.add(paste_ed2k_links);					                popup_menu.addSeparator();					           //     popup_menu.add(column_setup);					                popup_menu.add(properties);					                break;					                					     case B :   popup_menu = new JPopupMenu();			                        popup_menu.add(stop_download);			                        popup_menu.add(cancel_download);			                        popup_menu.addSeparator();			                        popup_menu.add(copy_ed2k_links);			                        popup_menu.add(paste_ed2k_links);			                        popup_menu.addSeparator();			                 //       popup_menu.add(column_setup);			                        popup_menu.add(properties);			                        break;			                        					     case C :   popup_menu = new JPopupMenu();					                popup_menu.add(start_download);	                                popup_menu.add(cancel_download);	                                popup_menu.addSeparator();	                                popup_menu.add(copy_ed2k_links);	                                popup_menu.add(paste_ed2k_links);	                                popup_menu.addSeparator();	                          //      popup_menu.add(column_setup);	                                popup_menu.add(properties);	                                break;	                                					     case D :   popup_menu = new JPopupMenu();			                        popup_menu.add(start_download);                                    popup_menu.add(cancel_download);                                    popup_menu.addSeparator();                                    popup_menu.add(copy_ed2k_links);                                    popup_menu.add(paste_ed2k_links);                                    popup_menu.addSeparator();                             //       popup_menu.add(column_setup);                                    popup_menu.add(properties);                                    break;                                  					     case E :   popup_menu = new JPopupMenu();					                //popup_menu.add(copy_ed2k_links);                                    popup_menu.add(paste_ed2k_links);                            //        popup_menu.addSeparator();                            //        popup_menu.add(column_setup);                                    break;                                    					     case F :   popup_menu = new JPopupMenu();					                popup_menu.add(start_download);			                        popup_menu.add(stop_download);			                        popup_menu.add(cancel_download);			                        popup_menu.addSeparator();			                        popup_menu.add(copy_ed2k_links);			                        popup_menu.add(paste_ed2k_links);			                 //       popup_menu.addSeparator();			                 //       popup_menu.add(column_setup);			                        break;					 }					 					 popup_menu.show(e.getComponent(), e.getX(), e.getY());				 }			}						}				this.addMouseListener(new PopupListener());	}		private DownloadSession[] getDownloadSessionsByIndexes(int[] indexes) {		DownloadSession[] result = new DownloadSession[indexes.length];		int k = 0;		for(int i : indexes) {			int j = 0;			for(DownloadSession session : _download_manager.getDownloads()) {				if( j == this.convertRowIndexToModel(i) ) {					result[k++] = session;					break;				}				++j;			}		}		return result;	}		private DownloadSession[] getSelectedDownloadSessions() {				return getDownloadSessionsByIndexes(  this.getSelectedRows() );	}		/*	 *  --------------------------------------------------------------------------------------	 *                    |     STARTED    |         STOPPED    |       STARTED & STOPPED	 *  ---------------------------------------------------------------------------------------	 *  ONE_SELECTED      |       A                   C                     *	 *                    |	 *  MULTIPLE_SELECTED |       B                   D                     F	 *                    |	 *  VOID_LIST         |       *                   *                     *	 *                    |	 * 	 *          E - void list	 *          * - can't be	 *          	 *   Ac1 | Start download	 *   Ac2 | Stop download	 *   Ac3 | Cancel download	 *   Ac4 | Copy ed2k link(s)	 *   Ac5 | Paste ed2k link(s)	 *   Ac6 | Column setup	 *   Ac7 | Details	 *   	 *     |  Ac1    Ac2    Ac3    Ac4    Ac5    Ac6    Ac7	 *  --------------------------------------------------------  	 *   A |   -     Yes    Yes    Yes    Yes    Yes    Yes	 *     |	 *   B |   -     Yes    Yes    Yes    Yes    Yes    Yes	 *     |	 *   C |  Yes     -     Yes    Yes    Yes    Yes    Yes	 *     |	 *   D |  Yes     -     Yes    Yes    Yes    Yes    Yes	 *     |	 *   E |   -      -      -     -     Yes    Yes     -	 *     |	 *   F |  Yes    Yes    Yes    Yes    Yes    Yes     -	 */		private ConditionType whichCondition() {				DownloadSession[] download_sessions = getSelectedDownloadSessions();				if( ( download_sessions.length == 1 ) && 			( download_sessions[0].getStatus() == DownloadSession.STATUS_STARTED ) )			return ConditionType.A;				if( download_sessions.length > 1) {			boolean b = true;			for(DownloadSession session : download_sessions) {				if( session.getStatus() != DownloadSession.STATUS_STARTED ) {					b = false;					break;				}			}			if(b) return ConditionType.B;				}				if( ( download_sessions.length == 1 ) &&			( download_sessions[0].getStatus() == DownloadSession.STATUS_STOPPED ) )			return ConditionType.C;				if( download_sessions.length > 1 ) {			boolean b = true;			for(DownloadSession session : download_sessions) {				if( session.getStatus() != DownloadSession.STATUS_STOPPED ) { 					 b = false;					 break;				}			}			if(b) return ConditionType.D;			}				if( download_sessions.length == 0 ) return ConditionType.E;				if( download_sessions.length > 1 ) {			boolean some_started = false;			boolean some_stopped = false;			for(DownloadSession session : download_sessions) {				if(session.getStatus() == DownloadSession.STATUS_STARTED) some_started = true;				if(session.getStatus() == DownloadSession.STATUS_STOPPED) some_stopped = true;			}			if( some_started && some_stopped ) 				return ConditionType.F;		}				return null;	}		private enum ConditionType {		A,B,C,D,E,F	}	}

⌨️ 快捷键说明

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