Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » clipboard content not up to date
clipboard content not up to date [message #463317] Thu, 03 November 2005 11:57 Go to next message
Florian Huber is currently offline Florian Huber
Messages: 15
Registered: July 2009
Junior Member
Hi everybody!

I want to get selected text from an ole-integrated acrobat reader.
At present, to get the string, I select the text with the mouse, press
ctrl+c and press a button that reads the content clipboard.

To shorten the workflow, I post an "ctrl+c" keyevent to the display just
before I read the content of the clipboard.
The unsatisfying result of this operation: I get the old clipboard content.

The content is actual, only when I part the actions!

Can anybody help me with this problem?

I've written some code to illustrate this problem.
Just enter some text, press the "ctrlc" button (watch debug output) and at
the end "show clipboard".
Thank you,
Florian


import org.eclipse.swt.widgets.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;

public class clipboardTest{

static Clipboard cb = null;
static Display display = null;

public static void ctrlc(Text text){
System.out.println("ctrlc");

text.setFocus();

Event event = new Event();
event.type = SWT.KeyDown;
event.keyCode = SWT.CTRL;
display.post(event);

event = new Event();
event.type = SWT.KeyDown;
event.character = 'c';
display.post(event);

event = new Event();
event.type = SWT.KeyUp;
event.character = 'c';
display.post(event);

event = new Event();
event.type = SWT.KeyUp;
event.keyCode = SWT.CTRL;
display.post(event);
}//ctrlc

public static void showClipboard(){
TextTransfer transfer = TextTransfer.getInstance();
String data = (String) cb.getContents(transfer);
System.out.println("clipboard: " + data);
}//clipboardZeigen

public static void main(String[] args){
display = new Display();
cb = new Clipboard(display);

final Shell shell = new Shell(display);
shell.setLayout(new GridLayout(1, false));

final Text text = new Text(shell, SWT.BORDER);
text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

Button ctc = new Button(shell, SWT.PUSH);
ctc.setText("ctrlc");

Button showClipboard = new Button(shell, SWT.PUSH);
showClipboard.setText("show clipboard");

shell.pack();
shell.open();

ctc.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent event){
ctrlc(text);
showClipboard();
}
});

showClipboard.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent event){
showClipboard();
}
});

while(!shell.isDisposed()){
if(!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
}
Re: clipboard content not up to date [message #463357 is a reply to message #463317] Fri, 04 November 2005 09:37 Go to previous messageGo to next message
Florian Huber is currently offline Florian Huber
Messages: 15
Registered: July 2009
Junior Member
I found an other posting of the same problem:
http://dev.eclipse.org/mhonarc/lists/platform-swt-dev/msg045 92.html

but no answer :-(

F
Re: clipboard content not up to date [message #463393 is a reply to message #463357] Fri, 04 November 2005 19:37 Go to previous message
Veronika Irvine is currently offline Veronika Irvine
Messages: 1272
Registered: July 2009
Senior Member
When you use Display.post to post the Ctrl+C key events, this is quite
different from using the Clipboard.setContents() method. Your question is
not the same as the one in msg04592.html.

When you use Display.post, you add events to the event queue. These events
are not processed until the event loop is run. That means when you call
clipboard.getContents() right after posting CTRL+C, you should still get the
old clipboard contents because the CTRL+C is still waiting in the queue to
be processed.

"Florian Huber" <fhuber@picturesafe.de> wrote in message
news:1d044f35e1cc1eaf688af1293cb3b2aa$1@www.eclipse.org...
>I found an other posting of the same problem:
> http://dev.eclipse.org/mhonarc/lists/platform-swt-dev/msg045 92.html
>
> but no answer :-(
>
> F
>
Previous Topic:Update font size immediately
Next Topic:SWT.VIRTUAL TableViewer not sorting
Goto Forum:
  


Current Time: Mon Oct 20 21:13:05 GMT 2014

Powered by FUDForum. Page generated in 0.01735 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software