Java 类java.awt.datatransfer.StringSelection 实例源码
项目:incubator-netbeans
文件:NbClipboardTimeoutTest.java
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();
}
项目:incubator-netbeans
文件:NbClipboardNativeTest.java
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);
}
项目:incubator-netbeans
文件:DebuggingActionsProvider.java
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);
}
项目:CustomWorldGen
文件:GuiScreen.java
/**
* 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)
{
;
}
}
}
项目:incubator-netbeans
文件:ExplorerActionsImpl.java
@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
}
}
}
项目:geomapapp
文件:UnknownDataSet.java
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);
}
项目:incubator-netbeans
文件:TestMethodNode.java
@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()]);
}
项目:incubator-netbeans
文件:DebuggingJSActionsProvider.java
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);
}
项目: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
文件:SQLHistoryPanel.java
/**
* 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());
}
项目:incubator-netbeans
文件:HTMLTextArea.java
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) {
}
}
项目:geomapapp
文件:XBTable.java
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();
}
}
项目:rapidminer
文件:JEditTextArea.java
/**
* 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);
}
}
项目:ClassViewer
文件:HexPaneMenu.java
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
);
}
项目:ClassViewer
文件:TextPaneMenu.java
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);
}
项目:ClassViewer
文件:AsciiPaneMenu.java
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);
}
项目:OpenDA
文件:EPSGraphics.java
/** 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);
}
}
项目:openjdk-jdk10
文件:IndependenceSwingTest.java
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));
}
}
项目:SerenityCE
文件:SignCopy.java
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);
}
}
}));
}
项目:Wurst-MC-1.12
文件:GetPosCmd.java
@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.");
}
}
项目:BaseClient
文件:GuiScreen.java
/**
* 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)
{
;
}
}
}
项目:BaseClient
文件:GuiScreen.java
/**
* 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)
{
;
}
}
}
项目:powertext
文件:Main.java
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")));
}
}
}
项目:Backmemed
文件:GuiScreen.java
/**
* 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)
{
;
}
}
}
项目:Reer
文件:TaskTreeTab.java
/**
* 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);
}
项目:VISNode
文件:ProcessTransferHandler.java
/**
* 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);
}
项目:ClipIt
文件:ClipboardUtils.java
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);
}
项目:Cognizant-Intelligent-Test-Scripter
文件:JtableUtils.java
/**
* 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);
}
}
项目:incubator-netbeans
文件:DragDropUtilitiesTest.java
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);
}
项目:incubator-netbeans
文件:DragDropUtilitiesTest.java
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);
}
项目:incubator-netbeans
文件:Terminal.java
@Override
public void copyToClipboard() {
String text = getSelectedText();
if (text != null) {
StringSelection ss = new StringSelection(text);
systemClipboard.setContents(ss, ss);
}
}
项目:incubator-netbeans
文件:Term.java
/**
* Transfer selected text into clipboard.
*/
public void copyToClipboard() {
String text = sel.getSelection();
if (text != null) {
StringSelection ss = new StringSelection(text);
systemClipboard.setContents(ss, sel);
}
}
项目:JuggleMasterPro
文件:ClipboardJTextArea.java
final public void doCopy() {
final String strLtext = this.getText();
final boolean bolLnotEmpty = !strLtext.equals(Strings.strS_EMPTY);
if (bolLnotEmpty && this.objGcontrolJFrame.getJuggleMasterPro().bolGprogramTrusted) {
try {
Constants.objS_GRAPHICS_TOOLKIT.getSystemClipboard().setContents(new StringSelection(strLtext), null);
} catch (final Throwable objPthrowable) {
Tools.err("Error while copying program console into clipboard");
}
}
}
项目:geomapapp
文件:XMImage.java
public void copy() {
StringBuffer sb = new StringBuffer();
sb.append(tempInfo);
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
String tempString = sb.toString();
tempString = tempString.replaceAll("zoom.+","");
tempString = tempString.replaceAll("[\\(\\)=,\\w&&[^WESN\\d]]+","");
String [] result = tempString.split("\\s+");
tempString = "";
for ( int i =0; i < result.length; i++ ) {
if ( result[i].indexOf("\u00B0") != -1 && result[i].indexOf("\u00B4") == -1 ) {
result[i] = result[i].replaceAll("\\u00B0","");
}
if ( i == 2 ) {
if ( result[i].indexOf("W") != -1 ) {
result[i] = "-" + result[i];
}
result[i] = result[i].replaceAll("[WE]","");
}
else if ( i == 3 ) {
if ( result[i].indexOf("S") != -1 ) {
result[i] = "-" + result[i];
}
result[i] = result[i].replaceAll("[NS]","");
}
tempString += result[i] + "\t";
}
tempString = tempString.trim();
tempString = line.getCruiseID().trim() + "\t" + line.getID().trim() + "\t" + currentTime/1000.0 + "\t" + currentCDP + "\t" + tempString;
StringSelection ss = new StringSelection(tempString + "\n");
c.setContents(ss, ss);
}
项目:incubator-netbeans
文件:BasicAttachStepsProvider.java
protected void copyParameters(AttachSettings settings) {
String parameters = parameters(settings);
parameters = parameters.replace("<", "<").replace(">", ">"); // NOI18N
StringSelection s = new StringSelection(parameters);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(s, s);
ProfilerDialogs.displayInfo(Bundle.AttachDialog_CopiedToClipboard());
}
项目:incubator-netbeans
文件:CompletionLayoutPopup.java
private void pasteContent() throws HeadlessException {
Transferable transferable = layout.getSelectedValue().getTransferable();
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
if (transferable != null) {
clipboard.setContents(transferable, layout.getSelectedValue());
} else {
StringSelection contents = new StringSelection(layout.getSelectedValue().getFullText());
clipboard.setContents(contents, layout.getSelectedValue());
}
getEditorComponent().paste();
}
项目:AgentWorkbench
文件:DBConnection.java
/**
* This method puts the value of 'toClipboard' to the clipboard
* In case of an SQL-Error, the SQL-Statement will be placed in
* such a way and can be used in an external application as well.
* @param toClipboard String which will be placed in the clipboard
*/
public void put2Clipboard(String toClipboard) {
if (Application.isOperatingHeadless()==false) {
// --- Only in case that Agent.GUI is operated with graphical representation ------
StringSelection data = new StringSelection(toClipboard);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(data, data);
}
}
项目:BEAST
文件:CutUserAction.java
@Override
public void perform() {
try {
codeArea.getInsertToCode().getSaveBeforeRemove().save();
} catch (BadLocationException ex) {
Logger.getLogger(CutUserAction.class.getName()).log(Level.SEVERE, null, ex);
}
StringSelection stringSelection = new StringSelection(codeArea.getPane().getSelectedText());
clipboard.setContents(stringSelection, null);
codeArea.insertString("");
}
项目:geomapapp
文件:WFSViewServer.java
public void sendToDataTables( StringBuffer[] inputSBArr ) {
if ( inputSBArr != null && inputSBArr.length > 0 ) {
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
for ( int i = 1; i < inputSBArr.length; i++ ) {
inputSBArr[i] = inputSBArr[i].delete(0,inputSBArr[i].indexOf("\n")+1);
inputSBArr[0].append(inputSBArr[i]);
}
String inputStr = inputSBArr[0].toString();
if (inputStr.length() == 0) return;
StringSelection ss = new StringSelection(inputStr);
c.setContents(ss, ss);
mapApp.importDataTable( "Import from Clipboard (paste)...", currentLayerName + " - " + currentWFSTitle );
}
System.gc();
}
项目:jmt
文件:ExactTable.java
public void copyCells() {
StringBuffer sbf = new StringBuffer();
// Check to ensure we have selected only a contiguous block of
// cells
int numcols = getSelectedColumnCount();
int numrows = getSelectedRowCount();
int[] rowsselected = getSelectedRows();
int[] colsselected = getSelectedColumns();
if (!((numrows - 1 == rowsselected[rowsselected.length - 1] - rowsselected[0] && numrows == rowsselected.length) && (numcols - 1 == colsselected[colsselected.length - 1]
- colsselected[0] && numcols == colsselected.length))) {
JOptionPane.showMessageDialog(null, "Invalid Copy Selection", "Invalid Copy Selection", JOptionPane.ERROR_MESSAGE);
return;
}
for (int i = 0; i < numrows; i++) {
for (int j = 0; j < numcols; j++) {
sbf.append(getValueAt(rowsselected[i], colsselected[j]));
if (j < numcols - 1) {
sbf.append("\t");
}
}
sbf.append("\n");
}
stsel = new StringSelection(sbf.toString()) {
@Override
public void lostOwnership(Clipboard clipboard, Transferable contents) {
canPaste = false;
}
};
clip.setContents(stsel, stsel);
canPaste = true;
}