From: "Stephan Hoffmann" <Stephan.LIMITEDHoffmann@de.bosch.com>
Path: news.mathworks.com!newsfeed-00.mathworks.com!webcrossing
Newsgroups: comp.soft-sys.matlab
Subject: Re: Including CheckNodeTree.java to a Matlab GUI
Message-ID: <ef5a699.8@webcrossing.raydaftYaTP>
Date: Thu, 28 Jun 2007 03:28:22 -0400
References: <ef5a699.-1@webcrossing.raydaftYaTP> <ef5a699.5@webcrossing.raydaftYaTP> <ef5a699.6@webcrossing.raydaftYaTP>
Lines: 103
NNTP-Posting-Host: 194.39.218.10
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
Xref: news.mathworks.com comp.soft-sys.matlab:416140



Juan Manuel Romero Martin wrote:
 
> Hello Stephan,
>
> I was wondering if you already finish your code. I would like to do
> some similar and i dont have a clue how to do it. So your code will
> be very very helpful.
>
> Thanks in advances,
> Juan M. Romero Martin
  

Its pretty easy. You can choose the Java-Code above, and a second
Java class which i post in the next posting.

You have to build the Java classes with the same Java Plattform
included in your Matlab version.
In Matlab R2007a JDK 1.5.0_07 is included.

In Matlab you can use Yair Altman's UICOMPONENT.
Eg.:
        javaaddpath C:\JAVA\CheckNodeTree\build\classes\

        import java.CheckNodeTree.build.classes.*;
        import javax.swing.tree.*;
        import javax.swing.JScrollPane;
    

        root = DefaultMutableTreeNode('Root'); %
Load Browser
        checkNode(1) = CheckNode('Node');
        
        root.add(checkNode(1));

        model = DefaultTreeModel(root);
        checkTree = CheckNodeTree(model);
        treeFrame = JScrollPane(checkTree);

        Browser = uicomponent(treeFrame,'position',[10,313,235,610]);

===========================================================

import java.util.Enumeration;
import javax.swing.tree.DefaultMutableTreeNode;

public class CheckNode extends DefaultMutableTreeNode {

 public final static int SINGLE_SELECTION = 0;

 public final static int DIG_IN_SELECTION = 4;

 protected int selectionMode;

 protected boolean isSelected;

 public CheckNode() {
  this(null);
 }

 public CheckNode(Object userObject) {
  this(userObject, true, false);
 }

 public CheckNode(Object userObject, boolean allowsChildren,
   boolean isSelected) {
  super(userObject, allowsChildren);
  this.isSelected = isSelected;
  setSelectionMode(DIG_IN_SELECTION);
 }

 public void setSelectionMode(int mode) {
  selectionMode = mode;
 }

 public int getSelectionMode() {
  return selectionMode;
 }

 public void setSelected(boolean isSelected) {
  this.isSelected = isSelected;

  if ((selectionMode == DIG_IN_SELECTION) && (children != null)) {
   Enumeration e = children.elements();
   while (e.hasMoreElements()) {
    CheckNode node = (CheckNode) e.nextElement();
    node.setSelected(isSelected);
   }
  }
 }

 public boolean isSelected() {
  return isSelected;
 }

 // If you want to change "isSelected" by CellEditor,
 /*
    public void setUserObject(Object obj) { if (obj instanceof
Boolean) {
  * setSelected(((Boolean)obj).booleanValue()); } else {
  * super.setUserObject(obj); } }
  */

}