java类java.awt.datatransfer.StringSelection的实例源码

NbClipboardTimeoutTest.java 文件源码 项目:incubator-netbeans 阅读 27 收藏 0 点赞 0 评论 0
private static void makeSureSystemClipboardContainsString(
    Clipboard sys, NbClipboard clip
) throws InterruptedException {
    final CountDownLatch wait = new CountDownLatch(1);
    class FL implements FlavorListener {
        @Override
        public void flavorsChanged(FlavorEvent e) {
            wait.countDown();
        }
    }
    FL fl = new FL();
    sys.addFlavorListener(fl);
    StringSelection ss = new StringSelection("empty");
    clip.setContents(ss, ss);
    wait.await();
}
NbClipboardNativeTest.java 文件源码 项目:incubator-netbeans 阅读 26 收藏 0 点赞 0 评论 0
public void testOwnershipLostEvent() throws Exception {
    final int[] holder = new int[] { 0 };
    ExTransferable transferable = ExTransferable.create (new StringSelection("A"));

    // listen on ownershipLost
    transferable.addTransferListener (new TransferListener () {
        public void accepted (int action) {}
        public void rejected () {}
        public void ownershipLost () { holder[0]++; }
    });

    Clipboard c = Lookup.getDefault().lookup(Clipboard.class);

    c.setContents(transferable, null);

    assertTrue("Still has ownership", holder[0] == 0);

    c.setContents(new StringSelection("B"), null);

    assertTrue("Exactly one ownershipLost event have happened.", holder[0] == 1);
}
DebuggingActionsProvider.java 文件源码 项目:incubator-netbeans 阅读 33 收藏 0 点赞 0 评论 0
static void stackToCLBD(List<JPDAThread> threads) {
    StringBuffer frameStr = new StringBuffer(512);
    for (JPDAThread t : threads) {
        if (frameStr.length() > 0) {
            frameStr.append('\n');
        }
        frameStr.append("\"");
        frameStr.append(t.getName());
        frameStr.append("\"\n");
        appendStackInfo(frameStr, t);
    }
    Clipboard systemClipboard = getClipboard();
    Transferable transferableText =
            new StringSelection(frameStr.toString());
    systemClipboard.setContents(
            transferableText,
            null);
}
GuiScreen.java 文件源码 项目:CustomWorldGen 阅读 29 收藏 0 点赞 0 评论 0
/**
 * Stores the given string in the system clipboard
 */
public static void setClipboardString(String copyText)
{
    if (!StringUtils.isEmpty(copyText))
    {
        try
        {
            StringSelection stringselection = new StringSelection(copyText);
            Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringselection, (ClipboardOwner)null);
        }
        catch (Exception var2)
        {
            ;
        }
    }
}
ExplorerActionsImpl.java 文件源码 项目:incubator-netbeans 阅读 30 收藏 0 点赞 0 评论 0
@Override
public void actionPerformed(ActionEvent ev) {
    ExplorerManager em = manager;
    if (em == null) {
        return;
    }
    Node[] sel = em.getSelectedNodes();
    Transferable trans = getTransferableOwner(sel, copyCut);

    if (trans != null) {
        Clipboard clipboard = getClipboard();
        if (clipboard != null) {
            clipboard.setContents(trans, new StringSelection("")); // NOI18N
        }
    }
}
UnknownDataSet.java 文件源码 项目:geomapapp 阅读 24 收藏 0 点赞 0 评论 0
public void copy() {
    StringBuffer sb = new StringBuffer();
    for (int i=0;i<dataT.getColumnCount();i++) {
        sb.append(dataT.getColumnName(i)+"\t");
    }
    sb.append("\n");
    int sel[] = dataT.getSelectedRows();
    for (int i=0;i<sel.length;i++) {
        for (int j=0; j<dataT.getColumnCount();j++) {
            Object o = dataT.getValueAt(sel[i], j);
            if (o instanceof String && ((String)o).equals("NaN")) o = "";
            sb.append(o.toString()+"\t");
        }
        sb.append("\n");
    }
    Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
    StringSelection ss = new StringSelection(sb.toString());
    c.setContents(ss, ss);
}
TestMethodNode.java 文件源码 项目:incubator-netbeans 阅读 28 收藏 0 点赞 0 评论 0
@Override
   @NbBundle.Messages("LBL_CopyStackTrace=&Copy Stack Trace")
   public Action[] getActions(boolean context) {
List<Action> actions = new ArrayList<Action>();
if ((testcase.getTrouble() != null) && (testcase.getTrouble().getComparisonFailure() != null)){
           actions.add(new DiffViewAction(testcase));
       }
if (testcase.getTrouble() != null && testcase.getTrouble().getStackTrace() != null) {
    StringBuilder callStack = new StringBuilder();
    for(String stack : testcase.getTrouble().getStackTrace()) {
    if(stack != null) {
        callStack.append(stack.concat("\n"));
    }
    }
    if (callStack.length() > 0) {
    final String trace = callStack.toString();
    actions.add(new AbstractAction(Bundle.LBL_CopyStackTrace()) {
        @Override
        public void actionPerformed(ActionEvent e) {
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(trace), null);
        }
    });
    }
}
       return actions.toArray(new Action[actions.size()]);
   }
DebuggingJSActionsProvider.java 文件源码 项目:incubator-netbeans 阅读 26 收藏 0 点赞 0 评论 0
private void stackToCLBD(List<JPDAThread> threads) {
    StringBuffer frameStr = new StringBuffer(512);
    for (JPDAThread t : threads) {
        if (frameStr.length() > 0) {
            frameStr.append('\n');
        }
        frameStr.append("\"");
        frameStr.append(t.getName());
        frameStr.append("\"\n");
        appendStackInfo(frameStr, t);
    }
    Clipboard systemClipboard = getClipboard();
    Transferable transferableText =
            new StringSelection(frameStr.toString());
    systemClipboard.setContents(
            transferableText,
            null);
}
CopyStyleAction.java 文件源码 项目:incubator-netbeans 阅读 24 收藏 0 点赞 0 评论 0
@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

}
SQLHistoryPanel.java 文件源码 项目:incubator-netbeans 阅读 23 收藏 0 点赞 0 评论 0
/**
 * Map Transferable to createTransferableTSV from ResultSetJXTable
 *
 * This is needed so that CTRL-C Action of JTable gets the same
 * treatment as the transfer via the copy Methods of DataTableUI
 */
@Override
protected Transferable createTransferable(JComponent c) {
    StringBuilder sb = new StringBuilder();
    for (int id : sqlHistoryTable.getSelectedRows()) {
        int modelIndex = sqlHistoryTable.convertRowIndexToModel(id);
        if (sb.length() != 0) {
            sb.append(System.lineSeparator());
        }
        // Column 1 => Column of SQL
        String sql = (String) htm.getValueAt(modelIndex, 1);
        sb.append(sql);
        sb.append(";");
    }
    return new StringSelection(sb.toString());
}
HTMLTextArea.java 文件源码 项目:incubator-netbeans 阅读 25 收藏 0 点赞 0 评论 0
public void exportToClipboard(JComponent comp, Clipboard clip, int action) {
    try {
        int selStart = getSelectionStart();
        int selLength = getSelectionEnd() - selStart;

        StringWriter plainTextWriter = new StringWriter();

        try {
            new ExtendedHTMLWriter(plainTextWriter, (HTMLDocument) getDocument(), selStart, selLength).write();
        } catch (Exception e) {
        }

        String plainText = NcrToUnicode.decode(plainTextWriter.toString());
        clip.setContents(new StringSelection(plainText), null);

        if (action == TransferHandler.MOVE) {
            getDocument().remove(selStart, selLength);
        }
    } catch (BadLocationException ble) {
    }
}
XBTable.java 文件源码 项目:geomapapp 阅读 25 收藏 0 点赞 0 评论 0
public void keyReleased(KeyEvent e) {
    if (e.isControlDown()&&(e.getKeyCode()==KeyEvent.VK_C||e.getKeyCode()==KeyEvent.VK_X)) {
        Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
        StringBuffer s = new StringBuffer();
        for (int i=0;i<getColumnCount();i++)
            s.append(getColumnName(i)+"\t");
        s.append("\n");
        int sel[] = getSelectedRows();
        for (int i=0;i<sel.length;i++) {
            for (int j=0; j<getColumnCount();j++) {
                Object o = getValueAt(sel[i], j);
                if (o instanceof String && ((String)o).equals("NaN")) o = "";
                s.append(o+"\t");
            }
            s.append("\n");
        }
        StringSelection ss = new StringSelection(s.toString());
        try {
            cb.setContents(ss, ss);
        } catch (Exception ex) {
        }
        e.consume();
    }
}
JEditTextArea.java 文件源码 项目:rapidminer 阅读 29 收藏 0 点赞 0 评论 0
/**
 * Places the selected text into the clipboard.
 */
public void copy() {
    if (selectionStart != selectionEnd) {
        Clipboard clipboard = getToolkit().getSystemClipboard();

        String selection = getSelectedText();

        int repeatCount = inputHandler.getRepeatCount();
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < repeatCount; i++) {
            buf.append(selection);
        }

        clipboard.setContents(new StringSelection(buf.toString()), null);
    }
}
HexPaneMenu.java 文件源码 项目:ClassViewer 阅读 29 收藏 0 点赞 0 评论 0
public HexPaneMenu(TextArea textArea) {
    MenuItem copy = new MenuItem("_Copy");
    this.setStyle(FontUtils.setUIFont(this.getStyle()));
    copy.setMnemonicParsing(true);
    copy.setOnAction(e -> {
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

        StringSelection s = new StringSelection(
                textArea.getSelectedText().replace("\n", "")
        );

        clipboard.setContents(s, null);
    });
    copy.setGraphic(new ImageView(ImageUtils.copyImage));


    getItems().addAll(
            copy
    );
}
TextPaneMenu.java 文件源码 项目:ClassViewer 阅读 34 收藏 0 点赞 0 评论 0
public TextPaneMenu(TextArea textArea) {
    this.textArea = textArea;
    MenuItem copy = new MenuItem("_Copy");
    this.setStyle(FontUtils.setUIFont(this.getStyle()));
    copy.setMnemonicParsing(true);
    copy.setOnAction(e -> {
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

        StringSelection s = new StringSelection(
                textArea.getSelectedText()
        );

        clipboard.setContents(s, null);
    });
    copy.setGraphic(new ImageView(ImageUtils.copyImage));

    getItems().addAll(copy);
}
AsciiPaneMenu.java 文件源码 项目:ClassViewer 阅读 27 收藏 0 点赞 0 评论 0
public AsciiPaneMenu(TextArea textArea) {
    this.textArea = textArea;
    MenuItem copy = new MenuItem("_Copy");
    this.setStyle(FontUtils.setUIFont(this.getStyle()));
    copy.setMnemonicParsing(true);
    copy.setOnAction(e -> {
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

        StringSelection s = new StringSelection(
                textArea.getSelectedText().replace("\n", "")
        );

        clipboard.setContents(s, null);
    });
    copy.setGraphic(new ImageView(ImageUtils.copyImage));

    getItems().addAll(copy);
}
EPSGraphics.java 文件源码 项目:OpenDA 阅读 28 收藏 0 点赞 0 评论 0
/** Issue the PostScript showpage command, then write and flush the output.
 *  If the output argument of the constructor was null, then write
 *  to the clipboard.
 */
public void showpage() {
    _buffer.append("showpage\n");
    if (_out != null) {
        PrintWriter output = new PrintWriter(
                new BufferedOutputStream(_out));

        output.println(_buffer.toString());
        output.flush();
    } else {
        // Write to clipboard instead
        // NOTE: This doesn't work at least with jdk 1.3beta
        if (_clipboard == null) {
            _clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        }
        StringSelection sel = new StringSelection(_buffer.toString());
        _clipboard.setContents(sel, sel);
    }
}
IndependenceSwingTest.java 文件源码 项目:openjdk-jdk10 阅读 29 收藏 0 点赞 0 评论 0
public void getClipboardsContent() throws Exception {
    sClip = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable tp;
    Transferable ts;

    StringSelection content = new StringSelection(tf1.getText());
    sClip.setContents(content,content);

    tp = pClip.getContents(this);
    ts = sClip.getContents(this);

    // Paste the contents of System clipboard on textfield tf2 while the paste the contents of
    // of primary clipboard on textfiled tf3
    if ((ts != null) && (ts.isDataFlavorSupported(DataFlavor.stringFlavor))) {
        tf2.setBackground(Color.white);
        tf2.setForeground(Color.black);
        tf2.setText((String) ts.getTransferData(DataFlavor.stringFlavor));
    }

    if ((tp != null) && (tp.isDataFlavorSupported(DataFlavor.stringFlavor))) {
        tf3.setBackground(Color.white);
        tf3.setForeground(Color.black);
        tf3.setText((String) tp.getTransferData(DataFlavor.stringFlavor));
    }
}
SignCopy.java 文件源码 项目:SerenityCE 阅读 29 收藏 0 点赞 0 评论 0
public SignCopy() {
    branches.add(new CommandBranch(ctx -> {
        if (mc.objectMouseOver.getBlockPos() != null) {
            TileEntity tileEntity = mc.theWorld.getTileEntity(mc.objectMouseOver.getBlockPos());
            if (tileEntity != null && tileEntity instanceof TileEntitySign) {
                TileEntitySign sign = (TileEntitySign) tileEntity;
                StringBuilder builder = new StringBuilder();
                for (IChatComponent component : sign.signText) {
                    builder.append(component.getUnformattedText());
                    builder.append(System.getProperty("line.separator"));
                }

                Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
                clipboard.setContents(new StringSelection(builder.toString()), null);
            }
        }
    }));
}
GetPosCmd.java 文件源码 项目:Wurst-MC-1.12 阅读 25 收藏 0 点赞 0 评论 0
@Override
public void call(String[] args) throws CmdException
{
    if(args.length > 1)
        throw new CmdSyntaxError();
    BlockPos blockpos = new BlockPos(WMinecraft.getPlayer());
    String pos =
        blockpos.getX() + " " + blockpos.getY() + " " + blockpos.getZ();
    if(args.length == 0)
        ChatUtils.message("Position: " + pos);
    else if(args.length == 1 && args[0].equalsIgnoreCase("copy"))
    {
        Toolkit.getDefaultToolkit().getSystemClipboard()
            .setContents(new StringSelection(pos), null);
        ChatUtils.message("Position copied to clipboard.");
    }
}
GuiScreen.java 文件源码 项目:BaseClient 阅读 31 收藏 0 点赞 0 评论 0
/**
 * Stores the given string in the system clipboard
 */
public static void setClipboardString(String copyText)
{
    if (!StringUtils.isEmpty(copyText))
    {
        try
        {
            StringSelection stringselection = new StringSelection(copyText);
            Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringselection, (ClipboardOwner)null);
        }
        catch (Exception var2)
        {
            ;
        }
    }
}
GuiScreen.java 文件源码 项目:BaseClient 阅读 29 收藏 0 点赞 0 评论 0
/**
 * Stores the given string in the system clipboard
 */
public static void setClipboardString(String copyText)
{
    if (!StringUtils.isEmpty(copyText))
    {
        try
        {
            StringSelection stringselection = new StringSelection(copyText);
            Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringselection, (ClipboardOwner)null);
        }
        catch (Exception var2)
        {
            ;
        }
    }
}
Main.java 文件源码 项目:powertext 阅读 25 收藏 0 点赞 0 评论 0
public void Cut()
{
    if(jTabbedPane1.getTabCount()>0)
    {
        int sel = jTabbedPane1.getSelectedIndex();
        RSyntaxTextArea textPane = (RSyntaxTextArea) Editor.get(sel).getTextPane();
        String selected_text = textPane.getSelectedText();
        StringSelection ss = new StringSelection(selected_text);
        clip.setContents(ss, ss); copylistModel.addElement(selected_text);
        textPane.replaceSelection("");

        String tabtext = jTabbedPane1.getTitleAt(sel);
        if (tabtext.contains("*"))
        {  }
        else
        {
            jTabbedPane1.setTitleAt(sel, jTabbedPane1.getTitleAt(sel) + "*");
            //jTabbedPane1.setIconAt(sel, new ImageIcon(this.getClass().getResource("resources/unsaved.png")));
        }
    }
}
GuiScreen.java 文件源码 项目:Backmemed 阅读 42 收藏 0 点赞 0 评论 0
/**
 * Stores the given string in the system clipboard
 */
public static void setClipboardString(String copyText)
{
    if (!StringUtils.isEmpty(copyText))
    {
        try
        {
            StringSelection stringselection = new StringSelection(copyText);
            Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringselection, (ClipboardOwner)null);
        }
        catch (Exception var2)
        {
            ;
        }
    }
}
TaskTreeTab.java 文件源码 项目:Reer 阅读 27 收藏 0 点赞 0 评论 0
/**
 * Copies the selected tasks names to the clipboard
 */
private void copySelectedTaskNames() {

    String names = getSelectedTaskNames();
    if (names.length() == 0) {
        return;
    }

    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(names), null);
}
ProcessTransferHandler.java 文件源码 项目:VISNode 阅读 29 收藏 0 点赞 0 评论 0
/**
 * Creates the transferable
 *
 * @param c
 * @return Transferable
 */
@Override
protected Transferable createTransferable(JComponent c) {
    JList list = (JList) c;
    Object[] values = list.getSelectedValues();
    String buff = "";
    for (int i = 0; i < values.length; i++) {
        Class val = (Class) values[i];
        buff = val.getName();
    }
    return new StringSelection(buff);
}
ClipboardUtils.java 文件源码 项目:ClipIt 阅读 37 收藏 0 点赞 0 评论 0
public static void setClipBoard(String text) {
  if (StringUtils.isBlank(text)) {
    return;
  }
  Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
  StringSelection selection = new StringSelection(text);
  clipboard.setContents(selection, selection);
}
JtableUtils.java 文件源码 项目:Cognizant-Intelligent-Test-Scripter 阅读 33 收藏 0 点赞 0 评论 0
/**
 * Reads the cell values of selected cells of the <code>tmodel</code> and
 * uploads into clipboard in supported format
 *
 * @param isCut CUT flag,<code>true</code> for CUT and <code>false</code>
 * for COPY
 * @param table the source for the action
 * @see #escape(java.lang.Object)
 */
private static void copyToClipboard(boolean isCut, JTable table) {
    try {
        int numCols = table.getSelectedColumnCount();
        int numRows = table.getSelectedRowCount();
        int[] rowsSelected = table.getSelectedRows();
        int[] colsSelected = table.getSelectedColumns();
        if (numRows != rowsSelected[rowsSelected.length - 1] - rowsSelected[0] + 1 || numRows != rowsSelected.length
                || numCols != colsSelected[colsSelected.length - 1] - colsSelected[0] + 1 || numCols != colsSelected.length) {
            JOptionPane.showMessageDialog(null, "Invalid Selection", "Invalid Selection", JOptionPane.ERROR_MESSAGE);
            return;
        }
        StringBuilder excelStr = new StringBuilder();
        for (int i = 0; i < numRows; i++) {
            for (int j = 0; j < numCols; j++) {
                excelStr.append(escape(table.getValueAt(rowsSelected[i], colsSelected[j])));
                if (isCut) {
                    if (table.isCellEditable(rowsSelected[i], colsSelected[j])) {
                        table.setValueAt("", rowsSelected[i], colsSelected[j]);
                    }
                }
                if (j < numCols - 1) {
                    excelStr.append(CELL_BREAK);
                }
            }
            if (i < numRows - 1) {
                excelStr.append(LINE_BREAK);
            }
        }
        if (!excelStr.toString().isEmpty()) {
            StringSelection sel = new StringSelection(excelStr.toString());
            CLIPBOARD.setContents(sel, sel);
        }

    } catch (HeadlessException ex) {
        Logger.getLogger(JtableUtils.class.getName()).log(Level.SEVERE, null, ex);
    }
}
DragDropUtilitiesTest.java 文件源码 项目:incubator-netbeans 阅读 35 收藏 0 点赞 0 评论 0
public void testGetNodeTransferableForSingleNodeCopy() throws Exception {
    N node = new N();

    Transferable t = DragDropUtilities.getNodeTransferable(node, NodeTransfer.DND_COPY);

    assertEquals("One call to copy", 1, node.copy);
    assertEquals("Also one call to drag which delegates to copy", 1, node.drag);
    assertEquals("No call to cut", 0, node.cut);
    assertNotNull("Call to convertor", last);
    assertTrue("StringSelection got to ExClipboard convertor", last instanceof StringSelection);
}
DragDropUtilitiesTest.java 文件源码 项目:incubator-netbeans 阅读 33 收藏 0 点赞 0 评论 0
public void testGetNodeTransferableForSingleNodeCut() throws Exception {
    N node = new N();

    Transferable t = DragDropUtilities.getNodeTransferable(node, NodeTransfer.DND_MOVE);

    assertEquals("One call to cut", 1, node.cut);
    assertEquals("No call to drag", 0, node.drag);
    assertEquals("No call to copy", 0, node.copy);
    assertNotNull("Call to convertor", last);
    assertTrue("StringSelection got to ExClipboard convertor", last instanceof StringSelection);
}


问题


面经


文章

微信
公众号

扫码关注公众号