import ij.*; import ij.gui.HTMLDialog; import ij.plugin.*; import java.net.URL; // needed when loading images from a .jar file /** This plugin shows how to use the HTMLDialog class in ImageJ 1.49o and higher */ public class Test_HTML_Dialog implements PlugIn { public void run(String arg) { if (IJ.versionLessThan("1.49o")) return; // The following is a nonmodal dialog. // Note that the dialog message is a long String (over several lines), // starting with " and ending with "". // For HTMLDialogs, you may, but need not specify the
, , and tags. new HTMLDialog("Short nonmodal dialog...", "new HTMLDialog(String title, String theHtmlMessage, boolean isModal);
isModal=true
.",
false);
// Get the URL of an image embedded in a .jar file, here the image of the 'About ImageJ box',
// from the .jar file of ImageJ
ImageJ imageJ = ij.IJ.getInstance();
URL exampleImageUrl = imageJ.getClass().getResource("/about.jpg");
// The following is a modal dialog; the user has to close it before continuing.
// It shows examples of HTML formatting.
// (Note: If you want to have quotes " in the HTML code, i.e. inside the Java Sting,
// don't forget to escape them with a preceding backslash.)
new HTMLDialog("Long modal dialog...",
""+
"<a name='top'> ... </a>
"+
" serves as the target for the internal link at the very bottom of this page (scroll down if necessary)."+
"Note that external links (like those above) in the HTMLDialog are opened in the default web browser."+ "
You can also have subscripts and superscrips as well as "+
"big and small text.
"+
"Apart from the <big>
and <small>
tags, there are also font sizes 1-7: "+
"1 2 3 4 "+
"5 6 7, using the "+
"<font size=\"1\"> ... </font>
etc. tags.
"+
"Instead of the <font>
tags, it's better to use CSS, however: "+
"For Red 80%, embed the text between these tags: "+
"<span style=\"color:red;font-size:80%\"> ... </span>
."+
"
Many special characters such as ½ , µ , etc. are available with symbolic names, "+
"including accented à, umlaut ä and other characters beyond the standard ASCII set.
"+
"Note that unicode support is beyond the HTML 3.2 standard. E.g. the right arrow has unicode 0x2192 "+
"but at least in Java 1.6 on my computer it looks just like an empty box: "+
"Newer Java versions might be better in this respect, but remember that some old computers don't "+
"support newer Java versions (e.g. some Macintosh computers)."+
"
Don't forget that the 'less than', 'greater than' and 'ampersand' symbols have a special meaning in HTML "+ "and must be written as special symbols: < > &"+ "
<ul>
tag and ends with </ul>
"+
"<li>
tag; a closing </li>
tag need not be present, but does not hurt."+
"<ol>
tag and ends with </ol>
."+
"<li>
tag) "+
"automatically gets number 2<dl>
tag. "+
"Each list entry consists of two parts, "+
"the definition term (<dt>
tag) and "+
"the definition data (<dd>
tag; displayed as indented text)."+
"</dl>
tag."+
"getResource(String name)
method of the main class in the .jar file.getResource
can be used to load the image. ImageJ imageJ = ij.IJ.getInstance();
"+
" URL exampleImageUrl = imageJ.getClass().getResource(\"/about.jpg\");
"+
"
and then the URL can be included in an <img src=\"URL\">
HTML tag."+
"
"+
"In case you are interested, the URL reads "+exampleImageUrl+"
"+
"This makes it obvious that you can't hardcode the URL, it will be different if ImageJ is in a different location."+
"
GenericDialog
s.gd.addHelp(String helpText)
starts "+
"with <html>
and ends with </html>
."+
""+
"Internal link to the <a name...
near the top."+
""
); //end of new HTMLDialog(title, theHtmlMessage)
} //end of public void run
}