CheckBoxTree

This is the forum for JIDE Common Layer which is open sourced at https://github.com/jidesoft/jide-oss. Please note, JIDE technical support doesn't monitor this forum as often as other forums. Please consider subscribe for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Moderator: JIDE Support

Forum rules
Community driven forum for open source JIDE Common Layer. JIDE technical support doesn't monitor this forum as often as other forums. If you only use JIDE Common Layer, please consider subscribing for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

CheckBoxTree

Postby venkataratna » Thu Aug 02, 2012 6:01 am

Hi,

I am using CheckBoxTree.In this I am using two separate Functionalities.

1. Select the Tree Node
2. Check the Checkbox

Both Operations i am using different methods.

1. Select the Tree Node Purpose i am using

myCheckBoxTree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent se) {

It is working fine.

2. Check the Checkbox purpose i am using

myCheckBoxTree.getCheckBoxTreeSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {

But in this scenario issues are
1. Functionality is not working
2. When ever i clicked the checkbox at that time Tree Node also selecting (So, automatically, 1st Functionality i.e. Select the Tree Node) functionality is working.

I need whenever i select Checkbox at that time Tree Node Does not Select. Only Checkbox is Checked

But i wrote, 2nd Functionality i..e. Check the Checkbox functionality in
myCheckBoxTree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent se) {

in this method,at that time functionality is working.

I need help of 2 Functionality scenarios 2 different Listener.

I saw your reply in this problem in below url

viewtopic.php?f=18&t=13541

But for me it is not working.

Even I tried addTreeCheckingListener(new TreeCheckingListener() {
public void valueChanged(TreeCheckingEvent e) {

It is not working.

Could you please give me the solutions.

Thanks,
Venkata.
venkataratna
 
Posts: 12
Joined: Tue May 29, 2012 4:22 am

Re: CheckBoxTree

Postby JIDE Support » Thu Aug 02, 2012 9:13 am

It's wired. The two listeners should be independent. Here is a screencast of my test case http://screencast.com/t/Mflx3cjHfwN. Could you please share the test case for investigation?

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: CheckBoxTree

Postby venkataratna » Tue Aug 07, 2012 8:00 am

Hi,

Thanks, For Reply. I wrote the code in same way (i.e. your video wise, i.e. Your URL)

1. myCheckBoxTree.getCheckBoxTreeSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
myMethod();
}
});

whenever i called this method it is not working.

2. myCheckBoxTree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
myMethod();
}
});

In this scenario i called this method, it is working.


Even I tried one more condition in 2nd one. This time I am calling mymethod() in 1st one format.
i.e.

myCheckBoxTree.getCheckBoxTreeSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
myMethod();
}
});



myCheckBoxTree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {

if(myCheckBoxTree.isClickInCheckBoxOnly()){
// Here I wrote CheckBox Selected Condition
}

}
});

Could you please give me the solutions.

Thanks,
Venkata.
venkataratna
 
Posts: 12
Joined: Tue May 29, 2012 4:22 am

Re: CheckBoxTree

Postby JIDE Support » Tue Aug 07, 2012 8:35 am

Do you mean the listener was not triggered by "it is not working"? If it is the case, please share your standalone test case for us to investigate.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: CheckBoxTree

Postby venkataratna » Thu Aug 16, 2012 6:14 am

Hi,

Thank you for Reply.

I used two different Listeners but it is effecting on one on another.

When i click Check Box, Tree Node is highlighting and It is going to Tree Node Selecting Listeners Functionality.

How to rectify this issue.

Please give me the Solution.

Here i am Coping my Code.

Code: Select all
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.FlowLayout;

import java.awt.Insets;

import java.util.Properties;

import javax.swing.BoxLayout;
import javax.swing.DefaultListModel;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;

import com.jidesoft.pane.OutlookTabbedPane;

import com.jidesoft.swing.CheckBoxTree;
import com.jidesoft.swing.JideButton;
import com.jidesoft.swing.JideTabbedPane;

public class TreeSelected extends JFrame{
   public CheckBoxTree checkBoxTree;
   public JScrollPane jideScrollpane;
   public JideButton jideBtn;
   public OutlookTabbedPane outlookTabbedPane = new OutlookTabbedPane();
   public Dimension outlookTabbedPaneSize;
   public JPanel OutLookPanel;
   public JPanel searchOutLookPanel;
   public JPanel contentPane;
   
   public DefaultListModel eventmodel=new DefaultListModel();
   
   public static void main(String[] args) {
      EventQueue.invokeLater(new Runnable() {
         public void run() {
            try {
               TreeSelected frame = new TreeSelected();
               frame.setSize(900,700);
               frame.setTitle("CheckBoxFunctionality");
               
                  frame.setVisible(true);
               
               JMenu fileMenu = new JMenu("File");

               fileMenu.add(new JMenuItem("New"));
               fileMenu.add(new JMenuItem("Open"));
               fileMenu.add(new JMenuItem("Save"));
               fileMenu.add(new JMenuItem("Exit"));

               JMenu menu = new JMenu("Edit");

               menu.add(new JMenuItem("Cut"));
               menu.add(new JMenuItem("Copy"));
               menu.add(new JMenuItem("Paste"));
               menu.add(new JMenuItem("Select All"));

               JMenuBar menuBar = new JMenuBar();
               menuBar.add(fileMenu);
               menuBar.add(menu);

               frame.setJMenuBar(menuBar);

            } catch (Exception e) {
               e.printStackTrace();
            }
         }
      });
   }
   
   public TreeSelected() {
      
      contentPane=new JPanel();
      contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
      contentPane.setLayout(new BorderLayout(0, 0));
      setContentPane(contentPane);

      JideTabbedPane jideTabbedPane = new JideTabbedPane();
      jideTabbedPane.setTabAreaInsets(new Insets(0, 20, 0, 10));
      jideTabbedPane.setLayoutTrailingComponentBeforeButtons(true);
      jideTabbedPane.setUseDefaultShowCloseButtonOnTab(true);
      jideTabbedPane.setSize(900, 100);

      JPanel jPanel = new JPanel();
      jPanel.setBackground(UIManager.getColor("InternalFrame.inactiveTitleGradient"));
      jPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
      
      Properties properties = System.getProperties();

      checkBoxTree = new CheckBoxTree(properties);
      checkBoxTree.setRootVisible(true);
      jideScrollpane = new JScrollPane(checkBoxTree);
      jideBtn = new JideButton();
      jideBtn.add(jideScrollpane);
      
      checkBoxTree.setRootVisible(false);
         
      checkBoxTree.getCheckBoxTreeSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
         
               public void valueChanged(TreeSelectionEvent e) {
                        // TODO Auto-generated method stub
                  System.out.println("******************CheckBoxChecked  "+e.getSource())   ;
                  eventmodel.addElement("CheckBox Tree Selected");
               }
      });
      
      checkBoxTree.addTreeSelectionListener(new TreeSelectionListener() {
             public void valueChanged(TreeSelectionEvent se) {
                
              System.err.println("@@@@@@@@@@@@@@@@@@@@@@Tree Node Selected " +" "+ checkBoxTree.getCheckBoxTreeSelectionModel());
              eventmodel.addElement("Tree Node Selected");
             }
      });

      
      outlookTabbedPane = new OutlookTabbedPane();
      outlookTabbedPane.revalidate();
      
      outlookTabbedPane.add("JIDE View ", jideBtn);
      outlookTabbedPane.setVisible(true);

      outlookTabbedPaneSize = new Dimension();
      outlookTabbedPaneSize.height = 600;
      outlookTabbedPaneSize.width = 600;
   
      outlookTabbedPane.setPreferredSize(outlookTabbedPaneSize);
      
      OutLookPanel = new JPanel();
      
      OutLookPanel.setLayout(new BoxLayout(OutLookPanel, BoxLayout.PAGE_AXIS));
      OutLookPanel.setBackground(UIManager.getColor("InternalFrame.inactiveTitleGradient"));

      OutLookPanel.add(outlookTabbedPane);

      searchOutLookPanel = new JPanel();
      
      searchOutLookPanel.add(OutLookPanel);
              
      contentPane.add(searchOutLookPanel, BorderLayout.CENTER);
      
   }
}


Thanks,
Venkata.
venkataratna
 
Posts: 12
Joined: Tue May 29, 2012 4:22 am

Re: CheckBoxTree

Postby JIDE Support » Thu Aug 16, 2012 9:18 am

It's wired. This test case works fine on our end. A screencast could be found at http://screencast.com/t/7XC6ayuSaa08.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: CheckBoxTree

Postby venkataratna » Fri Aug 24, 2012 7:09 am

Hi,

Thank you For reply.

In My PC Some Settings are problem.After that i tested this code in othe PC,at that time also it is worked.

I tested in windows 7 PC it is working fine.In this PC Java 6,Eclipse Helios and Eclipse Indigo.It is working fine.

But my PC is xp 32 bit,i am using Java 6,Eclipse Helios and Eclipse Indigo.Here it is not worked.

Could you tell me the Your tested Environment.


Thanks,
Venkata.
venkataratna
 
Posts: 12
Joined: Tue May 29, 2012 4:22 am

Re: CheckBoxTree

Postby JIDE Support » Fri Aug 24, 2012 9:16 am

Thanks for your clarification. The environment we tested was: Windows 7 x64, JSDK 6, Intellij IDEA 11.1.3. Will try to test it in Windows Xp 32 when we found one. And keep you posted when we have any progress.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: CheckBoxTree

Postby ankur.leonardo » Wed Sep 05, 2012 7:00 am

i want to convert treepath to String and vice - versa. Please reply me ASAP.

because I am storing retrieved Treepaths in one of the columns of database in the TEXT format and then again fetching Sting to convert to TreePath.

E.g. - [[Condition, DIABETES], [Condition, HYPERTENSION], [Condition, HIV], [Condition, CHD, Angina]]

i want to individual store values in database in such format as below :

Condition, DIABETES
Condition, HYPERTENSION
Condition, HIV
Condition, CHD, Angina

and again fetch row to convert to treepath. Quick help would be appreciated.
Also reply the solution at my ID - ankursoni.leonardo@gmail.com

thanking you all. :)
ankur.leonardo
 
Posts: 6
Joined: Wed Sep 05, 2012 6:49 am

Re: CheckBoxTree

Postby JIDE Support » Wed Sep 05, 2012 9:12 am

Looks like your request is about an ObjectConverter. There is no existing converter included in JIDE package. However, we do have some sample code in JIDE ExComboBoxDemo FYI.
Code: Select all
        ObjectConverterManager.registerConverter(TreePath.class, new ObjectConverter() {
            @Override
            public String toString(Object object, ConverterContext context) {
                return object == null ? "" : object.toString();
            }

            @Override
            public boolean supportToString(Object object, ConverterContext context) {
                return true;
            }

            @Override
            public Object fromString(String string, ConverterContext context) {
                if (string != null) {
                    String text = string.trim();
                    int n = text.indexOf("[");
                    if (n >= 0) {
                        text = text.substring(n);
                    }
                    if (text.startsWith("[") && text.endsWith("]")) {
                        String s = text.substring(1, text.length()-1);
                        String[] split = s.split(",");
                        Object[] nodes = new Object[split.length];
                        for (int i = 0; i < nodes.length; i++) {
                            nodes[i] = new DefaultMutableTreeNode(split[i]);
                        }
                        return new TreePath(split);
                    }
                }
                return null;
            }

            @Override
            public boolean supportFromString(String string, ConverterContext context) {
                return true;
            }
        }, new ConverterContext("TreePath"));

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: CheckBoxTree

Postby ankur.leonardo » Wed Sep 05, 2012 9:48 pm

thank you very much. I shall update my response when i implement it :). JIDE Support team rocks !!
ankur.leonardo
 
Posts: 6
Joined: Wed Sep 05, 2012 6:49 am

Re: CheckBoxTree

Postby ankur.leonardo » Thu Sep 06, 2012 2:16 am

I have already created Tree at the beginning, then i try to select the nodes which were present in the database as discussed in previous talks.

i used code like :

loop{
tree.getCheckBoxTreeSelectionModel()
.addSelectionPath(new TreePath(nodes));
}

but I am not able to see the tree selected in the GUI. Even though i properly get all the nodes in Treepath format as :
[Condition, CHD]
[Condition, HIV]

In case if you have doubt that what have i done to design GUI and place code , sending you my sample code :

CheckBoxTree tree= new CheckBoxTree(conditionsRoot);
tree.addMouseListener(new FilterClinicalDataConditionsListener(tree, conditionsRoot));
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
final ImageIcon leafIcon = new ImageIcon("middle.gif");
final DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
renderer.setClosedIcon(new ImageIcon("right.gif"));
renderer.setOpenIcon(new ImageIcon("down.gif"));
renderer.setLeafIcon(leafIcon);
tree.setCellRenderer(renderer);
tree.setFont(new Font("calibri", Font.PLAIN, 18));
tree.putClientProperty("JTree.lineStyle", "None");
tree.addTreeSelectionListener(new XListener(tree, root));
// **********************************************show checked nodes
// Your Code
for (int loop = 0; loop < nodes.length; loop++) {
nodes[loop] = new DefaultMutableTreeNode(split[loop]);
}
tree.getCheckBoxTreeSelectionModel().addSelectionPath(new TreePath(nodes));
}
}
final JScrollPane scrollPane = new JScrollPane(tree);
scrollPane.setBounds(labelX, 200, 325, 350);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
panel.add(scrollPane);


suggest me where m I getting wrong , whether at making nodes or diaplaying GUI.
Attachments
untitled.JPG
untitled.JPG (5.06 KiB) Viewed 47094 times
ankur.leonardo
 
Posts: 6
Joined: Wed Sep 05, 2012 6:49 am

Re: CheckBoxTree

Postby JIDE Support » Thu Sep 06, 2012 11:39 am

Please use the TreePath used by CheckBoxTree instead of a new TreePath instance. You could retrieve the TreePath instance in use by invoking JTree#getPathForRow()/getPathForLocation().

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: CheckBoxTree

Postby ankur.leonardo » Thu Sep 06, 2012 12:21 pm

JTree#getPathForRow()/getPathForLocation() i guess give exact path if you know. but what i am doing is retrieving random node from database. elaborate more how can i use it in my code.

thanks for reply.....
regards.
ankur.leonardo
 
Posts: 6
Joined: Wed Sep 05, 2012 6:49 am

Re: CheckBoxTree

Postby JIDE Support » Thu Sep 06, 2012 12:36 pm

Understand that you are recreating the entire tree. In this case, you might have to compare your new TreePath instance with the new JTree's TreePaths to find the correct instance. You then will be able to pass that correct instance to select it.

B.T.W., it's required by Swing DefaultTreeSelectionModel. If you use your newly created TreePath instance to make tree selection, it will also fail.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: CheckBoxTree

Postby ankur.leonardo » Mon Sep 10, 2012 9:21 pm

tree.getCheckBoxTreeSelectionModel().addSelectionPath(tree.getPathForRow(2)); is not working for me i dont know why :(
when the tree gets display all options are unchecked.

kindly give the solution. URGENT.
ankur.leonardo
 
Posts: 6
Joined: Wed Sep 05, 2012 6:49 am

Re: CheckBoxTree

Postby JIDE Support » Tue Sep 11, 2012 8:25 am

It's weird. Is it possible to share with us a test case for further investigation? You can also give the attached CheckBoxTreeDemo a try. In this demo I use the same code to select the third node.
Code: Select all
/*
 * @(#)CheckBoxTreeDemo.java 9/10/2005
 *
 * Copyright 2002 - 2005 JIDE Software Inc. All rights reserved.
 */

import com.jidesoft.icons.IconsFactory;
import com.jidesoft.plaf.LookAndFeelFactory;
import com.jidesoft.swing.*;
import com.jidesoft.tree.TreeUtils;

import javax.swing.*;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

/**
 * Demoed Component: {@link com.jidesoft.swing.CheckBoxTree} <br> Required jar files: jide-common.jar, jide-grids.jar
 * <br> Required L&F: any L&F
 */
public class CheckBoxTreeDemo extends AbstractDemo {
    private static final long serialVersionUID = 6399345108812286281L;
    private CheckBoxTree _tree;

    private static final String SINGLE_SELECTION = "Single Selection";
    private static final String CONTIGUOUS_SELECTION = "Contiguous Selection";
    private static final String DISCONTIGUOUS_SELECTION = "Discontiguous Selection";

    public CheckBoxTreeDemo() {
    }

    public String getName() {
        return "CheckBoxTree Demo";
    }

    public String getProduct() {
        return PRODUCT_NAME_COMMON;
    }

    @Override
    public String getDescription() {
        return "This is a demo of CheckBoxTree. \n" +
                "\n" +
                "Demoed classes:\n" +
                "com.jidesoft.swing.CheckBoxTree";
    }

    @Override
    public Component getOptionsPanel() {
        JPanel panel = new JPanel();
        panel.setLayout(new JideBoxLayout(panel, BoxLayout.Y_AXIS, 3));

        final JButton selectAll = new JButton(new AbstractAction("Select All") {
            private static final long serialVersionUID = -5580913906799074020L;

            public void actionPerformed(ActionEvent e) {
                if (_tree.getCheckBoxTreeSelectionModel().isDigIn()) {
                    _tree.getCheckBoxTreeSelectionModel().setSelectionPath(new TreePath(_tree.getModel().getRoot()));
                }
            }
        });
        JButton clearAll = new JButton(new AbstractAction("Clear All") {
            private static final long serialVersionUID = -2500587806953898010L;

            public void actionPerformed(ActionEvent e) {
                _tree.getCheckBoxTreeSelectionModel().clearSelection();
            }
        });

        final JCheckBox digIn = new JCheckBox("Dig In");
        digIn.addActionListener(new AbstractAction() {
            private static final long serialVersionUID = 3184279982208173561L;

            public void actionPerformed(ActionEvent e) {
                _tree.getCheckBoxTreeSelectionModel().setDigIn(digIn.isSelected());
                selectAll.setEnabled(digIn.isSelected());
            }
        });
        digIn.setSelected(_tree.getCheckBoxTreeSelectionModel().isDigIn());

        final JCheckBox checkBoxEnabled = new JCheckBox("CheckBox Enabled");
        checkBoxEnabled.addActionListener(new AbstractAction() {
            private static final long serialVersionUID = 7752042312121853308L;

            public void actionPerformed(ActionEvent e) {
                _tree.setCheckBoxEnabled(checkBoxEnabled.isSelected());
            }
        });
        checkBoxEnabled.setSelected(_tree.isCheckBoxEnabled());

        final JCheckBox clickInCheckBoxOnly = new JCheckBox("Click only valid in CheckBox");
        clickInCheckBoxOnly.addActionListener(new AbstractAction() {
            private static final long serialVersionUID = 5234198740430142668L;

            public void actionPerformed(ActionEvent e) {
                _tree.setClickInCheckBoxOnly(clickInCheckBoxOnly.isSelected());
            }
        });
        clickInCheckBoxOnly.setSelected(_tree.isClickInCheckBoxOnly());

        final JCheckBox treeEnabled = new JCheckBox("Tree Enabled ");
        treeEnabled.addActionListener(new AbstractAction() {
            private static final long serialVersionUID = -1027526532901305794L;

            public void actionPerformed(ActionEvent e) {
                _tree.setEnabled(treeEnabled.isSelected());
            }
        });
        treeEnabled.setSelected(_tree.isEnabled());

        final JCheckBox selectPartialFirst = new JCheckBox("Select Partial ");
        selectPartialFirst.addActionListener(new AbstractAction() {
            private static final long serialVersionUID = 6687098092701174807L;

            public void actionPerformed(ActionEvent e) {
                _tree.setSelectPartialOnToggling(selectPartialFirst.isSelected());
            }
        });
        selectPartialFirst.setSelected(_tree.isSelectPartialOnToggling());

        String[] selectionModes = new String[]{
                CheckBoxTreeDemo.SINGLE_SELECTION,
                CheckBoxTreeDemo.CONTIGUOUS_SELECTION,
                CheckBoxTreeDemo.DISCONTIGUOUS_SELECTION
        };

        JComboBox comboBox = new JComboBox(selectionModes);
        comboBox.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED && e.getItem() instanceof String) {
                    if ((e.getItem()).equals(CheckBoxTreeDemo.SINGLE_SELECTION)) {
                        _tree.getCheckBoxTreeSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
                    }
                    else if ((e.getItem()).equals(CheckBoxTreeDemo.CONTIGUOUS_SELECTION)) {
                        _tree.getCheckBoxTreeSelectionModel().setSelectionMode(TreeSelectionModel.CONTIGUOUS_TREE_SELECTION);
                    }
                    else {
                        _tree.getCheckBoxTreeSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
                    }
                }
            }
        });
        int mode = _tree.getCheckBoxTreeSelectionModel().getSelectionMode();
        switch (mode) {
            case TreeSelectionModel.SINGLE_TREE_SELECTION:
                comboBox.setSelectedIndex(0);
                break;
            case TreeSelectionModel.CONTIGUOUS_TREE_SELECTION:
                comboBox.setSelectedIndex(1);
                break;
            case TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION:
                comboBox.setSelectedIndex(2);
                break;
        }

        final JCheckBox singleEventMode = new JCheckBox("Single Event Mode");
        singleEventMode.addActionListener(new AbstractAction() {
            private static final long serialVersionUID = -8967823755465307651L;

            public void actionPerformed(ActionEvent e) {
                _tree.getCheckBoxTreeSelectionModel().setSingleEventMode(singleEventMode.isSelected());
            }
        });
        singleEventMode.setSelected(_tree.getCheckBoxTreeSelectionModel().isSingleEventMode());

        panel.add(new JLabel("Set Selection Mode:"));
        panel.add(comboBox);
        panel.add(Box.createVerticalStrut(3));
        panel.add(digIn);
        panel.add(singleEventMode);
        panel.add(checkBoxEnabled);
        panel.add(clickInCheckBoxOnly);
        panel.add(treeEnabled);
        panel.add(selectPartialFirst);
        panel.add(Box.createVerticalStrut(3));
        JPanel buttonPanel = new JPanel(new GridLayout(1, 0, 6, 6));
        buttonPanel.add(selectAll);
        buttonPanel.add(clearAll);
        panel.add(buttonPanel);
        panel.add(Box.createGlue());
        return panel;
    }

    public Component getDemoPanel() {
        JPanel panel = new JPanel(new BorderLayout(6, 6));

        final TreeModel treeModel = DemoData.createSongTreeModel();

        JPanel treePanel = new JPanel(new BorderLayout(2, 2));
        treePanel.setBorder(BorderFactory.createCompoundBorder(new JideTitledBorder(new PartialEtchedBorder(PartialEtchedBorder.LOWERED, PartialSide.NORTH), "Albums", JideTitledBorder.LEADING, JideTitledBorder.ABOVE_TOP),
                BorderFactory.createEmptyBorder(6, 0, 0, 0)));
        _tree = new CheckBoxTree(treeModel) {
            @Override
            public Dimension getPreferredScrollableViewportSize() {
                return new Dimension(400, 400);
            }
        };
        _tree.setRootVisible(false);
        _tree.setShowsRootHandles(true);
        DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) _tree.getActualCellRenderer();
        renderer.setLeafIcon(IconsFactory.getImageIcon(QuickFilterTreeDemo.class, "/icons/song.png"));
        renderer.setClosedIcon(IconsFactory.getImageIcon(QuickFilterTreeDemo.class, "/icons/album.png"));
        renderer.setOpenIcon(IconsFactory.getImageIcon(QuickFilterTreeDemo.class, "/icons/album.png"));

        SearchableUtils.installSearchable(_tree);

        TreeUtils.expandAll(_tree, true);

        JPanel listsPanel = new JPanel(new GridLayout(1, 2));

        final JList selectedList = new JList();
        final JList eventsList = new JList();
        final DefaultListModel eventsModel = new DefaultListModel();
        _tree.getCheckBoxTreeSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
            public void valueChanged(TreeSelectionEvent e) {
                TreePath[] paths = e.getPaths();
                for (TreePath path : paths) {
                    eventsModel.addElement((e.isAddedPath(path) ? "Added - " : "Removed - ") + path);
                }
                eventsModel.addElement("---------------");
                eventsList.ensureIndexIsVisible(eventsModel.size() - 1);

                TreePath[] treePaths = _tree.getCheckBoxTreeSelectionModel().getSelectionPaths();
                DefaultListModel selectedModel = new DefaultListModel();
                if (treePaths != null) {
                    for (TreePath path : treePaths) {
                        selectedModel.addElement(path);
                    }
                }
                selectedList.setModel(selectedModel);
            }
        });
        eventsList.setModel(eventsModel);

        selectedList.setVisibleRowCount(8);
        eventsList.setVisibleRowCount(8);
        JPanel selectedPanel = new JPanel(new BorderLayout());
        selectedPanel.setBorder(BorderFactory.createCompoundBorder(new JideTitledBorder(new PartialEtchedBorder(PartialEtchedBorder.LOWERED, PartialSide.NORTH), "Selected Songs", JideTitledBorder.LEADING, JideTitledBorder.ABOVE_TOP),
                BorderFactory.createEmptyBorder(6, 0, 0, 0)));
        selectedPanel.add(new JScrollPane(selectedList));

        JPanel eventsPanel = new JPanel(new BorderLayout());
        eventsPanel.setBorder(BorderFactory.createCompoundBorder(new JideTitledBorder(new PartialEtchedBorder(PartialEtchedBorder.LOWERED, PartialSide.NORTH), "Event Fired", JideTitledBorder.LEADING, JideTitledBorder.ABOVE_TOP),
                BorderFactory.createEmptyBorder(6, 0, 0, 0)));
        eventsPanel.add(new JScrollPane(eventsList));

        listsPanel.add(selectedPanel);
        listsPanel.add(eventsPanel);

        treePanel.add(listsPanel, BorderLayout.AFTER_LAST_LINE);
        treePanel.add(new JScrollPane(_tree));
        panel.add(treePanel);

        _tree.getCheckBoxTreeSelectionModel().addSelectionPath(_tree.getPathForRow(2));

        return panel;
    }

    @Override
    public String getDemoFolder() {
        return "B16.CheckBoxTree";
    }

    static public void main(String[] s) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                LookAndFeelFactory.installDefaultLookAndFeelAndExtension();
                showAsFrame(new CheckBoxTreeDemo());
            }
        });

    }
}


Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am


Return to JIDE Common Layer Open Source Project Discussion (Community Driven)

Who is online

Users browsing this forum: No registered users and 7 guests