Search in sources :

Example 1 with DropTargetDragEvent

use of java.awt.dnd.DropTargetDragEvent in project jna by java-native-access.

the class DropHandler method describe.

private void describe(String type, DropTargetEvent e) {
    if (false) {
        String msg = "drop: " + type;
        if (e instanceof DropTargetDragEvent) {
            DropTargetContext dtc = e.getDropTargetContext();
            DropTarget dt = dtc.getDropTarget();
            DropTargetDragEvent ev = (DropTargetDragEvent) e;
            msg += ": src=" + DragHandler.actionString(ev.getSourceActions()) + " tgt=" + DragHandler.actionString(dt.getDefaultActions()) + " act=" + DragHandler.actionString(ev.getDropAction());
        } else if (e instanceof DropTargetDropEvent) {
            DropTargetContext dtc = e.getDropTargetContext();
            DropTarget dt = dtc.getDropTarget();
            DropTargetDropEvent ev = (DropTargetDropEvent) e;
            msg += ": src=" + DragHandler.actionString(ev.getSourceActions()) + " tgt=" + DragHandler.actionString(dt.getDefaultActions()) + " act=" + DragHandler.actionString(ev.getDropAction());
        }
        if (!msg.equals(lastAction)) {
            System.out.println(lastAction = msg);
        }
    }
}
Also used : DropTargetDragEvent(java.awt.dnd.DropTargetDragEvent) DropTargetContext(java.awt.dnd.DropTargetContext) DropTarget(java.awt.dnd.DropTarget) DropTargetDropEvent(java.awt.dnd.DropTargetDropEvent)

Example 2 with DropTargetDragEvent

use of java.awt.dnd.DropTargetDragEvent in project jdk8u_jdk by JetBrains.

the class DisposeFrameOnDragTest method constructTestUI.

private static void constructTestUI() {
    final JFrame frame = new JFrame("Test frame");
    textArea = new JTextArea("Drag Me!");
    try {
        textArea.getDropTarget().addDropTargetListener(new DropTargetAdapter() {

            @Override
            public void drop(DropTargetDropEvent dtde) {
            //IGNORE
            }

            @Override
            public void dragOver(DropTargetDragEvent dtde) {
                frame.dispose();
            }
        });
    } catch (TooManyListenersException ex) {
        throw new RuntimeException(ex);
    }
    textArea.setSize(100, 100);
    textArea.setDragEnabled(true);
    textArea.select(0, textArea.getText().length());
    frame.add(textArea);
    frame.setBounds(100, 100, 100, 100);
    frame.setVisible(true);
}
Also used : DropTargetAdapter(java.awt.dnd.DropTargetAdapter) DropTargetDragEvent(java.awt.dnd.DropTargetDragEvent) TooManyListenersException(java.util.TooManyListenersException) JTextArea(javax.swing.JTextArea) JFrame(javax.swing.JFrame) DropTargetDropEvent(java.awt.dnd.DropTargetDropEvent)

Example 3 with DropTargetDragEvent

use of java.awt.dnd.DropTargetDragEvent in project jdk8u_jdk by JetBrains.

the class URLDragTest method init.

@Override
public void init() {
    setBackground(Color.red);
    setDropTarget(new DropTarget(this, DnDConstants.ACTION_COPY, new DropTargetAdapter() {

        @Override
        public void dragEnter(DropTargetDragEvent dtde) {
            dtde.acceptDrag(DnDConstants.ACTION_COPY);
        }

        @Override
        public void dragOver(DropTargetDragEvent dtde) {
            dtde.acceptDrag(DnDConstants.ACTION_COPY);
        }

        @Override
        public void drop(DropTargetDropEvent dtde) {
            dtde.acceptDrop(DnDConstants.ACTION_COPY);
            dtde.getCurrentDataFlavorsAsList().stream().map(DataFlavor::toString).forEach(Sysout::println);
        }
    }));
    String[] instructions = { "1) Open the browser.", "2) Drag any image from the browser page to the red square", "3) When the image is dropped you should se the list of available DataFlavors", "4) If you see application/x-java-url and text/uri-list flavors - test PASSED", "5) Otherwise the test is FAILED" };
    Sysout.createDialogWithInstructions(instructions);
}
Also used : Sysout(test.java.awt.regtesthelpers.Sysout) DropTargetAdapter(java.awt.dnd.DropTargetAdapter) DropTargetDragEvent(java.awt.dnd.DropTargetDragEvent) DropTarget(java.awt.dnd.DropTarget) DropTargetDropEvent(java.awt.dnd.DropTargetDropEvent)

Example 4 with DropTargetDragEvent

use of java.awt.dnd.DropTargetDragEvent in project intellij-community by JetBrains.

the class XXXXX method initComponent.

private void initComponent() {
    myPanel.setLayout(new BorderLayout());
    myPanel.add(myHeaderPanel, BorderLayout.NORTH);
    myGutterComponent.setOpaque(true);
    myScrollPane.setViewportView(myEditorComponent);
    //myScrollPane.setBorder(null);
    myScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    myScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    myScrollPane.setRowHeaderView(myGutterComponent);
    myEditorComponent.setTransferHandler(new MyTransferHandler());
    myEditorComponent.setAutoscrolls(true);
    if (mayShowToolbar()) {
        JLayeredPane layeredPane = new JBLayeredPane() {

            @Override
            public void doLayout() {
                final Component[] components = getComponents();
                final Rectangle r = getBounds();
                for (Component c : components) {
                    if (c instanceof JScrollPane) {
                        c.setBounds(0, 0, r.width, r.height);
                    } else {
                        final Dimension d = c.getPreferredSize();
                        final MyScrollBar scrollBar = getVerticalScrollBar();
                        c.setBounds(r.width - d.width - scrollBar.getWidth() - 30, 20, d.width, d.height);
                    }
                }
            }

            @Override
            public Dimension getPreferredSize() {
                return myScrollPane.getPreferredSize();
            }
        };
        layeredPane.add(myScrollPane, JLayeredPane.DEFAULT_LAYER);
        myPanel.add(layeredPane);
        new ContextMenuImpl(layeredPane, myScrollPane, this);
    } else {
        myPanel.add(myScrollPane);
    }
    myEditorComponent.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() >= KeyEvent.VK_A && e.getKeyCode() <= KeyEvent.VK_Z) {
                myCharKeyPressed = true;
            }
            KeyboardInternationalizationNotificationManager.showNotification();
        }

        @Override
        public void keyTyped(@NotNull KeyEvent event) {
            myNeedToSelectPreviousChar = false;
            if (event.isConsumed()) {
                return;
            }
            if (processKeyTyped(event)) {
                event.consume();
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
            myCharKeyPressed = false;
        }
    });
    MyMouseAdapter mouseAdapter = new MyMouseAdapter();
    myEditorComponent.addMouseListener(mouseAdapter);
    myGutterComponent.addMouseListener(mouseAdapter);
    MyMouseMotionListener mouseMotionListener = new MyMouseMotionListener();
    myEditorComponent.addMouseMotionListener(mouseMotionListener);
    myGutterComponent.addMouseMotionListener(mouseMotionListener);
    myEditorComponent.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(@NotNull FocusEvent e) {
            myCaretCursor.activate();
            for (Caret caret : myCaretModel.getAllCarets()) {
                int caretLine = caret.getLogicalPosition().line;
                repaintLines(caretLine, caretLine);
            }
            fireFocusGained();
        }

        @Override
        public void focusLost(@NotNull FocusEvent e) {
            clearCaretThread();
            for (Caret caret : myCaretModel.getAllCarets()) {
                int caretLine = caret.getLogicalPosition().line;
                repaintLines(caretLine, caretLine);
            }
            fireFocusLost();
        }
    });
    UiNotifyConnector connector = new UiNotifyConnector(myEditorComponent, new Activatable.Adapter() {

        @Override
        public void showNotify() {
            myGutterComponent.updateSize();
        }
    });
    Disposer.register(getDisposable(), connector);
    try {
        final DropTarget dropTarget = myEditorComponent.getDropTarget();
        if (dropTarget != null) {
            // might be null in headless environment
            dropTarget.addDropTargetListener(new DropTargetAdapter() {

                @Override
                public void drop(@NotNull DropTargetDropEvent e) {
                }

                @Override
                public void dragOver(@NotNull DropTargetDragEvent e) {
                    Point location = e.getLocation();
                    getCaretModel().moveToLogicalPosition(getLogicalPositionForScreenPos(location.x, location.y, true));
                    getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
                }
            });
        }
    } catch (TooManyListenersException e) {
        LOG.error(e);
    }
    myPanel.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(@NotNull ComponentEvent e) {
            myMarkupModel.recalcEditorDimensions();
            myMarkupModel.repaint(-1, -1);
        }
    });
}
Also used : UiNotifyConnector(com.intellij.util.ui.update.UiNotifyConnector) EditorFragmentComponent(com.intellij.codeInsight.hint.EditorFragmentComponent) DropTargetDragEvent(java.awt.dnd.DropTargetDragEvent) Activatable(com.intellij.util.ui.update.Activatable) DropTargetAdapter(java.awt.dnd.DropTargetAdapter) JBLayeredPane(com.intellij.ui.components.JBLayeredPane) DropTarget(java.awt.dnd.DropTarget) DropTargetDropEvent(java.awt.dnd.DropTargetDropEvent)

Example 5 with DropTargetDragEvent

use of java.awt.dnd.DropTargetDragEvent in project intellij-community by JetBrains.

the class YYYYYYY method initComponent.

private void initComponent() {
    myPanel.setLayout(new BorderLayout());
    myPanel.add(myHeaderPanel, BorderLayout.NORTH);
    myGutterComponent.setOpaque(true);
    myScrollPane.setViewportView(myEditorComponent);
    //myScrollPane.setBorder(null);
    myScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    myScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    myScrollPane.setRowHeaderView(myGutterComponent);
    myEditorComponent.setTransferHandler(new MyTransferHandler());
    myEditorComponent.setAutoscrolls(true);
    if (mayShowToolbar()) {
        JLayeredPane layeredPane = new JBLayeredPane() {

            @Override
            public void doLayout() {
                final Component[] components = getComponents();
                final Rectangle r = getBounds();
                for (Component c : components) {
                    if (c instanceof JScrollPane) {
                        c.setBounds(0, 0, r.width, r.height);
                    } else {
                        final Dimension d = c.getPreferredSize();
                        final MyScrollBar scrollBar = getVerticalScrollBar();
                        c.setBounds(r.width - d.width - scrollBar.getWidth() - 30, 20, d.width, d.height);
                    }
                }
            }

            @Override
            public Dimension getPreferredSize() {
                return myScrollPane.getPreferredSize();
            }
        };
        layeredPane.add(myScrollPane, JLayeredPane.DEFAULT_LAYER);
        myPanel.add(layeredPane);
        new ContextMenuImpl(layeredPane, myScrollPane, this);
    } else {
        myPanel.add(myScrollPane);
    }
    myEditorComponent.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(@NotNull KeyEvent e) {
            if (e.getKeyCode() >= KeyEvent.VK_A && e.getKeyCode() <= KeyEvent.VK_Z) {
                myCharKeyPressed = true;
            }
            KeyboardInternationalizationNotificationManager.showNotification();
        }

        @Override
        public void keyTyped(@NotNull KeyEvent event) {
            myNeedToSelectPreviousChar = false;
            if (event.isConsumed()) {
                return;
            }
            if (processKeyTyped(event)) {
                event.consume();
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
            myCharKeyPressed = false;
        }
    });
    MyMouseAdapter mouseAdapter = new MyMouseAdapter();
    myEditorComponent.addMouseListener(mouseAdapter);
    myGutterComponent.addMouseListener(mouseAdapter);
    MyMouseMotionListener mouseMotionListener = new MyMouseMotionListener();
    myEditorComponent.addMouseMotionListener(mouseMotionListener);
    myGutterComponent.addMouseMotionListener(mouseMotionListener);
    myEditorComponent.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(@NotNull FocusEvent e) {
            myCaretCursor.activate();
            for (Caret caret : myCaretModel.getAllCarets()) {
                int caretLine = caret.getLogicalPosition().line;
                repaintLines(caretLine, caretLine);
            }
            fireFocusGained();
        }

        @Override
        public void focusLost(@NotNull FocusEvent e) {
            clearCaretThread();
            for (Caret caret : myCaretModel.getAllCarets()) {
                int caretLine = caret.getLogicalPosition().line;
                repaintLines(caretLine, caretLine);
            }
            fireFocusLost();
        }
    });
    UiNotifyConnector connector = new UiNotifyConnector(myEditorComponent, new Activatable.Adapter() {

        @Override
        public void showNotify() {
            myGutterComponent.updateSize();
        }
    });
    Disposer.register(getDisposable(), connector);
    try {
        final DropTarget dropTarget = myEditorComponent.getDropTarget();
        if (dropTarget != null) {
            // might be null in headless environment
            dropTarget.addDropTargetListener(new DropTargetAdapter() {

                @Override
                public void drop(@NotNull DropTargetDropEvent e) {
                }

                @Override
                public void dragOver(@NotNull DropTargetDragEvent e) {
                    Point location = e.getLocation();
                    getCaretModel().moveToLogicalPosition(getLogicalPositionForScreenPos(location.x, location.y, true));
                    getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
                }
            });
        }
    } catch (TooManyListenersException e) {
        LOG.error(e);
    }
    myPanel.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(@NotNull ComponentEvent e) {
            myMarkupModel.recalcEditorDimensions();
            myMarkupModel.repaint(-1, -1);
        }
    });
}
Also used : UiNotifyConnector(com.intellij.util.ui.update.UiNotifyConnector) EditorFragmentComponent(com.intellij.codeInsight.hint.EditorFragmentComponent) Override(java.lang.Override) DropTargetDragEvent(java.awt.dnd.DropTargetDragEvent) Activatable(com.intellij.util.ui.update.Activatable) DropTargetAdapter(java.awt.dnd.DropTargetAdapter) JBLayeredPane(com.intellij.ui.components.JBLayeredPane) DropTarget(java.awt.dnd.DropTarget) DropTargetDropEvent(java.awt.dnd.DropTargetDropEvent)

Aggregations

DropTargetDragEvent (java.awt.dnd.DropTargetDragEvent)12 DropTarget (java.awt.dnd.DropTarget)9 DropTargetDropEvent (java.awt.dnd.DropTargetDropEvent)9 DropTargetAdapter (java.awt.dnd.DropTargetAdapter)7 EditorFragmentComponent (com.intellij.codeInsight.hint.EditorFragmentComponent)3 JBLayeredPane (com.intellij.ui.components.JBLayeredPane)3 Activatable (com.intellij.util.ui.update.Activatable)3 UiNotifyConnector (com.intellij.util.ui.update.UiNotifyConnector)3 Point (java.awt.Point)3 Component (java.awt.Component)2 DataFlavor (java.awt.datatransfer.DataFlavor)2 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)2 DropTargetContext (java.awt.dnd.DropTargetContext)2 DropTargetListener (java.awt.dnd.DropTargetListener)2 InvalidDnDOperationException (java.awt.dnd.InvalidDnDOperationException)2 IOException (java.io.IOException)2 DropTargetEvent (java.awt.dnd.DropTargetEvent)1 Override (java.lang.Override)1 TooManyListenersException (java.util.TooManyListenersException)1 JFrame (javax.swing.JFrame)1