Centralized Variables in NetBeans IDE Strings Tables

In previous blog entries, and in the new NetBeans File Template Plug-in Tutorial, I describe how to create a branded file template. The file template is branded with the Sun Microsystems copyright text. However, I've just discovered a different way of branding a file. It's not the most efficient way of doing so, but it's fun because it's different. Maybe it will give you some ideas of doing other similar things.

There are really only two steps to this process (which is another cool thing about this approach):

  1. Define copyright variables in a Strings Table. Go to Tools > Options. In the Options dialog box, expand Editing, select Java Sources, and click Strings Table. The Java Sources - Strings Table dialog box pops up. By default, only the USER variable is defined. So now, just add a string for each line of the copyright text, and include some spacing:

    COPYRIGHT1=
    COPYRIGHT2=
    COPYRIGHT3=Copyright (c) 2005 Sun Microsystems, Inc.  All rights reserved.  U.S.
    COPYRIGHT4=Government Rights - Commercial software.  Government users are subject
    COPYRIGHT5=to the Sun Microsystems, Inc. standard license agreement and
    COPYRIGHT6=applicable provisions of the FAR and its supplements.  Use is subject
    COPYRIGHT7=to license terms.
    COPYRIGHT8=
    COPYRIGHT9=This distribution may include materials developed by third parties.
    COPYRIGHT10=Sun, Sun Microsystems, the Sun logo, Java and J2EE are trademarks
    COPYRIGHT11=or registered trademarks of Sun Microsystems, Inc. in the U.S. and
    COPYRIGHT12=other countries.
    COPYRIGHT13=
    COPYRIGHT14=Copyright (c) 2005 Sun Microsystems, Inc. Tous droits reserves.
    COPYRIGHT15=
    COPYRIGHT16=

    My Strings Table now looks like this:

  2. Specify the copyright variables in a file template. Again in the Options dialog box, expand Source Creation and Management, expand Templates, and then find a Java template to which you want to add the copyright text. For example, expand Java Classes, select Java Class, right-click it and choose Open. The template opens in the Source Editor. Now add all the variables you defined to the template:

    /\*
     \* __NAME__.java
     \*
     \* Created on __DATE__, __TIME__
     \*
     \* __COPYRIGHT1__
     \* __COPYRIGHT2__
     \* __COPYRIGHT3__
     \* __COPYRIGHT4__
     \* __COPYRIGHT5__
     \* __COPYRIGHT6__
     \* __COPYRIGHT7__
     \* __COPYRIGHT8__
     \* __COPYRIGHT9__
     \* __COPYRIGHT10__
     \* __COPYRIGHT11__
     \* __COPYRIGHT12__
     \* __COPYRIGHT13__
     \* __COPYRIGHT14__
     \* __COPYRIGHT15__
     \* __COPYRIGHT16__
     \*
     \*/
    
    package Templates.Classes;
    
    /\*\*
     \*
     \* @author __USER__
     \*/
    public class Class {
    
        /\*\* Creates a new instance of __NAME__ \*/
        public Class() {
        }
    
    }

When you save the file, you've changed the template. So when you create a new Java class in the New File wizard, all the variables above will be replaced by the values in the Strings Table. A question you might be asking right now is: "Why don't you just put the copyright text straight into the template? What's the point of defining all those variables in the Strings Table in the first place?" Good question. The answer: What happens if the copyright text changes? If I'd defined the copyright text in the template, I'd have to change it in the template -- as well as in every other template where I defined the copyright text. By defining the copyright text in the Strings Table, I've got one centralized place where I can edit the copyright text. (At the very least, COPYRIGHT3 and COPYRIGHT14 will change once a year!) Of course, what this approach doesn't support is the ability to share the file template with others -- that's where the NetBeans plug-ins come in handy because the end-product of plug-in development is a binary file that you can easily transfer to a colleague, via e-mail, disk, or shared server.

Comments:

Good work! It looks like you are developing the NetBeans manual in these pages.

Posted by Miguel A Paraz on July 03, 2005 at 11:44 AM PDT #

Thanks Miguel. Are there any specific things you're interested in that you'd like me to blog about?

Posted by Geertjan on July 06, 2005 at 02:06 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today