Search in sources :

Example 16 with TextTransfer

use of org.eclipse.swt.dnd.TextTransfer in project translationstudio8 by heartsome.

the class SegmentViewer method copy.

/**
	 * 执行复制时对标记的处理,复制后在OS系统中不能包含标记占位符 ;
	 */
private void copy() {
    super.doOperation(ITextOperationTarget.COPY);
    TextTransfer plainTextTransfer = TextTransfer.getInstance();
    XLiffTextTransfer hsTextTransfer = XLiffTextTransfer.getInstance();
    Clipboard clipboard = new Clipboard(getTextWidget().getDisplay());
    String plainText = (String) clipboard.getContents(plainTextTransfer);
    if (plainText == null || plainText.length() == 0) {
        return;
    }
    plainText = plainText.replaceAll(Utils.getLineSeparator(), "\n");
    plainText = plainText.replaceAll(Constants.LINE_SEPARATOR_CHARACTER + "", "");
    plainText = plainText.replaceAll(Constants.TAB_CHARACTER + "", "\t");
    plainText = plainText.replaceAll(Constants.SPACE_CHARACTER + "", " ");
    plainText = plainText.replaceAll("​", "");
    clipboard.clearContents();
    Object[] data = new Object[] { PATTERN.matcher(plainText).replaceAll(""), plainText };
    Transfer[] types = new Transfer[] { plainTextTransfer, hsTextTransfer };
    clipboard.setContents(data, types, DND.CLIPBOARD);
    clipboard.dispose();
}
Also used : Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 17 with TextTransfer

use of org.eclipse.swt.dnd.TextTransfer in project translationstudio8 by heartsome.

the class GetActiveKeyDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite tparent = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout();
    layout.marginWidth = 10;
    layout.marginTop = 10;
    tparent.setLayout(layout);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(tparent);
    Composite compNav = new Composite(tparent, SWT.NONE);
    GridLayout navLayout = new GridLayout();
    compNav.setLayout(navLayout);
    createNavigation(compNav);
    Group groupActivekey = new Group(tparent, SWT.NONE);
    groupActivekey.setText(Messages.getString("license.GetActiveKeyDialog.activekey"));
    GridDataFactory.fillDefaults().grab(true, true).applyTo(groupActivekey);
    GridLayout layoutGroup = new GridLayout(2, false);
    layoutGroup.marginWidth = 5;
    layoutGroup.marginHeight = 20;
    groupActivekey.setLayout(layoutGroup);
    StyledText text = new StyledText(groupActivekey, SWT.WRAP | SWT.READ_ONLY);
    text.setBackground(text.getParent().getBackground());
    text.setText(Messages.getString("license.GetActiveKeyDialog.activemessage"));
    GridData dataText = new GridData();
    dataText.horizontalSpan = 2;
    dataText.widthHint = 470;
    text.setLayoutData(dataText);
    int start = Messages.getString("license.GetActiveKeyDialog.activemessage").indexOf(Messages.getString("license.GetActiveKeyDialog.ts"));
    int length = Messages.getString("license.GetActiveKeyDialog.ts").length();
    StyleRange styleRange = new StyleRange();
    styleRange.start = start;
    styleRange.length = length;
    styleRange.fontStyle = SWT.BOLD;
    styleRange.foreground = Display.getDefault().getSystemColor(SWT.COLOR_BLUE);
    text.setStyleRange(styleRange);
    Label label = new Label(groupActivekey, SWT.WRAP | SWT.NONE);
    label.setText(Messages.getString("license.GetActiveKeyDialog.activemessage1"));
    GridDataFactory.fillDefaults().span(2, 1).applyTo(label);
    textActivekey = new Text(groupActivekey, SWT.MULTI | SWT.WRAP);
    textActivekey.setEditable(false);
    textActivekey.setText(activekey);
    textActivekey.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
    GridDataFactory.fillDefaults().grab(true, false).hint(SWT.DEFAULT, 150).applyTo(textActivekey);
    Button btnCopy = new Button(groupActivekey, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.END).applyTo(btnCopy);
    btnCopy.setImage(Activator.getImageDescriptor("images/help/copy.png").createImage());
    btnCopy.setToolTipText(Messages.getString("license.GetActiveKeyDialog.copytoclipboard"));
    btnCopy.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            Clipboard cb = new Clipboard(Display.getCurrent());
            String textData = textActivekey.getText();
            TextTransfer textTransfer = TextTransfer.getInstance();
            cb.setContents(new Object[] { textData }, new Transfer[] { textTransfer });
        }
    });
    return tparent;
}
Also used : Group(org.eclipse.swt.widgets.Group) StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) StyleRange(org.eclipse.swt.custom.StyleRange) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Transfer(org.eclipse.swt.dnd.Transfer) Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 18 with TextTransfer

use of org.eclipse.swt.dnd.TextTransfer in project translationstudio8 by heartsome.

the class GridCopyEnable method copy.

void copy() {
    if (focusContent == null || focusContent.equals("")) {
        return;
    }
    if (selection.x != selection.y) {
        String plainText = focusContent.substring(selection.x, selection.y);
        Object[] data = new Object[] { plainText };
        TextTransfer plainTextTransfer = TextTransfer.getInstance();
        Transfer[] types = new Transfer[] { plainTextTransfer };
        clipboard.setContents(data, types);
    }
}
Also used : TextTransfer(org.eclipse.swt.dnd.TextTransfer) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 19 with TextTransfer

use of org.eclipse.swt.dnd.TextTransfer in project translationstudio8 by heartsome.

the class CopyDataToClipboardSerializer method serialize.

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 });
}
Also used : LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 20 with TextTransfer

use of org.eclipse.swt.dnd.TextTransfer in project eclipse.platform.swt by eclipse.

the class ClipboardExample method createTextTransfer.

void createTextTransfer(Composite copyParent, Composite pasteParent) {
    // TextTransfer
    Label l = new Label(copyParent, SWT.NONE);
    // $NON-NLS-1$
    l.setText("TextTransfer:");
    final Text copyText = new Text(copyParent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    copyText.setText("some\nplain\ntext");
    GridData data = new GridData(GridData.FILL_BOTH);
    data.widthHint = HSIZE;
    data.heightHint = VSIZE;
    copyText.setLayoutData(data);
    Button b = new Button(copyParent, SWT.PUSH);
    b.setText("Copy");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        String textData = copyText.getText();
        if (textData.length() > 0) {
            status.setText("");
            clipboard.setContents(new Object[] { textData }, new Transfer[] { TextTransfer.getInstance() });
        } else {
            status.setText("No text to copy");
        }
    }));
    l = new Label(pasteParent, SWT.NONE);
    // $NON-NLS-1$
    l.setText("TextTransfer:");
    final Text pasteText = new Text(pasteParent, SWT.READ_ONLY | SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    data = new GridData(GridData.FILL_BOTH);
    data.widthHint = HSIZE;
    data.heightHint = VSIZE;
    pasteText.setLayoutData(data);
    b = new Button(pasteParent, SWT.PUSH);
    b.setText("Paste");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        String textData = (String) clipboard.getContents(TextTransfer.getInstance());
        if (textData != null && textData.length() > 0) {
            status.setText("");
            pasteText.setText("begin paste>" + textData + "<end paste");
        } else {
            status.setText("No text to paste");
        }
    }));
}
Also used : RTFTransfer(org.eclipse.swt.dnd.RTFTransfer) StyledText(org.eclipse.swt.custom.StyledText) Image(org.eclipse.swt.graphics.Image) Rectangle(org.eclipse.swt.graphics.Rectangle) ImageData(org.eclipse.swt.graphics.ImageData) Table(org.eclipse.swt.widgets.Table) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) Clipboard(org.eclipse.swt.dnd.Clipboard) ImageDataProvider(org.eclipse.swt.graphics.ImageDataProvider) SelectionListener.widgetSelectedAdapter(org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter) ImageTransfer(org.eclipse.swt.dnd.ImageTransfer) Composite(org.eclipse.swt.widgets.Composite) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Canvas(org.eclipse.swt.widgets.Canvas) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) FileTransfer(org.eclipse.swt.dnd.FileTransfer) TableItem(org.eclipse.swt.widgets.TableItem) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) FileDialog(org.eclipse.swt.widgets.FileDialog) Display(org.eclipse.swt.widgets.Display) Group(org.eclipse.swt.widgets.Group) File(java.io.File) Transfer(org.eclipse.swt.dnd.Transfer) SWT(org.eclipse.swt.SWT) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) HTMLTransfer(org.eclipse.swt.dnd.HTMLTransfer) List(org.eclipse.swt.widgets.List) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ScrollBar(org.eclipse.swt.widgets.ScrollBar) Label(org.eclipse.swt.widgets.Label) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) RTFTransfer(org.eclipse.swt.dnd.RTFTransfer) ImageTransfer(org.eclipse.swt.dnd.ImageTransfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) FileTransfer(org.eclipse.swt.dnd.FileTransfer) Transfer(org.eclipse.swt.dnd.Transfer) HTMLTransfer(org.eclipse.swt.dnd.HTMLTransfer) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text)

Aggregations

TextTransfer (org.eclipse.swt.dnd.TextTransfer)77 Clipboard (org.eclipse.swt.dnd.Clipboard)65 Point (org.eclipse.swt.graphics.Point)19 Transfer (org.eclipse.swt.dnd.Transfer)18 TableItem (org.eclipse.swt.widgets.TableItem)14 StyledText (org.eclipse.swt.custom.StyledText)10 Control (org.eclipse.swt.widgets.Control)8 Text (org.eclipse.swt.widgets.Text)6 IAction (org.eclipse.jface.action.IAction)5 HTMLTransfer (org.eclipse.swt.dnd.HTMLTransfer)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 Button (org.eclipse.swt.widgets.Button)5 Composite (org.eclipse.swt.widgets.Composite)5 ArrayList (java.util.ArrayList)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 DragSourceEvent (org.eclipse.swt.dnd.DragSourceEvent)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 GridData (org.eclipse.swt.layout.GridData)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 Label (org.eclipse.swt.widgets.Label)4