/** * Navigator.java 1.00 96/10/07 Merlin Hughes * * Copyright (c) 1996 Prominence Dot Com, Inc. All Rights Reserved. * * Permission to use, copy, modify, and distribute this software * for non-commercial purposes and without fee is hereby granted * provided that this copyright notice appears in all copies. * * http://prominence.com/ merlin@prominence.com */ import java.awt.*; import java.net.*; import java.io.*; import java.util.*; public class Navigator extends Frame implements Runnable { Sextant parent; Page page; Scrollbar bar; Label status; Button go; String target; public Navigator () { super ("Sextant Navigator"); setBackground (Color.black); setLayout (new BorderLayout (1, 1)); Panel top = new Panel (); top.setBackground (Color.white); top.setLayout (new BorderLayout ()); add ("Center", top); bar = new Scrollbar (Scrollbar.VERTICAL); top.add ("East", bar); page = new Page (bar); page.setFont (new Font ("Helvetica", Font.BOLD, 14)); top.add ("Center", page); Panel bottom = new Panel (); bottom.setBackground (Color.white); bottom.setLayout (new BorderLayout ()); add ("South", bottom); status = new Label ("Loading..."); status.setForeground (Color.blue); status.setFont (new Font ("Helvetica", Font.PLAIN, 14)); bottom.add ("Center", status); go = new Button ("Go!"); go.setFont (new Font ("Helvetica", Font.BOLD, 14)); bottom.add ("East", go); } public void init (Sextant parent) { this.parent = parent; target = parent.getParameter ("target", "_new"); if (parent.getParameter ("title") != null) setTitle (parent.getParameter ("title")); page.init (parent); new Thread (this).start (); } public void run () { try { URL url = new URL (parent.getDocumentBase (), parent.getParameter ("map", "siteMap.txt")); InputStream i = url.openStream (); DataInputStream dI = new DataInputStream (i); String line; while ((line = dI.readLine ()) != null) { StringTokenizer tokens = new StringTokenizer (line, "|"); try { String lineUrl = tokens.nextToken ().trim (), lineName = tokens.nextToken ().trim (), lineComment = tokens.nextToken ().trim (); int depth = 0; while (lineUrl.charAt (depth) == '-') ++ depth; page.addLine (depth, new URL (parent.getDocumentBase (), lineUrl.substring (depth)), lineName, lineComment); } catch (Exception ex) { System.out.println ("Misformatted line: " + line); } } dI.close (); status.setText ("Loaded."); page.layout (); page.repaint (); } catch (IOException ex) { status.setText (ex.toString ()); } } public boolean handleEvent (Event e) { if ((e.id == -1) && (e.target == this)) { init ((Sextant) e.arg); } else if ((e.id == Event.WINDOW_DESTROY) && (e.target == this)) { hide (); } else if ((e.id == Event.ACTION_EVENT) && (e.target == go)) { URL url = page.currentURL (); if (url != null) parent.getAppletContext ().showDocument (url, target); } else if ((e.id == Event.LIST_SELECT) && (e.target == page)) { status.setText ((String) e.arg); } else if ((e.id == Event.ACTION_EVENT) && (e.target == page)) { parent.getAppletContext ().showDocument ((URL) e.arg, target); } else if ((e.target == bar) && (e.id >= Event.SCROLL_LINE_UP) && (e.id <= Event.SCROLL_ABSOLUTE)) { page.repaint (); } return super.handleEvent (e); } public Dimension preferredSize () { return new Dimension (320, 240); } }