JDisplay Listing Colouriser
©1996-2010 Roedy Green, Canadian Mind Products
Introduction
JDisplay stands for Java Display. It
started out as a way to display Java source code listings in a variety of colours, fonts, sizes, and weights to help
make them more presentable and readable on a website. Then I expanded it to handle HTML,
bat, btm, SQL, ini, csv, and *.properties files.
Then I expanded it further the handle mft, sf, mf and http files.
Why would you use it? For the same sorts of reasons you use colours and fonts in an IDE like IntelliJ or Eclipse.
They make your code much easier to understand for visitors to your website. The techniques used are more much more
efficient of bandwidth than displaying images.
There is no server-side code used. Java utilities parse the code snippets into compact binary tokens, assigning
colours, fonts, sizes and weights to each token. The tokens are compressed with GZIP and stored in *.ser files.
These are not as compact as the original text since they include colourising information for each chunk of text. They are
usually more compact that the equivalent formatted HTML, but for very small files they can be bigger because of the serialisation
overhead of all the fully qualified token class names for the various types of token at the head of the *.ser files.
Then the tokens can be rendered three ways:
- using a Java Applet. This is usually best for very large listings.
- as piece of CSS style-decorated HTML code you include in your html as an iframe. This is usually best for
intermediate listings.
- inline in your HTML. This is usually best for short listings. The problem, in the process of editing the html
it is fairly easy to damage the generated listings. They must be regenerated before every upload.
I have been using the JDisplay suite of utilities for many years. I did not write it for public use. I offer it on an
as-is basis. The code itself in well documented, but there is no step-by-step documentation on getting it to work.
I presume the user is familiar with bat and ant files and Java building.
I have not included the enormous HTML static macros package which I use for deciding the sizes and display
rendering method for each snippet, though I did include the code to make those decisions hooked into your own
framework. At some point in the near future I will make the htmlmacros package available for download separately.
The parsers are rough and ready. They need to work on code snippets and erroneous code, not perfect code the way a
standard parser does. If improve the parsers, or add new ones, please pass them along for the public
distribution.
JDisplay is enormously more complicated than it appears on the surface. You can spelunk and discover all manner of
interesting code you can cannibalise. There are finite state machines, clipregion sensitive Canvas rendering, HTML generators, ObjectStreams…
Advantages
- You can render three different ways: Applet, inline, or iframe.
- uses CSS not old-fashioned <font tags.
- works on snippets with syntax errors.
- does some cleverer things than usual e.g. bold where a symbol is defined, variable size matching () {},
grouping numerics in 3s or 4s with subtle colour differences
- has parsers for HTML, SQL etc, not just Java.
- it has been extended by a third party to colourise code snippets in Javadoc.
- For large listings, with Applet rendering, it is more efficient than HTML since it transmits a compressed
binary token stream.
Disadvantages
Packages
| com.mindprod.compactor |
compacts html to remove excess white space. |
| com.mindprod.entities |
interconvert & ⇔ & etc. |
| com.mindprod.filter |
set of FilenameFilters |
| com.mindprod.htmlmacros jdisplay.java |
part of a large static macros package to expand macros embedded in HTML before the files are uploaded to
the server. |
| com.mindprod.hunkio |
does IO in big hunks. |
| com.mindprod.jdisplayaux |
static macro to decide which of three ways to render a given snippet and inserts the appropriate HTML to do
that into your HTML. |
| com.mindprod.jdisplayorphans |
detects orphans not referenced by any of your HTML. |
| com.mindprod.jprep |
parses the snippets of code, producing binary *.ser files. |
| com.mindprod.jtokens |
Tokens and parsers for various languages rendered. |
| mindprod.css |
style sheet that controls the fonts/tokens/sizes |
Program Flow
- Run jprep to parse snippets to binary *.ser files and
iframe/*.html files.
- Manually decide which of three methods to use, and insert the appropriate HTML. (or rig up some code to do this
automatically using code in JDisplayAux). To see what the embedded HTML looks like see Java Presenter Student Project which describes how JDisplay works inside. This
HTML was generated with static macros. You might do the same, or compose the embedded HTML directly.
- Upload to website.
- View code inline, as iframe, or via invocation of JDisplay Applet.
Examples
- Listing expanded inline as HTML with classes for each token. Style sheet mindprod.css
controls the colour, font, size and weight. HTML looks like this
The display looks like this:
...
Border b1 = BorderFactory.createLineBorder( Color.black );
Border b2 = BorderFactory.createEtchedBorder( EtchedBorder.LOWERED );
Border b3 = new BevelBorder ( BevelBorder.LOWERED, Color.red );
JPanel panel = new JPanel();
panel.setBorder( b2 );
- Listing using a separate iframe in HTML with classes for each token. Style sheet mindprod.css controls the colour, font, size and weight. The HTML to include an iframe JDisplay looks
like this:
The display itself looks like this:
- Listing using the JDisplay Applet to render a *.ser binary token file. The HTML to
invoke an Applet to display the JDisplay binary token *.ser file looks like this:
The display itself looks like this:
Prerequisites
If, jdisplay, the above Program Listing Display Java Applet does not work…
- This Java Applet needs at least 32-bit (not 64-bit) Java 1.5. For best results use the latest 1.6.0_18. and a recent browser.
- Firefox 3.6 requires Java 1.6.0_10 or later.
- If you have Windows 7 64-bit and Internet Explorer 64-bit, you can use 64-bit Java.
- You should see the Applet above looking much like the screenshot. If you don’t, the following should help you get it working:
- If you are using Microsoft Internet Explorer, try another browser. Seriously. Microsoft has taken great pains, over and over, to screw up Java and every other multi-platform standardisation.
- If you are using Internet Explorer 7 or 8, you must allow blocked content permission for Active X to run. This also gives permission to Java to run. Click the Information bar, and then click Allow blocked content. Unfortunately, this also allows dangerous ActiveX code to run. However, you must do this in order to get access to perfectly-safe Java Applets running in a sandbox. This is part of Microsoft’s war on Java. Don’t put up with it! Use a different browser.
- Especially if this Applet has worked before, try clearing the browser cache and rebooting.
- To ensure your Java is up to date, check with Wassup. First, download it and run it as an application independent of your browser, then run it online as an Applet to add the complication of your browser.
- If the above Applet does not work, check the Java console for error messages.
- If the above Applet does not work, you might have better luck with the downloadable version.
- If you are using Mac OS X and would like an improved Look and Feel, download the QuaQua look & feel from randelshofer.ch/quaqua. UnZip the contained quaqua.jar and install it in ~/Library/Java/Extensions or one of the other ext dirs.
- If you still can’t get the program working click HELP for more detail.
- If you can’t get the above Applet working after trying the advice above and from the HELP button below, have bugs to report or ideas to improve the program or its documentation, please send me an email at
.

| Package | Version | Released | Licence | Language | Notes | |
|---|

JDisplay |
4.4 |
2010-02-10 |
free |
Java |

zip for JDisplay Java source and compiled class files to run on your own machine as an Applet.
First install the most recent Java.
To install, extract the zip download with WinZip,
(or similar unzip utility) into any directory you please,
often J:\ — ticking off the
“user folder names” option. To check out the corresponding source from the Subversion repository, use the TortoiseSVN repo-browser to access jdisplay source in repository with [Tortoise] Subversion client on wush.net/svn/mindprod/com/mindprod/jdisplay/.
download ASP PAD XML program description for the current version of JDisplay.
JDisplay is free.
Full source included.
You may even include the source code, modified or unmodified
in commercial programs that you write and distribute. Non-military use only. |
|
|
| |
|---|
Directory Structure
Let’s say your html lives in:
E:\mindprod\jgloss
Then the corresponding program listing snippets will live in:
E:\mindprod\jgloss\snippet
the generated *.ser files live in
E:\mindprod\jgloss\snippet\ser
and the generated iframe *.html files will live in
E:\mindprod\jgloss\snippet\iframe
All off this must be uploaded to your website.
Resolving Problems
All code should be included with the exception of the htmlmacros package. If you find
something missing you can probably download it. In any case, please let me know, so I
can include it.
If you have questions, please feel free to ask at
. It will help me put together some
minimalist documentation. If you are interested in using JDisplay in other contexts (e.g. without htmlmacros), I will be willing to help and write interfacing code at no charge. One PhD student from
Germany has used JDisplay to automatically colourise source code listings embedded in JavaDoc. He has not yet
publicly released the code. I wrote JDisplay originally primarily to demonstrate my vision of the future of what
program listings should look like in advanced editors that I call SCIDs. I would love to see JDisplay-like logic in an IDE editor.