FileDocCategorySizeDatePackage
TreeLink1_0.javaAPI DocExample3984Sun Dec 27 15:20:28 GMT 1998None

TreeLink1_0

public class TreeLink1_0 extends Applet
Applet GUI demo of Gamelan TreeLayout layout manager. Constructs a tree and, for each entry, makes a button that jumps to it. The input language is a file like this: R Java Resources # root L - Resources at Sun # label B http://www.sun.com/foo/bar Interesting Stuff # URLbutton B http://javasoft.com/b/c More Stuff # URLbutton The result is (supposedly) a beautiful(?) tree. Each L is a top-level label, and each B is in the tree below it. Could be made much fancier with getParameter("FontName"), "FontSize", adjusting width with fontMetrics, etc. Works adequately for now.

Fields Summary
Label
root
TreeLayout
tl
Label
l
Button
b
Hashtable
h
int
wid
int
ht
int
htIncr
Constructors Summary
Methods Summary
public booleanaction(java.awt.Event e, java.lang.Object o)

		URL u = (URL)h.get(e.target);
		showStatus("Showing document at URL " + u);

		getAppletContext().showDocument(u);
		// No error checking on showDocument() -- the
		// browser will honk at the user if the link
		// is invalid. We should open "u" ourselves,
		// check the open, and close it. Or not...

		return true;
	
protected voideprintln(java.lang.String s)

		System.err.println(s);
		showStatus("Error, see Java Console");
	
public java.lang.StringgetAppletInfo()
Return information about this applet.

		return "TreeLink1_0 Demo Applet\n" +
			"Copyright Learning Tree International";
	
public java.lang.String[][]getParameterInfo()
Return list of allowable parameters.

		String param_info[][] = {
			{"TreeLink1_0",    "filename",    "List of links"},
		};
		return param_info;
	
public voidinit()


	// Initialize this TreeLink1_0 applet
	   

		showStatus("TreeLink1_0 initializing tree...");

		URL origin = getCodeBase();

		h = new Hashtable();

		// Read the configuration file from the URL.
		try {

			setLayout(tl = new TreeLayout());

			String txt;
			String fn;	// Control file name
			if ((fn = getParameter("treelink")) == null)
				fn = "treelink.txt";
			URL ctlFile = new URL(origin, fn);
			DataInputStream is =
				new DataInputStream(ctlFile.openStream());

			// Read the control file a line at a time, parse
			// it, and save the ones that are links in 
			// the Hashtable indexed by their pushbutton

			while ((txt = is.readLine()) != null) {
				StringTokenizer st = new StringTokenizer(txt);
				if (st.countTokens() < 3) {
					println("TreeLink1_0: Bad input: " + txt);
					return;
				}
				String type = st.nextToken();
				String bURL = st.nextToken();
				String text = "";
				while (st.hasMoreTokens())
					text += st.nextToken() + " ";
				if (false)
					println("Type " + type + "; link " +
						bURL + "; text " + text);
				ht += htIncr;
				if (type.equals("R")) {
					add("root",
					root = new Label(text));
					root.setBackground(Color.pink);
					tl.setRoot(root);	// required!
				} else if (type.equals("L")) {
					add("label", l = new Label(text));
					l.setBackground(Color.pink);
					tl.setParent(l, root);
				} else if (type.equals("B")) {
					add("button", b = new Button(text));
					if (bURL.indexOf(':") > 0)
						h.put(b, new URL(bURL));
					else
						h.put(b, new URL(origin, bURL));
					tl.setParent(b, l);
				} else {
					println("TreeLink:1_0 Invalid input " + txt);
				}
			}
		} catch(MalformedURLException mfc) {
			println("TreeLink1_0: Error: " + mfc);
		} catch(IOException billg) {
			println("TreeLink1_0: Error: " + billg);
		}

		setSize(wid, ht);
		System.out.println("Size now " + size());

		showStatus("TreeLink1_0 ready");
	
public voidpaint(java.awt.Graphics g)

		tl.paintLines(g, getForeground());
	
protected voidprintln(java.lang.String s)

		System.out.println(s);
		showStatus("Informational message(s), see Java Console");