当前位置: 首页>>代码示例>>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;未经允许,请勿转载。