set font in text window using macro language commands?

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

set font in text window using macro language commands?

Bill Christens-Barry-2
Hi,

After searching the list archives and online documentation for ImageJ, I've not yet identified how I can set the font and its attributes for printing in a text window. My goal is to use a monospaced font to facilitate the alignment of printed text in lines that have variable numbers of space characters.

I would also like to be able (in macros) to use tabs in text printed in text windows. My attempts (macOS 10.14.6, ImageJ v1.53b40) to do this using something like:

  print("Indent \t tabbed text");    // ==> Indent   tabbed text
  print("Indent \t\t tabbed text");  // ==> Indent    tabbed text

and so forth with various numbers of tabs and spaces seem to treat the tab ("\t") as being equivalent to a single space.

Are there macro commands allowing font setting in text windows (including the Log window)?

Thanks.

Bill

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

Re: set font in text window using macro language commands?

Michael Schmid
Hi Bill,

you can't set the font of the Log or a text output window (even not from
Java), but you can have columns:

   title="[my text]"
   run("New... ", "name="+title+" type=Table");
   print(title, "\\Headings:column1\tc2\n");
   print(title, "abcdef\t123\n");
   print(title, "abc\t123456\n");

Note that you have to print the linefeed characters '\n' yourself.
For more possibilities, see
   https://imagej.nih.gov/ij/macros/TableTricks.txt

It won't help if you need a mixture of normal text lines and tables.

Michael
________________________________________________________________
On 29.05.20 18:22, Bill Christens-Barry wrote:

> Hi,
>
> After searching the list archives and online documentation for ImageJ, I've not yet identified how I can set the font and its attributes for printing in a text window. My goal is to use a monospaced font to facilitate the alignment of printed text in lines that have variable numbers of space characters.
>
> I would also like to be able (in macros) to use tabs in text printed in text windows. My attempts (macOS 10.14.6, ImageJ v1.53b40) to do this using something like:
>
>    print("Indent \t tabbed text");    // ==> Indent   tabbed text
>    print("Indent \t\t tabbed text");  // ==> Indent    tabbed text
>
> and so forth with various numbers of tabs and spaces seem to treat the tab ("\t") as being equivalent to a single space.
>
> Are there macro commands allowing font setting in text windows (including the Log window)?
>
> Thanks.
>
> Bill
>
> --
> 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: set font in text window using macro language commands?

Bill Christens-Barry-2
In reply to this post by Bill Christens-Barry-2
Hi Michael,

Thanks for your explanation and good stuff on fonts in Text Windows. Use of a Table will give me some options. Also, I've found that I can construct text files from ImageJ Text Windows that align properly when viewed in an external editor, although these files still misalign when opened and viewed in ImageJ.

Thanks,

Bill

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

Re: set font in text window using macro language commands?

jmutterer
Hi Bill and Michael.
It seems you can actually switch the font of the Log window after it's been
created with the following javascript:

IJ.selectWindow("Log");
tw = WindowManager.getFrontWindow();
tp =  tw.getTextPanel();
tp.setFont(new Font("Monospaced", Font.PLAIN, 24), true);

Sincerely,
Jerome

On Fri, 29 May 2020 at 22:40, Bill Christens-Barry <[hidden email]>
wrote:

> Hi Michael,
>
> Thanks for your explanation and good stuff on fonts in Text Windows. Use
> of a Table will give me some options. Also, I've found that I can construct
> text files from ImageJ Text Windows that align properly when viewed in an
> external editor, although these files still misalign when opened and viewed
> in ImageJ.
>
> Thanks,
>
> Bill
>
> --
> 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: set font in text window using macro language commands?

CARL Philippe (LBP)
In reply to this post by Michael Schmid
Dear Michael,
Would you mind to send a Java version of you small macro below?
I thank you very much in advance.
Kindest regards,
Philippe

----- Le 29 Mai 20, à 19:37, Michael Schmid [hidden email] a écrit :

Hi Bill,

you can't set the font of the Log or a text output window (even not from
Java), but you can have columns:

   title="[my text]"
   run("New... ", "name="+title+" type=Table");
   print(title, "\\Headings:column1\tc2\n");
   print(title, "abcdef\t123\n");
   print(title, "abc\t123456\n");

Note that you have to print the linefeed characters '\n' yourself.
For more possibilities, see
   https://imagej.nih.gov/ij/macros/TableTricks.txt

It won't help if you need a mixture of normal text lines and tables.

Michael
________________________________________________________________
On 29.05.20 18:22, Bill Christens-Barry wrote:

> Hi,
>
> After searching the list archives and online documentation for ImageJ, I've not yet identified how I can set the font and its attributes for printing in a text window. My goal is to use a monospaced font to facilitate the alignment of printed text in lines that have variable numbers of space characters.
>
> I would also like to be able (in macros) to use tabs in text printed in text windows. My attempts (macOS 10.14.6, ImageJ v1.53b40) to do this using something like:
>
>    print("Indent \t tabbed text");    // ==> Indent   tabbed text
>    print("Indent \t\t tabbed text");  // ==> Indent    tabbed text
>
> and so forth with various numbers of tabs and spaces seem to treat the tab ("\t") as being equivalent to a single space.
>
> Are there macro commands allowing font setting in text windows (including the Log window)?
>
> Thanks.
>
> Bill
>
> --
> 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: set font in text window using macro language commands?

Wayne Rasband-2
In reply to this post by Bill Christens-Barry-2
> On May 29, 2020, at 12:22 PM, Bill Christens-Barry <[hidden email]> wrote:
>
> Hi,
>
> After searching the list archives and online documentation for ImageJ, I've not yet identified how I can set the font and its attributes for printing in a text window. My goal is to use a monospaced font to facilitate the alignment of printed text in lines that have variable numbers of space characters.

The ImageJ 1.53c4 daily adds a macro-callable TextWindow.setFont(name,style,size) method for setting the font used in the Log window. The following example displays 32 point monospaced text. Tabs are not supported. Change the second argument to 1 for bold text.

   close("Log");
   call("ij.text.TextWindow.setFont","Monospaced", 0, 32);
   print("This is a line of 32 point monospaced text.");
   print("1234567890  1234567890  1234567890”);

-wayne


>
> I would also like to be able (in macros) to use tabs in text printed in text windows. My attempts (macOS 10.14.6, ImageJ v1.53b40) to do this using something like:
>
>  print("Indent \t tabbed text");    // ==> Indent   tabbed text
>  print("Indent \t\t tabbed text");  // ==> Indent    tabbed text
>
> and so forth with various numbers of tabs and spaces seem to treat the tab ("\t") as being equivalent to a single space.
>
> Are there macro commands allowing font setting in text windows (including the Log window)?
>
> Thanks.
>
> Bill

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

Re: set font in text window using macro language commands?

Michael Schmid
In reply to this post by CARL Philippe (LBP)
Hi Philippe,

here is a JavaScript example:

   title="my text";
   IJ.run("New... ", "name=["+title+"] type=Table");
   frame = WindowManager.getFrame(title);
   //Java only, then continue with 'tw' not 'frame':
   //TextWindow tw = (TextWindow)frame;
   tp = frame.getTextPanel();  //tw.getTextPanel();
   tp.setColumnHeadings("column1\tc2");
   tp.append("abcdef\t123\n");


For Java, obviously declare title as String, frame as java.awt.Frame, tp
as ij.text.TextPanel.
Before creating a new table, make sure that there is none with the given
title (WindowManager.getFrame(title) should return null), otherwise it
will result in a mess (it will create a new empty frame, but
modifications go to the preexisting one).

You can find more Java code for handling the 'print to table' functions
at ij.macro.Functions, method handleTextWindowCommand
 
https://github.com/imagej/imagej1/blob/master/ij/macro/Functions.java#L3655


Best,

Michael
________________________________________________________________
On 03.06.20 20:34, CARL Philippe (LBP) wrote:

> Dear Michael,
> Would you mind to send a Java version of you small macro below?
> I thank you very much in advance.
> Kindest regards,
> Philippe
>
> ----- Le 29 Mai 20, à 19:37, Michael Schmid [hidden email] a écrit :
>
> Hi Bill,
>
> you can't set the font of the Log or a text output window (even not from
> Java), but you can have columns:
>
>     title="[my text]"
>     run("New... ", "name="+title+" type=Table");
>     print(title, "\\Headings:column1\tc2\n");
>     print(title, "abcdef\t123\n");
>     print(title, "abc\t123456\n");
>
> Note that you have to print the linefeed characters '\n' yourself.
> For more possibilities, see
>     https://imagej.nih.gov/ij/macros/TableTricks.txt
>
> It won't help if you need a mixture of normal text lines and tables.
>
> Michael
> ________________________________________________________________
> On 29.05.20 18:22, Bill Christens-Barry wrote:
>> Hi,
>>
>> After searching the list archives and online documentation for ImageJ, I've not yet identified how I can set the font and its attributes for printing in a text window. My goal is to use a monospaced font to facilitate the alignment of printed text in lines that have variable numbers of space characters.
>>
>> I would also like to be able (in macros) to use tabs in text printed in text windows. My attempts (macOS 10.14.6, ImageJ v1.53b40) to do this using something like:
>>
>>     print("Indent \t tabbed text");    // ==> Indent   tabbed text
>>     print("Indent \t\t tabbed text");  // ==> Indent    tabbed text
>>
>> and so forth with various numbers of tabs and spaces seem to treat the tab ("\t") as being equivalent to a single space.
>>
>> Are there macro commands allowing font setting in text windows (including the Log window)?
>>
>> Thanks.
>>
>> Bill
>>
>> --
>> 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
>

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

Re: set font in text window using macro language commands?

CARL Philippe (LBP)
Hi Michael,
How are you doing?
Let's say I have a plugin where I'm using the code below (you gave me almost a month ago).
This plugin can be launched several times and of course the content of the generated table window will be different on each launch.
Thus what would up to you be the best strategy for either killing the former table or erasing it's content at the beginning of the next launch ?
Kindest regards,
Philippe

----- Le 4 Juin 20, à 10:15, Michael Schmid [hidden email] a écrit :

Hi Philippe,

here is a JavaScript example:

   title="my text";
   IJ.run("New... ", "name=["+title+"] type=Table");
   frame = WindowManager.getFrame(title);
   //Java only, then continue with 'tw' not 'frame':
   //TextWindow tw = (TextWindow)frame;
   tp = frame.getTextPanel();  //tw.getTextPanel();
   tp.setColumnHeadings("column1\tc2");
   tp.append("abcdef\t123\n");


For Java, obviously declare title as String, frame as java.awt.Frame, tp
as ij.text.TextPanel.
Before creating a new table, make sure that there is none with the given
title (WindowManager.getFrame(title) should return null), otherwise it
will result in a mess (it will create a new empty frame, but
modifications go to the preexisting one).

You can find more Java code for handling the 'print to table' functions
at ij.macro.Functions, method handleTextWindowCommand
 
https://github.com/imagej/imagej1/blob/master/ij/macro/Functions.java#L3655


Best,

Michael
________________________________________________________________
On 03.06.20 20:34, CARL Philippe (LBP) wrote:

> Dear Michael,
> Would you mind to send a Java version of you small macro below?
> I thank you very much in advance.
> Kindest regards,
> Philippe
>
> ----- Le 29 Mai 20, à 19:37, Michael Schmid [hidden email] a écrit :
>
> Hi Bill,
>
> you can't set the font of the Log or a text output window (even not from
> Java), but you can have columns:
>
>     title="[my text]"
>     run("New... ", "name="+title+" type=Table");
>     print(title, "\\Headings:column1\tc2\n");
>     print(title, "abcdef\t123\n");
>     print(title, "abc\t123456\n");
>
> Note that you have to print the linefeed characters '\n' yourself.
> For more possibilities, see
>     https://imagej.nih.gov/ij/macros/TableTricks.txt
>
> It won't help if you need a mixture of normal text lines and tables.
>
> Michael
> ________________________________________________________________
> On 29.05.20 18:22, Bill Christens-Barry wrote:
>> Hi,
>>
>> After searching the list archives and online documentation for ImageJ, I've not yet identified how I can set the font and its attributes for printing in a text window. My goal is to use a monospaced font to facilitate the alignment of printed text in lines that have variable numbers of space characters.
>>
>> I would also like to be able (in macros) to use tabs in text printed in text windows. My attempts (macOS 10.14.6, ImageJ v1.53b40) to do this using something like:
>>
>>     print("Indent \t tabbed text");    // ==> Indent   tabbed text
>>     print("Indent \t\t tabbed text");  // ==> Indent    tabbed text
>>
>> and so forth with various numbers of tabs and spaces seem to treat the tab ("\t") as being equivalent to a single space.
>>
>> Are there macro commands allowing font setting in text windows (including the Log window)?
>>
>> Thanks.
>>
>> Bill
>>
>> --
>> 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
>

--
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: set font in text window using macro language commands?

Michael Schmid
Hi Philippe,

a rough answer, I did not try it.
In a macro, you can have
   print("[My Window]", "\\Update:The_new_contents)"
so you can look up the corresponding java code in ij.macro.Functions.java

https://github.com/imagej/imagej1/blob/master/ij/macro/Functions.java#L3612
https://github.com/imagej/imagej1/blob/master/ij/macro/Functions.java#L3657

//If you don't have the reference to the TextWindow any more:
   Frame frame = WindowManager.getFrame(title);
//if (!(frame instanceof TextWindow)) make a new TextWindow
   TextWindow tw = (TextWindow)frame;
//then clear it and append the new contents
   TextPanel tp = tw.getTextPanel();
   tp.clear();
   tp.append(myNewContentsString);


Best,

Michael
________________________________________________________________
On 01.07.20 08:33, CARL Philippe (LBP) wrote:

> Hi Michael,
> How are you doing?
> Let's say I have a plugin where I'm using the code below (you gave me almost a month ago).
> This plugin can be launched several times and of course the content of the generated table window will be different on each launch.
> Thus what would up to you be the best strategy for either killing the former table or erasing it's content at the beginning of the next launch ?
> Kindest regards,
> Philippe
>
> ----- Le 4 Juin 20, à 10:15, Michael Schmid [hidden email] a écrit :
>
> Hi Philippe,
>
> here is a JavaScript example:
>
>     title="my text";
>     IJ.run("New... ", "name=["+title+"] type=Table");
>     frame = WindowManager.getFrame(title);
>     //Java only, then continue with 'tw' not 'frame':
>     //TextWindow tw = (TextWindow)frame;
>     tp = frame.getTextPanel();  //tw.getTextPanel();
>     tp.setColumnHeadings("column1\tc2");
>     tp.append("abcdef\t123\n");
>
>
> For Java, obviously declare title as String, frame as java.awt.Frame, tp
> as ij.text.TextPanel.
> Before creating a new table, make sure that there is none with the given
> title (WindowManager.getFrame(title) should return null), otherwise it
> will result in a mess (it will create a new empty frame, but
> modifications go to the preexisting one).
>
> You can find more Java code for handling the 'print to table' functions
> at ij.macro.Functions, method handleTextWindowCommand
>  
> https://github.com/imagej/imagej1/blob/master/ij/macro/Functions.java#L3655
>
>
> Best,
>
> Michael
> ________________________________________________________________
> On 03.06.20 20:34, CARL Philippe (LBP) wrote:
>> Dear Michael,
>> Would you mind to send a Java version of you small macro below?
>> I thank you very much in advance.
>> Kindest regards,
>> Philippe
>>
>> ----- Le 29 Mai 20, à 19:37, Michael Schmid [hidden email] a écrit :
>>
>> Hi Bill,
>>
>> you can't set the font of the Log or a text output window (even not from
>> Java), but you can have columns:
>>
>>      title="[my text]"
>>      run("New... ", "name="+title+" type=Table");
>>      print(title, "\\Headings:column1\tc2\n");
>>      print(title, "abcdef\t123\n");
>>      print(title, "abc\t123456\n");
>>
>> Note that you have to print the linefeed characters '\n' yourself.
>> For more possibilities, see
>>      https://imagej.nih.gov/ij/macros/TableTricks.txt
>>
>> It won't help if you need a mixture of normal text lines and tables.
>>
>> Michael
>> ________________________________________________________________
>> On 29.05.20 18:22, Bill Christens-Barry wrote:
>>> Hi,
>>>
>>> After searching the list archives and online documentation for ImageJ, I've not yet identified how I can set the font and its attributes for printing in a text window. My goal is to use a monospaced font to facilitate the alignment of printed text in lines that have variable numbers of space characters.
>>>
>>> I would also like to be able (in macros) to use tabs in text printed in text windows. My attempts (macOS 10.14.6, ImageJ v1.53b40) to do this using something like:
>>>
>>>      print("Indent \t tabbed text");    // ==> Indent   tabbed text
>>>      print("Indent \t\t tabbed text");  // ==> Indent    tabbed text
>>>
>>> and so forth with various numbers of tabs and spaces seem to treat the tab ("\t") as being equivalent to a single space.
>>>
>>> Are there macro commands allowing font setting in text windows (including the Log window)?
>>>
>>> Thanks.
>>>
>>> Bill
>>>
>>> --
>>> 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
>>
>
> --
> 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