home *** CD-ROM | disk | FTP | other *** search
/ Late Night VRML 2.0 with Java CD-ROM / code.zip / Ch12 / ui / tree / testleaf.java < prev    next >
Text File  |  1996-12-20  |  3KB  |  147 lines

  1. /*
  2.     This class is an extension of the Frame class for use as the
  3.     main window of an application.
  4.  
  5.     You can add controls or menus to testleaf with Cafe Studio.
  6.  */
  7.  
  8. import java.awt.*;
  9. import tree.*;
  10.  
  11. public class testleaf extends Frame implements TreeToolObserver
  12. {
  13.  
  14.     public testleaf() {
  15.  
  16.     super("testleaf window");
  17.  
  18.     //{{INIT_MENUS
  19.     //}}
  20.  
  21.     //{{INIT_CONTROLS
  22.     String cFold = new String("e:\\users\\csg\\.hotjava\\tree\\closfold.gif");
  23.     String oFold = new String("e:\\users\\csg\\.hotjava\\tree\\openfold.gif");
  24.  
  25.     root =          new TreeNode("Root",cFold,oFold);
  26.     TreeNode a =    new TreeNode("This",cFold,oFold);
  27.     TreeNode b =    new TreeNode("does",cFold,oFold);
  28.     TreeNode c =    new TreeNode("work",cFold,oFold);
  29.     TreeNode d =    new TreeNode("finally",cFold,oFold);
  30.  
  31.     tree = new Tree(root);
  32.     tool = new TreeTool(tree);
  33.     tool.addObserver(this);
  34.     // do NOT add any nodes until treeCanvas has been created
  35.     tool.addNode(root,a);
  36.     tool.addNode(root,b);
  37.     tool.addNode(b,c);
  38.     tool.addNode(root,d);
  39.     sPanel = new scrollPanel(50,50,200,300,tool);
  40.     add(sPanel);
  41.  
  42.     setBackground(Color.lightGray);
  43.  
  44.     setLayout(null);
  45.     addNotify();
  46.     resize(insets().left + insets().right + 600, insets().top + insets().bottom + 600);
  47.     //}}
  48.  
  49.     show();
  50.     }
  51.  
  52.     public synchronized void show() {
  53.     move(50, 50);
  54.     super.show();
  55.     }
  56.  
  57.     public boolean handleEvent(Event event) {
  58.  
  59.     if (event.id == Event.WINDOW_DESTROY) {
  60.         hide();         // hide the Frame
  61.         dispose();      // tell windowing system to free resources
  62.         System.exit(0); // exit
  63.         return true;
  64.     }
  65.     return super.handleEvent(event);
  66.     }
  67.  
  68.     public boolean action(Event event, Object arg) {
  69.     if (event.target instanceof MenuItem) {
  70.         String label = (String) arg;
  71.         if (label.equalsIgnoreCase("&About...")) {
  72.         selectedAbout();
  73.         return true;
  74.         } else if (label.equalsIgnoreCase("E&xit")) {
  75.         selectedExit();
  76.         return true;
  77.         } else if (label.equalsIgnoreCase("&Open...")) {
  78.         selectedOpen();
  79.         return true;
  80.         }
  81.     }
  82.     return super.action(event, arg);
  83.     }
  84.  
  85.     public static void main(String args[]) {
  86.     new testleaf();
  87.     }
  88.  
  89.     //{{DECLARE_MENUS
  90.     //}}
  91.  
  92.     //{{DECLARE_CONTROLS
  93.     //}}
  94.  
  95.     TreeNode root = null;
  96.     TreeNode selected = null;
  97.     Tree tree = null;
  98.     TreeTool tool = null;
  99.  
  100.     scrollPanel sPanel;
  101.  
  102.     TreeNode    tNode;
  103.     TreeTool    tT;
  104.     treeCanvas  tC;
  105.  
  106.     public void selectedOpen() {
  107.     (new FileDialog(this, "Open...")).show();
  108.     }
  109.     public void selectedExit() {
  110.     }
  111.     public void selectedAbout() {
  112.     }
  113.  
  114.   public void nodeSelected(TreeNode node) {
  115.     //System.out.println("TreeTestApplet::nodeSelected("+node+")");
  116.     //selected = node;
  117.   }
  118.  
  119.  
  120.   public void nodeUnSelected(TreeNode node) {
  121.     //System.out.println("TreeTestApplet::nodeUnSelected("+node+")");
  122.     //selected = null;
  123.   }
  124.  
  125.  
  126.   public void nodeOpened(TreeNode node) {
  127.     //System.out.println("TreeTestApplet::nodeOpened("+node+")");
  128.   }
  129.  
  130.  
  131.   public void nodeClosed(TreeNode node) {
  132.     //System.out.println("TreeTestApplet::nodeClosed("+node+")");
  133.   }
  134.  
  135.   public void nodeAdded(TreeNode where,TreeNode node) {
  136.     //System.out.println("TreeTestApplet::nodeAdded("+node+")");
  137.   }
  138.  
  139.  
  140.   public void nodeRemoved(TreeNode node) {
  141.    // System.out.println("TreeTestApplet::nodeRemoved("+node+")");
  142.   }
  143.  
  144. }
  145.  
  146.  
  147.