How String.copy(str) in java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How String.copy(str) in java

CARL Philippe (LBP)
Dear all,

I’m really sorry to have what is very probably a very easy question, namely
"how to copy a String or Double to the clipboard within a plugin".

This question is actually more or less similar to the conversion of the
macro "String.copy(str)" instruction.

Besides answering this question, I would as well be interested in how I
could have find this information alone, i.e. without having posted this
thread.

Indeed, I have looked for "String.copy(str)" within ij.macro. Functions.java
without being able to locate it (as well as already posted threads about
such a question).

I thank you very much in advance for your answer and help.

Philippe

 

Philippe CARL

Laboratoire de Biophotonique et Pharmacologie

UMR 7213 CNRS - Université de Strasbourg

Faculté de Pharmacie

74 route du Rhin

67401 ILLKIRCH

Tel : +33(0)3 68 85 41 84


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: How String.copy(str) in java

Michael Schmid
Hi Philippe,

you might try something like this (code stolen from
ij.plugin.frame.Editor; I used it in one of my plugins):

   Clipboard clip = getToolkit().getSystemClipboard();
   if (clip!=null) {
     StringSelection contents = new StringSelection(s);
     clip.setContents(contents, this);
   }


The clipboard owner (a ClipboardOwner; here 'this' in setContents) seems
to be not critical; it can be also the StringSelection as long as you
don't need to know when the contents of the clipboard is modified.
   http://stackoverflow.com/questions/8421007/java-clipboardowner-purpose

Michael
________________________________________________________________
On 2016-03-21 12:17, Philippe CARL wrote:

> Dear all,
>
> I’m really sorry to have what is very probably a very easy question, namely
> "how to copy a String or Double to the clipboard within a plugin".
>
> This question is actually more or less similar to the conversion of the
> macro "String.copy(str)" instruction.
>
> Besides answering this question, I would as well be interested in how I
> could have find this information alone, i.e. without having posted this
> thread.
>
> Indeed, I have looked for "String.copy(str)" within ij.macro. Functions.java
> without being able to locate it (as well as already posted threads about
> such a question).
>
> I thank you very much in advance for your answer and help.
>
> Philippe
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: How String.copy(str) in java

Peter Haub
In reply to this post by CARL Philippe (LBP)
may this helps (found via www search)

http://stackoverflow.com/questions/3591945/copying-to-clipboard-in-java

Peter

On 21.03.2016 12:17, Philippe CARL wrote:

> Dear all,
>
> I’m really sorry to have what is very probably a very easy question, namely
> "how to copy a String or Double to the clipboard within a plugin".
>
> This question is actually more or less similar to the conversion of the
> macro "String.copy(str)" instruction.
>
> Besides answering this question, I would as well be interested in how I
> could have find this information alone, i.e. without having posted this
> thread.
>
> Indeed, I have looked for "String.copy(str)" within ij.macro. Functions.java
> without being able to locate it (as well as already posted threads about
> such a question).
>
> I thank you very much in advance for your answer and help.
>
> Philippe
>
>  
>
> Philippe CARL
>
> Laboratoire de Biophotonique et Pharmacologie
>
> UMR 7213 CNRS - Université de Strasbourg
>
> Faculté de Pharmacie
>
> 74 route du Rhin
>
> 67401 ILLKIRCH
>
> Tel : +33(0)3 68 85 41 84
>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: How String.copy(str) in java

CARL Philippe (LBP)
Yes working thank you!!!

-----Message d'origine-----
De : ImageJ Interest Group [mailto:[hidden email]] De la part de Peter
Haub
Envoyé : lundi 21 mars 2016 13:16
À : [hidden email]
Objet : Re: How String.copy(str) in java

may this helps (found via www search)

http://stackoverflow.com/questions/3591945/copying-to-clipboard-in-java

Peter

On 21.03.2016 12:17, Philippe CARL wrote:

> Dear all,
>
> I’m really sorry to have what is very probably a very easy question,
> namely "how to copy a String or Double to the clipboard within a plugin".
>
> This question is actually more or less similar to the conversion of
> the macro "String.copy(str)" instruction.
>
> Besides answering this question, I would as well be interested in how
> I could have find this information alone, i.e. without having posted
> this thread.
>
> Indeed, I have looked for "String.copy(str)" within ij.macro.
> Functions.java without being able to locate it (as well as already
> posted threads about such a question).
>
> I thank you very much in advance for your answer and help.
>
> Philippe
>
>  
>
> Philippe CARL
>
> Laboratoire de Biophotonique et Pharmacologie
>
> UMR 7213 CNRS - Université de Strasbourg
>
> Faculté de Pharmacie
>
> 74 route du Rhin
>
> 67401 ILLKIRCH
>
> Tel : +33(0)3 68 85 41 84
>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: How String.copy(str) in java

Jan Eglinger
In reply to this post by CARL Philippe (LBP)
Hi Philippe,

to answer the second part of your question:

On 21.03.2016 12:17, Philippe CARL wrote:
> Besides answering this question, I would as well be interested in how I
> could have find this information alone, i.e. without having posted this
> thread.
>
> Indeed, I have looked for "String.copy(str)" within ij.macro. Functions.java
> without being able to locate it (as well as already posted threads about
> such a question).

You were actually very close. Searching the file Functions.java for
"copy" gives 18 instances, among them the function copyStringToClipboard():

https://github.com/imagej/ImageJA/blob/master/src/main/java/ij/macro/Functions.java#L4390-L4396

which uses code similar to the one the other answers are pointing to on
stackoverflow.com


Jan

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: How String.copy(str) in java

CARL Philippe (LBP)
In reply to this post by CARL Philippe (LBP)
Dear Jan,
Thanks a lot for your answer and after it I really don't know (and
understand) how I could have missed what you pointed me out (especially
since I had found the String doString() method within Functions.java).
In all cases you closed a potential paradox and the only answer is that I
was blind this morning.
Thanks as well to Michael for his answer, but I wasn't able to reproduce the
" getToolkit().getSystemClipboard();" nor the " clip.setContents(contents,
this);" and the code I finally used is indeed similar to the one found in
copyStringToClipboard().
In fact I didn't really understand the ClipboardOwner issue about
setContents, i.e. the difference between setting the setContents
ClipboardOwner to "this", "null" or the StringSelection.
My best regards,
Philippe

-----Message d'origine-----
De : Jan Eglinger [mailto:[hidden email]] Envoyé : lundi 21 mars
2016 15:18 À : [hidden email]; [hidden email] Objet : Re: How
String.copy(str) in java

Hi Philippe,

to answer the second part of your question:

On 21.03.2016 12:17, Philippe CARL wrote:
> Besides answering this question, I would as well be interested in how
> I could have find this information alone, i.e. without having posted
> this thread.
>
> Indeed, I have looked for "String.copy(str)" within ij.macro.
> Functions.java without being able to locate it (as well as already
> posted threads about such a question).

You were actually very close. Searching the file Functions.java for "copy"
gives 18 instances, among them the function copyStringToClipboard():

https://github.com/imagej/ImageJA/blob/master/src/main/java/ij/macro/Functio
ns.java#L4390-L4396

which uses code similar to the one the other answers are pointing to on
stackoverflow.com


Jan

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html