// ==========================================================================
// $Id: TCOption.java,v 1.4 2002/09/09 20:12:31 hitoshi Exp $
// TCOption : command line option for TimerClock
// ==========================================================================
// Copyright (C) 2002 Yamauchi, Hitoshi
//
//   Max-Planck-Institut fuer Informatik AG4
//   Stuhlsatzenhausweg 85, 66123 Saarbruecken
//   http://www.mpi-sb.mpg.de/
// 
// This software can be redistributed only under GNU copyleft.
//
// @author Yamauchi Hitoshi »³Æâ ÀÆ
// ==========================================================================
// $Revision: 1.4 $
// $Date: 2002/09/09 20:12:31 $
// $Author: hitoshi $
// ==========================================================================
package de.mpg.mpisb.timerclock;

import  java.util.*;

/**
 * TCOption : command line option (switch)
 */
public final class TCOption extends OptionMap
{
  /*
   * constants
   */
  public static final String ProgramName  = "Timer Clock";
  public static final String VersionStr   = "version 0.1.1 : 2002-9-9(Mon)";
  public static final String CopyrightStr = "Copyright (C) 2002 Yamauchi Hitoshi";

  /**
   * constructor
   */
  public TCOption()
  {
    Option[] options = 
    {
      // mode
      new Option("help",    	"h",  Option.NO_ARG, Option.BOOLEAN, null, 
		 "print help message"),
      new Option("version",   	"V",  Option.NO_ARG, Option.BOOLEAN, null, 
		 "Show this version"),
      new Option("verbose", 	"v",  Option.NO_ARG, Option.BOOLEAN, 
		 new Boolean(false), 
		 "verbose mode"),
      // time
      new Option("period", 	"p",  Option.REQUIRED_ARG, Option.INT, 
		 new Integer(600), "set the period (seconds)"),
      // font
      new Option("font-name", 	"f",  Option.REQUIRED_ARG, Option.STRING,
		 new String("TimesRoman"), "font family name"),
      new Option("font-italic",	"i",  Option.REQUIRED_ARG, Option.BOOLEAN, 
		 new Boolean(false), "italic if true"),
      new Option("font-bold",	"b",  Option.REQUIRED_ARG, Option.BOOLEAN,
		 new Boolean(false), "bold face if true"),
    };

    this.setOptions(options);
  }

  /**
   * usage and exit for TimerClock
   */
  public void usage()
  {
    String s = ProgramName + "\n" +
      Option.getHelpString("\t", this.peekOptions()) + "\n" + 
      CopyrightStr + " " + VersionStr;
    System.err.println(s);
    System.exit(1);
  }

  /*
   * test for TCOption
   */
  public static void main(String [] arg)
  {
    TCOption opt = new TCOption();
    opt.getOpts(arg);
    if(opt.get("help") != null)
    {
      opt.usage();
    }
    if(opt.get("version") != null)
    {
      String s = ProgramName + " " + CopyrightStr + " " + VersionStr;
      System.out.println(s);
      System.exit(1);      
    }
    System.out.println(opt.toString());
  }
}
