Forum Controls
Spotlight Features

The Rich Engineering Heritage Behind Dependency Injection

Andrew McVeigh takes us on a tour of the rich heritage behind dependency injection, what it represents, and tells us why its here to stay.

NetBeans 6: Matisse Updates

NetBeans 6 delivers great updates to the Matisse GUI builder. Spend a few minutes with Roman Strobl and get an expert briefing on what's new and what has changed.

Introduction to Groovy Part 3

In this, the third and final installation of Andres' Introduction to Groovy series, you learn about how Groovy handles variable numbers of arguments, named parameters, currying, and more about Groovy operators. Including, some new operators.

Easier Custom Components with Swing Fuse

Swing Fuse (actually just Fuse), is a framework designed to make it easier to create your own custom desktop components. In this article, Daniel Spiewak shows you how to get started and provides sample source code you can download.

Benchmark Analysis: Guice vs Spring

Willam Louth shows how he uses JXInsight Probes to investigate probable performance issues with code bases that he is not familiar with. He also highlights possible pitfalls in creating a benchmark, as well as in the analysis of results.
Replies: 0 - Pages: 1  
Threads: [ Previous | Next ]
  Click to reply to this thread Reply

AWT: See what flavours are in a drop

At 5:12 AM on Apr 29, 2006, Jochen Bedersdorfer DeveloperZone Top 100 wrote:

Ever wondered what information you could possibly get from a drop in a Drag&Drop operation? Wonder no more. Use the following small helper class and drag something over it. It will show you the available DataFlavors.

Use it with draggables from native applications (browser URL, files, text snippets etc.) and you might be surprised about the different DataFlavors available!

import java.awt.*; // imports not expanded to safe space
import java.awt.dnd.*;
import java.awt.datatransfer.*;
import javax.swing.*;
/** @author beders (Jochen Bedersdorfer) */
public class UniversalDropViewer extends JTextArea implements DropTargetListener{
  public UniversalDropViewer() {
    new DropTarget(this, this);   
    setText("Drag something over me!");
  }  
  public void dragEnter(DropTargetDragEvent aDtde) {
    StringBuilder sb = new StringBuilder(300);
    for (DataFlavor d : aDtde.getCurrentDataFlavorsAsList()) {
      sb.append(d.getHumanPresentableName()).append(":  ").append(d.getMimeType()).append(" (").
      append(d.getDefaultRepresentationClassAsString()).append(")\n");      
    }
    setText(sb.toString());    
  }
  public void dragOver(DropTargetDragEvent aDtde) {}
  public void dropActionChanged(DropTargetDragEvent aDtde) {}
  public void dragExit(DropTargetEvent aDte) {}
  public void drop(DropTargetDropEvent aDtde) {}
  public static void main(String[] args) {
    JFrame fr = new JFrame("UDV");
    fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    fr.add(new JScrollPane(new UniversalDropViewer()));    
    fr.setSize(600,700);
    fr.setVisible(true);
  }
}

thread.rss_message