Package me.mabra.hellonzb.util

Source Code of me.mabra.hellonzb.util.MyDropTargetAdapter

/*******************************************************************************
* HelloNzb -- The Binary Usenet Tool
* Copyright (C) 2010-2013 Matthias F. Brandstetter
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
******************************************************************************/
package me.mabra.hellonzb.util;

import me.mabra.hellonzb.HelloNzb;
import me.mabra.hellonzb.parser.NzbParser;

import javax.swing.*;
import javax.xml.stream.XMLStreamException;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTargetAdapter;
import java.awt.dnd.DropTargetDropEvent;
import java.io.File;
import java.io.IOException;
import java.util.List;


public class MyDropTargetAdapter extends DropTargetAdapter
{
  private HelloNzb mainApp;
  private MyLogger logger;
 
 
  public MyDropTargetAdapter(HelloNzb mainApp)
  {
    this.mainApp = mainApp;
    this.logger = mainApp.getLogger();
  }
 
  @SuppressWarnings("unchecked")
  public void drop(DropTargetDropEvent dtde)
  {
    if(dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
    {
      try
      {
        dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
        List<File> list = (List<File>) dtde.getTransferable().getTransferData(
            DataFlavor.javaFileListFlavor);
        for(File file : list)
        {
          // valid file type?
          if(!file.isFile())
            continue;
          if(!file.canRead())
            continue;
         
          try
          {
            mainApp.addNzbToQueue(new NzbParser(file.getAbsolutePath(), mainApp.getPrefValue("GeneralSettingsDownloadDir")));
          }
          catch(XMLStreamException e)
          {
            String msg = mainApp.getLocaler().getBundleText("PopupXMLParserError");
            String title = mainApp.getLocaler().getBundleText("PopupErrorTitle");
            JOptionPane.showMessageDialog(null, msg, title, JOptionPane.ERROR_MESSAGE);
            logger.printStackTrace(e);
          }
          catch(java.text.ParseException e)
          {
            String msg = e.getMessage();
            String title = mainApp.getLocaler().getBundleText("PopupErrorTitle");
            JOptionPane.showMessageDialog(null, msg, title, JOptionPane.ERROR_MESSAGE);
            logger.printStackTrace(e);
          }
        }
      }
      catch(UnsupportedFlavorException e)
      {
        logger.printStackTrace(e);
      }
      catch(IOException e)
      {
        logger.printStackTrace(e);
      }
    }
  }
}


































TOP

Related Classes of me.mabra.hellonzb.util.MyDropTargetAdapter

TOP
Copyright © 2018 www.massapi.com. 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.