2129N/A/*
2362N/A * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
2129N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2129N/A *
2129N/A * This code is free software; you can redistribute it and/or modify it
2129N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
2129N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
2129N/A *
2129N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2129N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2129N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2129N/A * version 2 for more details (a copy is included in the LICENSE file that
2129N/A * accompanied this code).
2129N/A *
2129N/A * You should have received a copy of the GNU General Public License version
2129N/A * 2 along with this work; if not, write to the Free Software Foundation,
2129N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2129N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
2129N/A */
2129N/A
2129N/A/*
2129N/A* Panel is a DropTarget
2129N/A*
2129N/A*/
2129N/A
2129N/Aimport java.awt.*;
2129N/Aimport java.awt.datatransfer.*;
2129N/Aimport java.awt.dnd.*;
2129N/Aimport java.io.*;
2129N/A
2129N/A
2129N/Aclass DnDTarget extends Panel implements DropTargetListener {
2129N/A private int dragOperation = DnDConstants.ACTION_COPY | DnDConstants.ACTION_MOVE;
2129N/A Color bgColor;
2129N/A Color htColor;
2129N/A
2129N/A DnDTarget(Color bgColor, Color htColor) {
2129N/A super();
2129N/A this.bgColor = bgColor;
2129N/A this.htColor = htColor;
2129N/A setBackground(bgColor);
2129N/A setDropTarget(new DropTarget(this, this));
2129N/A }
2129N/A
2129N/A
2129N/A public void dragEnter(DropTargetDragEvent e) {
2129N/A System.out.println("[Target] dragEnter");
2129N/A setBackground(htColor);
2129N/A repaint();
2129N/A }
2129N/A
2129N/A public void dragOver(DropTargetDragEvent e) {
2129N/A System.out.println("[Target] dragOver");
2129N/A }
2129N/A
2129N/A public void dragExit(DropTargetEvent e) {
2129N/A System.out.println("[Target] dragExit");
2129N/A setBackground(bgColor);
2129N/A repaint();
2129N/A }
2129N/A
2129N/A public void dragScroll(DropTargetDragEvent e) {
2129N/A System.out.println("[Target] dragScroll");
2129N/A }
2129N/A
2129N/A public void dropActionChanged(DropTargetDragEvent e) {
2129N/A System.out.println("[Target] dropActionChanged");
2129N/A }
2129N/A
2129N/A public void drop(DropTargetDropEvent dtde) {
2129N/A System.out.println("[Target] drop");
2129N/A boolean success = false;
2129N/A if ((dtde.getDropAction() & dragOperation) == 0) {
2129N/A dtde.rejectDrop();
2129N/A Label label = new Label("[no links here :) ]");
2129N/A label.setBackground(Color.cyan);
2129N/A add(label);
2129N/A } else {
2129N/A dtde.acceptDrop(dragOperation);
2129N/A DataFlavor[] dfs = dtde.getCurrentDataFlavors();
2129N/A if (dfs != null && dfs.length >= 1){
2129N/A Transferable transfer = dtde.getTransferable();
2129N/A try {
2129N/A Button button = (Button)transfer.getTransferData(dfs[0]);
2129N/A if( button != null ){
2129N/A add(button);
2129N/A success = true;
2129N/A }
2129N/A } catch (IOException ioe) {
2129N/A System.out.println(ioe.getMessage());
2129N/A return;
2129N/A } catch (UnsupportedFlavorException ufe) {
2129N/A System.out.println(ufe.getMessage());
2129N/A return;
2129N/A } catch (Exception e) {
2129N/A System.out.println(e.getMessage());
2129N/A return;
2129N/A }
2129N/A }
2129N/A }
2129N/A setBackground(bgColor);
2129N/A dtde.dropComplete(success);
2129N/A
2129N/A invalidate();
2129N/A validate();
2129N/A repaint();
2129N/A }
2129N/A}