コード例 #1
0
ファイル: ColorChooser.java プロジェクト: okohll/svg_editor
  /**
   * returns whether the given flavor is a color flavor
   *
   * @param flavor a flavor
   * @return whether the given flavor is a color flavor
   */
  public boolean isColorDataFlavor(DataFlavor flavor) {

    boolean isColorDataFlavor = false;

    if (flavor != null) {

      isColorDataFlavor =
          (flavor.isMimeTypeEqual(colorFlavor) || flavor.isMimeTypeEqual(w3cSVGColorFlavor));
    }

    return isColorDataFlavor;
  }
コード例 #2
0
    public boolean isAcceptable(Transferable transferable, Point point) {
      int row = getPropertiesTable().rowAtPoint(point);
      if (row >= 0) {
        int column = getPropertiesTable().columnAtPoint(point);
        if (column != 1) {
          return false;
        }

        if (!getPropertiesTable().isCellEditable(row, column)) {
          return false;
        }
      } else if (!(getHolder() instanceof MutableTestPropertyHolder)) {
        return false;
      }

      DataFlavor[] flavors = transferable.getTransferDataFlavors();
      for (int i = 0; i < flavors.length; i++) {
        DataFlavor flavor = flavors[i];
        if (flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType)) {
          try {
            Object modelItem = transferable.getTransferData(flavor);
            if (modelItem instanceof PropertyModelItem
                && ((PropertyModelItem) modelItem).getProperty().getModelItem()
                    != getHolder().getModelItem()) {
              return PropertyExpansionUtils.canExpandProperty(
                  getHolder().getModelItem(), ((PropertyModelItem) modelItem).getProperty());
            }
          } catch (Exception ex) {
            SoapUI.logError(ex);
          }
        }
      }

      return false;
    }
コード例 #3
0
ファイル: JDragTree.java プロジェクト: TheSeeker/Thaw
 public synchronized Object getTransferData(final DataFlavor flavor)
     throws UnsupportedFlavorException {
   if (flavor.isMimeTypeEqual(JDragTree.TREEPATH_FLAVOR.getMimeType())) return _path;
   else throw new UnsupportedFlavorException(flavor);
 }
コード例 #4
0
ファイル: JDragTree.java プロジェクト: TheSeeker/Thaw
    public void drop(final DropTargetDropEvent e) {
      _timerHover.stop(); // Prevent hover timer from doing an unwanted expandPath or collapsePath

      if (!isDropAcceptable(e)) {
        e.rejectDrop();
        return;
      }

      e.acceptDrop(e.getDropAction());

      final Transferable transferable = e.getTransferable();

      final DataFlavor[] flavors = transferable.getTransferDataFlavors();

      for (int i = 0; i < flavors.length; i++) {
        final DataFlavor flavor = flavors[i];
        if (flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType)) {
          try {
            final Point pt = e.getLocation();
            final TreePath pathTarget = getClosestPathForLocation(pt.x, pt.y);
            final TreePath pathSource = (TreePath) transferable.getTransferData(flavor);

            if ((pathTarget == null) || (pathSource == null)) {
              e.dropComplete(false);
              return;
            }

            final MutableTreeNode sourceNode = (MutableTreeNode) pathSource.getLastPathComponent();
            final MutableTreeNode oldParent = (MutableTreeNode) sourceNode.getParent();

            final MutableTreeNode targetNode = (MutableTreeNode) pathTarget.getLastPathComponent();
            final MutableTreeNode newParent = (MutableTreeNode) targetNode.getParent();

            if (!sourceNode.isLeaf() && (targetNode.getParent() == sourceNode)) {
              // trying to drag a folder into its own childs
              e.dropComplete(false);
              return;
            }

            final DefaultTreeModel model = (DefaultTreeModel) getModel();
            final TreePath pathNewChild = null;

            if (targetNode.isLeaf() || JDragTree.this.isCollapsed(pathTarget)) {
              // collapsed tree node or leaf
              // dropped on a leaf, insert into leaf's parent AFTER leaf
              int idx = newParent.getIndex(targetNode);
              if (idx < 0) {
                JDragTree.logger.warning("child not found in parent!!!");
                e.dropComplete(false);
                return;
              } else {
                idx++; // insert AFTER targetNode

                // remove node from oldParent ...
                final Object[] removedChilds = {sourceNode};
                final int[] childIndices = {oldParent.getIndex(sourceNode)};
                sourceNode.removeFromParent();
                model.nodesWereRemoved(oldParent, childIndices, removedChilds);

                // ... and insert into newParent
                if (idx >= newParent.getChildCount()) {
                  // newParent.add( sourceNode );
                  newParent.insert(sourceNode, newParent.getChildCount());
                  final int insertedIndex[] = {newParent.getChildCount() - 1};
                  model.nodesWereInserted(newParent, insertedIndex);
                } else {
                  newParent.insert(sourceNode, idx);
                  final int insertedIndex[] = {idx};
                  model.nodesWereInserted(newParent, insertedIndex);
                }
              }
            } else {
              // expanded node, insert UNDER the node (before first child)
              // remove node from oldParent ...
              final Object[] removedChilds = {sourceNode};
              final int[] childIndices = {oldParent.getIndex(sourceNode)};
              sourceNode.removeFromParent();
              model.nodesWereRemoved(oldParent, childIndices, removedChilds);
              // ... and add to newParent
              targetNode.insert(sourceNode, 0);
              final int insertedIndex[] = {0};
              model.nodesWereInserted(targetNode, insertedIndex);
            }

            if (pathNewChild != null)
              setSelectionPath(pathNewChild); // Mark this as the selected path in the tree
            break; // No need to check remaining flavors
          } catch (final UnsupportedFlavorException ufe) {
            JDragTree.logger.log(
                Level.SEVERE, "Exception thrown in drop(DropTargetDropEvent e)", ufe);
            e.dropComplete(false);
            return;
          } catch (final IOException ioe) {
            JDragTree.logger.log(
                Level.SEVERE, "Exception thrown in drop(DropTargetDropEvent e)", ioe);
            e.dropComplete(false);
            return;
          }
        }
      }
      e.dropComplete(true);
    }