home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-12-20 | 3.3 KB | 147 lines |
- /*
- This class is an extension of the Frame class for use as the
- main window of an application.
-
- You can add controls or menus to testleaf with Cafe Studio.
- */
-
- import java.awt.*;
- import tree.*;
-
- public class testleaf extends Frame implements TreeToolObserver
- {
-
- public testleaf() {
-
- super("testleaf window");
-
- //{{INIT_MENUS
- //}}
-
- //{{INIT_CONTROLS
- String cFold = new String("e:\\users\\csg\\.hotjava\\tree\\closfold.gif");
- String oFold = new String("e:\\users\\csg\\.hotjava\\tree\\openfold.gif");
-
- root = new TreeNode("Root",cFold,oFold);
- TreeNode a = new TreeNode("This",cFold,oFold);
- TreeNode b = new TreeNode("does",cFold,oFold);
- TreeNode c = new TreeNode("work",cFold,oFold);
- TreeNode d = new TreeNode("finally",cFold,oFold);
-
- tree = new Tree(root);
- tool = new TreeTool(tree);
- tool.addObserver(this);
- // do NOT add any nodes until treeCanvas has been created
- tool.addNode(root,a);
- tool.addNode(root,b);
- tool.addNode(b,c);
- tool.addNode(root,d);
- sPanel = new scrollPanel(50,50,200,300,tool);
- add(sPanel);
-
- setBackground(Color.lightGray);
-
- setLayout(null);
- addNotify();
- resize(insets().left + insets().right + 600, insets().top + insets().bottom + 600);
- //}}
-
- show();
- }
-
- public synchronized void show() {
- move(50, 50);
- super.show();
- }
-
- public boolean handleEvent(Event event) {
-
- if (event.id == Event.WINDOW_DESTROY) {
- hide(); // hide the Frame
- dispose(); // tell windowing system to free resources
- System.exit(0); // exit
- return true;
- }
- return super.handleEvent(event);
- }
-
- public boolean action(Event event, Object arg) {
- if (event.target instanceof MenuItem) {
- String label = (String) arg;
- if (label.equalsIgnoreCase("&About...")) {
- selectedAbout();
- return true;
- } else if (label.equalsIgnoreCase("E&xit")) {
- selectedExit();
- return true;
- } else if (label.equalsIgnoreCase("&Open...")) {
- selectedOpen();
- return true;
- }
- }
- return super.action(event, arg);
- }
-
- public static void main(String args[]) {
- new testleaf();
- }
-
- //{{DECLARE_MENUS
- //}}
-
- //{{DECLARE_CONTROLS
- //}}
-
- TreeNode root = null;
- TreeNode selected = null;
- Tree tree = null;
- TreeTool tool = null;
-
- scrollPanel sPanel;
-
- TreeNode tNode;
- TreeTool tT;
- treeCanvas tC;
-
- public void selectedOpen() {
- (new FileDialog(this, "Open...")).show();
- }
- public void selectedExit() {
- }
- public void selectedAbout() {
- }
-
- public void nodeSelected(TreeNode node) {
- //System.out.println("TreeTestApplet::nodeSelected("+node+")");
- //selected = node;
- }
-
-
- public void nodeUnSelected(TreeNode node) {
- //System.out.println("TreeTestApplet::nodeUnSelected("+node+")");
- //selected = null;
- }
-
-
- public void nodeOpened(TreeNode node) {
- //System.out.println("TreeTestApplet::nodeOpened("+node+")");
- }
-
-
- public void nodeClosed(TreeNode node) {
- //System.out.println("TreeTestApplet::nodeClosed("+node+")");
- }
-
- public void nodeAdded(TreeNode where,TreeNode node) {
- //System.out.println("TreeTestApplet::nodeAdded("+node+")");
- }
-
-
- public void nodeRemoved(TreeNode node) {
- // System.out.println("TreeTestApplet::nodeRemoved("+node+")");
- }
-
- }
-
-
-