Search in sources :

Example 1 with CheckBoxNodeEditor

use of org.scijava.swing.checkboxtree.CheckBoxNodeEditor in project mafscaling by vimsh.

the class VVTCalc method createTreePanel.

protected void createTreePanel() {
    DefaultMutableTreeNode wotTreeRoot = new DefaultMutableTreeNode("Root");
    DefaultTreeModel treeModel = new DefaultTreeModel(wotTreeRoot);
    pullTree = new JTree(treeModel);
    pullTree.setCellRenderer(new PullNodeRenderer());
    pullTree.setCellEditor(new CheckBoxNodeEditor(pullTree));
    pullTree.setEditable(true);
    pullTree.setRootVisible(false);
    pullTree.setOpaque(false);
    pullTree.setBackground(null);
    pullTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    pullTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            Object obj = ((DefaultMutableTreeNode) e.getPath().getLastPathComponent()).getUserObject();
            if (obj instanceof CheckBoxNodeData) {
                CheckBoxNodeData checkBoxNode = (CheckBoxNodeData) obj;
                XYSeriesCollection dataset;
                XYSeries series;
                for (int i = 0; i < hiddenSeries.size(); ++i) {
                    dataset = (XYSeriesCollection) chartPanels[i].getChart().getXYPlot().getDataset(0);
                    if (checkBoxNode.isChecked()) {
                        series = hiddenSeries.get(i).get(checkBoxNode.getText());
                        if (series != null) {
                            dataset.addSeries(series);
                            hiddenSeries.get(i).remove(checkBoxNode.getText());
                        }
                    } else {
                        for (int j = 0; j < dataset.getSeriesCount(); ++j) {
                            series = dataset.getSeries(j);
                            if (series.getDescription().equals(checkBoxNode.getText())) {
                                hiddenSeries.get(i).put(checkBoxNode.getText(), series);
                                dataset.removeSeries(j);
                            }
                        }
                    }
                }
            }
        }
    });
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) JTree(javax.swing.JTree) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) CheckBoxNodeEditor(org.scijava.swing.checkboxtree.CheckBoxNodeEditor) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) CheckBoxNodeData(org.scijava.swing.checkboxtree.CheckBoxNodeData) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection)

Example 2 with CheckBoxNodeEditor

use of org.scijava.swing.checkboxtree.CheckBoxNodeEditor in project mafscaling by vimsh.

the class LogView method createWotTreePanel.

protected void createWotTreePanel() {
    wotTreeMenu = new JPopupMenu();
    JMenuItem item = new JMenuItem("Select All");
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            if (wotSelectedNode != null)
                setWotNodesChecked(true);
        }
    });
    wotTreeMenu.add(item);
    item = new JMenuItem("Clear All");
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            if (wotSelectedNode != null)
                setWotNodesChecked(false);
        }
    });
    wotTreeMenu.add(item);
    DefaultMutableTreeNode wotTreeRoot = new DefaultMutableTreeNode("Root");
    DefaultTreeModel treeModel = new DefaultTreeModel(wotTreeRoot);
    wotTree = new JTree(treeModel);
    wotTree.setCellRenderer(new FileNodeRenderer());
    wotTree.setCellEditor(new CheckBoxNodeEditor(wotTree));
    wotTree.setEditable(true);
    wotTree.setRootVisible(false);
    wotTree.setOpaque(false);
    wotTree.setBackground(null);
    wotTree.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent event) {
            if (event.getButton() == MouseEvent.BUTTON3) {
                TreePath pathForLocation = wotTree.getPathForLocation(event.getPoint().x, event.getPoint().y);
                if (pathForLocation != null) {
                    wotTree.setComponentPopupMenu(wotTreeMenu);
                    wotSelectedNode = (DefaultMutableTreeNode) pathForLocation.getLastPathComponent();
                } else {
                    wotTree.setComponentPopupMenu(null);
                    wotSelectedNode = null;
                }
            }
            super.mousePressed(event);
        }
    });
    wotTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
}
Also used : ChartMouseEvent(org.jfree.chart.ChartMouseEvent) MouseEvent(java.awt.event.MouseEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ActionEvent(java.awt.event.ActionEvent) CheckBoxNodeEditor(org.scijava.swing.checkboxtree.CheckBoxNodeEditor) MouseAdapter(java.awt.event.MouseAdapter) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) JPopupMenu(javax.swing.JPopupMenu) JTree(javax.swing.JTree) ActionListener(java.awt.event.ActionListener) TreePath(javax.swing.tree.TreePath) JMenuItem(javax.swing.JMenuItem)

Aggregations

JTree (javax.swing.JTree)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)2 CheckBoxNodeEditor (org.scijava.swing.checkboxtree.CheckBoxNodeEditor)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 JMenuItem (javax.swing.JMenuItem)1 JPopupMenu (javax.swing.JPopupMenu)1 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)1 TreeSelectionListener (javax.swing.event.TreeSelectionListener)1 TreePath (javax.swing.tree.TreePath)1 ChartMouseEvent (org.jfree.chart.ChartMouseEvent)1 XYSeries (org.jfree.data.xy.XYSeries)1 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)1 CheckBoxNodeData (org.scijava.swing.checkboxtree.CheckBoxNodeData)1