本文整理汇总了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();
}
示例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);
}
示例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);
}
示例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)
{
;
}
}
}
示例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
}
}
}
示例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);
}
示例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()]);
}
示例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);
}
示例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
}
示例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());
}
示例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) {
}
}
示例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();
}
}
示例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);
}
}
示例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);
}
示例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);
}