Gridarta Editor
TransferableTreeNode.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.gui.mapmenu;
21 
22 import java.awt.datatransfer.DataFlavor;
23 import java.awt.datatransfer.Transferable;
24 import java.awt.datatransfer.UnsupportedFlavorException;
25 import javax.swing.tree.TreePath;
26 import org.jetbrains.annotations.NotNull;
27 
32 public class TransferableTreeNode implements Transferable {
33 
37  @NotNull
38  private static final DataFlavor TREE_PATH_FLAVOR = new DataFlavor(TreePath.class, "Tree Path");
39 
43  @NotNull
44  private final TreePath treePath;
45 
50  public TransferableTreeNode(@NotNull final TreePath treePath) {
51  this.treePath = treePath;
52  }
53 
54  @NotNull
55  @Override
56  public DataFlavor @NotNull [] getTransferDataFlavors() {
57  return new DataFlavor[] { TREE_PATH_FLAVOR, };
58  }
59 
60  @Override
61  public boolean isDataFlavorSupported(@NotNull final DataFlavor flavor) {
62  return flavor.getRepresentationClass() == TreePath.class;
63  }
64 
65  @Override
66  @NotNull
67  public TreePath getTransferData(@NotNull final DataFlavor flavor) throws UnsupportedFlavorException {
68  if (isDataFlavorSupported(flavor)) {
69  return treePath;
70  }
71 
72  throw new UnsupportedFlavorException(flavor);
73  }
74 
75 }
net.sf.gridarta.gui.mapmenu.TransferableTreeNode
A Transferable that transfers TreePath instances.
Definition: TransferableTreeNode.java:32
net.sf.gridarta.gui.mapmenu.TransferableTreeNode.getTransferData
TreePath getTransferData(@NotNull final DataFlavor flavor)
Definition: TransferableTreeNode.java:67
net.sf.gridarta.gui.mapmenu.TransferableTreeNode.isDataFlavorSupported
boolean isDataFlavorSupported(@NotNull final DataFlavor flavor)
Definition: TransferableTreeNode.java:61
net.sf.gridarta.gui.mapmenu.TransferableTreeNode.getTransferDataFlavors
DataFlavor[] getTransferDataFlavors()
Definition: TransferableTreeNode.java:56
net.sf.gridarta.gui.mapmenu.TransferableTreeNode.TREE_PATH_FLAVOR
static final DataFlavor TREE_PATH_FLAVOR
A DataFlavor for transferring TreePath instances.
Definition: TransferableTreeNode.java:38
net.sf.gridarta.gui.mapmenu.TransferableTreeNode.treePath
final TreePath treePath
The TreePath being transferred.
Definition: TransferableTreeNode.java:44
net.sf.gridarta.gui.mapmenu.TransferableTreeNode.TransferableTreeNode
TransferableTreeNode(@NotNull final TreePath treePath)
Creates a new instance.
Definition: TransferableTreeNode.java:50