//============================================================================== // AbstractVersion.java //============================================================================== package tribble.build; // System imports import java.awt.BorderLayout; import java.awt.Button; import java.awt.FlowLayout; import java.awt.Frame; import java.awt.GridLayout; import java.awt.Panel; import java.awt.TextField; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.lang.Package; import java.lang.Thread; import java.util.Date; /******************************************************************************* * Display the version information for a package. * *
* This abstract base class provides the capabilities to display version/build
* information for a package. Concrete classes that extend this base class must
* provide the actual version information. Such derived classes can be
* machine-generated; see {@link MakeVersionInfo}.
*
* @version $Revision: 1.7 $ $Date: 2007/07/13 04:18:52 $
* @since 2002-07-31
* @author
* David R. Tribble,
* david@tribble.com.
*
* Copyright ©2002 by David R. Tribble, all rights reserved.
*
* Permission is granted to freely use and distribute this source
* code provided that the original copyright and authorship notices remain
* intact.
*
* @see MakeVersionInfo
*/
public abstract class AbstractVersion
implements WindowListener, ActionListener
{
// Identification
/** Revision information. */
static final String REV =
"@(#)tribble/build/AbstractVersion.java $Revision: 1.7 $ $Date: 2007/07/13 04:18:52 $\n";
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Protected variables
/** The main GUI frame/window. */
protected Frame m_frame;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Private variables
/***************************************************************************
* Execute this class.
*
* @param args
* Command line arguments.
*
* @param vs
* Version information, which should be an object of a class derived from
* this class ({@link AbstractVersion}).
*
* @since 1.6, 2002-11-03
*/
public static void run(String[] args, AbstractVersion vs)
{
if (args.length > 0)
vs.showText();
else
vs.showGui();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Public static methods
// (None)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Public methods
/***************************************************************************
* Retrieve the component name.
*
* @return
* The name (or title) of the component.
*
* @since 1.1, 2002-07-31
*/
public abstract String getName();
/***************************************************************************
* Retrieve the package name.
*
* @return
* The name of the package, e.g. "my.package.name".
*
* @since 1.1, 2002-07-31
*/
public abstract String getPackage();
/***************************************************************************
* Retrieve the version string.
*
* @return
* The version number of the package.
* This is typically of the form "M.m.u.p".
*
* @since 1.1, 2002-07-31
*/
public abstract String getVersion();
/***************************************************************************
* Retrieve the major release number.
*
* @return
* The major version number of the package.
* This is typically the first number of the whole version number.
*
* @since 1.1, 2002-07-31
*/
public abstract int getMajor();
/***************************************************************************
* Retrieve the minor release number.
*
* @return
* The minor version number of the package.
* This is typically the second number of the whole version number.
*
* @since 1.1, 2002-07-31
*/
public abstract int getMinor();
/***************************************************************************
* Retrieve the patch number/name.
*
* @return
* The patch number or name of the package.
*
* @since 1.1, 2002-07-31
*/
public abstract String getPatch();
/***************************************************************************
* Retrieve the build date.
*
* @return
* The date that the package was compiled.
*
* @since 1.1, 2002-07-31
*/
public abstract Date getBuildDate();
/***************************************************************************
* Retrieve the build date.
*
* @return
* The date that the package was compiled as a string in ISO-8601 format
* ("YYYY-MM-DD HH:MM").
*
* @since 1.1, 2002-07-31
*/
public abstract String getIsoBuildDate();
/***************************************************************************
* Retrieve the embedded 'what' string.
*
* @return
* A string containing one or more 'what' strings, each beginning with
* the prefix "@(#)" and ending with a suffix of "\n".
*
* @since 1.1, 2002-07-31
*/
public abstract String getWhatString();
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/***************************************************************************
* AWT window event: window is being closed.
*
* @param ev
* The AWT window event.
*
* @since 1.1, 2002-07-31
*/
public void windowClosing(WindowEvent ev)
// implements java.event.WindowListener
{
// The frame is being closed
closeMe();
}
/***************************************************************************
* AWT window event: window has been activated.
*
* @param ev
* The AWT window event.
*
* @since 1.1, 2002-07-31
*/
public void windowActivated(WindowEvent ev)
// implements java.event.WindowListener
{
// Do nothing
}
/***************************************************************************
* AWT window event: window has been closed.
*
* @param ev
* The AWT window event.
*
* @since 1.1, 2002-07-31
*/
public void windowClosed(WindowEvent ev)
// implements java.event.WindowListener
{
// Do nothing
}
/***************************************************************************
* AWT window event: window has been deactivated.
*
* @param ev
* The AWT window event.
*
* @since 1.1, 2002-07-31
*/
public void windowDeactivated(WindowEvent ev)
// implements java.event.WindowListener
{
// Do nothing
}
/***************************************************************************
* AWT window event: window has been deiconified (maximized).
*
* @param ev
* The AWT window event.
*
* @since 1.1, 2002-07-31
*/
public void windowDeiconified(WindowEvent ev)
// implements java.event.WindowListener
{
// Do nothing
}
/***************************************************************************
* AWT window event: window has been iconified (minimized).
*
* @param ev
* The AWT window event.
*
* @since 1.1, 2002-07-31
*/
public void windowIconified(WindowEvent ev)
// implements java.event.WindowListener
{
// Do nothing
}
/***************************************************************************
* AWT window event: window has been opened.
*
* @param ev
* The AWT window event.
*
* @since 1.1, 2002-07-31
*/
public void windowOpened(WindowEvent ev)
// implements java.event.WindowListener
{
// Do nothing
}
/***************************************************************************
* AWT window event: a window action has been performed.
*
* @param ev
* The AWT window event.
*
* @since 1.1, 2002-07-31
*/
public void actionPerformed(ActionEvent ev)
// implements java.event.ActionListener
{
// The 'close' button has been pressed
closeMe();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/***************************************************************************
* Display the version information (contained in the 'what' string) in
* text form to the standard output stream.
*
* @since 1.1, 2002-07-31
*/
public void showText()
{
String what;
Package pk;
// Retrieve the version information 'what' string
what = this.getWhatString();
// Display the 'what' string contents
for (int i = 1+4; i < what.length(); i++)
{
char ch;
ch = what.charAt(i);
if (ch == '\n')
{
System.out.println();
i += 4;
}
else
System.out.print(ch);
}
pk = this.getClass().getPackage();
if (pk != null)
{
String s;
s = pk.getSpecificationTitle();
s = (s != null ? s : "");
System.out.println("SpecificationTitle=" + s);
s = pk.getSpecificationVersion();
s = (s != null ? s : "");
System.out.println("SpecificationVersion=" + s);
s = pk.getSpecificationVendor();
s = (s != null ? s : "");
System.out.println("SpecificationVendor=" + s);
s = pk.getImplementationTitle();
s = (s != null ? s : "");
System.out.println("ImplementationTitle=" + s);
s = pk.getImplementationVersion();
s = (s != null ? s : "");
System.out.println("ImplementationVersion=" + s);
s = pk.getImplementationVendor();
s = (s != null ? s : "");
System.out.println("ImplementationVendor=" + s);
}
System.out.flush();
}
/***************************************************************************
* Display the version information (contained in the 'what' string) in
* GUI windowing form.
*
* @since 1.1, 2002-07-31
*/
public void showGui()
{
String what;
Panel p;
Panel p2;
Panel tp1;
Panel tp2;
TextField t1;
TextField t2;
Button b;
int n;
Package pk;
// Retrieve the version information 'what' string
what = this.getWhatString();
// Create a GUI frame/window
m_frame = new Frame("Version Information");
// Establish window event listeners
m_frame.addWindowListener(this);
// Create the main panel of the frame
p = new Panel(new BorderLayout());
m_frame.add(p);
n = 0;
for (int i = 1; i < what.length(); i++)
if (what.charAt(i) == '\n')
n++;
pk = this.getClass().getPackage();
if (pk != null)
n += 2*3;
// Create the left text field
tp1 = new Panel(new GridLayout(n, 1));
tp1.setEnabled(false);
p.add(tp1, BorderLayout.WEST);
// Create the right text field
tp2 = new Panel(new GridLayout(n, 1));
tp2.setEnabled(false);
p.add(tp2, BorderLayout.CENTER);
for (int i = 1; i < what.length(); i++)
{
TextField t;
String s;
int j;
if (what.charAt(i) == '@')
i += 4;
for (j = i; i < what.length(); i++)
if (what.charAt(i) == '=')
break;
s = what.substring(j, i);
t = new TextField(s);
t.setEditable(false);
tp1.add(t);
for (j = ++i; i < what.length(); i++)
if (what.charAt(i) == '\n')
break;
s = what.substring(j, i);
t = new TextField(s);
t.setEditable(false);
tp2.add(t);
}
// Display package information
if (pk != null)
{
TextField t;
String s;
int j;
s = "SpecificationTitle";
t = new TextField(s);
t.setEditable(false);
tp1.add(t);
s = pk.getSpecificationTitle();
s = (s != null ? s : "");
t = new TextField(s);
t.setEditable(false);
tp2.add(t);
s = "SpecificationVersion";
t = new TextField(s);
t.setEditable(false);
tp1.add(t);
s = pk.getSpecificationVersion();
s = (s != null ? s : "");
t = new TextField(s);
t.setEditable(false);
tp2.add(t);
s = "SpecificationVendor";
t = new TextField(s);
t.setEditable(false);
tp1.add(t);
s = pk.getSpecificationVendor();
s = (s != null ? s : "");
t = new TextField(s);
t.setEditable(false);
tp2.add(t);
s = "ImplementationTitle";
t = new TextField(s);
t.setEditable(false);
tp1.add(t);
s = pk.getImplementationTitle();
s = (s != null ? s : "");
t = new TextField(s);
t.setEditable(false);
tp2.add(t);
s = "ImplementationVersion";
t = new TextField(s);
t.setEditable(false);
tp1.add(t);
s = pk.getImplementationVersion();
s = (s != null ? s : "");
t = new TextField(s);
t.setEditable(false);
tp2.add(t);
s = "ImplementationVendor";
t = new TextField(s);
t.setEditable(false);
tp1.add(t);
s = pk.getImplementationVendor();
s = (s != null ? s : "");
t = new TextField(s);
t.setEditable(false);
tp2.add(t);
}
// Create the 'close' button
p2 = new Panel(new FlowLayout());
p.add(p2, BorderLayout.SOUTH);
b = new Button("Close");
b.addActionListener(this);
p2.add(b);
// Display the frame
m_frame.setSize(480, n*24+60);
m_frame.setLocation(240, 120);
m_frame.setVisible(true);
//m_frame.pack();
m_frame.show();
// Wait for the user to close the frame
try
{
synchronized (this)
{
///System.out.println("$ main: wait");
wait(1*60*60*1000L); // (A), wait 1 hr for a notify from (B)
}
}
catch (Exception ex)
{
// Ignore
}
// Terminate
m_frame.setVisible(false);
m_frame.dispose();
///System.out.println("$ main: done");
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Protected constructor methods
/***************************************************************************
* Default constructor.
*
* @since 1.1, 2002-07-31
*/
protected AbstractVersion()
{
// Do nothing
}
/*+REMOVED, 1.5 2002-10-30
/***************************************************************************
* Constructor.
*
* @param name
* The name of the AWT frame.
*
* @since 1.1, 2002-08-01
*\/
protected AbstractVersion(String name)
{
super(name);
}
+*/
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Private methods
/***************************************************************************
* Callback method to indicate that the GUI window for this program has been
* closed.
*
* @since 1.1, 2002-07-31
*
* @see #windowClosing
* @see #actionPerformed
*/
private void closeMe()
{
// Shut down the frame
synchronized (this)
{
///System.out.println("$ closeMe: notify");
this.notify(); // (b), thump main thread at (A)
}
}
}
// End AbstractVersion.java