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.0@webcrossing.raydaftYaTP>
Date: Wed, 13 Jun 2007 01:43:39 -0400
References: <ef5a699.-1@webcrossing.raydaftYaTP>
Lines: 130
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:413738



Sorry, there is missing the end of the Class:

[...] kRenderer() {
  setLayout(null);
  add(check = new JCheckBox());
  add(label = new TreeLabel());
  check.setBackground(UIManager.getColor("Tree.textBackground"));
  label.setForeground(UIManager.getColor("Tree.textForeground"));
 }

 public Component getTreeCellRendererComponent(JTree tree, Object
value,
   boolean isSelected, boolean expanded, boolean leaf, int row,
   boolean hasFocus) {
  if (!(value instanceof CheckNode)) {
   return dtcr.getTreeCellRendererComponent(tree, value, isSelected,
expanded, leaf, row, hasFocus);
  }
  String stringValue = tree.convertValueToText(value, isSelected,
    expanded, leaf, row, hasFocus);
  setEnabled(tree.isEnabled());
  check.setSelected(((CheckNode) value).isSelected());
  label.setFont(tree.getFont());
  label.setText(stringValue);
  label.setSelected(isSelected);
  label.setFocus(hasFocus);
  if (leaf) {
   label.setIcon(UIManager.getIcon("Tree.leafIcon"));
  } else if (expanded) {
   label.setIcon(UIManager.getIcon("Tree.openIcon"));
  } else {
   label.setIcon(UIManager.getIcon("Tree.closedIcon"));
  }
  return this;
 }

 public Dimension getPreferredSize() {
  Dimension d_check = check.getPreferredSize();
  Dimension d_label = label.getPreferredSize();
  return new Dimension(d_check.width + d_label.width,
    (d_check.height < d_label.height ? d_label.height
      : d_check.height));
 }

 public void doLayout() {
  Dimension d_check = check.getPreferredSize();
  Dimension d_label = label.getPreferredSize();
  int y_check = 0;
  int y_label = 0;
  if (d_check.height < d_label.height) {
   y_check = (d_label.height - d_check.height) / 2;
  } else {
   y_label = (d_check.height - d_label.height) / 2;
  }
  check.setLocation(0, y_check);
  check.setBounds(0, y_check, d_check.width, d_check.height);
  label.setLocation(d_check.width, y_label);
  label.setBounds(d_check.width, y_label, d_label.width,
d_label.height);
 }

 public void setBackground(Color color) {
  if (color instanceof ColorUIResource)
   color = null;
  super.setBackground(color);
 }

 public class TreeLabel extends JLabel {
  boolean isSelected;

  boolean hasFocus;
 
  public TreeLabel() {
  }

  public void setBackground(Color color) {
   if (color instanceof ColorUIResource)
    color = null;
   super.setBackground(color);
  }

  public void paint(Graphics g) {
   String str;
   if ((str = getText()) != null) {
    if (0 < str.length()) {
     if (isSelected) {
      g.setColor(UIManager
        .getColor("Tree.selectionBackground"));
     } else {
      g.setColor(UIManager.getColor("Tree.textBackground"));
     }
     
     Dimension d = getPreferredSize();
     int imageOffset = 0;
     Icon currentI = getIcon();
     if (currentI != null) {
      imageOffset = currentI.getIconWidth()
      + Math.max(0, getIconTextGap() - 1);
     }
     g.fillRect(imageOffset, 0, d.width - 1 - imageOffset,
       d.height);
     if (hasFocus) {
      g.setColor(UIManager
        .getColor("Tree.selectionBorderColor"));
      g.drawRect(imageOffset, 0, d.width - 1 - imageOffset,
        d.height - 1);
     }
    }
   }
   super.paint(g);
  }

  public Dimension getPreferredSize() {
   Dimension retDimension = super.getPreferredSize();
   if (retDimension != null) {
    retDimension = new Dimension(retDimension.width + 3,
      retDimension.height);
   }
   return retDimension;
  }

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

  public void setFocus(boolean hasFocus) {
   this.hasFocus = hasFocus;
  }
 }
}