Chapter 2. Quick Start

Table of Contents

This chapter will introduce the reader to the use of the Templates plugin by walking the user through the creation of several related Templates which exploit the dynamic capabilities of the Velocity engine embedded within the plugin. Since jEdit is an application developed in Java, this tutorial will describe the creation of a number of templates intended to facilitate the creation of Java classes.

Our Starting Point

Java Joe, our hypothetical programmer, writes Java code for a living. Like most programmers, he's always on the lookout for ways to increase his efficiency. He's been using jEdit as his development environment, and has created some static templates for use with the Templates plugin to provide a starting point for his Java classes. Although static files help to kickstart his projects, he finds himself wishing that the templates were more dynamic. He's heard that this sort of functionality has been added to the Templates plugin and decides to try to make use of this new functionality in his custom templates.

The templates that Joe has created include:

  • Java class skeleton

  • Generic method template

  • Accessor/Mutator (Getter/Setter) template

  • Copyright/license notice

The Java class skeleton contains the following code:

package com.javajoe.mypackage;

import javax.swing.*;
/**
 * Class description goes here
 */
public class SomeClass extends Parent implements InterfaceList
{
	// Insert class variables here

	public static void main(String[] args) {
		// Main method
	}

	//Constructors
	public SomeClass() {
		super();
	}
	
	// Accessors & Mutators
	
	// Implementors
}

The method template looks like this:

    /**
     * Method comment goes here
     */
    public void doSomething(paramType paramName) {
    }

The accessor/mutator template looks like this:

    /**
     * Accessor comment
     */
    public returnType getVariable() {
        return variable;
    }

    /**
     * Mutator comment
     */
    public void setVariable(paramType paramName) {
        this.variable = paramName;
    }

Finally, the license template contains the following:

/*
 * MyClass.java
 *
 * Copyright (c) 2002 Java Joe
 * Give my code a good home.
 */

Typically, Joe would perform the following steps during the creation of a new Java class:

  1. Call the Java class template to create the class skeleton.

  2. Modify the code by changing the package, adding required import statments, adding the class name, superclass (if required), interfaces (if required), and code for the main() method and constructor.

  3. Move the cursor to the top of the file and call the template for the copyright/license notice.

  4. Add class variables beneath "Insert class variables here".

  5. Run the accessor/mutator template as required to create getters/setters for the class variables (in the "Accessors & Mutators" section.

  6. Add methods as required to the "Implementors" section using the generic method template.