Skip to main content

Showing licenses for your application

Posted by kirillcool on August 13, 2005 at 8:46 AM PDT

Most of the nowadays open-source and commercial products extensively use other products. Although the "not invented here" syndrome is infective, things such as look-and-feel, layout managers, graph libraries, reporting tools etc. are taken from well-known and actively maintained third party sites. These tools come in variety of licenses, most of which require you to include the corresponding licenses along with the executable version of your own library. Here is a graphical way to organize all licenses in one user-friendly window.

Here is a screenshot of license viewer for JAXB Workshop that uses ten other libraries (click screenshot to view full-scale version):


The left panel shows tree with all third-party libraries (the root is your own library). Libraries can be grouped (in screenshot above, JUNG library uses three other libraries, which are grouped under it). Each tree entry shows the library name and the license abbreviation. Clicking on a tree entry shows the corresponding license in the right text pane, along with the library name, library URL and license full name above the license.

The source for the license viewer can be found in the CVS repository at this link. Sample code for using the license viewer is:

    
LicenseDialog licenseDialog = new LicenseDialog(
  ownerFrame,      // your application frame
  "JAXB Workshop", // library name
  new LicenseDialog.LibraryDetails(
    "https://jaxb-workshop.dev.java.net/", // library URL
    LicenseDialog.LicenseType.BSD,         // license enum
    "license/bsd_license.txt"));           // resource name for license text

The license viewer comes with about ten pre-defined licenses (such as Apache, BSD, LGPL etc.), which can be referenced using enum value as above. For licenses that are not pre-defined:

     
licenseDialog.addNewRootLibrary(
  "SJSXP",  // library name
  new LicenseDialog.LibraryDetails(
    "https://sjsxp.dev.java.net/",                   // library URL
    "Sun BCL",                                       // license abbreviation
    "Sun Binary Code License",                       // license full name
    LicenseDialog.LicenseType.getLicenseIcon("10"),  // icon for license entry in the tree
    "license/sun_bcl_license.txt"));                 // resource name for license text

The license viewer provides a helper function for creating standard-looking icon (getLicenseIcon used above). For defining library groups:

     
licenseDialog.addNewChildLibrary(
    "JUNG",                   // parent library name
    "Commons Collections",    // library name
    new LicenseDialog.LibraryDetails(
      "http://jakarta.apache.org/commons/collections/",   // library URL
      LicenseDialog.LicenseType.APACHE2,                  // license enum
      "license/apache2_license.txt"));                    // resource name for license text

As can be seen, you are responsible for bundling the license text itself as a resource with your application.

     
licenseDialog.expandAll(true);
licenseDialog.setLicenseTextAreaFont(
   new Font("Tahoma", Font.PLAIN, 12));

These two functions expand all branches in the license tree and set font for the license text pane. Finally, set preferred size and location for the license viewer and show it:

     
Dimension dim = new Dimension(800, 600);
licenseDialog.setSize(dim);
licenseDialog.setPreferredSize(dim);
licenseDialog.setResizable(false);
licenseDialog.pack();
licenseDialog.setLocation(...);
licenseDialog.setVisible(true);

You can see the license viewer in action by WebStarting this link (requires JVM 5.0+) and going to Help -> View licenses.

The next logical step would be to create a new project on java.net that will provide such viewer along with bundled versions of most-popular licenses. Volunteers (a slight chance to win immortal glory is implicitly guaranteed)?

Related Topics >>