home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-03-31 | 8.8 KB | 290 lines |
- /*
- * Demo.java
- *
- * Copyright (c) 1997 Oracle Corp, Inc. All Rights Reserved.
- *
- * Oracle grants you ("Licensee") a non-exclusive, royalty free, license
- * to use, modify and redistribute this software in source and binary code
- * form, provided that i) this copyright notice and license appear on all
- * copies of the software; and ii) Licensee does not utilize the software
- * in a manner which is disparaging to Oracle.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
- * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
- * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. ORACLE AND ITS LICENSORS SHALL NOT BE
- * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
- * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL ORACLE OR ITS
- * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
- * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
- * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
- * OR INABILITY TO USE SOFTWARE, EVEN IF ORACLE HAS BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * This software is not designed or intended for use in on-line control of
- * aircraft, air traffic, aircraft navigation or aircraft communications; or in
- * the design, construction, operation or maintenance of any nuclear
- * facility. Licensee represents and warrants that it will not use or
- * redistribute the Software for such purposes.
- */
-
- package oracle.help;
-
- // imports
- import java.net.URL;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.BorderLayout;
- import java.awt.Label;
- import java.awt.Button;
- import java.awt.Color;
- import java.awt.Cursor;
- import java.awt.MenuBar;
- import java.awt.Menu;
- import java.awt.MenuItem;
- import java.awt.FlowLayout;
- import java.awt.Frame;
- import java.awt.List;
- import java.awt.Panel;
- import java.awt.event.WindowEvent;
- import java.awt.event.WindowAdapter;
-
- // Help classes
- import oracle.help.Book;
- import oracle.help.Help;
-
- // Ewt classes
- import oracle.ewt.EwtContainer;
- import oracle.ewt.border.Border;
- import oracle.ewt.graphics.frame.PlainFramePainter;
- import oracle.ewt.graphics.frame.FramePainter;
- import oracle.ewt.border.GroupBoxBorder;
-
-
- /*
- * Demo class - a simple demo that calls Oracle Help for Java for help.
- */
- public class Demo implements ActionListener
- {
- /**
- * Creates a new instance of Demo.
- */
- public Demo(String base, String filebase)
- {
- // create a frame
- _frame = new Frame("Help Demo");
-
- /*
- * Initialize the help system
- */
- // create a help object
- _help = new Help();
-
- // Create a help book
- _book = Help.createBook(base, filebase, "Sample Doc");
- if (_book == null)
- {
- System.out.println("Failed to create the book");
- System.exit(0);
- }
-
- // Add the book to the help system
- _help.addBook(_book);
-
- /*
- * Create a menubar and populate it with File and Help menus
- */
- MenuBar menubar = new MenuBar();
-
- // File menu
- Menu filemenu = new Menu(FILE);
- _exitMenuitem = new MenuItem(EXIT);
- filemenu.add(_exitMenuitem);
- _exitMenuitem.addActionListener(this);
- menubar.add(filemenu);
-
- // Help menu
- Menu helpmenu = new Menu("Help");
- _contentsMenuitem = new MenuItem(CONTENTS);
- _contentsMenuitem.addActionListener(this);
- helpmenu.add(_contentsMenuitem);
- _indexMenuitem = new MenuItem(INDEX);
- _indexMenuitem.addActionListener(this);
- helpmenu.add(_indexMenuitem);
- _searchMenuitem = new MenuItem(SEARCH);
- _searchMenuitem.addActionListener(this);
- helpmenu.add(_searchMenuitem);
- menubar.add(helpmenu);
- _showAllMenuitem = new MenuItem(SHOWALL);
- _showAllMenuitem.addActionListener(this);
- helpmenu.add(_showAllMenuitem);
- _hideAllMenuitem = new MenuItem(HIDEALL);
- _hideAllMenuitem.addActionListener(this);
- helpmenu.add(_hideAllMenuitem);
-
- _frame.setMenuBar(menubar);
- _frame.setBackground(Color.lightGray);
-
-
- /* Create a groupbox for contents, index and search */
- EwtContainer north = new EwtContainer();
- _contentsButton = new Button(CONTENTS);
- _contentsButton.addActionListener(this);
- north.add(_contentsButton);
- _indexButton = new Button(INDEX);
- _indexButton.addActionListener(this);
- north.add(_indexButton);
- _searchButton = new Button(SEARCH);
- _searchButton.addActionListener(this);
- north.add(_searchButton);
- north.setBorder(new GroupBoxBorder("Java Help Views",
- PlainFramePainter.getFramePainter(), 1));
- _frame.add(north, BorderLayout.NORTH);
-
-
- /* create a groupbox for the topic buttons */
- EwtContainer center = new EwtContainer();
- _topicButtons = new Button[TOPICS.length];
- for (int i = 0; i < TOPICS.length; i++)
- {
- _topicButtons[i] = new Button(TOPICS[i]);
- _topicButtons[i].addActionListener(this);
- center.add(_topicButtons[i]);
- }
- center.setBorder(new GroupBoxBorder("Buttons for context-sensitive help",
- PlainFramePainter.getFramePainter(), 1));
- _frame.add(center, BorderLayout.CENTER);
-
- _frame.setSize(350, 180);
- _frame.setResizable(false);
- _frame.validate();
- _frame.setVisible(true);
-
- // add a listener to handle window-close events
- _frame.addWindowListener(
- new WindowAdapter()
- {
- public void windowClosing(WindowEvent e)
- {
- System.exit(0);
- }
- }
- );
- }
-
- /*
- * ActionListener implementation to display help.
- */
- public void actionPerformed(ActionEvent e)
- {
- Object source = e.getSource();
-
- /* handle the menu events here */
- if (source == _exitMenuitem)
- {
- System.exit(0);
- }
- else if ((source == _contentsMenuitem) ||
- (source == _contentsButton))
- {
- _help.showContents();
- }
- else if ((source == _indexMenuitem) ||
- (source == _indexButton))
- {
- _frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
- _help.showIndex();
- _frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
- }
- else if ((source == _searchMenuitem) ||
- (source == _searchButton))
- {
- _help.showSearch();
- }
- else if (source == _showAllMenuitem)
- {
- _help.setVisible(true);
- }
- else if (source == _hideAllMenuitem)
- {
- _help.setVisible(false);
- }
- /* handle rest of the button events here */
- else if (source instanceof Button)
- {
- String topic = ((Button) source).getLabel();
- _frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
- _help.showTopic(_book, topic);
- _frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
- }
- }
-
- public static void main(String[] args)
- {
- String basename = null;
- String path;
-
- // If there are two command-line arguments, then use them as the
- // baseURL and the basename.
- if (args.length != 2)
- {
- path = args[0];
- basename = args[1];
- }
- else
- {
- // Look for install.root environment variable; If it is defined
- // then use that as the baseURL and "demodoc" as the basename.
- path = System.getProperty("install.root");
- if (path == null)
- {
- System.out.println("Demo baseURL baseName");
- System.out.println("Example : Demo file:/doc discoverer");
- System.exit(0);
- }
- else
- {
- String basestring = "file://";
- String separator = System.getProperty("file.separator");
- if (separator.equals("\\"))
- basestring = "file:///";
- path = basestring + path + "demodoc" + separator;
- basename = "discoverer";
- }
- }
-
- try
- {
- Demo demo = new Demo(path, basename);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
- // instance variables
- private Help _help; // help object
- private Book _book; // help book
- private Frame _frame; // demo frame
- private Button _contentsButton, _indexButton, _searchButton;
- private Button _topicButtons[];
- private MenuItem _exitMenuitem, _contentsMenuitem, _searchMenuitem,
- _indexMenuitem, _showAllMenuitem, _hideAllMenuitem;
-
-
- // menu labels
- private static final String FILE = "File";
- private static final String EXIT = "Exit";
- private static final String CONTENTS = "Show Contents ...";
- private static final String INDEX = "Show Index ..";
- private static final String SEARCH = "Search ..";
- private static final String SHOWALL = "Show Help System";
- private static final String HIDEALL = "Hide Help System";
-
- // context-sensitive topics - these topics must exist in the OHT file.
- private static final String[] TOPICS = {
- "topic1", "topic2", "topic3", "topic4", "topic5",
- "topic6", "topic7", "topic8", "topic9", "topic10",};
- }
-