當前位置: 首頁>>代碼示例>>Java>>正文


Java StringSelection類代碼示例

本文整理匯總了Java中java.awt.datatransfer.StringSelection的典型用法代碼示例。如果您正苦於以下問題:Java StringSelection類的具體用法?Java StringSelection怎麽用?Java StringSelection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


StringSelection類屬於java.awt.datatransfer包,在下文中一共展示了StringSelection類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: makeSureSystemClipboardContainsString

import java.awt.datatransfer.StringSelection; //導入依賴的package包/類
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();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:NbClipboardTimeoutTest.java

示例2: testOwnershipLostEvent

import java.awt.datatransfer.StringSelection; //導入依賴的package包/類
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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:NbClipboardNativeTest.java

示例3: stackToCLBD

import java.awt.datatransfer.StringSelection; //導入依賴的package包/類
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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:DebuggingActionsProvider.java

示例4: setClipboardString

import java.awt.datatransfer.StringSelection; //導入依賴的package包/類
/**
 * 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)
        {
            ;
        }
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:19,代碼來源:GuiScreen.java

示例5: actionPerformed

import java.awt.datatransfer.StringSelection; //導入依賴的package包/類
@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
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:ExplorerActionsImpl.java

示例6: copy

import java.awt.datatransfer.StringSelection; //導入依賴的package包/類
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);
}
 
開發者ID:iedadata,項目名稱:geomapapp,代碼行數:20,代碼來源:UnknownDataSet.java

示例7: getActions

import java.awt.datatransfer.StringSelection; //導入依賴的package包/類
@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()]);
   }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:TestMethodNode.java

示例8: stackToCLBD

import java.awt.datatransfer.StringSelection; //導入依賴的package包/類
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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:DebuggingJSActionsProvider.java

示例9: actionPerformed

import java.awt.datatransfer.StringSelection; //導入依賴的package包/類
@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
    
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:CopyStyleAction.java

示例10: createTransferable

import java.awt.datatransfer.StringSelection; //導入依賴的package包/類
/**
 * 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());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:SQLHistoryPanel.java

示例11: exportToClipboard

import java.awt.datatransfer.StringSelection; //導入依賴的package包/類
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) {
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:HTMLTextArea.java

示例12: keyReleased

import java.awt.datatransfer.StringSelection; //導入依賴的package包/類
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();
	}
}
 
開發者ID:iedadata,項目名稱:geomapapp,代碼行數:25,代碼來源:XBTable.java

示例13: copy

import java.awt.datatransfer.StringSelection; //導入依賴的package包/類
/**
 * 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);
	}
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:19,代碼來源:JEditTextArea.java

示例14: TextPaneMenu

import java.awt.datatransfer.StringSelection; //導入依賴的package包/類
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);
}
 
開發者ID:Glavo,項目名稱:ClassViewer,代碼行數:19,代碼來源:TextPaneMenu.java

示例15: AsciiPaneMenu

import java.awt.datatransfer.StringSelection; //導入依賴的package包/類
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);
}
 
開發者ID:Glavo,項目名稱:ClassViewer,代碼行數:19,代碼來源:AsciiPaneMenu.java


注:本文中的java.awt.datatransfer.StringSelection類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。