Home   Java   Email 

Syntax Highlighter

  Demo
The Source Code
Download
Security
 About the Program
Syntax Highlighter is a Java program which marks up program source code as it is edited. Currently Java and C++ source code is recognized.

The program is written in Java, and demonstrates the following Swing components:

  • Multiple Document Interface (MDI), using JInternalFrame and JMenu,
  • JToolBar and toolTips,
  • Documents and Views,
  • JButton, JCheckBox, JList and JComboBox (highlight properties).
  • The program allows several document windows, with a common menu and tool bar. The menu contains the usual File, Edit and Window items. On the File menu, Save and Save As are not implemented.
    In a browser, the File|Open and Edit clipboard functions will by default be disabled. They can be enabled by granting the approprite access permissions explicitly. See the section on Security.

    The Highlight menu lists the available highlighters: Java, C++ or Plain Text. Each has a sub-menu, with items Apply and Properties.

    Apply attaches the selected highlighter to the current document window. Properties presents a window in which the highlighters properties may be viewed and changed.

    The Options menu lets you choose a Swing-provided Look & Feel, and change the menu font sizes.

      About
    The Source Code
    Download
    Security
     Run the Demonstration
    There are two versions of the demo: the Plugin and the Applet.

    The plugin demo

    This version uses the Java Runtime Environment (JRE) Plugin 1.2.1. If you do not have the plugin, your browser may ask if you wish to download it now (about 10Mb download).

    The program has been tested with Internet Explorer 3.02 and 5.00, and with Netscape 4.51. It takes some time to load: the program file is 140k.

    The applet demo

    The applet version requires a browser which supports Java 1.2.1. It has been tested with appletviewer, but not with any browser.

      About
    Demo
    Download
    Security
     Download the Source Code
    Here is the source code: a zip file of about 80k:

    The Java source code

    (Copyright Nick Lawson.)

      About
    The Source Code
    Demo
    Security
     Download the Program
    If you have a Java Runtime Environment 1.2.1 (JRE 1.2.1) you can download the program and run it locally. This should work with any system with this JRE. It even works with the linux pre-1.2.2 (up to a point...)

    The download is a jar file.

    Download the program jar file (140k)
    And to run it, CD to the directory containing the downloaded file and type:
    java -jar token.jar
    at the command prompt.

    Most likely however, you will want to restrict the permissions for this untrusted code. See the section on Security.

      About
    Demo
    The Source Code
    Download
     Security Considerations
    If you download the program you may want to limit its permissions, and conversely you may want to give the plugin demonstration file read access.

    In all JRE1.2 environments, i.e. command-line, appletviewer, and browser plugin, the permissions and consequently the enabled menu items, are determined by the content of the java security policy file .java.policy. This sample .java.policy file contains all the relevant permissions for both command line and browser environments. Unwanted permissions can be deleted or commented out.

    These permissions can be created using policytool (in jdk/bin).

    Note that a browser must be stopped and restarted for changed permissions to take effect.

    To run the downloaded program from the command line with these permissions in effect, rather than the default, which is all permissions, cd to the directory containing the downloaded nrl.jar file and use

    java -Djava.security.manager -jar token.jar
    To run the downloaded program using appletviewer with these permissions in effect, rather than the sandbox default, cd to the directory containing the downloaded token.jar file and use
    appletviewer -J-Djava.security.manager demoPage.html
    where demoPage.html is a saved copy of the applet or plugin page.


       Home   Java   Email