Example usage for java.awt.dnd DropTargetDropEvent getSource

List of usage examples for java.awt.dnd DropTargetDropEvent getSource

Introduction

In this page you can find the example usage for java.awt.dnd DropTargetDropEvent getSource.

Prototype

public Object getSource() 

Source Link

Document

The object on which the Event initially occurred.

Usage

From source file:tk.tomby.tedit.core.Workspace.java

/**
 * Creates a new WorkSpace object.//from w w w .j a v  a  2  s  . c  o m
 */
public Workspace() {
    super();

    setLayout(new BorderLayout());
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    MessageManager.addMessageListener(MessageManager.BUFFER_GROUP_NAME, new IMessageListener<BufferMessage>() {
        public void receiveMessage(BufferMessage message) {
            Workspace.this.receiveMessage(message);
        }
    });

    MessageManager.addMessageListener(MessageManager.PREFERENCE_GROUP_NAME,
            new IMessageListener<PreferenceMessage>() {
                public void receiveMessage(PreferenceMessage message) {
                    Workspace.this.receiveMessage(message);
                }
            });

    bufferPane = new JTabbedPane();
    bufferPane.setMinimumSize(new Dimension(600, 400));
    bufferPane.setPreferredSize(new Dimension(800, 600));
    bufferPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);

    bottomPort = createDockingPort(0, 80);
    rightPort = createDockingPort(80, 0);
    leftPort = createDockingPort(80, 0);

    splitPaneRight = createSplitPane(JSplitPane.HORIZONTAL_SPLIT, bufferPane, rightPort);
    splitPaneLeft = createSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPort, splitPaneRight);
    splitPaneBottom = createSplitPane(JSplitPane.VERTICAL_SPLIT, splitPaneLeft, bottomPort);

    bufferPane.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent evt) {
            MessageManager
                    .sendMessage(new WorkspaceMessage(evt.getSource(), bufferPane.getSelectedComponent()));
        }
    });

    bufferPane.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent evt) {
            if (evt.getClickCount() == 2) {
                splitPaneLeft.setDividerLocation(0.0d);
                splitPaneBottom.setDividerLocation(1.0d);
                splitPaneRight.setDividerLocation(1.0d);
            }
        }
    });

    DropTarget dropTarget = new DropTarget(bufferPane, new DropTargetAdapter() {
        public void drop(DropTargetDropEvent dtde) {
            if (log.isDebugEnabled()) {
                log.debug("drop start");
            }

            try {
                if (log.isDebugEnabled()) {
                    log.debug(dtde.getSource());
                }

                Transferable tr = dtde.getTransferable();
                DataFlavor[] flavors = tr.getTransferDataFlavors();

                for (int i = 0; i < flavors.length; i++) {
                    DataFlavor flavor = flavors[i];

                    if (log.isDebugEnabled()) {
                        log.debug("mime-type:" + flavor.getMimeType());
                    }

                    if (flavor.isMimeTypeEqual("text/plain")) {
                        final Object obj = tr.getTransferData(flavor);

                        if (log.isDebugEnabled()) {
                            log.debug(obj);
                        }

                        if (obj instanceof String) {
                            TaskManager.execute(new Runnable() {
                                public void run() {
                                    BufferFactory factory = new BufferFactory();
                                    IBuffer buffer = factory.createBuffer();
                                    buffer.open((String) obj);

                                    addBuffer(buffer);
                                }
                            });
                        }

                        dtde.dropComplete(true);

                        return;
                    }
                }
            } catch (UnsupportedFlavorException e) {
                log.warn(e.getMessage(), e);
            } catch (IOException e) {
                log.warn(e.getMessage(), e);
            }

            dtde.rejectDrop();

            if (log.isDebugEnabled()) {
                log.debug("drop end");
            }
        }
    });

    bufferPane.setDropTarget(dropTarget);

    this.add(BorderLayout.CENTER, splitPaneBottom);
}

From source file:unikn.dbis.univis.visualization.pivottable.VPivotTable.java

public void addDimension(VDimension dimension, DropTargetDropEvent dtde) {

    if (dtde.getSource() == dropAreaX.getDropTarget()) {

        if (xAxisDimensions.size() < 1) { // noch kein X-Achsen-Element spezifiziert

            if (LOG.isDebugEnabled()) {
                LOG.debug("GUI: dropped as column value [" + dimension + "] Root: " + dimension.getBlueprint());
            }//  w  w w.  ja  v  a2  s.  c  o  m

            xAxisDimensions.add(dimension);

            // Shows the dropped dimensions in x drop area box.
            dropAreaX.setForeground(Color.BLACK);

            StringBuilder sb = new StringBuilder();
            for (VDimension d : xAxisDimensions) {
                sb.append(d).append("\n");
            }
            dropAreaX.setText(sb.toString());

            selectionChanged = true;
        } else { // es wurde schon X-Achsen-Element festgelegt --> momentan nur 1 ausgewertet
            if (LOG.isErrorEnabled()) {
                LOG.error("Currently only one Element for X-Axis allowed.");
            }
            selectionChanged = false;
        }

    } // end of dropAreaX (DropTarget)
    else if (dtde.getSource() == dropAreaY.getDropTarget()) {

        if (!yAxisDimensions.contains(dimension)) { // nur wenn noch nicht enthalten

            if (LOG.isDebugEnabled()) {
                LOG.debug("GUI: dropped as row value [" + dimension + "] Root: " + dimension.getBlueprint());
            }

            yAxisDimensions.add(dimension);

            // Shows the dropped dimensions in y drop area box.
            dropAreaY.setForeground(Color.BLACK);

            StringBuilder sb = new StringBuilder();
            for (VDimension d : yAxisDimensions) {
                sb.append(d).append("\n");
            }
            dropAreaY.setText(sb.toString());

            selectionChanged = true;
        } else {
            selectionChanged = false;
        }
    } // end of dropAreaY (DropTarget)

    if (selectionChanged && (xAxisDimensions.size() > 0 || yAxisDimensions.size() > 0)) {
        createPivotTable(false);
    }
}