Package org.jmule.core.downloadmanager

Examples of org.jmule.core.downloadmanager.DownloadSession


  }
 
  public void downloadAdded(final FileHash fileHash) {
    SWTThread.getDisplay().asyncExec(new JMRunnable() {
      public void JMRun() {
        DownloadSession session;
        try {
          session = download_manager.getDownload(fileHash);
          addDownlaodSession(session);
          MainWindow.getLogger().fine(_._("mainwindow.logtab.message_download_added",session.getSharingName()));
        } catch (DownloadManagerException e) {
          e.printStackTrace();
        }
       
      }
View Full Code Here


  }

  public void downloadRemoved(final FileHash fileHash) {
    SWTThread.getDisplay().asyncExec(new JMRunnable() {
      public void JMRun() {
        DownloadSession session = null;
       
        for(BufferedTableRow s : line_list) {
          DownloadSession x = (DownloadSession) s.getData(SWTConstants.ROW_OBJECT_KEY);
          if (x.getFileHash().equals(fileHash)) {
            session = x;
            break;
          }
        }
        if (session == null) return ;
View Full Code Here

  }

  public void downloadStarted(final FileHash fileHash) {
    SWTThread.getDisplay().asyncExec(new JMRunnable() {
      public void JMRun() {
        DownloadSession downloadSession;
        try {
          downloadSession = download_manager.getDownload(fileHash);
        } catch (DownloadManagerException e) {
          e.printStackTrace();
          return ;
        }
        updateRow(downloadSession);
        MainWindow.getLogger().fine(_._("mainwindow.logtab.message_download_started",downloadSession.getSharingName()));
    }});
   
  }
View Full Code Here

  }

  public void downloadStopped(final FileHash fileHash) {
    SWTThread.getDisplay().asyncExec(new JMRunnable() {
      public void JMRun() {
        DownloadSession downloadSession;
        try {
          downloadSession = download_manager.getDownload(fileHash);
        } catch (DownloadManagerException e) {
          e.printStackTrace();
          return ;
        }
        updateRow(downloadSession);
        MainWindow.getLogger().fine(_._("mainwindow.logtab.message_download_stopped",downloadSession.getSharingName()));
    }});
  }
View Full Code Here

    upload_speed.setComparator(new Comparator() {
      public int compare(Object o1, Object o2) {
        Float u_speed1 = null;
        Float u_speed2 = null;
        try {
          DownloadSession d_session1 = (DownloadSession)o1;
          DownloadSession d_session2 = (DownloadSession)o2;
          UploadSession u_session1 = null;
          UploadSession u_session2 = null;
          if(_upload_manager.hasUpload(d_session1.getFileHash()))
            u_session1 = _upload_manager.getUpload(d_session1.getFileHash());
           if(_upload_manager.hasUpload(d_session2.getFileHash()))
            u_session2 = _upload_manager.getUpload(d_session2.getFileHash());
           u_speed1 = new Float((u_session1!=null)?u_session1.getSpeed():0.0f);
           u_speed2 = new Float((u_session2!=null)?u_session2.getSpeed():0.0f);
        }catch(Throwable cause) {
          cause.printStackTrace();
        }
         return Misc.compareAllObjects(u_speed1, u_speed2, "floatValue", true);
     
    });
   
    table_columns.add(upload_speed);
   
    TableColumnExt pieces = new TableColumnExt();
    pieces.setIdentifier(UIConstants.DOWNLOAD_LIST_PROGRESS_COLUMN_ID);
    pieces.setModelIndex(DownloadTableModel.PIECES);
    pieces.setVisible(_pref.isColumnVisible(UIConstants.DOWNLOAD_LIST_PROGRESS_COLUMN_ID));
    pieces.setHeaderValue("Pieces");
    pieces.setCellRenderer(new PiecesTableCellRenderer());
    pieces.setComparator(new GeneralComparator("getPercentCompleted"));
   
    table_columns.add(pieces);
   
    TableColumnExt done = new TableColumnExt();
    done.setIdentifier(UIConstants.DOWNLOAD_LIST_COMPLETED_COLUMN_ID);
    done.setModelIndex(DownloadTableModel.DONE);
    done.setVisible(_pref.isColumnVisible(UIConstants.DOWNLOAD_LIST_COMPLETED_COLUMN_ID));
    done.setHeaderValue("Done");
    done.setCellRenderer(new DoneTableCellRenderer());
    done.setComparator(new GeneralComparator("getPercentCompleted"));
   
    table_columns.add(done);
   
    TableColumnExt progress_bar = new TableColumnExt();
    progress_bar.setIdentifier(UIConstants.DOWNLOAD_LIST_PROGRESS_BAR_COLUMN_ID);
    progress_bar.setModelIndex(DownloadTableModel.PROGRESS_BAR);
    progress_bar.setVisible(_pref.isColumnVisible(UIConstants.DOWNLOAD_LIST_PROGRESS_BAR_COLUMN_ID));
    progress_bar.setHeaderValue("Progress");
    progress_bar.setCellRenderer(new ProgressBarTableCellRenderer());
    progress_bar.setComparator(new GeneralComparator("getPercentCompleted"));
   
    table_columns.add(progress_bar);
   
    TableColumnExt complete_sources = new TableColumnExt();
    complete_sources.setIdentifier(UIConstants.DOWNLOAD_LIST_COMPLETE_SOURCES_COLUMN_ID);
    complete_sources.setModelIndex(DownloadTableModel.COMPLETE_SOURCES);
    complete_sources.setVisible(_pref.isColumnVisible(UIConstants.DOWNLOAD_LIST_COMPLETE_SOURCES_COLUMN_ID));
    complete_sources.setVisible(true);
    complete_sources.setHeaderValue("Complete sources");
    complete_sources.setCellRenderer(new CompletedSourcesTableCellRenderer());
    complete_sources.setComparator(new GeneralComparator("getCompletedSources"));
   
    table_columns.add(complete_sources);
   
    TableColumnExt partial_sources = new TableColumnExt();
    partial_sources.setIdentifier(UIConstants.DOWNLOAD_LIST_PARTIAL_SOURCES_COLUMN_ID);
    partial_sources.setModelIndex(DownloadTableModel.PARTIAL_SOURCES);
    partial_sources.setVisible(_pref.isColumnVisible(UIConstants.DOWNLOAD_LIST_PARTIAL_SOURCES_COLUMN_ID));
    partial_sources.setVisible(true);
    partial_sources.setHeaderValue("Partial sources");
    partial_sources.setCellRenderer(new PartialSourcesTableCellRenderer());
    partial_sources.setComparator(new GeneralComparator("getPartialSources"));
   
    table_columns.add(partial_sources);
   
    TableColumnExt eta = new TableColumnExt();
    eta.setIdentifier(UIConstants.DOWNLOAD_LIST_REMAINING_COLUMN_ID);
    eta.setModelIndex(DownloadTableModel.ETA);
    eta.setVisible(_pref.isColumnVisible(UIConstants.DOWNLOAD_LIST_REMAINING_COLUMN_ID));
    eta.setHeaderValue("ETA");
    eta.setCellRenderer(new ETATableCellRenderer());
    eta.setComparator(new GeneralComparator("getETA"));
   
    table_columns.add(eta);
   
    TableColumnExt status = new TableColumnExt();
    status.setIdentifier(UIConstants.DOWNLOAD_LIST_STATUS_COLUMN_ID);
    status.setModelIndex(DownloadTableModel.STATUS);
    status.setVisible(_pref.isColumnVisible(UIConstants.DOWNLOAD_LIST_STATUS_COLUMN_ID));
    status.setHeaderValue("Status");
    status.setCellRenderer(new StatusTableCellRenderer());
    status.setComparator(new GeneralComparator("getStatus"));
   
    table_columns.add(status);
   
    super.buildColumns(new DownloadTableModel());
   
    class PopupListener extends MouseAdapter {
     
      JMenuItem start_download, stop_download, cancel_download,
                    paste_ed2k_links, copy_ed2k_links, column_setup, properties;
     
      public PopupListener() {
         start_download = new JMenuItem("Start download");
         start_download.setIcon(ImgRep.getIcon("start_download.png"));
         start_download.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            for(DownloadSession session : getSelectedDownloadSessions())
              if(session.getStatus() == DownloadStatus.STOPPED
              try {
                _download_manager.startDownload(session.getFileHash());
              }catch(Throwable cause) {
                cause.printStackTrace();
              }
          }
         });
         stop_download = new JMenuItem("Stop download");
         stop_download.setIcon(ImgRep.getIcon("stop_download.png"));
         stop_download.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            for(DownloadSession session : getSelectedDownloadSessions())
              if(session.getStatus() == DownloadStatus.STARTED
               try {
              _download_manager.startDownload(session.getFileHash());
               }catch( Throwable cause ) {
                 cause.printStackTrace();
               }
          }
         });
         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())
              try {
              _download_manager.cancelDownload(session.getFileHash());
              }catch( Throwable cause ) {
                cause.printStackTrace();
              }
          }
         });
         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);
          }
         });
View Full Code Here

 
  class PiecesTableCellRenderer  extends JPanel implements TableCellRenderer { //extends DefaultTableCellRenderer {

    public Component getTableCellRendererComponent(JTable table, Object value,
        boolean isSelected, boolean hasFocus, int row, int column) {
      DownloadSession session = (DownloadSession)value;
      this.setFileSize(session.getFileSize());
      this.setGapList(session.getGapList());
      this.setTransferredBytesCount(session.getTransferredBytes());
      JPanel panel = new JPanel();
      panel.setLayout(new GridLayout(1,1));
      //panel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
      panel.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(204, 204, 204), 1, true));
      if(isSelected) {
View Full Code Here

  }
 
  class ProgressBarTableCellRenderer extends JProgressBar implements  TableCellRenderer { //extends DefaultTableCellRenderer {
        public Component getTableCellRendererComponent(JTable table, Object value,
        boolean isSelected, boolean hasFocus, int row, int column) {
      DownloadSession session = (DownloadSession)value;
      //JProgressBar progress_bar = new JProgressBar();
      this.setMinimum(0);
      this.setMaximum((int)session.getFileSize());
      this.setValue((int)session.getTransferredBytes());
      this.setStringPainted(true);
      this.setBackground(Color.WHITE);
      this.setForeground(new Color(0,100,199));
      //this.setBorder(javax.swing.BorderFactory.createEtchedBorder());
      this.setBorder(new javax.swing.border.LineBorder(java.awt.Color.lightGray, 1, true));
View Full Code Here

         });
         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);
          }
         });
View Full Code Here

       //    case Peer.TCP_SOCKET_CONNECTED : this.setText(" " + "Connected");
      //}
      //ugly hack
      Object[] objects = (Object[])value;
      Peer peer = (Peer)objects[0];
      DownloadSession session = (DownloadSession)objects[1];
      this.setText(PeerInfoFormatter.formatPeerStatus(session.getPeerDownloadStatus(peer)));
      return this;
    }
View Full Code Here

TOP

Related Classes of org.jmule.core.downloadmanager.DownloadSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.