/**
   * This method causes a transfer to a component from a clipboard or a DND drop operation. The
   * Transferable represents the data to be imported into the component.
   *
   * @param comp The component to receive the transfer. This argument is provided to enable sharing
   *     of TransferHandlers by multiple components.
   * @param t The data to import
   * @return <code>true</code> iff the data was inserted into the component.
   */
  public boolean importData(JComponent comp, Transferable t) {

    JTextComponent c = (JTextComponent) comp;
    withinSameComponent = c == exportComp;

    // if we are importing to the same component that we exported from
    // then don't actually do anything if the drop location is inside
    // the drag location and set shouldRemove to false so that exportDone
    // knows not to remove any data
    if (withinSameComponent && c.getCaretPosition() >= p0 && c.getCaretPosition() <= p1) {
      shouldRemove = false;
      return true;
    }

    boolean imported = false;
    DataFlavor importFlavor = getImportFlavor(t.getTransferDataFlavors(), c);
    if (importFlavor != null) {
      try {
        InputContext ic = c.getInputContext();
        if (ic != null) ic.endComposition();
        Reader r = importFlavor.getReaderForText(t);
        handleReaderImport(r, c);
        imported = true;
      } catch (UnsupportedFlavorException ufe) {
        ufe.printStackTrace();
      } catch (BadLocationException ble) {
        ble.printStackTrace();
      } catch (IOException ioe) {
        ioe.printStackTrace();
      }
    }

    return imported;
  }
Example #2
0
  public boolean isDataFlavorSupported(DataFlavor flavor) {

    if (!flavor.equals(data_flavor[0]) && !flavor.equals(extra_flavor)) {
      return false;
    }
    return true;
  }
Example #3
0
  @Override
  public void dragOver(DropTargetDragEvent arg) {
    try {
      currentFlavor = null;

      for (DataFlavor resultFlavor : arg.getCurrentDataFlavors()) {
        for (DataFlavor supportedflavour : supportedDataFlavors) {
          if (resultFlavor.equals(supportedflavour)) {
            currentFlavor = supportedflavour;
          }
        }
      }
      Point p = arg.getLocation();
      TreePath path = tree.getPathForLocation(p.x, p.y);
      boolean isnull = path == null ? true : false;
      if (!isnull && currentFlavor != null) {
        arg.acceptDrag(1);
      } else {
        arg.rejectDrag();
      }

    } catch (Exception e) {
      arg.rejectDrag();
    }
  }
  /**
   * Returns an object which represents the data to be transferred. The class of the object returned
   * is defined by the representation class of the flavor.
   *
   * @param flavor the requested flavor for the data
   * @exception IOException if the data is no longer available in the requested flavor.
   * @exception UnsupportedFlavorException if the requested data flavor is not supported.
   * @see DataFlavor#getRepresentationClass
   */
  public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
    Object result = null;

    if (flavor.equals(flavors[0])) {
      StringBuffer buffer = new StringBuffer();

      if (this.types != null) {
        for (int i = 0; i < this.types.size(); i++) {
          SibType current = this.types.get(i);

          if (i > 0) {
            buffer.append(", ");
          }

          if (current == null) {
            buffer.append("null");
          } else {
            buffer.append(current.toString());
          }
        }
      }

      result = buffer.toString();
    } else if (flavor.equals(flavors[1])) {
      result = this.types;
    }

    if (result == null) {
      throw new UnsupportedFlavorException(flavor);
    }

    return result;
  }
 @Override
 public boolean isDataFlavorSupported(DataFlavor flavor) {
   for (DataFlavor flv : flavors) {
     if (flv.equals(flavor)) return true;
   }
   return false;
 }
Example #6
0
		/* 判断该Transfer是否支持flavor数据类型的传送 */
		public boolean isDataFlavorSupported(DataFlavor flavor) {
			boolean b = false;
			b |= flavor.equals(flavors[FILE]);
			b |= flavor.equals(flavors[STRING]);
			b |= flavor.equals(flavors[PLAIN]);
			return (b);
		}
    @Nullable
    public Object getTransferData(DataFlavor flavor)
        throws UnsupportedFlavorException, IOException {
      if (ourDataFlavor.equals(flavor)) {
        return myDataProxy;
      } else if (DataFlavor.stringFlavor.equals(flavor)) {
        return getDataAsText();
      } else if (DataFlavor.javaFileListFlavor.equals(flavor)) {
        return getDataAsFileList();
      } else if (flavor.equals(LinuxDragAndDropSupport.uriListFlavor)) {
        final List<File> files = getDataAsFileList();
        if (files != null) {
          return LinuxDragAndDropSupport.toUriList(files);
        }
      } else if (flavor.equals(LinuxDragAndDropSupport.gnomeFileListFlavor)) {
        final List<File> files = getDataAsFileList();
        if (files != null) {
          final String string =
              (myDataProxy.isCopied() ? "copy\n" : "cut\n")
                  + LinuxDragAndDropSupport.toUriList(files);
          return new ByteArrayInputStream(string.getBytes(CharsetToolkit.UTF8_CHARSET));
        }
      } else if (flavor.equals(LinuxDragAndDropSupport.kdeCutMarkFlavor)
          && !myDataProxy.isCopied()) {
        return new ByteArrayInputStream("1".getBytes());
      }

      return null;
    }
Example #8
0
  public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
    if (flavor.equals(jexDataFlavor)) {
      Logs.log("Transfering typename", 1, this);
      return tn;
    } else if (flavor.equals(DataFlavor.stringFlavor)) {
      // This is where we should get the directories of the selected object in the selected entries.
      TreeSet<JEXEntry> entries = JEXStatics.jexManager.getSelectedEntries();
      String CompleteObjectDirList = ""; // a lsv list of each file within a JEXData object
      for (JEXEntry e : entries) {
        // Get the object with matching type name
        JEXData d = e.getData(tn);

        // Put together the absolute path of the object's database directory
        String dirPath =
            FileUtility.getFileParent(
                JEXWriter.getDatabaseFolder() + File.separator + d.getDetachedRelativePath());

        // Compile a single string with dir1 + File.pathSeparator + dir2 + File.separator ... that
        // includes every file in the directory (including subfolders)
        File[] files = new File(dirPath).listFiles();
        LSVList pathList = (LSVList) FileUtility.getAllAbsoluteFilePaths(files, new LSVList());

        CompleteObjectDirList += pathList.toString() + "\n";
      }
      Logs.log("Transfering string value " + tn.toString(), 1, this);
      String result = CompleteObjectDirList; // Change what we return...
      return result;
    } else {
      throw new UnsupportedFlavorException(flavor);
    }
  }
  @SuppressWarnings("unchecked")
  @Override
  public void drop(DropTargetDropEvent dtde) {
    for (DataFlavor dataFlover : dtde.getCurrentDataFlavors()) {
      if (dataFlover.isFlavorJavaFileListType()) {
        try {
          dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);

          for (File file :
              (List<File>) dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor)) {
            if (file.isFile() && file.canRead()) {
              fileText.setText(file.getCanonicalPath());
              break;
            }
          }

          dtde.getDropTargetContext().dropComplete(true);
        } catch (UnsupportedFlavorException e1) {
          //
        } catch (IOException e2) {
          //
        }
      }
    }
  }
    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;
    }
  /** Determine if the dragged data is a file list. */
  private boolean isDragOk(
      final java.io.PrintStream out, final java.awt.dnd.DropTargetDragEvent evt) {
    boolean ok = false;

    // Get data flavors being dragged
    java.awt.datatransfer.DataFlavor[] flavors = evt.getCurrentDataFlavors();

    // See if any of the flavors are a file list
    int i = 0;
    while (!ok && i < flavors.length) {
      // BEGIN 2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support
      // added.
      // Is the flavor a file list?
      final DataFlavor curFlavor = flavors[i];
      if (curFlavor.equals(java.awt.datatransfer.DataFlavor.javaFileListFlavor)
          || curFlavor.isRepresentationClassReader()) {
        ok = true;
      }
      // END 2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support
      // added.
      i++;
    } // end while: through flavors

    // If logging is enabled, show data flavors
    if (out != null) {
      if (flavors.length == 0) log(out, "FileDrop: no data flavors.");
      for (i = 0; i < flavors.length; i++) log(out, flavors[i].toString());
    } // end if: logging enabled

    return ok;
  } // end isDragOk
Example #12
0
 /**
  * Returns <code>true</code> if this data flavor is supported.
  *
  * @param flavor The data flavor.
  * @return Whether this data flavor is supported.
  */
 public boolean isDataFlavorSupported(DataFlavor flavor) {
   for (DataFlavor myFlavor : supportedFlavors) {
     if (myFlavor.equals(flavor)) {
       return true;
     }
   }
   return false;
 }
Example #13
0
 public boolean canPaste() {
   Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
   for (DataFlavor df : clipboard.getAvailableDataFlavors()) {
     if (df.equals(PrimitiveIdTransferable.PRIMITIVE_ID_LIST_FLAVOR)) return true;
   }
   // FIXME: check whether there are selected objects in the JOSM copy/paste buffer
   return false;
 }
 public static void main(String[] args) {
   Comparator<DataFlavor> comparator = DataFlavorUtil.getDataFlavorComparator();
   DataFlavor flavor1 = DataFlavor.imageFlavor;
   DataFlavor flavor2 = DataFlavor.selectionHtmlFlavor;
   if (comparator.compare(flavor1, flavor2) == 0) {
     throw new RuntimeException(
         flavor1.getMimeType() + " and " + flavor2.getMimeType() + " should not be equal");
   }
 }
 @Override
 public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
   if (flavor.equals(selectionFlavor)) {
     return selection;
   }
   if (flavor.equals(PointTransferable.pointFlavor)) {
     return startPoint;
   }
   throw new UnsupportedFlavorException(flavor);
 }
    /**
     * Returns <tt>true</tt> if <var>flavor</var> is one of the supported flavors. Flavors are
     * supported using the <code>equals(...)</code> method.
     *
     * @param flavor The data flavor to check
     * @return Whether or not the flavor is supported
     * @since 1.1
     */
    public boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor) {
      // Native object
      if (flavor.equals(DATA_FLAVOR)) return true;

      // String
      if (flavor.equals(java.awt.datatransfer.DataFlavor.stringFlavor)) return true;

      // We can't do anything else
      return false;
    } // end isDataFlavorSupported
  @Override
  public boolean isDataFlavorSupported(DataFlavor flavor) {
    for (DataFlavor df : supportedFlavors) {
      if (df.equals(flavor)) {
        return true;
      }
    }

    return false;
  }
Example #18
0
 /**
  * Returns the <code>Transferable</code>'s data in the requested <code>DataFlavor</code> if
  * possible. If the desired flavor is <code>DataFlavor.stringFlavor</code>, or an equivalent
  * flavor, the <code>String</code> representing the selection is returned. If the desired flavor
  * is <code>DataFlavor.plainTextFlavor</code>, or an equivalent flavor, a <code>Reader</code> is
  * returned. <b>Note:</b> The behavior of this method for <code>DataFlavor.plainTextFlavor</code>
  * and equivalent <code>DataFlavor</code>s is inconsistent with the definition of <code>
  * DataFlavor.plainTextFlavor</code>.
  *
  * @param flavor the requested flavor for the data
  * @return the data in the requested flavor, as outlined above
  * @throws UnsupportedFlavorException if the requested data flavor is not equivalent to either
  *     <code>DataFlavor.stringFlavor</code> or <code>DataFlavor.plainTextFlavor</code>
  * @throws IOException if an IOException occurs while retrieving the data. By default,
  *     StringSelection never throws this exception, but a subclass may.
  * @throws NullPointerException if flavor is <code>null</code>
  * @see java.io.Reader
  */
 public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
   // JCK Test StringSelection0007: if 'flavor' is null, throw NPE
   if (flavor.equals(flavors[STRING])) {
     return (Object) data;
   } else if (flavor.equals(flavors[PLAIN_TEXT])) {
     return new StringReader(data == null ? "" : data);
   } else {
     throw new UnsupportedFlavorException(flavor);
   }
 }
 @Override
 public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
   if (objectFlavor.equals(flavor)) {
     return items;
   } else if (textFlavor.equals(flavor)) {
     return toString();
   } else {
     throw new UnsupportedFlavorException(flavor);
   }
 }
Example #20
0
    /**
     * Returns <tt>true</tt> if <var>flavor</var> is one of the supported flavors. Flavors are
     * supported using the <code>equals(...)</code> method.
     *
     * @param flavor The data flavor to check
     * @return Whether or not the flavor is supported
     * @since 1.1
     */
    @Override
    public boolean isDataFlavorSupported(DataFlavor flavor) {
      // Native object
      if (flavor.equals(DATA_FLAVOR)) return true;

      // String
      if (flavor.equals(DataFlavor.stringFlavor)) return true;

      // We can't do anything else
      return false;
    } // end isDataFlavorSupported
 @Override
 public void dragEnter(DropTargetDragEvent dtde) {
   for (DataFlavor df : dtde.getCurrentDataFlavors()) {
     Class<?> repClass = df.getDefaultRepresentationClass();
     boolean canDrop = InputStream.class.isAssignableFrom(repClass);
     if (canDrop) {
       dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
       return;
     }
   }
 }
Example #22
0
 public Object getTransferData(DataFlavor flavor)
     throws UnsupportedFlavorException, IOException {
   if (f == null) throw new IOException();
   if (flavor.equals(DataFlavor.javaFileListFlavor)) {
     final List coll = new ArrayList(1);
     coll.add(f);
     return coll;
   } else if (flavor.equals(DataFlavor.stringFlavor)) {
     return f.getAbsolutePath();
   }
   throw new UnsupportedFlavorException(flavor);
 }
    /**
     * Returns the data encapsulated in this {@link TransferableObject}. If the {@link Fetcher}
     * constructor was used, then this is when the {@link Fetcher#getObject getObject()} method will
     * be called. If the requested data flavor is not supported, then the {@link Fetcher#getObject
     * getObject()} method will not be called.
     *
     * @param flavor The data flavor for the data to return
     * @return The dropped data
     * @since 1.1
     */
    public Object getTransferData(java.awt.datatransfer.DataFlavor flavor)
        throws java.awt.datatransfer.UnsupportedFlavorException, java.io.IOException {
      // Native object
      if (flavor.equals(DATA_FLAVOR)) return fetcher == null ? data : fetcher.getObject();

      // String
      if (flavor.equals(java.awt.datatransfer.DataFlavor.stringFlavor))
        return fetcher == null ? data.toString() : fetcher.getObject().toString();

      // We can't do anything else
      throw new java.awt.datatransfer.UnsupportedFlavorException(flavor);
    } // end getTransferData
 /**
  * @param flavor
  * @param supportedFlavors
  * @return
  */
 public static boolean isFlavorSupported(DataFlavor flavor, DataFlavor[] supportedFlavors) {
   for (int i = 0; i < supportedFlavors.length; i++) {
     if (supportedFlavors[i].getPrimaryType().equals(flavor.getPrimaryType())
         && supportedFlavors[i].getSubType().equals(flavor.getSubType())
         && flavor
             .getRepresentationClass()
             .isAssignableFrom(supportedFlavors[i].getRepresentationClass())) {
       return true;
     }
   }
   return false;
 }
Example #25
0
  /**
   * 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;
  }
 public Object getTransferData(java.awt.datatransfer.DataFlavor flavor)
     throws java.awt.datatransfer.UnsupportedFlavorException, java.io.IOException {
   if (flavor.equals(objectArrayPropertyItemFlavor)) {
     return objectArrayPropertyItem;
   } else if (flavor.equals(java.awt.datatransfer.DataFlavor.stringFlavor)) {
     return objectArrayPropertyItem.getObjectArrayProperty()
         + "["
         + objectArrayPropertyItem.getIndex()
         + "]";
   } else {
     throw new java.awt.datatransfer.UnsupportedFlavorException(flavor);
   }
 }
  /**
   * This method is called to query whether the transfer can be imported.
   *
   * <p>Will return true for urls, strings, javaFileLists
   *
   * @override
   */
  public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {

    // accept this if any input flavor matches any of our supported flavors
    for (int i = 0; i < transferFlavors.length; i++) {
      DataFlavor inflav = transferFlavors[i];
      if (inflav.match(urlFlavor)
          || inflav.match(stringFlavor)
          || inflav.match(DataFlavor.javaFileListFlavor)) return true;
    }

    // nope, never heard of this type
    return false;
  }
Example #28
0
 /**
  * Returns <code>true</code> if the component can import this data flavor.
  *
  * @param comp The component to import data.
  * @param flavors An array of data flavors.
  */
 @Override
 public boolean canImport(JComponent comp, DataFlavor[] flavors) {
   if (flavors == null) {
     return false;
   } else {
     for (DataFlavor flavor : flavors) {
       if (flavor.equals(buildQueueFlavor)) {
         return true;
       }
     }
     return false;
   }
 }
Example #29
0
  /**
   * This method has the same behavior as {@link #equals(Object)}. The only difference being that it
   * takes a {@code DataFlavor} instance as a parameter.
   *
   * @param that the <code>DataFlavor</code> to compare with <code>this</code>
   * @return <code>true</code> if <code>that</code> is equivalent to this <code>DataFlavor</code>;
   *     <code>false</code> otherwise
   * @see #selectBestTextFlavor
   */
  public boolean equals(DataFlavor that) {
    if (that == null) {
      return false;
    }
    if (this == that) {
      return true;
    }

    if (representationClass == null) {
      if (that.getRepresentationClass() != null) {
        return false;
      }
    } else {
      if (!representationClass.equals(that.getRepresentationClass())) {
        return false;
      }
    }

    if (mimeType == null) {
      if (that.mimeType != null) {
        return false;
      }
    } else {
      if (!mimeType.match(that.mimeType)) {
        return false;
      }

      if ("text".equals(getPrimaryType())
          && DataTransferer.doesSubtypeSupportCharset(this)
          && representationClass != null
          && !(isRepresentationClassReader()
              || String.class.equals(representationClass)
              || isRepresentationClassCharBuffer()
              || DataTransferer.charArrayClass.equals(representationClass))) {
        String thisCharset = DataTransferer.canonicalName(getParameter("charset"));
        String thatCharset = DataTransferer.canonicalName(that.getParameter("charset"));
        if (thisCharset == null) {
          if (thatCharset != null) {
            return false;
          }
        } else {
          if (!thisCharset.equals(thatCharset)) {
            return false;
          }
        }
      }
    }

    return true;
  }
    @Override
    public boolean canImport(TransferSupport support) {
      if (support.isDrop() && !mDropEnabled) return false;

      if (support.getComponent() == mTextArea && mTextHandler.canImport(support)) return true;

      for (DataFlavor flavor : support.getDataFlavors()) {
        if (flavor.isFlavorJavaFileListType()) {
          return true;
        }
      }

      return false;
    }