All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ca.odell.glazedlists.impl.Main Maven / Gradle / Ivy

There is a newer version: 1.9.1
Show newest version
/* Glazed Lists                                                 (c) 2003-2006 */
/* http://publicobject.com/glazedlists/                      publicobject.com,*/
/*                                                     O'Dell Engineering Ltd.*/
package ca.odell.glazedlists.impl;

import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.net.URL;
import java.util.Map;
import java.util.jar.Attributes;
import java.util.jar.Manifest;

/**
 * Show version information for the current .jar file.
 *
 * 

This requires a some special attributes in the manifest to work: *

  • Built-By, the person who made this build *
  • Built-At, the time this build was created *
  • Contributors, a comma-separated list of developers * *

    Plus some standard manifest attributes are used: *

  • Implementation-Title *
  • Implementation-URL *
  • Implementation-Version * * @author Jesse Wilson */ public class Main { public static void main(String[] args) { final String PATH_TO_THIS_CLASS = "/ca/odell/glazedlists/impl/Main.class"; // find the main attributes from the manifest final Map attributes; try { // get a path to the manifest, or die trying String pathToThisClass = Main.class.getResource(PATH_TO_THIS_CLASS).toString(); int jarDelimiterCharacter = pathToThisClass.lastIndexOf("!"); if(jarDelimiterCharacter == -1) return; String manifestPath = pathToThisClass.substring(0, jarDelimiterCharacter + 1) + "/META-INF/MANIFEST.MF"; URL manifestUrl = new URL(manifestPath); // load the manifest and save the attributes of interest Manifest manifest = new Manifest(manifestUrl.openStream()); attributes = manifest.getMainAttributes(); } catch(IOException e) { return; } // the title String title = (String)attributes.get(Attributes.Name.IMPLEMENTATION_TITLE); String titleHtml = "" + title + ""; // the url String urlHtml = (String)attributes.get(Attributes.Name.IMPLEMENTATION_URL); // the version String versionHtml = (String)attributes.get(Attributes.Name.IMPLEMENTATION_VERSION); // when it was built StringBuffer builtHtml = new StringBuffer(); builtHtml.append(attributes.get(new Attributes.Name("Built-By"))); builtHtml.append("
    "); builtHtml.append(attributes.get(new Attributes.Name("Built-At"))); builtHtml.append("
    "); builtHtml.append("Source: ").append(attributes.get(new Attributes.Name("Source-Version"))); // the contributors String contributorsHtml = (String)attributes.get(new Attributes.Name("Contributors")); contributorsHtml = contributorsHtml.replaceAll(",\\s*", "
    "); // lay it all out on a panel JFrame frame = new JFrame(title); frame.getContentPane().setLayout(new GridBagLayout()); frame.getContentPane().add(new JLabel("" + titleHtml + ""), new GridBagConstraints(0, 0, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 10, 10, 10), 0, 0)); frame.getContentPane().add(new JLabel("" + urlHtml + ""), new GridBagConstraints(0, 1, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets( 0, 10, 10, 10), 0, 0)); frame.getContentPane().add(new JLabel("Version:"), new GridBagConstraints(0, 2, 1, 1, 0.5, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(10, 10, 10, 10), 0, 0)); frame.getContentPane().add(new JLabel("" + versionHtml + ""), new GridBagConstraints(1, 2, 1, 1, 0.5, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(10, 10, 10, 10), 0, 0)); frame.getContentPane().add(new JLabel("Built:"), new GridBagConstraints(0, 3, 1, 1, 0.5, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(10, 10, 10, 10), 0, 0)); frame.getContentPane().add(new JLabel("" + builtHtml + ""), new GridBagConstraints(1, 3, 1, 1, 0.5, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(10, 10, 10, 10), 0, 0)); frame.getContentPane().add(new JLabel("Contributors:"), new GridBagConstraints(0, 4, 1, 1, 0.5, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(10, 10, 10, 10), 0, 0)); frame.getContentPane().add(new JLabel("" + contributorsHtml + ""), new GridBagConstraints(1, 4, 1, 1, 0.5, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(10, 10, 10, 10), 0, 0)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } }




  • © 2015 - 2024 Weber Informatics LLC | Privacy Policy