2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2015 - Marcos CARDINOT
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
13 package org.scilab.modules.xcos.palette.listener;
15 import java.awt.Point;
16 import java.awt.datatransfer.Transferable;
17 import java.awt.dnd.DnDConstants;
18 import java.awt.dnd.DragGestureEvent;
19 import java.awt.dnd.DragGestureListener;
20 import java.awt.dnd.InvalidDnDOperationException;
22 import org.scilab.modules.gui.messagebox.ScilabModalDialog;
23 import org.scilab.modules.gui.messagebox.ScilabModalDialog.IconType;
24 import org.scilab.modules.xcos.palette.PaletteBlockCtrl;
25 import org.scilab.modules.xcos.palette.PaletteCtrl;
26 import org.scilab.modules.xcos.palette.view.PaletteBlockView;
27 import org.scilab.modules.xcos.palette.view.PaletteManagerView;
28 import org.scilab.modules.xcos.utils.XcosMessages;
31 * Install the handler for dragging nodes into a graph.
32 * @author Marcos CARDINOT <mcardinot@gmail.com>
34 public final class PaletteDragGestureListener implements DragGestureListener {
39 public PaletteDragGestureListener() {
43 * @param e The associated event
46 public void dragGestureRecognized(DragGestureEvent e) {
47 PaletteBlockCtrl blockCtrl = ((PaletteBlockView) e.getComponent()).getController();
48 PaletteCtrl paletteCtrl = blockCtrl.getPaletteCtrl();
50 if (paletteCtrl == null) {
54 // ctrl is not down ? clear selections
55 if (e.getDragAction() != DnDConstants.ACTION_COPY) {
56 PaletteCtrl.clearSelections();
58 blockCtrl.setSelected(true);
60 if (PaletteManagerView.get() == null) {
61 PaletteManagerView.restore(null);
63 final PaletteManagerView winView = PaletteManagerView.get();
65 winView.setInfo(XcosMessages.LOADING_BLOCKS);
67 Transferable transfer = paletteCtrl.getTransferable();
68 if (transfer != null) {
69 e.startDrag(null, null, new Point(), transfer, null);
71 } catch (InvalidDnDOperationException exception) {
72 ScilabModalDialog.show(winView, XcosMessages.UNABLE_TO_LOAD_SELECTED_BLOCKS,
73 XcosMessages.XCOS_ERROR, IconType.ERROR_ICON);
75 winView.setInfo(XcosMessages.EMPTY_INFO);