Hi Dejan,

The link below shows how to implement a renderer and editor out of a
component:

http://lists.canoo.com/mailman/private/ulc-developer/2005/002596.html

As for the bug "ULCCheckBox does not work as Tree Cell Editor", it will be
taken up in one one of the future releases of ULC. I can't promise which one
but we will try to do it in 6.1.1.

I will try and create:
1. a work around for the bug
2 a composite widget (container) as a renderer/editor

Thanks and regards,

Janak

>-----Original Message-----
>From: Dejan Pecar [mailto:[EMAIL PROTECTED]
>Sent: Friday, May 19, 2006 9:45 PM
>To: Janak Mulani
>Subject: Re[2]: [ULC-developer] checkbox editor and renderer in a
>ulctree
>
>
>hi janak,
>
>thanks a lot for your help.
>
>but the solution covers only "the tip of the mountain".
>we're currently developing an application framework for about 50
>application programmers.
>so what we do is we take the ulc classes subclass or wrap them
>that the programmers can port their swing applications
>with minimal effort to ulc (we have such a application framework
>for swing).
>
>nearly all of the the components are done. but we have problems to
>support the previous functionality for the tree.
>one thing is checkbox but we have cases where we have 2 checkboxes
>and a picture in a tree leaf.
>
>the swing sample below covers the functionality we basically need
>(the sample is senseless but it shows what we need).
>
>the workaround you showed me i could use when i knew that i had
>one or two cases to use this but this isn't the case.
>the tree will be used in ten'th or even hundereds of cases with
>slighty different editors or renderers.
>
>so, when can we expect the bug entry you made to be fixed ?
>and do see the possiblity to have also a container as tree
>renderer and editor ?
>
>
>import javax.swing.*;
>import javax.swing.event.ChangeEvent;
>import javax.swing.tree.TreeCellRenderer;
>import javax.swing.tree.DefaultTreeCellRenderer;
>import javax.swing.tree.DefaultMutableTreeNode;
>import javax.swing.tree.TreeCellEditor;
>import javax.swing.tree.TreePath;
>import java.util.Vector;
>import java.util.EventObject;
>import java.awt.*;
>import java.awt.event.MouseEvent;
>import java.awt.event.ItemListener;
>import java.awt.event.ItemEvent;
>
>public class SwingTreeCheckTest {
>    public static void main(String args[]) {
>        JFrame frame = new JFrame("CheckBox Tree");
>
>        CheckBoxNode accessibilityOptions[] = {
>                new CheckBoxNode("Move system caret with
>focus/selection changes", "1.png", false, true),
>                new CheckBoxNode("Always expand alt text for
>images", "2.png", true, true)};
>        CheckBoxNode browsingOptions[] = {
>                new CheckBoxNode("Notify when downloads complete",
>"3.png", false, false),
>                new CheckBoxNode("Disable script debugging",
>"4.png", true, false),
>                new CheckBoxNode("Use AutoComplete", "5.png", true, true),
>                new CheckBoxNode("Browse in a new process",
>"6.png", false, true)};
>
>        Vector accessVector = new NamedVector("Accessibility",
>accessibilityOptions);
>        Vector browseVector = new NamedVector("Browsing", browsingOptions);
>
>        Object rootNodes[] = {accessVector, browseVector};
>        Vector rootVector = new NamedVector("Root", rootNodes);
>
>        JTree tree = new JTree(rootVector);
>        CheckBoxNodeRenderer renderer = new CheckBoxNodeRenderer();
>        tree.setCellRenderer(renderer);
>        tree.setCellEditor(new CheckBoxNodeEditor(tree));
>
>        tree.setEditable(true);
>        JScrollPane scrollPane = new JScrollPane(tree);
>
>        tree.setRowHeight(0);
>
>        frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
>        frame.setSize(300, 150);
>        frame.setVisible(true);
>    }
>}
>
>class CheckBoxNodeRenderer implements TreeCellRenderer {
>    private JPanel leafRenderer = new JPanel();
>    public JLabel img = new JLabel();
>    public JCheckBox box1 = new JCheckBox();
>    public JCheckBox box2 = new JCheckBox();
>    public JLabel label = new JLabel();
>    public String imgname;
>    private DefaultTreeCellRenderer nonLeafRenderer = new
>DefaultTreeCellRenderer();
>    Color selectionBorderColor, selectionForeground,
>selectionBackground, textForeground, textBackground;
>
>    public CheckBoxNodeRenderer() {
>        leafRenderer.setLayout(new BoxLayout(leafRenderer,
>BoxLayout.X_AXIS));
>        leafRenderer.setBorder(BorderFactory.createEmptyBorder());
>
>        Font fontValue;
>        fontValue = UIManager.getFont("Tree.font");
>        if(fontValue != null) {
>            box1.setFont(fontValue);
>            box2.setFont(fontValue);
>            label.setFont(fontValue);
>        }
>        Boolean booleanValue = (Boolean)
>UIManager.get("Tree.drawsFocusBorderAroundIcon");
>        box1.setFocusPainted((booleanValue != null) && booleanValue);
>        box2.setFocusPainted((booleanValue != null) && booleanValue);
>
>        leafRenderer.add(img);
>        leafRenderer.add(box1);
>        leafRenderer.add(box2);
>        leafRenderer.add(label);
>
>        selectionBorderColor =
>UIManager.getColor("Tree.selectionBorderColor");
>        selectionForeground =
>UIManager.getColor("Tree.selectionForeground");
>        selectionBackground =
>UIManager.getColor("Tree.selectionBackground");
>        textForeground = UIManager.getColor("Tree.textForeground");
>        textBackground = UIManager.getColor("Tree.textBackground");
>    }
>
>    public Component getTreeCellRendererComponent(JTree tree,
>Object value, boolean selected, boolean expanded, boolean leaf,
>int row, boolean hasFocus) {
>        Component returnValue;
>        if(leaf) {
>            String stringValue = tree.convertValueToText(value,
>selected, expanded, leaf, row, false);
>            label.setText(stringValue);
>            box1.setSelected(false);
>            box2.setSelected(false);
>            img.setIcon(null);
>            imgname = "";
>
>            leafRenderer.setEnabled(tree.isEnabled());
>            box1.setEnabled(tree.isEnabled());
>            box2.setEnabled(tree.isEnabled());
>            label.setEnabled(tree.isEnabled());
>
>            if(selected) {
>                leafRenderer.setForeground(selectionForeground);
>                leafRenderer.setBackground(selectionBackground);
>                box1.setForeground(selectionForeground);
>                box1.setBackground(selectionBackground);
>                box2.setForeground(selectionForeground);
>                box2.setBackground(selectionBackground);
>                label.setForeground(selectionForeground);
>                label.setBackground(selectionBackground);
>            } else {
>                leafRenderer.setForeground(textForeground);
>                leafRenderer.setBackground(textBackground);
>                box1.setForeground(textForeground);
>                box1.setBackground(textBackground);
>                box2.setForeground(textForeground);
>                box2.setBackground(textBackground);
>                label.setForeground(textForeground);
>                label.setBackground(textBackground);
>            }
>
>            if((value != null) && (value instanceof
>DefaultMutableTreeNode)) {
>                Object userObject = ((DefaultMutableTreeNode)
>value).getUserObject();
>                if(userObject instanceof CheckBoxNode) {
>                    CheckBoxNode node = (CheckBoxNode) userObject;
>                    label.setText(node.getText());
>                    box1.setSelected(node.isSelected());
>                    box2.setSelected(node.isSelected2());
>                    imgname = node.img;
>                    img.setIcon(new
>ImageIcon(this.getClass().getResource(node.img)));
>                }
>            }
>            returnValue = leafRenderer;
>        } else {
>            returnValue =
>nonLeafRenderer.getTreeCellRendererComponent(tree, value,
>selected, expanded, leaf, row, hasFocus);
>        }
>        return returnValue;
>    }
>}
>
>class CheckBoxNodeEditor extends AbstractCellEditor implements
>TreeCellEditor {
>    CheckBoxNodeRenderer renderer = new CheckBoxNodeRenderer();
>    ChangeEvent changeEvent = null;
>    JTree tree;
>
>    public CheckBoxNodeEditor(JTree tree) {
>        this.tree = tree;
>    }
>
>    public Object getCellEditorValue() {
>        return new CheckBoxNode(renderer.label.getText(),
>renderer.imgname, renderer.box1.isSelected(), renderer.box2.isSelected());
>    }
>
>    public boolean isCellEditable(EventObject event) {
>        //System.out.println("isCellEditable: " + event);
>        boolean returnValue = false;
>        if(event instanceof MouseEvent) {
>            MouseEvent mouseEvent = (MouseEvent) event;
>            TreePath path =
>tree.getPathForLocation(mouseEvent.getX(), mouseEvent.getY());
>            if(path != null) {
>                Object node = path.getLastPathComponent();
>                if((node != null) && (node instanceof
>DefaultMutableTreeNode)) {
>                    DefaultMutableTreeNode treeNode =
>(DefaultMutableTreeNode) node;
>                    Object userObject = treeNode.getUserObject();
>                    returnValue = ((treeNode.isLeaf()) &&
>(userObject instanceof CheckBoxNode));
>                }
>            }
>        }
>        return returnValue;
>    }
>
>    public Component getTreeCellEditorComponent(JTree tree, Object
>value, boolean selected, boolean expanded, boolean leaf, int row) {
>        Component editor =
>renderer.getTreeCellRendererComponent(tree, value, true, expanded,
>leaf, row, true);
>        // editor always selected / focused
>        ItemListener itemListener = new ItemListener() {
>            public void itemStateChanged(ItemEvent itemEvent) {
>                if(stopCellEditing()) {
>                    fireEditingStopped();
>                }
>            }
>        };
>        if(editor instanceof JPanel) {
>            renderer.box1.addItemListener(itemListener);
>            renderer.box2.addItemListener(itemListener);
>        }
>        return editor;
>    }
>}
>
>class CheckBoxNode {
>    String text;
>    String img;
>
>    boolean selected;
>    boolean selected2;
>
>    public CheckBoxNode(String text, String img, boolean selected,
>boolean selected2) {
>        this.text = text;
>        this.img = img;
>        this.selected = selected;
>        this.selected2 = selected2;
>    }
>
>    public boolean isSelected() {
>        return selected;
>    }
>
>    public void setSelected(boolean newValue) {
>        selected = newValue;
>    }
>    public boolean isSelected2() {
>        return selected2;
>    }
>    public void setSelected2(boolean selected2) {
>        this.selected2 = selected2;
>    }
>
>    public String getText() {
>        return text;
>    }
>
>    public void setText(String newValue) {
>        text = newValue;
>    }
>
>    public String toString() {
>        return getClass().getName() + "[" + text + "/" + selected
>+ "/" + selected2 + "]";
>    }
>}
>
>class NamedVector extends Vector<Object> {
>    String name;
>    public NamedVector(String name) {
>        this.name = name;
>    }
>    public NamedVector(String name, Object elements[]) {
>        this.name = name;
>        for(int i = 0, n = elements.length; i < n; i++) {
>            add(elements[i]);
>        }
>    }
>    public String toString() {
>        return "[" + name + "]";
>    }
>}
>
>
>
>
>gruss
>  Dejan
>mailto:[EMAIL PROTECTED]

_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer

Reply via email to