TreeLinkpublic class TreeLink 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 | URLButton | b | Hashtable | h | int | wid | int | ht | int | htIncr |
Methods Summary |
---|
protected void | eprintln(java.lang.String s)
System.err.println(s);
showStatus("Error, see Java Console");
| public java.lang.String | getAppletInfo()Return information about this applet.
return "TreeLink Demo Applet\n" +
"Copyright Learning Tree International";
| public java.lang.String[][] | getParameterInfo()Return list of allowable parameters.
String param_info[][] = {
{"TreeLink", "filename", "List of links"},
};
return param_info;
| public void | init()
// Initialize this TreeLink applet
showStatus("TreeLink 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);
BufferedReader is =
new BufferedReader(
new InputStreamReader(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) {
if (txt.startsWith("#"))
continue;
StringTokenizer st = new StringTokenizer(txt);
if (st.countTokens() < 3) {
println("TreeLink: Bad input: " + txt);
return;
}
String type = st.nextToken();
String bURL = st.nextToken();
String text = "";
while (st.hasMoreTokens())
text += st.nextToken() + " ";
// 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")) {
URL u;
if (bURL.indexOf(':") > 0)
u = new URL(bURL);
else
u = new URL(origin, bURL);
add("button", b = new URLButton(this, text, u));
tl.setParent(b, l);
} else {
println("TreeLink: Invalid input " + txt);
}
}
} catch(MalformedURLException mfc) {
println("TreeLink: Error: " + mfc);
} catch(IOException billg) {
println("TreeLink: Error: " + billg);
}
setSize(wid, ht);
System.out.println("Size now " + getSize());
showStatus("TreeLink ready");
| public void | paint(java.awt.Graphics g)
tl.paintLines(g, getForeground());
| protected void | println(java.lang.String s)
System.out.println(s);
showStatus("Informational message(s), see Java Console");
|
|