Java Code Examples for java.awt.datatransfer.Transferable

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project Custom-Salem, under directory /src/haven/.

Source file: Utils.java

  24 
vote

public static String getClipboard(){
  Transferable t=Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
  try {
    if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
      String text=(String)t.getTransferData(DataFlavor.stringFlavor);
      return text;
    }
  }
 catch (  UnsupportedFlavorException e) {
  }
catch (  IOException e) {
  }
  return "";
}
 

Example 2

From project ceres, under directory /ceres-ui/src/main/java/com/bc/ceres/swing/actions/.

Source file: CopyAction.java

  22 
vote

@Override public void execute(){
  Selection selection=getSelection();
  Transferable transferable=selection.createTransferable(true);
  if (transferable != null) {
    getClipboard().setContents(transferable,selection);
  }
}
 

Example 3

From project Clotho-Core, under directory /ClothoApps/SequenceChecker/src/jaligner/ui/clipboard/.

Source file: ClipboardHandlerAWT.java

  22 
vote

/** 
 * Gets the contents of the system clipboard
 * @return The text contents of the system clipboard 
 */
public String getContents(){
  String contents=null;
  Clipboard c=Toolkit.getDefaultToolkit().getSystemClipboard();
  Transferable data=c.getContents(null);
  if (data != null && data.isDataFlavorSupported(DataFlavor.stringFlavor)) {
    try {
      contents=((String)(data.getTransferData(DataFlavor.stringFlavor)));
    }
 catch (    Exception e) {
      logger.log(Level.WARNING,"Failed getting tranfer data: " + e.getMessage(),e);
    }
  }
  return contents;
}
 

Example 4

From project freemind, under directory /freemind/accessories/plugins/.

Source file: ClonePasteAction.java

  22 
vote

public Transferable addHook(MindMapNode pOriginalNode){
  Transferable copy=getMindMapController().copy(pOriginalNode,true);
  Vector selecteds=Tools.getVectorWithSingleElement(pOriginalNode);
  getMindMapController().addHook(pOriginalNode,selecteds,ClonePlugin.PLUGIN_LABEL);
  return copy;
}
 

Example 5

From project groovejaar, under directory /src/groovejaar/.

Source file: ExtendedTextField.java

  22 
vote

/** 
 * Checks if the action can be performed.
 * @return True if the action is allowed
 */
public boolean isEnabled(){
  if (comp.isEditable() && comp.isEnabled()) {
    Transferable contents=Toolkit.getDefaultToolkit().getSystemClipboard().getContents(this);
    return contents.isDataFlavorSupported(DataFlavor.stringFlavor);
  }
 else   return false;
}
 

Example 6

From project Haven-and-Hearth-client-modified-by-Ender, under directory /src/haven/.

Source file: Utils.java

  22 
vote

public static String getClipboard(){
  Transferable t=Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
  try {
    if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
      String text=(String)t.getTransferData(DataFlavor.stringFlavor);
      return text;
    }
  }
 catch (  UnsupportedFlavorException e) {
  }
catch (  IOException e) {
  }
  return "";
}
 

Example 7

From project jchempaint, under directory /src/main/org/openscience/jchempaint/action/.

Source file: CopyPasteAction.java

  22 
vote

@SuppressWarnings("unchecked") private void handleSystemClipboard(Clipboard clipboard){
  Transferable clipboardContent=clipboard.getContents(this);
  DataFlavor flavors[]=clipboardContent.getTransferDataFlavors();
  String text="System.clipoard content";
  for (int i=0; i < flavors.length; ++i) {
    text+="\n\n Name: " + flavors[i].getHumanPresentableName();
    text+="\n MIME Type: " + flavors[i].getMimeType();
    text+="\n Class: ";
    Class cl=flavors[i].getRepresentationClass();
    if (cl == null)     text+="null";
 else     text+=cl.getName();
  }
  logger.debug(text);
}
 

Example 8

From project jftp, under directory /src/main/java/com/myjavaworld/gui/.

Source file: MLabelTextField.java

  22 
vote

public boolean canPaste(){
  if (!isEditable()) {
    return false;
  }
  Clipboard clipBoard=Toolkit.getDefaultToolkit().getSystemClipboard();
  Transferable t=clipBoard.getContents(this);
  return t.isDataFlavorSupported(DataFlavor.stringFlavor);
}
 

Example 9

From project jMemorize, under directory /src/jmemorize/gui/swing/actions/edit/.

Source file: PasteAction.java

  22 
vote

private void updateEnablement(){
  MainFrame mainFrame=Main.getInstance().getFrame();
  if (mainFrame == null)   return;
  Transferable contents=mainFrame.getToolkit().getSystemClipboard().getContents(null);
  setEnabled(mainFrame != null && m_selectionProvider != null && !Main.getInstance().isSessionRunning() && contents.isDataFlavorSupported(GeneralTransferHandler.CARDS_FLAVOR) || contents.isDataFlavorSupported(GeneralTransferHandler.CATEGORY_FLAVOR));
}
 

Example 10

From project JoshEdit, under directory /org/lateralgm/joshedit/.

Source file: Selection.java

  22 
vote

/** 
 * Returns the number of lines affected by a potential paste in this selection.
 * @return Same as getInsertRipple(clipboard text).
 */
public int getPasteRipple(){
  Clipboard clipboard=Toolkit.getDefaultToolkit().getSystemClipboard();
  Transferable contents=clipboard.getContents(null);
  try {
    String str=(String)contents.getTransferData(DataFlavor.stringFlavor);
    return getInsertRipple(str);
  }
 catch (  UnsupportedFlavorException e) {
  }
catch (  IOException e) {
  }
  return 0;
}
 

Example 11

From project lilith, under directory /lilith/src/main/java/de/huxhorn/lilith/swing/transfer/.

Source file: MainFrameTransferHandler16.java

  22 
vote

@Override public boolean importData(TransferHandler.TransferSupport support){
  if (!canImport(support)) {
    return false;
  }
  Transferable t=support.getTransferable();
  return importData(t);
}
 

Example 12

From project Moneychanger, under directory /src/main/java/com/moneychanger/ui/custom/.

Source file: ClipboardClass.java

  22 
vote

public void actionPerformed(ActionEvent event){
  Transferable clipboardContent=clipboard.getContents(this);
  if ((clipboardContent != null) && (clipboardContent.isDataFlavorSupported(DataFlavor.stringFlavor))) {
    try {
      String tempString;
      tempString=(String)clipboardContent.getTransferData(DataFlavor.stringFlavor);
      destinationString=tempString;
    }
 catch (    Exception e) {
      e.printStackTrace();
    }
  }
}
 

Example 13

From project OMS3, under directory /src/main/java/ngmf/ui/.

Source file: TableListener.java

  22 
vote

public void pasteClipboard(){
  Transferable t=Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
  try {
    if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
      addContents((String)t.getTransferData(DataFlavor.stringFlavor));
      table.repaint();
    }
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
}
 

Example 14

From project OWASP-WebScarab, under directory /src/org/owasp/webscarab/util/swing/.

Source file: TextComponentContextMenu.java

  22 
vote

public boolean isEnabled(){
  if (comp.isEditable() && comp.isEnabled()) {
    Transferable contents=Toolkit.getDefaultToolkit().getSystemClipboard().getContents(this);
    return contents.isDataFlavorSupported(DataFlavor.stringFlavor);
  }
 else   return false;
}
 

Example 15

From project SpoutcraftAPI, under directory /src/main/java/org/spoutcraft/spoutcraftapi/gui/.

Source file: GenericTextProcessor.java

  22 
vote

private static String getClipboardString(){
  try {
    Transferable transfer=Toolkit.getDefaultToolkit().getSystemClipboard().getContents((Object)null);
    if (transfer != null && transfer.isDataFlavorSupported(DataFlavor.stringFlavor)) {
      String var1=(String)transfer.getTransferData(DataFlavor.stringFlavor);
      return var1;
    }
  }
 catch (  Exception var2) {
    ;
  }
  return null;
}
 

Example 16

From project SPREAD, under directory /src/colorpicker/swing/.

Source file: ColorSwatch.java

  22 
vote

public void actionPerformed(ActionEvent e){
  Object src=e.getSource();
  if (src == copyItem) {
    BufferedImage image=new BufferedImage(100,100,BufferedImage.TYPE_INT_RGB);
    Graphics2D g=image.createGraphics();
    g.setColor(getBackground());
    g.fillRect(0,0,image.getWidth(),image.getHeight());
    g.dispose();
    Transferable contents=new ImageTransferable(image);
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(contents,null);
  }
}
 

Example 17

From project Terasology, under directory /src/main/java/org/terasology/rendering/gui/widgets/.

Source file: UIText.java

  22 
vote

/** 
 * Get the text from the clipboard.
 * @return Returns the text from the clipboard.
 */
private String getClipboard(){
  Transferable t=Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
  try {
    if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
      String text=(String)t.getTransferData(DataFlavor.stringFlavor);
      return text;
    }
  }
 catch (  UnsupportedFlavorException e) {
  }
catch (  IOException e) {
  }
  return "";
}
 

Example 18

From project Briss, under directory /src/main/java/at/laborg/briss/.

Source file: BrissTransferHandler.java

  21 
vote

@Override public boolean importData(TransferSupport support){
  if (!canImport(support))   return false;
  Transferable t=support.getTransferable();
  try {
    String dropInput=(String)t.getTransferData(DataFlavor.stringFlavor);
    String[] filenames=dropInput.split("\n");
    for (    String filename : filenames) {
      filename=filename.replaceAll("\\n","");
      filename=filename.replaceAll("\\t","");
      filename=filename.replaceAll("\\r","");
      if (filename.trim().endsWith(".pdf")) {
        File loadFile=null;
        try {
          URI uri=new URI(filename);
          loadFile=new File(uri);
        }
 catch (        URISyntaxException e1) {
          e1.printStackTrace();
        }
        try {
          this.brissGUI.importNewPdfFile(loadFile);
        }
 catch (        PdfException e) {
          e.printStackTrace();
        }
        break;
      }
    }
  }
 catch (  UnsupportedFlavorException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
  return true;
}
 

Example 19

From project codjo-standalone-common, under directory /src/main/java/net/codjo/gui/.

Source file: TextAreaTargetDnd.java

  21 
vote

/** 
 * Description of the Method
 * @param event Description of Parameter
 */
public void drop(DropTargetDropEvent event){
  try {
    Transferable transferable=event.getTransferable();
    if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
      event.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
      String s=(String)transferable.getTransferData(DataFlavor.stringFlavor);
      text.insert(s,text.getText().length());
      event.getDropTargetContext().dropComplete(true);
    }
 else {
      event.rejectDrop();
    }
  }
 catch (  java.io.IOException exception) {
    exception.printStackTrace();
    System.err.println("Exception" + exception.getMessage());
    event.rejectDrop();
  }
catch (  UnsupportedFlavorException ufException) {
    ufException.printStackTrace();
    System.err.println("Exception" + ufException.getMessage());
    event.rejectDrop();
  }
}
 

Example 20

From project dawn-isencia, under directory /com.isencia.passerelle.engine/src/main/java/com/isencia/passerelle/actor/gui/graph/.

Source file: ModelGraphPanel.java

  21 
vote

/** 
 * Assuming the contents of the clipboard is MoML code, paste it into the current model by issuing a change request.
 */
public void paste(){
  postUndoableEdit("paste");
  Clipboard clipboard=java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
  Transferable transferable=clipboard.getContents(this);
  GraphPane graphPane=_jgraph.getGraphPane();
  GraphController controller=(GraphController)graphPane.getGraphController();
  GraphModel model=controller.getGraphModel();
  if (transferable == null)   return;
  try {
    NamedObj container=(NamedObj)model.getRoot();
    StringBuffer moml=new StringBuffer();
    String pastedSegment=(String)transferable.getTransferData(DataFlavor.stringFlavor);
    pastedSegment=translateFiguresInSegment(pastedSegment,20,20);
    moml.append("<group name=\"auto\">\n");
    moml.append(pastedSegment);
    moml.append("</group>\n");
    MoMLChangeRequest change=new MoMLChangeRequest(this,container,moml.toString());
    change.setUndoable(true);
    container.requestChange(change);
  }
 catch (  Exception ex) {
    MessageHandler.error("Paste failed",ex);
  }
}
 

Example 21

From project encog-java-workbench, under directory /src/main/java/org/encog/workbench/frames/document/tree/.

Source file: ProjectTree.java

  21 
vote

public void drop(DropTargetDropEvent dtde){
  if (EncogWorkBench.getInstance().getMainWindow().getTabManager().notWithModalTabOpen())   return;
  try {
    if (EncogWorkBench.getInstance().getProjectDirectory() == null) {
      EncogWorkBench.displayError("Error","Open a project before using drag and drop.");
      return;
    }
    if (!EncogWorkBench.askQuestion("Drag and Drop","Copy the file(s) to the project?")) {
      return;
    }
    Transferable tr=dtde.getTransferable();
    DataFlavor[] flavors=tr.getTransferDataFlavors();
    for (int i=0; i < flavors.length; i++) {
      if (flavors[i].isFlavorJavaFileListType()) {
        dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
        java.util.List list=(java.util.List)tr.getTransferData(flavors[i]);
        for (int j=0; j < list.size(); j++) {
          File sourceFile=new File(list.get(j).toString());
          if (sourceFile.isDirectory()) {
            EncogWorkBench.displayError("Drag and Drop","Can't drop folder.");
            return;
          }
          String name=sourceFile.getName();
          File targetFile=new File(EncogWorkBench.getInstance().getProjectDirectory(),name);
          FileUtil.copy(sourceFile,targetFile);
        }
        dtde.dropComplete(true);
        EncogWorkBench.getInstance().refresh();
        return;
      }
    }
  }
 catch (  Exception e) {
    EncogWorkBench.displayError("Drag and Drop",e);
  }
  dtde.rejectDrop();
}
 

Example 22

From project ISAcreator, under directory /src/main/java/org/isatools/isacreator/common/.

Source file: ReOrderableJList.java

  21 
vote

public void dragGestureRecognized(DragGestureEvent dge){
  try {
    Point clickPoint=dge.getDragOrigin();
    int index=locationToIndex(clickPoint);
    if (index == -1)     return;
    Transferable trans;
    if (getSelectedValues().length > 1) {
      List<Object> target=new ArrayList<Object>();
      target.addAll(Arrays.asList(getSelectedValues()));
      trans=new RJLTransferable(target);
    }
 else {
      Object target=getModel().getElementAt(index);
      trans=new RJLTransferable(target);
    }
    draggedIndex=index;
    dragSource.startDrag(dge,Cursor.getDefaultCursor(),trans,this);
  }
 catch (  InvalidDnDOperationException e) {
    log.info(e.getMessage());
  }
}
 

Example 23

From project jreepad, under directory /src/jreepad/editor/.

Source file: EditPopupHandler.java

  21 
vote

private void enableMenuItems(MouseEvent e){
  JTextComponent textComp=(JTextComponent)e.getComponent();
  String selectedText=textComp.getSelectedText();
  boolean textSelected=selectedText != null && selectedText.length() > 0;
  boolean isEditable=textComp.isEditable();
  JMenuItem item=(JMenuItem)itemMap.get(ITEM_COPY);
  if (item != null) {
    item.setEnabled(textSelected);
  }
  item=(JMenuItem)itemMap.get(ITEM_CUT);
  if (item != null) {
    item.setEnabled(textSelected && isEditable);
  }
  Clipboard clipboard=Toolkit.getDefaultToolkit().getSystemClipboard();
  Transferable contents=clipboard.getContents(null);
  boolean hasTransferableText=(contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor);
  item=(JMenuItem)itemMap.get(ITEM_PASTE);
  if (item != null) {
    item.setEnabled(hasTransferableText && isEditable);
  }
}
 

Example 24

From project Kayak, under directory /Kayak-ui/src/main/java/com/github/kayak/ui/messageview/.

Source file: MessageSignalDropAdapter.java

  21 
vote

@Override public void drop(DropTargetDropEvent dtde){
  Transferable transferable=dtde.getTransferable();
  if (transferable.isDataFlavorSupported(MessageDescriptionNode.MESSAGE_DATA_FLAVOR)) {
    try {
      MessageDescription desc=(MessageDescription)transferable.getTransferData(MessageDescriptionNode.MESSAGE_DATA_FLAVOR);
      Bus bus=(Bus)transferable.getTransferData(MessageDescriptionNode.BUS_DATA_FLAVOR);
      receiver.dropped(desc,bus);
      return;
    }
 catch (    UnsupportedFlavorException ex) {
      Exceptions.printStackTrace(ex);
    }
catch (    IOException ex) {
      Exceptions.printStackTrace(ex);
    }
  }
 else   if (transferable.isDataFlavorSupported(SignalDescriptionNode.SIGNAL_DATA_FLAVOR)) {
    try {
      SignalDescription desc=(SignalDescription)transferable.getTransferData(SignalDescriptionNode.SIGNAL_DATA_FLAVOR);
      Bus bus=(Bus)transferable.getTransferData(SignalDescriptionNode.BUS_DATA_FLAVOR);
      receiver.dropped(desc,bus);
      return;
    }
 catch (    UnsupportedFlavorException ex) {
      Exceptions.printStackTrace(ex);
    }
catch (    IOException ex) {
      Exceptions.printStackTrace(ex);
    }
  }
}
 

Example 25

From project LanguageSpecCreator, under directory /src/SpecificationCreation/look/.

Source file: TreeTransferHandler.java

  21 
vote

/** 
 * Perform the actual import. Only supports drag and drop.
 * @param info TransferHandler.TransferSupport
 * @return true if the value has been imported, false if there was an error
 */
public boolean importData(TransferHandler.TransferSupport info){
  if (!info.isDrop())   return false;
  Transferable t=info.getTransferable();
  try {
    String data=(String)t.getTransferData(DataFlavor.stringFlavor);
    if (info.getDropLocation() instanceof JList.DropLocation) {
      JList.DropLocation loc=(JList.DropLocation)info.getDropLocation();
      pane.addToList(data);
    }
 else {
      JTree.DropLocation loc=(JTree.DropLocation)info.getDropLocation();
      pane.makeNode(data,loc.getPath());
    }
    return true;
  }
 catch (  Exception e) {
    e.printStackTrace();
    return false;
  }
}
 

Example 26

From project LateralGM, under directory /org/lateralgm/main/.

Source file: FileChooser.java

  21 
vote

public List<?> getDropList(TransferHandler.TransferSupport evt){
  Transferable tr=evt.getTransferable();
  DataFlavor df=getSupportedFlavor(evt.getDataFlavors());
  if (df == null)   return null;
  try {
    if (df.isFlavorJavaFileListType())     return (List<?>)tr.getTransferData(DataFlavor.javaFileListFlavor);
    if (!df.isRepresentationClassReader() || !MIME_URI_LIST.equals(df.getSubType()))     return null;
    BufferedReader br=new BufferedReader(df.getReaderForText(tr));
    List<URI> uriList=new LinkedList<URI>();
    String line;
    while ((line=br.readLine()) != null) {
      try {
        if (line.isEmpty() || line.length() == 1 && line.charAt(0) == (char)0)         continue;
        uriList.add(new URI(line));
      }
 catch (      URISyntaxException ex) {
      }
catch (      IllegalArgumentException ex) {
      }
    }
    br.close();
    return uriList;
  }
 catch (  UnsupportedFlavorException e) {
  }
catch (  IOException e) {
  }
  return null;
}
 

Example 27

From project milton, under directory /milton/milton-client-app/src/main/java/bradswebdavclient/.

Source file: ResourceTransferHandler.java

  21 
vote

public final void drop(DropTargetDropEvent dtde){
  System.out.println("drop");
  try {
    int action=dtde.getDropAction();
    Transferable transferable=dtde.getTransferable();
    Point pt=dtde.getLocation();
    if (executeDrop(transferable,pt,action)) {
      dtde.acceptDrop(action);
      dtde.dropComplete(true);
      return;
    }
  }
 catch (  Exception e) {
    System.out.println(e);
    dtde.rejectDrop();
    dtde.dropComplete(false);
  }
}
 

Example 28

From project milton2, under directory /milton-client-app/src/main/java/bradswebdavclient/.

Source file: ResourceTransferHandler.java

  21 
vote

public final void drop(DropTargetDropEvent dtde){
  System.out.println("drop");
  try {
    int action=dtde.getDropAction();
    Transferable transferable=dtde.getTransferable();
    Point pt=dtde.getLocation();
    if (executeDrop(transferable,pt,action)) {
      dtde.acceptDrop(action);
      dtde.dropComplete(true);
      return;
    }
  }
 catch (  Exception e) {
    System.out.println(e);
    dtde.rejectDrop();
    dtde.dropComplete(false);
  }
}
 

Example 29

From project multibit, under directory /src/main/java/org/multibit/viewsystem/swing/action/.

Source file: PasteSwatchAction.java

  21 
vote

private Image getImageFromClipboard(){
  Transferable transferable=Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
  if (transferable != null && transferable.isDataFlavorSupported(DataFlavor.imageFlavor)) {
    try {
      return (Image)transferable.getTransferData(DataFlavor.imageFlavor);
    }
 catch (    UnsupportedFlavorException e) {
      e.printStackTrace();
    }
catch (    IOException e) {
      e.printStackTrace();
    }
  }
  return null;
}
 

Example 30

From project niravCS2103, under directory /CS2103/src/gui/.

Source file: JotItDownTray.java

  21 
vote

/** 
 * getting text from clipboard
 * @return text
 */
private String getClipboard(){
  Transferable t=Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
  try {
    if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
      String text=(String)t.getTransferData(DataFlavor.stringFlavor);
      return text;
    }
  }
 catch (  UnsupportedFlavorException e) {
    logger.error("UnsupportedFlavorException");
  }
catch (  IOException e) {
    logger.error("IOException");
  }
  logger.warn("null text from clipboard.");
  return null;
}
 

Example 31

From project pegadi, under directory /storysketch/src/main/java/org/pegadi/storysketch/.

Source file: StorySketchPanel.java

  21 
vote

public void graph_drop(DropTargetDropEvent dtde){
  Transferable t=dtde.getTransferable();
  DataFlavor[] flavors=t.getTransferDataFlavors();
  boolean canImport=false;
  for (  DataFlavor flavor : flavors) {
    if (DataFlavor.stringFlavor.equals(flavor)) {
      canImport=true;
    }
  }
  if (!canImport) {
    return;
  }
  try {
    dtde.acceptDrop(DnDConstants.ACTION_COPY);
    String str=(String)t.getTransferData(DataFlavor.stringFlavor);
    JMenu insert=createInsertMenu(dtde.getLocation(),str);
    JPopupMenu menu=new JPopupMenu();
    menu.add(insert);
    menu.show(graph,(int)dtde.getLocation().getX(),(int)dtde.getLocation().getY());
  }
 catch (  UnsupportedFlavorException ignored) {
  }
catch (  IOException ignored) {
  }
}
 

Example 32

From project QView, under directory /QView-suite/jre1.5.0_11/sample/jnlp/webpad/src/version1/.

Source file: ClipboardHandler.java

  21 
vote

public static String fromClipboard(){
  System.out.println("fromClipboard: ");
  initialize();
  if (_cs != null) {
    Transferable t=_cs.getContents();
    try {
      return (String)t.getTransferData(DataFlavor.stringFlavor);
    }
 catch (    Throwable ex) {
      System.out.println(ex);
      return "";
    }
  }
 else {
    return _content;
  }
}
 

Example 33

From project salem, under directory /src/org/apxeolog/salem/widgets/.

Source file: SLineEdit.java

  21 
vote

/** 
 * Get the String residing on the clipboard.
 * @return any text found on the Clipboard; if none found, return an emptyString.
 */
public String getClipboardContents(){
  String result="";
  Clipboard clipboard=Toolkit.getDefaultToolkit().getSystemClipboard();
  Transferable contents=clipboard.getContents(null);
  boolean hasTransferableText=(contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor);
  if (hasTransferableText) {
    try {
      result=(String)contents.getTransferData(DataFlavor.stringFlavor);
    }
 catch (    UnsupportedFlavorException ex) {
    }
catch (    IOException ex) {
    }
  }
  return result;
}
 

Example 34

From project sradonia-tools, under directory /src/main/java/net/sradonia/gui/tree/.

Source file: AbstractTreeTransferHandler.java

  21 
vote

public void drop(DropTargetDropEvent dtde){
  try {
    Transferable transferable=dtde.getTransferable();
    DefaultMutableTreeNode node=(DefaultMutableTreeNode)transferable.getTransferData(NodeTransferable.NODE_FLAVOR);
    int action=dtde.getDropAction();
    Point location=dtde.getLocation();
    if (canPerformAction(tree,node,action,location)) {
      DefaultMutableTreeNode newParentNode=(DefaultMutableTreeNode)tree.getPathForLocation(location.x,location.y).getLastPathComponent();
      if (executeDrop(tree,node,newParentNode,action)) {
        dtde.acceptDrop(action);
        dtde.dropComplete(true);
        return;
      }
    }
  }
 catch (  Exception e) {
  }
  dtde.rejectDrop();
  dtde.dropComplete(false);
}
 

Example 35

From project VisiCut, under directory /src/com/t_oster/visicut/gui/beans/.

Source file: FilesDropSupport.java

  21 
vote

public void drop(DropTargetDropEvent event){
  Transferable transferable=event.getTransferable();
  event.acceptDrop(DnDConstants.ACTION_MOVE);
  DataFlavor uriListFlavor=null;
  try {
    uriListFlavor=new DataFlavor("text/uri-list;class=java.lang.String");
  }
 catch (  ClassNotFoundException e) {
  }
  try {
    if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
      List data=(List)transferable.getTransferData(DataFlavor.javaFileListFlavor);
      this.filesDropped(data);
    }
 else {
      if (transferable.isDataFlavorSupported(uriListFlavor)) {
        String data=(String)transferable.getTransferData(uriListFlavor);
        List files=textURIListToFileList(data);
        this.filesDropped(files);
      }
    }
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
}
 

Example 36

From project codjo-data-process, under directory /codjo-data-process-gui/src/main/java/net/codjo/dataprocess/gui/util/sqleditor/components/.

Source file: StringTransferHandler.java

  19 
vote

@Override public boolean importData(JComponent jc,Transferable tt){
  if (canImport(jc,tt.getTransferDataFlavors())) {
    try {
      String str=(String)tt.getTransferData(DataFlavor.stringFlavor);
      importString(jc,str);
      return true;
    }
 catch (    UnsupportedFlavorException ufe) {
      ;
    }
catch (    IOException ioe) {
      ;
    }
  }
  return false;
}
 

Example 37

From project cowgraph, under directory /CowGraph/CowGraphVisualEditor/src/zbeans/cowgraph/visual/editor/.

Source file: CowGraphVisualEditorScene.java

  19 
vote

CowGraphVisualEditorScene(){
  mainLayer=new LayerWidget(this);
  addChild(mainLayer);
  getActions().addAction(ActionFactory.createAcceptAction(new AcceptProvider(){
    @Override public ConnectorState isAcceptable(    Widget widget,    Point point,    Transferable transferable){
      Node node=NodeTransfer.node(transferable,NodeTransfer.DND_COPY_OR_MOVE);
      GraphElementType type=node.getLookup().lookup(GraphElementType.class);
      if (type != null) {
        return ConnectorState.ACCEPT;
      }
 else {
        return ConnectorState.REJECT;
      }
    }
    @Override public void accept(    Widget widget,    Point point,    Transferable transferable){
      addGraphElementsFromTransferable(transferable,widget.convertLocalToScene(point));
      getView().requestFocusInWindow();
    }
  }
));
  getActions().addAction(ActionFactory.createZoomAction());
  getActions().addAction(ActionFactory.createPanAction());
}
 

Example 38

From project FScape, under directory /src/main/java/de/sciss/fscape/gui/.

Source file: OpPanel.java

  19 
vote

public void lostOwnership(Clipboard clipBoard,Transferable contents){
  Operator op;
  try {
    op=(Operator)contents.getTransferData(Operator.flavor);
    op.dispose();
  }
 catch (  Exception e1) {
    GUIUtil.displayError(win.getWindow(),e1,"lostOwnership");
  }
}
 

Example 39

From project JaamSim, under directory /com/sandwell/JavaSimulation3D/.

Source file: EntityTransferHandler.java

  19 
vote

/** 
 * Add the the dropped item to the Window
 */
public boolean importData(JComponent destination,Transferable transferable){
  Region region=((Sim3DWindow)((JRootPane)destination).getParent()).getRegion();
  OrbitBehavior behavior=((Sim3DWindow)((JRootPane)destination).getParent()).behavior;
  ObjectType type=null;
  try {
    type=(ObjectType)transferable.getTransferData(TransferableObjectType.OBJECT_TYPE_FLAVOR);
  }
 catch (  UnsupportedFlavorException e) {
    throw new ErrorException(e);
  }
catch (  IOException e) {
    throw new ErrorException(e);
  }
  int i=1;
  Class<? extends Entity> proto=type.getJavaClass();
  String name=proto.getSimpleName();
  while (Simulation.getNamedEntity(String.format("%s%d",name,i)) != null) {
    i++;
  }
  name=String.format("%s%d",name,i);
  DisplayEntity dEntity=(DisplayEntity)InputAgent.defineEntity(proto,name,true);
  Point dropLocation=destination.getMousePosition();
  Vector3d universeLocation=behavior.getUniversePointFromMouseLoc(dropLocation.x,dropLocation.y,OrbitBehavior.Plane.XY_PLANE,0.0d);
  dEntity.setPosition(universeLocation);
  dEntity.setAlignment(new Vector3d(0.0,0.0,-0.5));
  dEntity.initializeGraphics();
  dEntity.enterRegion(region);
  FrameBox.setSelectedEntity(dEntity);
  dEntity.updateInputPosition();
  dEntity.updateInputSize();
  dEntity.updateInputAlignment();
  return true;
}
 

Example 40

From project jCAE, under directory /jcae/core/src/org/jcae/netbeans/cad/.

Source file: GeomCConvertor.java

  19 
vote

public Transferable convert(Transferable t){
  Node[] ns=NodeTransfer.nodes(t,NodeTransfer.COPY | NodeTransfer.MOVE);
  if (ns != null && ns.length == 1) {
    final NbShape shape=GeomUtils.getShape(ns[0]);
    if (shape != null) {
      ExTransferable r=ExTransferable.create(t);
      ExTransferable.Single s=LoaderTransfer.transferable(null,LoaderTransfer.COPY | LoaderTransfer.MOVE);
      ExTransferable.Single ss=new ExTransferable.Single(s.getTransferDataFlavors()[0]){
        public Object getData(){
          return BrepDataObject.createInMemory(shape);
        }
      }
;
      r.put(ss);
      return r;
    }
  }
  return t;
}
 

Example 41

From project jgraphx, under directory /examples/com/mxgraph/examples/swing/editor/.

Source file: JTableRenderer.java

  19 
vote

@SuppressWarnings("serial") public MyTable(){
  data=new Object[30][5];
  for (int i=0; i < 30; i++) {
    data[i][0]=new Boolean(false);
    data[i][1]="Column " + i;
    data[i][2]=(Math.random() > 0.5) ? new ImageIcon(JTableRenderer.class.getResource(IMAGE_PATH + "preferences.gif")) : null;
    data[i][3]=(Math.random() > 0.5) ? new ImageIcon(JTableRenderer.class.getResource(IMAGE_PATH + "preferences.gif")) : null;
    data[i][4]=(Math.random() > 0.5) ? new ImageIcon(JTableRenderer.class.getResource(IMAGE_PATH + "preferences.gif")) : null;
  }
  setModel(createModel());
  setTableHeader(null);
  setAutoscrolls(true);
  setGridColor(Color.WHITE);
  TableColumn column=getColumnModel().getColumn(0);
  column.setMaxWidth(20);
  column=getColumnModel().getColumn(2);
  column.setMaxWidth(12);
  column=getColumnModel().getColumn(3);
  column.setMaxWidth(12);
  column=getColumnModel().getColumn(4);
  column.setMaxWidth(12);
  setTransferHandler(new TransferHandler(){
    @Override public int getSourceActions(    JComponent c){
      return COPY_OR_MOVE;
    }
    protected Transferable createTransferable(    JComponent c){
      sourceRow=getSelectedRow();
      dragSource=JTableRenderer.this;
      return new mxGraphTransferable(null,null,null);
    }
  }
);
  setDragEnabled(true);
  setDropTarget(new DropTarget(this,DnDConstants.ACTION_COPY_OR_MOVE,this));
  setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
 

Example 42

From project jsmaa, under directory /main/src/main/java/fi/smaa/jsmaa/gui/.

Source file: LeftTreeTransferHandler.java

  19 
vote

@Override protected Transferable createTransferable(JComponent c){
  if (!isLeftTree(c)) {
    return null;
  }
  Object lastPathComponent=((JTree)c).getSelectionPath().getLastPathComponent();
  if (!(lastPathComponent instanceof Criterion) && !(lastPathComponent instanceof Alternative)) {
    return null;
  }
  return new TransferableObject(lastPathComponent);
}
 

Example 43

From project kabeja, under directory /blocks/ui/src/main/java/org/kabeja/ui/impl/.

Source file: DraftFileTransferHandler.java

  19 
vote

public boolean importData(JComponent c,Transferable t){
  List files=getFileList(t);
  if (files.size() > 0) {
    File f=(File)files.get(0);
    if (f.getAbsolutePath().toLowerCase().endsWith(".dxf")) {
      this.c.processInput(f);
    }
    return true;
  }
  return false;
}
 

Example 44

From project rpiplanner, under directory /src/rpiplanner/view/.

Source file: CourseTransferHandler.java

  19 
vote

@Override protected Transferable createTransferable(JComponent c){
  if (c instanceof JList) {
    Course toExport=(Course)((JList)c).getSelectedValue();
    return new CourseTransfer(toExport);
  }
 else   if (c instanceof CourseDisplay) {
    CourseDisplay cd=(CourseDisplay)c;
    Course toExport=cd.getCourse();
    return new CourseTransfer(toExport,cd);
  }
  return super.createTransferable(c);
}
 

Example 45

From project ScissLib, under directory /src/main/java/de/sciss/gui/.

Source file: NumberField.java

  19 
vote

/** 
 * Overridden to import a Number or String if it is available.
 */
public boolean importData(JComponent c,Transferable t){
  Number n=null;
  try {
    if (t.isDataFlavorSupported(numberFlavor)) {
      n=(Number)t.getTransferData(numberFlavor);
    }
 else     if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
      n=(Number)getFormatter().stringToValue((String)t.getTransferData(DataFlavor.stringFlavor));
    }
    if (n != null) {
      setNumber(n);
      fireNumberChanged();
      return true;
    }
  }
 catch (  UnsupportedFlavorException e1) {
  }
catch (  IOException e2) {
  }
catch (  ParseException e3) {
  }
  return false;
}
 

Example 46

From project sikuli, under directory /sikuli-ide/src/main/java/org/sikuli/ide/.

Source file: ConsolePane.java

  19 
vote

protected Transferable createTransferable(JComponent c){
  JTextPane aTextPane=(JTextPane)c;
  HTMLEditorKit kit=((HTMLEditorKit)aTextPane.getEditorKit());
  StyledDocument sdoc=aTextPane.getStyledDocument();
  int sel_start=aTextPane.getSelectionStart();
  int sel_end=aTextPane.getSelectionEnd();
  int i=sel_start;
  StringBuffer output=new StringBuffer();
  while (i < sel_end) {
    Element e=sdoc.getCharacterElement(i);
    Object nameAttr=e.getAttributes().getAttribute(StyleConstants.NameAttribute);
    int start=e.getStartOffset(), end=e.getEndOffset();
    if (nameAttr == HTML.Tag.BR) {
      output.append("\n");
    }
 else     if (nameAttr == HTML.Tag.CONTENT) {
      if (start < sel_start)       start=sel_start;
      if (end > sel_end)       end=sel_end;
      try {
        String str=sdoc.getText(start,end - start);
        output.append(str);
      }
 catch (      BadLocationException ble) {
        ble.printStackTrace();
      }
    }
    i=end;
  }
  return new StringSelection(output.toString());
}
 

Example 47

From project SPaTo_Visual_Explorer, under directory /src/net/spato/sve/app/data/.

Source file: DataTransferHandler.java

  19 
vote

@SuppressWarnings("unchecked") public boolean handleTransferable(Transferable t){
  if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
    File ff[];
    try {
      ff=((java.util.List<File>)t.getTransferData(DataFlavor.javaFileListFlavor)).toArray(new File[0]);
    }
 catch (    Exception e) {
      app.console.logError("Error while getting the names of the dropped/pasted files: ",e);
      e.printStackTrace();
      return false;
    }
    handleDroppedFiles(ff);
    return true;
  }
  if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
    String str=null;
    try {
      str=(String)t.getTransferData(DataFlavor.stringFlavor);
    }
 catch (    Exception e) {
      app.console.logError("Error while retrieving the dropped/pasted text: ",e);
      e.printStackTrace();
      return false;
    }
    if (str.startsWith("file://")) {
      File ff[]=new File[0];
      for (      String line : PApplet.split(str,"\n")) {
        line=PApplet.trim(line);
        if ((line.length() > 0) && line.startsWith("file://"))         ff=(File[])PApplet.append(ff,new File(line.substring(7)));
      }
      handleDroppedFiles(ff);
    }
 else     new DataImportWizard(app,str).start();
    return true;
  }
  return false;
}
 

Example 48

From project SwingOSC, under directory /src/main/java/de/sciss/swingosc/.

Source file: DummyTransferHandler.java

  19 
vote

public boolean importData(JComponent c,Transferable t){
  try {
    if (t.isDataFlavorSupported(dummyFlavor)) {
      client.reply(importDummyMsg);
      return true;
    }
 else     if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
      importStringArgs[3]=t.getTransferData(DataFlavor.stringFlavor);
      client.reply(new OSCMessage(getOSCCommand(),importStringArgs));
      return true;
    }
 else     if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
      final List fileList=(List)t.getTransferData(DataFlavor.javaFileListFlavor);
      if (!fileList.isEmpty()) {
        final Object[] importFilesArgs=new Object[fileList.size() + 3];
        importFilesArgs[0]=importStringArgs[0];
        importFilesArgs[1]=importStringArgs[1];
        importFilesArgs[2]="files";
        for (int i=0, j=3; i < fileList.size(); i++, j++) {
          importFilesArgs[j]=((File)fileList.get(i)).getAbsolutePath();
        }
        client.reply(new OSCMessage(getOSCCommand(),importFilesArgs));
        return true;
      }
    }
    return oldHandler == null ? super.importData(c,t) : oldHandler.importData(c,t);
  }
 catch (  IOException ex) {
    SwingOSC.printException(ex,getOSCCommand());
  }
catch (  UnsupportedFlavorException ex) {
    SwingOSC.printException(ex,getOSCCommand());
  }
  return false;
}
 

Example 49

From project tika, under directory /tika-app/src/main/java/org/apache/tika/gui/.

Source file: ParsingTransferHandler.java

  19 
vote

@SuppressWarnings("unchecked") public boolean importData(JComponent component,Transferable transferable){
  try {
    if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
      importFiles((List<File>)transferable.getTransferData(DataFlavor.javaFileListFlavor));
    }
 else     if (transferable.isDataFlavorSupported(urlListFlavor)) {
      Object data=transferable.getTransferData(urlListFlavor);
      tika.openURL(new URL(data.toString()));
    }
 else     if (transferable.isDataFlavorSupported(uriListFlavor)) {
      importFiles(uriToFileList(transferable.getTransferData(uriListFlavor)));
    }
    return true;
  }
 catch (  Exception e) {
    return false;
  }
}
 

Example 50

From project TransFile, under directory /src/net/sourceforge/transfile/ui/swing/.

Source file: OperationComponent.java

  19 
vote

/** 
 * TODO doc
 * @return <br>A non-null value <br>A new value
 */
private final JLabel createFileIconLabel(){
  final JLabel result=new JLabel(getIconForFileName(this.getOperation().getFileName()));
  resizeIconIfTooSmall(result);
  result.addMouseListener(new DragMouseHandler());
  result.setTransferHandler(new TransferHandler("icon"){
    @Override protected final void exportDone(    final JComponent source,    final Transferable data,    final int action){
      if (TransferHandler.NONE == action) {
        OperationComponent.this.getOperation().getController().start();
      }
    }
    @Override public final Icon getVisualRepresentation(    final Transferable transferable){
      return result.getIcon();
    }
    private static final long serialVersionUID=9018854963146765450L;
  }
);
  return result;
}