jmeter-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Milamber <milam...@apache.org>
Subject Re: svn commit: r1231754 - in /jmeter/trunk/src/core/org/apache/jmeter/gui: MainFrame.java TopLevelTransferHandler.java
Date Sun, 15 Jan 2012 22:03:11 GMT
Hello,

My system is GNU/Linux (Debian 6 + Gnome 2.30)

* Works fine with jdk 1.6
* Compile ok with 1.5, but don't works (drag n drop)
It is not a big issue for me (I prefer use 6 or 7 with JMeter).

Milamber

Le 15/01/2012 21:06, pmouawad@apache.org a ecrit :
> Author: pmouawad
> Date: Sun Jan 15 21:06:49 2012
> New Revision: 1231754
>
> URL: http://svn.apache.org/viewvc?rev=1231754&view=rev
> Log:
> Bug 52281 - Support for file Drag and Drop
> Had to find an alternate implementation as TransferHandler.TransferSupport  is not supported
in JDK5
>
> Removed:
>     jmeter/trunk/src/core/org/apache/jmeter/gui/TopLevelTransferHandler.java
> Modified:
>     jmeter/trunk/src/core/org/apache/jmeter/gui/MainFrame.java
>
> Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/MainFrame.java
> URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/MainFrame.java?rev=1231754&r1=1231753&r2=1231754&view=diff
> ==============================================================================
> --- jmeter/trunk/src/core/org/apache/jmeter/gui/MainFrame.java (original)
> +++ jmeter/trunk/src/core/org/apache/jmeter/gui/MainFrame.java Sun Jan 15 21:06:49 2012
> @@ -23,12 +23,24 @@ import java.awt.Component;
>  import java.awt.Dimension;
>  import java.awt.Font;
>  import java.awt.Insets;
> +import java.awt.datatransfer.DataFlavor;
> +import java.awt.datatransfer.Transferable;
> +import java.awt.datatransfer.UnsupportedFlavorException;
> +import java.awt.dnd.DnDConstants;
> +import java.awt.dnd.DropTarget;
> +import java.awt.dnd.DropTargetDragEvent;
> +import java.awt.dnd.DropTargetDropEvent;
> +import java.awt.dnd.DropTargetEvent;
> +import java.awt.dnd.DropTargetListener;
>  import java.awt.event.ActionEvent;
>  import java.awt.event.ActionListener;
>  import java.awt.event.MouseEvent;
>  import java.awt.event.WindowAdapter;
>  import java.awt.event.WindowEvent;
> +import java.io.File;
> +import java.io.IOException;
>  import java.util.HashSet;
> +import java.util.List;
>  import java.util.Set;
>  
>  import javax.swing.BorderFactory;
> @@ -57,6 +69,7 @@ import javax.swing.tree.TreePath;
>  import org.apache.jmeter.engine.event.LoopIterationEvent;
>  import org.apache.jmeter.gui.action.ActionNames;
>  import org.apache.jmeter.gui.action.ActionRouter;
> +import org.apache.jmeter.gui.action.LoadDraggedFile;
>  import org.apache.jmeter.gui.tree.JMeterCellRenderer;
>  import org.apache.jmeter.gui.tree.JMeterTreeListener;
>  import org.apache.jmeter.gui.util.JMeterMenuBar;
> @@ -67,13 +80,15 @@ import org.apache.jmeter.testelement.Tes
>  import org.apache.jmeter.threads.JMeterContextService;
>  import org.apache.jmeter.util.JMeterUtils;
>  import org.apache.jorphan.gui.ComponentUtil;
> +import org.apache.jorphan.logging.LoggingManager;
> +import org.apache.log.Logger;
>  
>  /**
>   * The main JMeter frame, containing the menu bar, test tree, and an area for
>   * JMeter component GUIs.
>   *
>   */
> -public class MainFrame extends JFrame implements TestListener, Remoteable {
> +public class MainFrame extends JFrame implements TestListener, Remoteable, DropTargetListener
{
>  
>      private static final long serialVersionUID = 240L;
>  
> @@ -89,6 +104,8 @@ public class MainFrame extends JFrame im
>      private static final boolean DISPLAY_TOOLBAR =
>              JMeterUtils.getPropDefault("jmeter.toolbar.display", true); // $NON-NLS-1$
>  
> +    private static final Logger log = LoggingManager.getLoggerForClass();
> +
>      /** The menu bar. */
>      private JMeterMenuBar menuBar;
>  
> @@ -153,7 +170,7 @@ public class MainFrame extends JFrame im
>  
>          GuiPackage.getInstance().setMainFrame(this);
>          init();
> -        initTransferHandler();
> +        initTopLevelDndHandler();
>          setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
>      }
>  
> @@ -408,9 +425,10 @@ public class MainFrame extends JFrame im
>  
>      /**
>       * Support for Test Plan Dnd
> +     * see BUG 52281 (when JDK6 will be minimum JDK target)
>       */
> -	public void initTransferHandler() {
> -    	this.setTransferHandler(new TopLevelTransferHandler());
> +	public void initTopLevelDndHandler() {
> +	    new DropTarget(this, this);
>      }
>      
>      public void setExtendedFrameTitle(String fname) {
> @@ -565,4 +583,60 @@ public class MainFrame extends JFrame im
>              ActionRouter.getInstance().actionPerformed(new ActionEvent(this, event.getID(),
ActionNames.EXIT));
>          }
>      }
> +
> +    public void dragEnter(DropTargetDragEvent dtde) {
> +        // NOOP        
> +    }
> +
> +    public void dragExit(DropTargetEvent dte) {
> +        // NOOP        
> +    }
> +
> +    public void dragOver(DropTargetDragEvent dtde) {
> +        // NOOP
> +    }
> +
> +    /**
> +     * Handler of Top level Dnd
> +     */
> +    public void drop(DropTargetDropEvent dtde) {
> +        try {
> +            Transferable tr = dtde.getTransferable();
> +            DataFlavor[] flavors = tr.getTransferDataFlavors();
> +            for (int i = 0; i < flavors.length; i++) {
> +                // Check for file lists specifically
> +                if (flavors[i].isFlavorJavaFileListType()) {
> +                    dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
> +                    try {
> +                        @SuppressWarnings("unchecked")
> +                        List<File> files = (List<File>) 
> +                                tr.getTransferData(DataFlavor.javaFileListFlavor);
> +                        if(files.isEmpty()) {
> +                            return;
> +                        }
> +                        File file = files.get(0);
> +                        if(!file.getName().endsWith(".jmx")) {
> +                            log.warn("Importing file:" + file.getName()+ "from DnD failed
because file extension does not end with .jmx");
> +                            return;
> +                        }
> +                        
> +                        ActionEvent fakeEvent = new ActionEvent(this, ActionEvent.ACTION_PERFORMED,
ActionNames.OPEN);
> +                        LoadDraggedFile.loadProject(fakeEvent, file);
> +                    } finally {
> +                        dtde.dropComplete(true);
> +                    }
> +                    return;
> +                }
> +            }
> +        } catch (UnsupportedFlavorException e) {
> +            log.warn("Dnd failed" , e);
> +        } catch (IOException e) {
> +            log.warn("Dnd failed" , e);
> +        }
> +        
> +    }
> +
> +    public void dropActionChanged(DropTargetDragEvent dtde) {
> +        // NOOP
> +    }
>  }
>
>
>
>   


Mime
View raw message