Example usage for javax.swing.event TreeExpansionEvent getPath

List of usage examples for javax.swing.event TreeExpansionEvent getPath

Introduction

In this page you can find the example usage for javax.swing.event TreeExpansionEvent getPath.

Prototype

public TreePath getPath() 

Source Link

Document

Returns the path to the value that has been expanded/collapsed.

Usage

From source file:com.mindcognition.mindraider.ui.swing.explorer.LabelsTree.java

public void treeCollapsed(TreeExpansionEvent e) {
    logger.debug("Tree colapsed event..." + e.getPath());
}

From source file:com.mindcognition.mindraider.ui.swing.explorer.LabelsTree.java

public void treeExpanded(TreeExpansionEvent e) {
    logger.debug("Tree expanded event..." + e.getPath());
}

From source file:com.mindcognition.mindraider.ui.swing.explorer.LabelsTree.java

public void treeWillExpand(TreeExpansionEvent e) throws ExpandVetoException {
    logger.debug("Tree will expand " + e.getPath());
}

From source file:com.mindcognition.mindraider.ui.swing.explorer.LabelsTree.java

public void treeWillCollapse(TreeExpansionEvent e) throws ExpandVetoException {
    logger.debug("Tree will collapse " + e.getPath());
}

From source file:de.codesourcery.eve.skills.ui.model.impl.MarketGroupTreeModelBuilder.java

public void attach(JTree tree) {
    if (tree == null) {
        throw new IllegalArgumentException("tree cannot be NULL");
    }//from w  w w .java2 s .c  om

    if (this.tree != null && this.tree != tree) {
        throw new IllegalStateException("Already attached to " + this.tree);
    }

    this.tree = tree;
    this.tree.setModel(getTreeModel());

    this.tree.addTreeWillExpandListener(new TreeWillExpandListener() {

        @Override
        public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
            final ITreeNode node = (ITreeNode) event.getPath().getLastPathComponent();
            fetchChildren(node, false);
        }

        @Override
        public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
        }
    });
}

From source file:de.codesourcery.eve.skills.ui.components.impl.ItemChooserComponent.java

private void handleTreeExpansion(TreeExpansionEvent event) {
    final ITreeNode n = (ITreeNode) event.getPath().getLastPathComponent();

    if (!(n instanceof LazyTreeNode)) {
        return;//from   www.j ava 2 s.  c  o m
    }

    final LazyTreeNode node = (LazyTreeNode) n;

    log.debug("handleTreeExpansion(): children fetched = " + node.childrenFetched());

    if (node.childrenFetched()) {
        return;
    }

    // fetch children
    final InventoryGroup group = (InventoryGroup) node.getValue();

    final List<InventoryType> items = dataModel.getInventoryTypes(group);

    log.debug(
            "handleTreeExpansion(): got " + items.size() + " inventory types for group" + group.getGroupName());

    Collections.sort(items, InventoryType.BY_NAME_COMPARATOR);

    final List<ITreeNode> nodes = new ArrayList<ITreeNode>();
    for (InventoryType t : items) {
        if (t.isPublished()) {
            nodes.add(new DefaultTreeNode(t));
        }
    }

    node.setChildrenFetched();

    treeBuilder.getTreeModel().addChildren(node, nodes);
}

From source file:eu.apenet.dpt.standalone.gui.APETabbedPane.java

/**
 * Creates the XML tree of the file or of the converted file (if file already converted)
 * @param file The file represented in the list
 * @return A JComponent containing the tree if it exists, or an error message if not
 *///from w w w.j a  v a 2 s  .c o m
public JComponent createEditionTree(File file) {
    labels = dataPreparationToolGUI.getLabels();
    if (file == null) {
        editionPane.setViewportView(createMsgEditionTree(labels.getString("noTreeBuild") + "..."));
        return null;
    }
    FileInstance fileInstance = dataPreparationToolGUI.getFileInstances().get(file.getName());
    if (tree != null && ((XMLTreeTableModel) tree.getTreeTableModel()).getName().equals(file.getName())
            && fileInstance.getLastOperation().equals(FileInstance.Operation.EDIT_TREE))
        return null;

    //        fileInstance.setLastOperation(FileInstance.Operation.CREATE_TREE);
    try {
        ReaderInputStream readerInputStream;
        if (fileInstance.getCurrentLocation() == null || fileInstance.getCurrentLocation().equals("")) {
            Reader reader = new FileReader(file.getAbsolutePath());
            readerInputStream = new ReaderInputStream(reader, "UTF-8");
        } else {
            Reader reader = new FileReader(fileInstance.getCurrentLocation());
            readerInputStream = new ReaderInputStream(reader, "UTF-8");
        }
        Document doc = DOMUtil.createDocument(readerInputStream);
        tree = new JXTreeTable();
        tree.setTreeTableModel(new XMLTreeTableModel(doc, dataPreparationToolGUI.getDateNormalization(),
                dataPreparationToolGUI.getLevelList(), labels, fileInstance, dataPreparationToolGUI));
        tree.setTreeCellRenderer(new XMLTreeTableRenderer());

        tree.addTreeExpansionListener(new TreeExpansionListener() {
            public void treeExpanded(TreeExpansionEvent treeExpansionEvent) {
                int row = tree.getRowForPath(treeExpansionEvent.getPath());
                tree.scrollRowToVisible(row);
                tree.scrollRowToVisible(row + 1);
                tree.scrollRowToVisible(row + 2);
                tree.scrollRowToVisible(row + 3);
                tree.scrollRowToVisible(row + 4);
            }

            public void treeCollapsed(TreeExpansionEvent treeExpansionEvent) {
            }
        });

        expandFirstLevel();
        //            tree.expandAll();
        //            tree.setHighlighters(HighlighterFactory.createSimpleStriping (HighlighterFactory.QUICKSILVER));
        JScrollPane paneTest = new JScrollPane(tree);
        editionPane.setViewportView(paneTest);
        tree.setEditable(true);
        dataPreparationToolGUI.enableSaveBtn();
        dataPreparationToolGUI.setTree(tree);
        ((XMLTreeTableModel) tree.getTreeTableModel()).setName(file.getName());
    } catch (Exception e) {
        LOG.info("Error creating tree", e);
        tree = null;
        editionPane
                .setViewportView(createMsgEditionTree(labels.getString("edition.error.fileNoXmlOrCorrupted")));
    }
    return tree;
}

From source file:com.mindcognition.mindraider.ui.swing.trash.TrashJPanel.java

/**
 * @see javax.swing.event.TreeExpansionListener#treeExpanded(javax.swing.event.TreeExpansionEvent)
 *///from  www .  j a  va 2  s .com
public void treeExpanded(TreeExpansionEvent e) {
    logger.debug("Tree expanded event..." + e.getPath());
}

From source file:com.orthancserver.SelectImageDialog.java

public SelectImageDialog() {
    tree_ = new JTree();

    tree_.addTreeWillExpandListener(new TreeWillExpandListener() {
        @Override// w  ww . j  av  a  2  s.c  o  m
        public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
            TreePath path = event.getPath();
            if (path.getLastPathComponent() instanceof MyTreeNode) {
                MyTreeNode node = (MyTreeNode) path.getLastPathComponent();
                node.LoadChildren((DefaultTreeModel) tree_.getModel());
            }
        }

        @Override
        public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
        }
    });

    tree_.addTreeSelectionListener(new TreeSelectionListener() {
        @Override
        public void valueChanged(TreeSelectionEvent e) {
            TreePath path = e.getNewLeadSelectionPath();
            if (path != null) {
                MyTreeNode node = (MyTreeNode) path.getLastPathComponent();
                if (node.UpdatePreview(preview_)) {
                    selectedType_ = node.GetResourceType();
                    selectedUuid_ = node.GetUuid();
                    selectedConnection_ = node.GetConnection();
                    okButton_.setEnabled(true);
                }

                removeServer_.setEnabled(node.GetResourceType() == ResourceType.SERVER);
            }
        }
    });

    tree_.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            TreePath path = tree_.getPathForLocation(e.getX(), e.getY());
            if (path != null) {
                MyTreeNode node = (MyTreeNode) path.getLastPathComponent();
                if (e.getClickCount() == 2 && node.GetResourceType() == ResourceType.INSTANCE) {
                    // Double click on an instance, close the dialog
                    isSuccess_ = true;
                    setVisible(false);
                }
            }
        }
    });

    final JPanel contentPanel = new JPanel();
    getContentPane().setLayout(new BorderLayout());
    contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(contentPanel, BorderLayout.CENTER);
    contentPanel.setLayout(new BorderLayout(0, 0));
    {
        JSplitPane splitPane = new JSplitPane();
        splitPane.setResizeWeight(0.6);
        contentPanel.add(splitPane);

        splitPane.setLeftComponent(new JScrollPane(tree_));
        splitPane.setRightComponent(preview_);
    }
    {
        JPanel buttonPane = new JPanel();
        buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
        getContentPane().add(buttonPane, BorderLayout.SOUTH);
        {
            JButton btnAddServer = new JButton("Add server");
            btnAddServer.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg) {
                    OrthancConfigurationDialog dd = new OrthancConfigurationDialog();
                    dd.setLocationRelativeTo(null); // Center dialog on screen

                    OrthancConnection orthanc = dd.ShowModal();
                    if (orthanc != null) {
                        AddOrthancServer(orthanc);
                        ((DefaultTreeModel) tree_.getModel()).reload();
                    }
                }
            });
            buttonPane.add(btnAddServer);
        }

        {
            buttonPane.add(removeServer_);
            removeServer_.setEnabled(false);

            removeServer_.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg) {
                    MyTreeNode selected = (MyTreeNode) tree_.getLastSelectedPathComponent();
                    if (selected.GetResourceType() == ResourceType.SERVER && JOptionPane.showConfirmDialog(null,
                            "Remove server \"" + selected.getUserObject() + "\"?", "WARNING",
                            JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                        ((DefaultTreeModel) tree_.getModel()).removeNodeFromParent(selected);
                    }
                }
            });
        }

        {
            okButton_.setEnabled(false);
            okButton_.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg) {
                    isSuccess_ = true;
                    setVisible(false);
                }
            });
            buttonPane.add(okButton_);
            getRootPane().setDefaultButton(okButton_);
        }
        {
            JButton cancelButton = new JButton("Cancel");
            cancelButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg) {
                    setVisible(false);
                }
            });
            buttonPane.add(cancelButton);
        }
    }

    setUndecorated(false);
    setSize(500, 500);
    setTitle("Select some series or some instance in Orthanc");
    setModal(true);
}

From source file:gov.sandia.umf.platform.ui.jobs.RunPanel.java

public RunPanel() {
    root = new NodeBase();
    model = new DefaultTreeModel(root);
    tree = new JTree(model);
    tree.setRootVisible(false);/* w w w.j av  a  2 s.  co  m*/
    tree.setShowsRootHandles(true);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);

    tree.setCellRenderer(new DefaultTreeCellRenderer() {
        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
                boolean expanded, boolean leaf, int row, boolean hasFocus) {
            super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);

            NodeBase node = (NodeBase) value;
            Icon icon = node.getIcon(expanded); // A node knows whether it should hold other nodes or not, so don't pass leaf to it.
            if (icon == null) {
                if (leaf)
                    icon = getDefaultLeafIcon();
                else if (expanded)
                    icon = getDefaultOpenIcon();
                else
                    icon = getDefaultClosedIcon();
            }
            setIcon(icon);

            return this;
        }
    });

    tree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent e) {
            NodeBase newNode = (NodeBase) tree.getLastSelectedPathComponent();
            if (newNode == null)
                return;
            if (newNode == displayNode)
                return;

            if (displayThread != null)
                synchronized (displayText) {
                    displayThread.stop = true;
                }
            displayNode = newNode;
            if (displayNode instanceof NodeFile)
                viewFile();
            else if (displayNode instanceof NodeJob)
                viewJob();
        }
    });

    tree.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            int keycode = e.getKeyCode();
            if (keycode == KeyEvent.VK_DELETE || keycode == KeyEvent.VK_BACK_SPACE) {
                delete();
            }
        }
    });

    tree.addTreeWillExpandListener(new TreeWillExpandListener() {
        public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
            TreePath path = event.getPath(); // TODO: can this ever be null?
            Object o = path.getLastPathComponent();
            if (o instanceof NodeJob)
                ((NodeJob) o).build(tree);
        }

        public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
        }
    });

    tree.addTreeExpansionListener(new TreeExpansionListener() {
        public void treeExpanded(TreeExpansionEvent event) {
            Rectangle node = tree.getPathBounds(event.getPath());
            Rectangle visible = treePane.getViewport().getViewRect();
            visible.height -= node.y - visible.y;
            visible.y = node.y;
            tree.repaint(visible);
        }

        public void treeCollapsed(TreeExpansionEvent event) {
            Rectangle node = tree.getPathBounds(event.getPath());
            Rectangle visible = treePane.getViewport().getViewRect();
            visible.height -= node.y - visible.y;
            visible.y = node.y;
            tree.repaint(visible);
        }
    });

    Thread refreshThread = new Thread() {
        public void run() {
            try {
                // Initial load
                synchronized (running) {
                    for (MNode n : AppData.runs)
                        running.add(0, new NodeJob(n)); // This should be efficient on a doubly-linked list.
                    for (NodeJob job : running)
                        root.add(job);
                }
                EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        model.nodeStructureChanged(root);
                        if (model.getChildCount(root) > 0)
                            tree.setSelectionRow(0);
                    }
                });

                // Periodic refresh to show status of running jobs
                int shortCycles = 100; // Force full scan on first cycle.
                while (true) {
                    NodeBase d = displayNode; // Make local copy (atomic action) to prevent it changing from under us
                    if (d instanceof NodeJob)
                        ((NodeJob) d).monitorProgress(RunPanel.this);
                    if (shortCycles++ < 20) {
                        Thread.sleep(1000);
                        continue;
                    }
                    shortCycles = 0;

                    synchronized (running) {
                        Iterator<NodeJob> i = running.iterator();
                        while (i.hasNext()) {
                            NodeJob job = i.next();
                            if (job != d)
                                job.monitorProgress(RunPanel.this);
                            if (job.complete >= 1)
                                i.remove();
                        }
                    }
                }
            } catch (InterruptedException e) {
            }
        }
    };
    refreshThread.setDaemon(true);
    refreshThread.start();

    displayText = new JTextArea();
    displayText.setEditable(false);

    final JCheckBox chkFixedWidth = new JCheckBox("Fixed-Width Font");
    chkFixedWidth.setFocusable(false);
    chkFixedWidth.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int size = displayText.getFont().getSize();
            if (chkFixedWidth.isSelected()) {
                displayText.setFont(new Font(Font.MONOSPACED, Font.PLAIN, size));
            } else {
                displayText.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, size));
            }
        }
    });

    displayPane.setViewportView(displayText);

    ActionListener graphListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (displayNode instanceof NodeFile) {
                NodeFile nf = (NodeFile) displayNode;
                if (nf.type == NodeFile.Type.Output || nf.type == NodeFile.Type.Result) {
                    String graphType = e.getActionCommand();
                    if (displayPane.getViewport().getView() instanceof ChartPanel
                            && displayGraph.equals(graphType)) {
                        viewFile();
                        displayGraph = "";
                    } else {
                        if (graphType.equals("Graph")) {
                            Plot plot = new Plot(nf.path.getAbsolutePath());
                            if (!plot.columns.isEmpty())
                                displayPane.setViewportView(plot.createGraphPanel());
                        } else // Raster
                        {
                            Raster raster = new Raster(nf.path.getAbsolutePath(), displayPane.getHeight());
                            displayPane.setViewportView(raster.createGraphPanel());
                        }
                        displayGraph = graphType;
                    }
                }
            }
        }
    };

    buttonGraph = new JButton("Graph", ImageUtil.getImage("analysis.gif"));
    buttonGraph.setFocusable(false);
    buttonGraph.addActionListener(graphListener);
    buttonGraph.setActionCommand("Graph");

    buttonRaster = new JButton("Raster", ImageUtil.getImage("prnplot.gif"));
    buttonRaster.setFocusable(false);
    buttonRaster.addActionListener(graphListener);
    buttonRaster.setActionCommand("Raster");

    Lay.BLtg(this, "C",
            Lay.SPL(Lay.BL("C", treePane = Lay.sp(tree)), Lay.BL("N",
                    Lay.FL(chkFixedWidth, Lay.FL(buttonGraph, buttonRaster), "hgap=50"), "C", displayPane),
                    "divpixel=250"));
    setFocusCycleRoot(true);
}