Java 类org.openide.util.datatransfer.ExClipboard 实例源码

项目:incubator-netbeans    文件:MatchingObjectNode.java   
@Override
public void actionPerformed(ActionEvent e) {
    File f = FileUtil.toFile(
            matchingObject.getFileObject());
    if (f != null) {
        String path = f.getPath();
        Clipboard clipboard = Lookup.getDefault().lookup(
                ExClipboard.class);
        if (clipboard == null) {
            Toolkit toolkit = Toolkit.getDefaultToolkit();
            if (toolkit != null) {
                clipboard = toolkit.getSystemClipboard();
            }
        }
        if (clipboard != null) {
            StringSelection strSel = new StringSelection(path);
            clipboard.setContents(strSel, null);
        }
    }
}
项目:incubator-netbeans    文件:NbClipboardIsUsedBySwingComponentsTest.java   
protected void setUp() throws Exception {
    MockServices.setServices(Clip.class);
    System.setProperty ("netbeans.security.nocheck", "true");
    Object clip = Lookup.getDefault ().lookup (ExClipboard.class);
    assertNotNull ("Some clipboard found", clip);
    assertEquals ("Correct clipboard found", Clip.class, clip.getClass());
    this.clip = (Clip)clip;

    if (System.getSecurityManager () == null) {
        java.text.NumberFormat.getInstance ();

        Object clazz = org.netbeans.TopSecurityManager.class;
        SecurityManager m = new org.netbeans.TopSecurityManager ();
        System.setSecurityManager (m);

        inMiddleOfSettingUpTheManager();

        org.netbeans.TopSecurityManager.makeSwingUseSpecialClipboard (this.clip);
    } else {
        inMiddleOfSettingUpTheManager();
    }

    field = new javax.swing.JTextField ();
}
项目:incubator-netbeans    文件:NbClipboardNativeTest.java   
public void testClipboard() throws Exception {
    MockServices.setServices(Cnv.class);
    Clipboard c = Lookup.getDefault().lookup(Clipboard.class);
    ExClipboard ec = Lookup.getDefault().lookup(ExClipboard.class);
    assertEquals("Clipboard == ExClipboard", c, ec);
    assertNotNull(Lookup.getDefault().lookup(ExClipboard.Convertor.class));
    assertEquals(Cnv.class, Lookup.getDefault().lookup(ExClipboard.Convertor.class).getClass());
    c.setContents(new ExTransferable.Single(DataFlavor.stringFlavor) {
        protected Object getData() throws IOException, UnsupportedFlavorException {
            return "17";
        }
    }, null);
    Transferable t = c.getContents(null);
    assertTrue("still supports stringFlavor", t.isDataFlavorSupported(DataFlavor.stringFlavor));
    assertEquals("correct string in clipboard", "17", t.getTransferData(DataFlavor.stringFlavor));
    assertTrue("support Integer too", t.isDataFlavorSupported(MYFLAV));
    assertEquals("correct Integer", new Integer(17), t.getTransferData(MYFLAV));
}
项目:incubator-netbeans    文件:Utils.java   
public void actionPerformed(ActionEvent event) {
    PasteType type = getPasteType();
    if (type != null) {
        try {
            Transferable trans = type.paste();
            if (trans != null) {
                ClipboardOwner owner = trans instanceof ClipboardOwner ?
                    (ClipboardOwner)trans : new StringSelection(""); // NOI18N
                Clipboard clipboard = (Clipboard)Lookup.getDefault().lookup(ExClipboard.class);
                clipboard.setContents(trans, owner);
            }
        } catch (java.io.IOException e) {
            ERR.log( Level.INFO, e.getLocalizedMessage(), e );
        }
    }
}
项目:incubator-netbeans    文件:CopyStyleAction.java   
@Override
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    BaseDocument bdoc = Utilities.getDocument(target);
    if(bdoc == null) {
        return ; //no document?!?!
    }
    DataObject csso = NbEditorUtilities.getDataObject(bdoc);
    if(csso == null) {
        return ; //document not backuped by DataObject
    }

    String pi = createText(csso);
    StringSelection ss = new StringSelection(pi);
    ExClipboard clipboard = Lookup.getDefault().lookup(ExClipboard.class);
    clipboard.setContents(ss, null);
    StatusDisplayer.getDefault().setStatusText( NbBundle.getMessage(CopyStyleAction.class, "MSG_Style_tag_in_clipboard"));  // NOI18N

}
项目:incubator-netbeans    文件:CopyPathToClipboardAction.java   
/**
 * Sets the clipboard context in textual-format.
 *
 * @param content
 */
@Messages({
    "# {0} - copied file path",
    "CTL_Status_CopyToClipboardSingle=Copy to Clipboard: {0}",
    "# {0} - number of copied paths",
    "CTL_Status_CopyToClipboardMulti={0} paths were copied to clipboard"
})
private void setClipboardContents(String content, int items) {
    Clipboard clipboard = Lookup.getDefault().lookup(ExClipboard.class);
    if (clipboard == null) {
        clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    }
    if (clipboard != null) {
        String statusText = items > 1
                ? Bundle.CTL_Status_CopyToClipboardMulti(items)
                : Bundle.CTL_Status_CopyToClipboardSingle(content);
        StatusDisplayer.getDefault().setStatusText(statusText);
        clipboard.setContents(new StringSelection(content), null);
    }
}
项目:incubator-netbeans    文件:ClipboardHistory.java   
@Override
public void clipboardChanged(ClipboardEvent ev) {
    ExClipboard clipboard = ev.getClipboard();

    Transferable transferable = null;
    String clipboardContent = null;
    try {
        transferable = clipboard.getContents(null);
        if (transferable != null && transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            clipboardContent = (String) transferable.getTransferData(DataFlavor.stringFlavor);
        }
    } catch (OutOfMemoryError oom) {            
        NotificationDisplayer.getDefault().notify( NbBundle.getBundle(ClipboardHistory.class).getString("clipboard-history-oom"),NotificationDisplayer.Priority.NORMAL.getIcon(), NbBundle.getBundle(ClipboardHistory.class).getString("clipboard-history-oom-details"), null);
        return;
    } catch (IOException ioe) {
        //ignored for bug #218255
    } catch (UnsupportedFlavorException ufe) {
    }

    if (clipboardContent != null) {
        addHistory(transferable, clipboardContent);
    }
}
项目:netbeans-mmd-plugin    文件:MMDGraphEditor.java   
@Override
public void componentClosed() {
  try {
    this.mindMapPanel.dispose();
    LOGGER.info("MMD Editor is disposed : " + this.mindMapPanel.toString());
  }
  finally {

    final Clipboard clipboard = NbUtils.findClipboard();
    if (clipboard instanceof ExClipboard) {
      ((ExClipboard) clipboard).removeClipboardListener(this);
    } else {
      clipboard.removeFlavorListener(this);
    }

    super.componentClosed();
  }
}
项目:incubator-netbeans    文件:NbClipboard.java   
NbClipboard( Clipboard systemClipboard ) {
    super("NBClipboard");   // NOI18N
    this.systemClipboard = systemClipboard;

    result = Lookup.getDefault().lookupResult(ExClipboard.Convertor.class);
    result.addLookupListener(this);

    systemClipboard.addFlavorListener(this);

    resultChanged(null);

    if (System.getProperty("netbeans.slow.system.clipboard.hack") != null) {
        slowSystemClipboard = Boolean.getBoolean("netbeans.slow.system.clipboard.hack"); // NOI18N
    } else if (Utilities.isMac()) {
        slowSystemClipboard = false;
    }
    else {
        slowSystemClipboard = true;
    }




    if (System.getProperty("sun.awt.datatransfer.timeout") == null) { // NOI18N
        System.setProperty("sun.awt.datatransfer.timeout", "1000"); // NOI18N
    }
    if (slowSystemClipboard) {
        Toolkit.getDefaultToolkit().addAWTEventListener(
            this, AWTEvent.WINDOW_EVENT_MASK);
    }
}
项目:incubator-netbeans    文件:DragDropUtilities.java   
/** Gets right transferable of given nodes (according to given
* drag action) and also converts the transferable.<br>
* Can be called only with correct action constant.
* @return The transferable.
*/
static Transferable getNodeTransferable(Node[] nodes, int dragAction)
throws IOException {
    Transferable[] tArray = new Transferable[nodes.length];

    for (int i = 0; i < nodes.length; i++) {
        if ((dragAction & DnDConstants.ACTION_MOVE) != 0) {
            tArray[i] = nodes[i].clipboardCut();
        } else {
            tArray[i] = nodes[i].drag ();
        }
    }
    Transferable result;
    if (tArray.length == 1) {
        // only one node, so return regular single transferable
        result = tArray[0];
    } else {
        // enclose the transferables into multi transferable
        result = ExternalDragAndDrop.maybeAddExternalFileDnd( new Multi(tArray) );
    }

    Clipboard c = getClipboard();
    if (c instanceof ExClipboard) {
        return ((ExClipboard) c).convert(result);
    } else {
        return result;
    }
}
项目:incubator-netbeans    文件:DragDropUtilitiesTest.java   
public ExClipboard.Convertor[] getConvertors() {
    return new ExClipboard.Convertor[] {new ExClipboard.Convertor() {
        public Transferable convert(Transferable t) {
            last = t;
            return t;
        }
    }};
}
项目:incubator-netbeans    文件:UI.java   
private static Clipboard getClipboard() {
    Clipboard clipboard = Lookup.getDefault().lookup(ExClipboard.class);

    if (clipboard == null) {
        clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    }
    return clipboard;
}
项目:incubator-netbeans    文件:Utils.java   
private PasteType getPasteType() {
    Clipboard clipboard = (Clipboard) Lookup.getDefault().lookup(ExClipboard.class);
    Transferable trans = clipboard.getContents(this);
    if (trans != null) {
        PasteType[] pasteTypes = categoryNode.getPasteTypes(trans);
        if (pasteTypes != null && pasteTypes.length != 0)
            return pasteTypes[0];
    }
    return null;
}
项目:incubator-netbeans    文件:Utils.java   
public void actionPerformed(ActionEvent event) {
    try {
        Transferable trans = itemNode.clipboardCut();
        if (trans != null) {
            Clipboard clipboard = (Clipboard)
                Lookup.getDefault().lookup(ExClipboard.class);
            clipboard.setContents(trans, new StringSelection("")); // NOI18N
        }
    } catch (java.io.IOException e) {
        ERR.log( Level.INFO, e.getLocalizedMessage(), e );
    }
}
项目:incubator-netbeans    文件:Utils.java   
public void actionPerformed(ActionEvent event) {
    try {
        Transferable trans = itemNode.clipboardCopy();
        if (trans != null) {
            Clipboard clipboard = (Clipboard)
                Lookup.getDefault().lookup(ExClipboard.class);
            clipboard.setContents(trans, new StringSelection("")); // NOI18N
        }
    } catch (java.io.IOException e) {
        ERR.log( Level.INFO, e.getLocalizedMessage(), e );
    }
}
项目:netbeans-mmd-plugin    文件:NbUtils.java   
@Nonnull
public static Clipboard findClipboard() {
  Clipboard result = Lookup.getDefault().lookup(ExClipboard.class);
  if (result == null) {
    result = Toolkit.getDefaultToolkit().getSystemClipboard();
  }
  return Assertions.assertNotNull("Clipbard is not found", result);
}
项目:netbeans-mmd-plugin    文件:MMDGraphEditor.java   
private void registerAsClipboardListener() {
  final Clipboard clipboard = NbUtils.findClipboard();
  if (clipboard instanceof ExClipboard) {
    ((ExClipboard) clipboard).addClipboardListener(this);
  } else {
    clipboard.addFlavorListener(this);
  }
  processClipboardChange(clipboard);
}
项目:netbeans-mmd-plugin    文件:MMDGraphEditor.java   
private void unregisterFromClipboardListeners() {
  final Clipboard clipboard = NbUtils.findClipboard();
  if (clipboard instanceof ExClipboard) {
    ((ExClipboard) clipboard).removeClipboardListener(this);
  } else {
    clipboard.removeFlavorListener(this);
  }
}
项目:incubator-netbeans    文件:NbClipboard.java   
protected synchronized ExClipboard.Convertor[] getConvertors () {
    return convertors;
}
项目:incubator-netbeans    文件:NbClipboard.java   
public synchronized void resultChanged(LookupEvent ev) {
    Collection<? extends ExClipboard.Convertor> c = result.allInstances();
    ExClipboard.Convertor[] temp = new ExClipboard.Convertor[c.size()];
    convertors = c.toArray(temp);
}
项目:incubator-netbeans    文件:NbClipboardIsUsedBySwingComponentsTest.java   
protected ExClipboard.Convertor[] getConvertors () {
    return new ExClipboard.Convertor[0];
}
项目:incubator-netbeans    文件:ManifestSection.java   
ClipboardConvertorSection(String name, Module module) throws InvalidException {
    super(name, module, ExClipboard.Convertor.class);
}
项目:incubator-netbeans    文件:QueryBuilderResultTable.java   
private void setClipboard(String contents) {
    ExClipboard clipboard = (ExClipboard) Lookup.getDefault().lookup(ExClipboard.class);
    StringSelection strSel = new StringSelection(contents);
    clipboard.setContents(strSel, strSel);
}
项目:incubator-netbeans    文件:ResultSetJXTable.java   
protected void copyRowValues(boolean withHeader) {
    ExClipboard clipboard = Lookup.getDefault().lookup(ExClipboard.class);
    StringSelection selection = createTransferableTSV(withHeader);
    clipboard.setContents(selection, selection);
}
项目:incubator-netbeans    文件:DocletAction.java   
private void leaveInClipboard(String text) {
    StringSelection ss = new StringSelection(text);
    ExClipboard clipboard = (ExClipboard) Lookup.getDefault().lookup(ExClipboard.class);
    clipboard.setContents(ss, null);
    StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(DocletAction.class, "MSG_documentation_in_clipboard"));
}
项目:nb-copy-fqn    文件:Clipboard.java   
public Clipboard() {
clipboard = Lookup.getDefault().lookup(ExClipboard.class);
if (clipboard == null) {
    clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
}
   }