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.DragGestureEvent;
18 import java.awt.dnd.DragGestureListener;
19 import java.awt.dnd.InvalidDnDOperationException;
21 import org.scilab.modules.gui.messagebox.ScilabModalDialog;
22 import org.scilab.modules.gui.messagebox.ScilabModalDialog.IconType;
23 import org.scilab.modules.xcos.palette.PaletteBlockCtrl;
24 import org.scilab.modules.xcos.palette.PaletteCtrl;
25 import org.scilab.modules.xcos.palette.view.PaletteBlockView;
26 import org.scilab.modules.xcos.palette.view.PaletteManagerView;
27 import org.scilab.modules.xcos.utils.XcosMessages;
30 * Install the handler for dragging nodes into a graph.
31 * @author Marcos CARDINOT <mcardinot@gmail.com>
33 public final class PaletteDragGestureListener implements DragGestureListener {
38 public PaletteDragGestureListener() {
42 * @param e The associated event
45 public void dragGestureRecognized(DragGestureEvent e) {
46 PaletteBlockCtrl blockCtrl = ((PaletteBlockView) e.getComponent()).getController();
47 PaletteCtrl paletteCtrl = blockCtrl.getPaletteCtrl();
49 if (paletteCtrl == null) {
52 blockCtrl.setSelected(true);
54 if (PaletteManagerView.get() == null) {
55 PaletteManagerView.restore(null);
57 final PaletteManagerView winView = PaletteManagerView.get();
59 winView.setInfo(XcosMessages.LOADING_BLOCKS);
61 Transferable transfer = paletteCtrl.getTransferable();
62 if (transfer != null) {
63 e.startDrag(null, null, new Point(), transfer, null);
65 } catch (InvalidDnDOperationException exception) {
66 ScilabModalDialog.show(winView, XcosMessages.UNABLE_TO_LOAD_SELECTED_BLOCKS,
67 XcosMessages.XCOS_ERROR, IconType.ERROR_ICON);
69 winView.setInfo(XcosMessages.EMPTY_INFO);