本文整理匯總了Java中org.eclipse.swt.dnd.Clipboard.setContents方法的典型用法代碼示例。如果您正苦於以下問題:Java Clipboard.setContents方法的具體用法?Java Clipboard.setContents怎麽用?Java Clipboard.setContents使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.swt.dnd.Clipboard
的用法示例。
在下文中一共展示了Clipboard.setContents方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: copySelectedAsTabDelimited
import org.eclipse.swt.dnd.Clipboard; //導入方法依賴的package包/類
private void copySelectedAsTabDelimited() {
StringBuffer stringBuffer = new StringBuffer();
int totalRowCount = debugDataViewer.getTableViewer().getTable().getItemCount();
int totalColumnCount = debugDataViewer.getTableViewer().getTable().getColumnCount();
boolean hasRow=false;
for (int rowCount = 0; rowCount < totalRowCount; rowCount++) {
for (int columnCount = 0; columnCount < totalColumnCount; columnCount++) {
Point cell = new Point(rowCount, columnCount);
if(debugDataViewer.getSelectedCell().contains(cell)){
stringBuffer.append(debugDataViewer.getTableViewer().getTable().getItem(rowCount).getText(columnCount) + "\t");
hasRow=true;
}
cell=null;
}
if(hasRow){
stringBuffer.append("\n");
hasRow=false;
}
}
Clipboard cb = new Clipboard(Display.getCurrent());
TextTransfer textTransfer = TextTransfer.getInstance();
String textData = stringBuffer.toString();
cb.setContents(new Object[] { textData }, new Transfer[] { textTransfer });
cb.dispose();
}
示例2: execute
import org.eclipse.swt.dnd.Clipboard; //導入方法依賴的package包/類
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
String url = getBookmarkUrl(selection);
if (url == null) {
return null;
}
Clipboard clipboard = new Clipboard(null);
try {
TextTransfer textTransfer = TextTransfer.getInstance();
Transfer[] transfers = new Transfer[] { textTransfer };
Object[] data = new Object[] { url };
clipboard.setContents(data, transfers);
} finally {
clipboard.dispose();
}
return null;
}
示例3: copyTree
import org.eclipse.swt.dnd.Clipboard; //導入方法依賴的package包/類
/**
* ツリーの選択されている部分をヘッダー付きでクリップボードにコピーします
*
* @param header ヘッダー
* @param tree ツリー
*/
public static void copyTree(String[] header, Tree tree) {
TreeItem[] treeItems = tree.getSelection();
StringBuilder sb = new StringBuilder();
sb.append(StringUtils.join(header, "\t"));
sb.append("\r\n");
for (TreeItem column : treeItems) {
String[] columns = new String[header.length];
for (int i = 0; i < header.length; i++) {
columns[i] = column.getText(i);
}
sb.append(StringUtils.join(columns, "\t"));
sb.append("\r\n");
}
Clipboard clipboard = new Clipboard(Display.getDefault());
clipboard.setContents(new Object[] { sb.toString() }, new Transfer[] { TextTransfer.getInstance() });
}
示例4: copy
import org.eclipse.swt.dnd.Clipboard; //導入方法依賴的package包/類
/**
* Copies the current selection to the clipboard.
*
* @param table the data source
*/
protected void copy(final Table table) {
if (canCopy(table)) {
final StringBuilder data = new StringBuilder();
for (int row = 0; row < table.getSelectionCount(); row++) {
for (int col = 0; col < table.getColumnCount(); col++) {
data.append(table.getSelection()[row].getText(col));
if (col == 0) {
data.append('=');
}
else if (row != table.getSelectionCount() - 1) {
data.append(NewLine.SYSTEM_LINE_SEPARATOR);
}
}
}
final Clipboard clipboard = new Clipboard(table.getDisplay());
clipboard.setContents(new String[] { data.toString() }, new TextTransfer[] { TextTransfer.getInstance() });
clipboard.dispose();
}
}
示例5: copyToClipboard
import org.eclipse.swt.dnd.Clipboard; //導入方法依賴的package包/類
private void copyToClipboard(TreeItem[] items, Clipboard clipboard) {
StringBuilder sb = new StringBuilder();
for (TreeItem item : items) {
Object data = item.getData();
if (data != null) {
sb.append(data.toString());
sb.append('\n');
}
}
String content = sb.toString();
if (content.length() > 0) {
clipboard.setContents(
new Object[] {sb.toString()},
new Transfer[] {TextTransfer.getInstance()}
);
}
}
示例6: copyTable
import org.eclipse.swt.dnd.Clipboard; //導入方法依賴的package包/類
/**
* Copies the current selection of a Table into the provided Clipboard, as
* multi-line text.
*
* @param clipboard The clipboard to place the copied content.
* @param table The table to copy from.
*/
private static void copyTable(Clipboard clipboard, Table table) {
int[] selection = table.getSelectionIndices();
// we need to sort the items to be sure.
Arrays.sort(selection);
// all lines must be concatenated.
StringBuilder sb = new StringBuilder();
// loop on the selection and output the file.
for (int i : selection) {
TableItem item = table.getItem(i);
LogMessage msg = (LogMessage)item.getData();
String line = msg.toString();
sb.append(line);
sb.append('\n');
}
// now add that to the clipboard
clipboard.setContents(new Object[] {
sb.toString()
}, new Transfer[] {
TextTransfer.getInstance()
});
}
示例7: copySelectionToClipboard
import org.eclipse.swt.dnd.Clipboard; //導入方法依賴的package包/類
/** Copy all selected messages to clipboard. */
public void copySelectionToClipboard(Clipboard clipboard) {
StringBuilder sb = new StringBuilder();
for (LogCatMessage m : getSelectedLogCatMessages()) {
sb.append(m.toString());
sb.append('\n');
}
if (sb.length() > 0) {
clipboard.setContents(
new Object[] {sb.toString()},
new Transfer[] {TextTransfer.getInstance()}
);
}
}
示例8: copyToClipboard
import org.eclipse.swt.dnd.Clipboard; //導入方法依賴的package包/類
protected void copyToClipboard(IStructuredSelection selection) {
StringBuilder sb = new StringBuilder();
for (Object object : (List<?>) selection.toList()) {
if(object instanceof TreeParent){
TreeParent tp = (TreeParent) object;
object = tp.getNamedElement();
if(object != null){
NamedElement elt = (NamedElement) object;
sb.append(elt.getNameAndVersion()).append("\n");
} else if(tp instanceof TreeProblem) {
sb.append(((TreeProblem) tp).getProblem()).append("\n");
}
}
}
TextTransfer textTransfer = TextTransfer.getInstance();
final Clipboard cb = new Clipboard(getSite().getShell().getDisplay());
try {
cb.setContents(new Object[]{sb.toString()}, new Transfer[]{textTransfer});
} finally {
cb.dispose();
}
}
示例9: copySelected
import org.eclipse.swt.dnd.Clipboard; //導入方法依賴的package包/類
/***************************************************************************
* Copy selected source rows
**************************************************************************/
public void copySelected()
{
GridItem[] selection = getGrid().getSelection();
Clipboard clipboard = new Clipboard(Display.getCurrent());
String data = "";
for (GridItem item : selection)
{
if (!data.isEmpty())
data += "\n";
String line = item.getText(CodeViewerColumn.CODE.ordinal());
if (line != null)
{
line = line.trim();
}
else
{
line = "";
}
data += line;
}
clipboard.setContents(new Object[] { data }, new Transfer[] { TextTransfer.getInstance() });
clipboard.dispose();
}
示例10: copyToClipboard
import org.eclipse.swt.dnd.Clipboard; //導入方法依賴的package包/類
private void copyToClipboard(IResource[] resources, String[] fileNames, String names, IJavaElement[] javaElements, TypedSource[] typedSources, int repeat, Clipboard clipboard) {
final int repeat_max_count= 10;
try{
clipboard.setContents(createDataArray(resources, javaElements, fileNames, names, typedSources),
createDataTypeArray(resources, javaElements, fileNames, typedSources));
} catch (SWTError e) {
if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD || repeat >= repeat_max_count)
throw e;
if (fAutoRepeatOnFailure) {
try {
Thread.sleep(500);
} catch (InterruptedException e1) {
// do nothing.
}
}
if (fAutoRepeatOnFailure || MessageDialog.openQuestion(fShell, ReorgMessages.CopyToClipboardAction_4, ReorgMessages.CopyToClipboardAction_5))
copyToClipboard(resources, fileNames, names, javaElements, typedSources, repeat + 1, clipboard);
}
}
示例11: serialize
import org.eclipse.swt.dnd.Clipboard; //導入方法依賴的package包/類
public void serialize() {
final Clipboard clipboard = command.getClipboard();
final String cellDelimeter = command.getCellDelimeter();
final String rowDelimeter = command.getRowDelimeter();
final TextTransfer textTransfer = TextTransfer.getInstance();
final StringBuilder textData = new StringBuilder();
int currentRow = 0;
for (LayerCell[] cells : copiedCells) {
int currentCell = 0;
for (LayerCell cell : cells) {
final String delimeter = ++currentCell < cells.length ? cellDelimeter : "";
if (cell != null) {
textData.append(cell.getDataValue() + delimeter);
} else {
textData.append(delimeter);
}
}
if (++currentRow < copiedCells.length) {
textData.append(rowDelimeter);
}
}
clipboard.setContents(new Object[]{textData.toString()}, new Transfer[]{textTransfer});
}
示例12: copyTable
import org.eclipse.swt.dnd.Clipboard; //導入方法依賴的package包/類
/**
* テーブルの選択されている部分をヘッダー付きでクリップボードにコピーします
*
* @param header ヘッダー
* @param table テーブル
*/
public static void copyTable(String[] header, Table table) {
TableItem[] tableItems = table.getSelection();
StringBuilder sb = new StringBuilder();
sb.append(StringUtils.join(header, "\t"));
sb.append("\r\n");
for (TableItem column : tableItems) {
String[] columns = new String[header.length];
for (int i = 0; i < header.length; i++) {
columns[i] = column.getText(i);
}
sb.append(StringUtils.join(columns, "\t"));
sb.append("\r\n");
}
Clipboard clipboard = new Clipboard(Display.getDefault());
clipboard.setContents(new Object[] { sb.toString() }, new Transfer[] { TextTransfer.getInstance() });
}
示例13: run
import org.eclipse.swt.dnd.Clipboard; //導入方法依賴的package包/類
public void run() {
Display display = Display.getDefault();
Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
Shell shell = getParentShell();
shell.setCursor(waitCursor);
try {
ProjectExplorerView explorerView = getProjectExplorerView();
if (explorerView != null) {
String sXml;
if (explorerView.isEditing()) {
sXml = explorerView.getEditingText();
}
else {
// copy to clipboard manager
sXml = copy(explorerView);
}
// copy to system clipboard
if (sXml != null) {
Clipboard clipboard = new Clipboard(display);
TextTransfer textTransfer = TextTransfer.getInstance();
clipboard.setContents(new String[]{sXml}, new Transfer[]{textTransfer});
clipboard.dispose();
}
}
}
catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to copy!");
}
finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
示例14: run
import org.eclipse.swt.dnd.Clipboard; //導入方法依賴的package包/類
public void run() {
Display display = Display.getDefault();
Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
Shell shell = getParentShell();
shell.setCursor(waitCursor);
try {
ProjectExplorerView explorerView = getProjectExplorerView();
if (explorerView != null) {
String sXml;
if (explorerView.isEditing()) {
sXml = explorerView.getEditingText();
explorerView.setEditingText("");
}
else {
// copy to clipboard manager
sXml = cut(explorerView);
}
// copy to system clipboard
if (sXml != null) {
Clipboard clipboard = new Clipboard(display);
TextTransfer textTransfer = TextTransfer.getInstance();
clipboard.setContents(new String[]{sXml}, new Transfer[]{textTransfer});
clipboard.dispose();
}
}
}
catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to cut!");
}
finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
示例15: saveCheckedElements2ClipboardAsExpession
import org.eclipse.swt.dnd.Clipboard; //導入方法依賴的package包/類
private void saveCheckedElements2ClipboardAsExpession(){
boolean first = true;
StringBuilder sb = new StringBuilder();
for (TreeElement el : elements) {
if (!el.isSelected()) {
continue;
}
if (!first) {
sb.append('|');
} else {
first = false;
}
String name = el.getName();
if (REGEX_SPECIAL_CHARS.matcher(name).find()) {
name = Pattern.quote(name);
}
sb.append('^').append(name).append('$');
}
if (sb.length() != 0) {
Clipboard clip = new Clipboard(getDisplay());
try {
clip.setContents(new String[] { sb.toString() },
new TextTransfer[] { TextTransfer.getInstance() });
} finally {
clip.dispose();
}
}
}