home *** CD-ROM | disk | FTP | other *** search
/ Oracle Video Server 3.0.3.1 / OracleVideoServerManager3.0.3.1.iso / vsmc30 / vsm.jar / oracle / help / Demo.java < prev    next >
Encoding:
Java Source  |  1998-03-31  |  8.8 KB  |  290 lines

  1. /*
  2.  * Demo.java
  3.  *
  4.  * Copyright (c) 1997 Oracle Corp, Inc. All Rights Reserved.
  5.  *
  6.  * Oracle grants you ("Licensee") a non-exclusive, royalty free, license
  7.  * to use, modify and redistribute this software in source and binary code
  8.  * form, provided that i) this copyright notice and license appear on all
  9.  * copies of the software; and ii) Licensee does not utilize the software
  10.  * in a manner which is disparaging to Oracle.
  11.  *
  12.  * This software is provided "AS IS," without a warranty of any kind. ALL
  13.  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
  14.  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  15.  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. ORACLE AND ITS LICENSORS SHALL NOT BE
  16.  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  17.  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL ORACLE OR ITS
  18.  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
  19.  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
  20.  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
  21.  * OR INABILITY TO USE SOFTWARE, EVEN IF ORACLE HAS BEEN ADVISED OF THE
  22.  * POSSIBILITY OF SUCH DAMAGES.
  23.  *
  24.  * This software is not designed or intended for use in on-line control of
  25.  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
  26.  * the design, construction, operation or maintenance of any nuclear
  27.  * facility. Licensee represents and warrants that it will not use or
  28.  * redistribute the Software for such purposes.
  29.  */
  30.  
  31. package oracle.help;
  32.  
  33. // imports
  34. import java.net.URL;
  35. import java.awt.event.ActionEvent;
  36. import java.awt.event.ActionListener;
  37. import java.awt.BorderLayout;
  38. import java.awt.Label;
  39. import java.awt.Button;
  40. import java.awt.Color;
  41. import java.awt.Cursor;
  42. import java.awt.MenuBar;
  43. import java.awt.Menu;
  44. import java.awt.MenuItem;
  45. import java.awt.FlowLayout;
  46. import java.awt.Frame;
  47. import java.awt.List;
  48. import java.awt.Panel;
  49. import java.awt.event.WindowEvent;
  50. import java.awt.event.WindowAdapter;
  51.  
  52. // Help classes
  53. import oracle.help.Book;
  54. import oracle.help.Help;
  55.  
  56. // Ewt classes
  57. import oracle.ewt.EwtContainer;
  58. import oracle.ewt.border.Border;
  59. import oracle.ewt.graphics.frame.PlainFramePainter;
  60. import oracle.ewt.graphics.frame.FramePainter;
  61. import oracle.ewt.border.GroupBoxBorder;
  62.  
  63.  
  64. /*
  65.  * Demo class - a simple demo that calls Oracle Help for Java for help.
  66.  */
  67. public class Demo implements ActionListener
  68. {
  69.   /**
  70.    * Creates a new instance of Demo.
  71.    */
  72.   public Demo(String base, String filebase)
  73.   {
  74.     // create a frame
  75.     _frame = new Frame("Help Demo");
  76.  
  77.     /*
  78.      * Initialize the help system
  79.      */
  80.     // create a help object
  81.     _help = new Help(); 
  82.  
  83.     // Create a help book
  84.     _book = Help.createBook(base, filebase, "Sample Doc");
  85.     if (_book == null)
  86.     {
  87.       System.out.println("Failed to create the book");
  88.       System.exit(0);
  89.     }
  90.  
  91.     // Add the book to the help system
  92.     _help.addBook(_book);
  93.  
  94.     /*
  95.      * Create a menubar and populate it with File and Help menus 
  96.      */
  97.     MenuBar menubar = new MenuBar();
  98.  
  99.     // File menu
  100.     Menu    filemenu    =  new Menu(FILE);
  101.     _exitMenuitem = new MenuItem(EXIT);
  102.     filemenu.add(_exitMenuitem);
  103.     _exitMenuitem.addActionListener(this);
  104.     menubar.add(filemenu);
  105.  
  106.     // Help menu
  107.     Menu helpmenu = new Menu("Help");
  108.     _contentsMenuitem = new MenuItem(CONTENTS);
  109.     _contentsMenuitem.addActionListener(this);
  110.     helpmenu.add(_contentsMenuitem);
  111.     _indexMenuitem    = new MenuItem(INDEX);
  112.     _indexMenuitem.addActionListener(this);
  113.     helpmenu.add(_indexMenuitem);
  114.     _searchMenuitem   = new MenuItem(SEARCH);
  115.     _searchMenuitem.addActionListener(this);
  116.     helpmenu.add(_searchMenuitem);
  117.     menubar.add(helpmenu);
  118.     _showAllMenuitem = new MenuItem(SHOWALL);
  119.     _showAllMenuitem.addActionListener(this);
  120.     helpmenu.add(_showAllMenuitem);
  121.     _hideAllMenuitem = new MenuItem(HIDEALL);
  122.     _hideAllMenuitem.addActionListener(this);
  123.     helpmenu.add(_hideAllMenuitem);
  124.  
  125.     _frame.setMenuBar(menubar);
  126.     _frame.setBackground(Color.lightGray);
  127.  
  128.  
  129.     /* Create a groupbox for contents, index and search */
  130.     EwtContainer north = new EwtContainer();
  131.     _contentsButton = new Button(CONTENTS);
  132.     _contentsButton.addActionListener(this);
  133.     north.add(_contentsButton);
  134.     _indexButton    = new Button(INDEX);
  135.     _indexButton.addActionListener(this);
  136.     north.add(_indexButton);
  137.     _searchButton   = new Button(SEARCH);
  138.     _searchButton.addActionListener(this);
  139.     north.add(_searchButton);
  140.     north.setBorder(new GroupBoxBorder("Java Help Views",
  141.                     PlainFramePainter.getFramePainter(), 1));
  142.     _frame.add(north, BorderLayout.NORTH);
  143.  
  144.  
  145.     /* create a groupbox for the topic buttons */
  146.     EwtContainer center = new EwtContainer();
  147.     _topicButtons = new Button[TOPICS.length];
  148.     for (int i = 0; i < TOPICS.length; i++)
  149.     {
  150.       _topicButtons[i] = new Button(TOPICS[i]);
  151.       _topicButtons[i].addActionListener(this);
  152.       center.add(_topicButtons[i]);
  153.     }
  154.     center.setBorder(new GroupBoxBorder("Buttons for context-sensitive help",
  155.                     PlainFramePainter.getFramePainter(), 1));
  156.     _frame.add(center, BorderLayout.CENTER);
  157.  
  158.     _frame.setSize(350, 180);
  159.     _frame.setResizable(false);
  160.     _frame.validate();
  161.     _frame.setVisible(true);
  162.  
  163.     // add a listener to handle window-close events
  164.     _frame.addWindowListener(
  165.       new WindowAdapter()
  166.       {
  167.         public void windowClosing(WindowEvent e)
  168.         {
  169.           System.exit(0);
  170.         }
  171.       }
  172.     );
  173.   }
  174.  
  175.   /*
  176.    * ActionListener implementation to display help.
  177.    */
  178.   public void actionPerformed(ActionEvent e)
  179.   {
  180.     Object source = e.getSource();
  181.  
  182.     /* handle the menu events here */
  183.     if (source == _exitMenuitem)
  184.     {
  185.       System.exit(0);
  186.     }
  187.     else if ((source == _contentsMenuitem) ||
  188.              (source == _contentsButton))
  189.     {
  190.       _help.showContents();
  191.     }
  192.     else if ((source == _indexMenuitem) ||
  193.              (source == _indexButton))
  194.     {
  195.       _frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
  196.       _help.showIndex();
  197.       _frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  198.     }
  199.     else if ((source == _searchMenuitem) || 
  200.              (source == _searchButton))
  201.     {
  202.       _help.showSearch();
  203.     }
  204.     else if (source == _showAllMenuitem)
  205.     {
  206.       _help.setVisible(true);
  207.     }
  208.     else if (source == _hideAllMenuitem)
  209.     {
  210.       _help.setVisible(false);
  211.     }
  212.     /* handle rest of the button events here */
  213.     else if (source instanceof Button)
  214.     {
  215.       String topic = ((Button) source).getLabel();
  216.       _frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
  217.       _help.showTopic(_book, topic);
  218.       _frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  219.     }
  220.   } 
  221.  
  222.   public static void main(String[] args)
  223.   {
  224.     String basename = null;
  225.     String path;
  226.  
  227.     // If there are two command-line arguments, then use them as the
  228.     // baseURL and the basename.
  229.     if (args.length != 2)
  230.     {
  231.       path = args[0];
  232.       basename = args[1];
  233.     }
  234.     else
  235.     {
  236.       // Look for install.root environment variable; If it is defined
  237.       // then use that as the baseURL and "demodoc" as the basename.
  238.       path = System.getProperty("install.root");
  239.       if (path == null)
  240.       {
  241.         System.out.println("Demo baseURL baseName");
  242.         System.out.println("Example : Demo file:/doc discoverer");
  243.         System.exit(0);
  244.       }
  245.       else
  246.       {
  247.         String basestring = "file://";
  248.         String separator = System.getProperty("file.separator");
  249.         if (separator.equals("\\"))
  250.           basestring = "file:///";
  251.         path = basestring + path + "demodoc" + separator;
  252.         basename = "discoverer";
  253.       }
  254.     }
  255.  
  256.     try
  257.     {
  258.       Demo demo = new Demo(path, basename);
  259.     }
  260.     catch (Exception e)
  261.     {
  262.       e.printStackTrace();
  263.     }
  264.   }
  265.  
  266.   // instance variables
  267.   private Help     _help;   // help object
  268.   private Book     _book;   // help book
  269.   private Frame    _frame;  // demo frame
  270.   private Button   _contentsButton, _indexButton, _searchButton;
  271.   private Button   _topicButtons[];
  272.   private MenuItem _exitMenuitem, _contentsMenuitem, _searchMenuitem,
  273.                    _indexMenuitem, _showAllMenuitem, _hideAllMenuitem;
  274.  
  275.  
  276.   // menu labels
  277.   private static final String FILE = "File";
  278.   private static final String EXIT = "Exit";
  279.   private static final String CONTENTS = "Show Contents ...";
  280.   private static final String INDEX    = "Show Index ..";
  281.   private static final String SEARCH   = "Search ..";
  282.   private static final String SHOWALL  = "Show Help System";
  283.   private static final String HIDEALL  = "Hide Help System";
  284.  
  285.   // context-sensitive topics - these topics must exist in the OHT file.
  286.   private static final String[] TOPICS = {
  287.     "topic1", "topic2", "topic3", "topic4", "topic5",
  288.     "topic6", "topic7", "topic8", "topic9", "topic10",};
  289. }
  290.