Example usage for javax.swing.tree DefaultMutableTreeNode isLeaf

List of usage examples for javax.swing.tree DefaultMutableTreeNode isLeaf

Introduction

In this page you can find the example usage for javax.swing.tree DefaultMutableTreeNode isLeaf.

Prototype

public boolean isLeaf() 

Source Link

Document

Returns true if this node has no children.

Usage

From source file:com.ssn.listener.SSNInstagramSelectionListener.java

@Override
public void valueChanged(TreeSelectionEvent event) {
    DefaultMutableTreeNode node = treeHelper.getTreeNode(event.getPath());

    if (this.form.getHiveTree() != null) {
        this.form.getHiveTree().clearSelection();
    }/*from ww  w.ja va  2  s  .c  o  m*/

    if (this.form.getFacebookTree() != null) {
        this.form.getFacebookTree().clearSelection();
    }

    if (node.isLeaf()) {
        try {
            this.form.setCursor(new Cursor(Cursor.WAIT_CURSOR));
            String instagramDirPath = SSNHelper.getInstagramPhotosDirPath();
            fileTree.m_display.setText("instagramMedia");
            String urlString = String.format(
                    "https://api.instagram.com/v1/users/self/media/recent/?access_token=%s",
                    accessGrant.getAccessToken());

            List<InstagramMedia> imageList = new ArrayList<>();
            getMedia(urlString, imageList);

            createComponents(this.form, imageList);
        } catch (Exception e) {

        }
    }

}

From source file:Main.java

private void myPopupEvent(MouseEvent e) {
    int x = e.getX();
    int y = e.getY();
    JTree tree = (JTree) e.getSource();
    TreePath path = tree.getPathForLocation(x, y);
    if (path == null)
        return;/*from   w  ww.j a v  a  2 s .com*/

    DefaultMutableTreeNode rightClickedNode = (DefaultMutableTreeNode) path.getLastPathComponent();

    TreePath[] selectionPaths = tree.getSelectionPaths();

    boolean isSelected = false;
    if (selectionPaths != null) {
        for (TreePath selectionPath : selectionPaths) {
            if (selectionPath.equals(path)) {
                isSelected = true;
            }
        }
    }
    if (!isSelected) {
        tree.setSelectionPath(path);
    }
    if (rightClickedNode.isLeaf()) {
        JPopupMenu popup = new JPopupMenu();
        final JMenuItem refreshMenuItem = new JMenuItem("refresh");
        refreshMenuItem.addActionListener(ev -> System.out.println("refresh!"));
        popup.add(refreshMenuItem);
        popup.show(tree, x, y);
    }
}

From source file:wsattacker.plugin.intelligentdos.ui.dialog.Result_NB.java

private void resultTreeValueChanged(javax.swing.event.TreeSelectionEvent evt) {// GEN-FIRST:event_jTree1ValueChanged
    JTree tree = (JTree) evt.getSource();
    DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
    if (selectedNode != null && selectedNode.isLeaf()) {
        SuccessfulAttack sa = (SuccessfulAttack) selectedNode.getUserObject();
        jLabel1.setText(FormatHelper.toHTML(sa));

        StringBuilder builder = new StringBuilder();
        builder.append("<html>");
        String format = "-";
        if (!Double.isNaN(sa.getRatio())) {
            format = df.format(sa.getRatio());
        }//  www  .  j av a 2 s.c o  m
        builder.append("Attack roundtrip time ratio: ").append(format);
        builder.append("<br />");
        builder.append("the payload is ").append(sa.getEfficiency().name());
        builder.append("<br />");
        builder.append("<br />");
        double reuqestsPerSecond = ((int) (sa.getParamItem().getReuqestsPerSecond() * 100.0)) / 100.0;
        builder.append(reuqestsPerSecond).append(" requests per second were sent");
        builder.append("<br />");
        if (sa.getTamperedContent() != null) {
            long l = (long) (sa.getTamperedContent().getBytes(Charset.forName("UTF-8")).length
                    * sa.getParamItem().getReuqestsPerSecond());
            builder.append("the traffic was (approx) ").append(FileUtils.byteCountToDisplaySize(l))
                    .append(" per second");
        }

        builder.append("</html>");

        successMetric.setText(builder.toString());

        jTextArea1.setText(sa.getXmlWithPlaceholder());

        JFreeChart createOverlaidChart = ChartHelper.createOverlaidChart(sa);
        JFreeChart createWhiskerChart = ChartHelper.createWhiskerChart(sa);
        ((ChartPanel) chartPanel1).setChart(createOverlaidChart);
        ((ChartPanel) chartPanel2).setChart(createWhiskerChart);
    } else {
        jLabel1.setText("");
        successMetric.setText("");
    }
}

From source file:au.org.ala.delta.editor.ui.CharacterTree.java

/**
 * This is a done to initiate a cell edit from a single click with drag and drop enabled.
 *//*from  www .  j a  v  a  2  s .  co m*/
protected void processMouseEvent(MouseEvent e) {

    super.processMouseEvent(e);
    _doubleProcessingMouseEvent = false;
    TreePath selectedPath = getSelectionPath();
    if (selectedPath != null) {
        Object lastComponent = selectedPath.getLastPathComponent();
        if (lastComponent instanceof DefaultMutableTreeNode) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) lastComponent;

            if (node.isLeaf()) {
                int row = getRowForPath(selectedPath);
                Rectangle bounds = getRowBounds(row);
                int pos = e.getX() - bounds.x;
                if (pos >= 0 && pos < 20) {
                    _doubleProcessingMouseEvent = true;
                    super.processMouseEvent(e);
                }
            }
        }
    }
}

From source file:au.org.ala.delta.editor.ui.CharacterTree.java

public CharacterTree() {

    setToggleClickCount(0);// w  w w  .  j ava  2  s .c  om
    _characterListBehaviour = new CharacterListBehaviour();
    _stateListBehaviour = new StateListBehaviour();

    ToolTipManager.sharedInstance().registerComponent(this);

    addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent e) {
            if (_doubleProcessingMouseEvent) {
                return;
            }
            if (!isEditing()) {
                int selectedRow = getClosestRowForLocation(e.getX(), e.getY());

                if ((selectedRow >= 0) && (e.getClickCount() == 2) && SwingUtilities.isLeftMouseButton(e)) {
                    Action action = getActionMap().get(SELECTION_ACTION_KEY);
                    if (action != null) {
                        action.actionPerformed(new ActionEvent(this, -1, ""));
                    }
                }
            }
        }
    });

    addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {

            TreePath selection = e.getNewLeadSelectionPath();
            if (selection != null) {
                Object lastComponent = selection.getLastPathComponent();
                if (lastComponent instanceof DefaultMutableTreeNode) {
                    DefaultMutableTreeNode node = (DefaultMutableTreeNode) lastComponent;

                    if (node.isLeaf()) {
                        CharacterTree.super.setTransferHandler(_stateTransferHandler);
                    } else {
                        CharacterTree.super.setTransferHandler(_characterTransferHandler);
                    }
                }
            }
        }
    });

    ActionMap actionMap = Application.getInstance().getContext().getActionMap(this);

    javax.swing.Action find = actionMap.get("find");
    if (find != null) {
        getActionMap().put("find", find);
    }

    javax.swing.Action findNext = actionMap.get("findNext");
    if (findNext != null) {
        getActionMap().put("findNext", findNext);
    }

    getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.CTRL_MASK), SELECTION_ACTION_KEY);

}

From source file:be.fedict.eid.tsl.tool.TslInternalFrame.java

@Override
public void valueChanged(TreeSelectionEvent event) {
    DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
    if (treeNode.isLeaf()) {
        TrustService trustService = (TrustService) treeNode.getUserObject();
        this.serviceName.setText(trustService.getName());
        this.serviceType.setText(trustService.getType()
                .substring(trustService.getType().indexOf("Svctype/") + "Svctype/".length()));
        this.serviceStatus.setText(trustService.getStatus()
                .substring(trustService.getStatus().indexOf("Svcstatus/") + "Svcstatus/".length()));
        X509Certificate certificate = trustService.getServiceDigitalIdentity();
        byte[] encodedCertificate;
        try {//from ww  w  . ja  va2s. com
            encodedCertificate = certificate.getEncoded();
        } catch (CertificateEncodingException e) {
            throw new RuntimeException("cert: " + e.getMessage(), e);
        }
        String sha1Thumbprint = DigestUtils.shaHex(encodedCertificate);
        this.serviceSha1Thumbprint.setText(sha1Thumbprint);

        String sha256Thumbprint = DigestUtils.sha256Hex(encodedCertificate);
        this.serviceSha256Thumbprint.setText(sha256Thumbprint);

        this.validityBegin.setText(certificate.getNotBefore().toString());
        this.validityEnd.setText(certificate.getNotAfter().toString());
    } else {
        this.serviceName.setText("");
        this.serviceType.setText("");
        this.serviceStatus.setText("");
        this.serviceSha1Thumbprint.setText("");
        this.serviceSha256Thumbprint.setText("");
        this.validityBegin.setText("");
        this.validityEnd.setText("");
    }
}

From source file:com.imaginea.betterdocs.BetterDocsAction.java

private TreeSelectionListener getTreeSelectionListener(final TreeNode root) {
    return new TreeSelectionListener() {
        @Override//from w w w  . j a v a 2  s  .  co m
        public void valueChanged(TreeSelectionEvent treeSelectionEvent) {
            DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) jTree.getLastSelectedPathComponent();

            if (selectedNode == null) {

            } else if (selectedNode.isLeaf() && root.getChildCount() > 0) {
                final CodeInfo codeInfo = (CodeInfo) selectedNode.getUserObject();
                final Document windowEditorDocument = windowEditor.getDocument();

                writeToDocument(codeInfo, windowEditorDocument);

                final List<Integer> linesForFolding = codeInfo.getLineNumbers();
                linesForFolding.add(windowEditorDocument.getLineCount() + 1);
                java.util.Collections.sort(linesForFolding);
                addFoldings(windowEditorDocument, linesForFolding);
            }
        }
    };
}

From source file:edu.ku.brc.af.ui.forms.formatters.DataObjFieldFormatSinglePanel.java

public void addField() {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) availableFieldsComp.getTree()
            .getLastSelectedPathComponent();
    if (node == null || !node.isLeaf() || !(node.getUserObject() instanceof DataObjDataFieldWrapper)) {
        return; // not really a field that can be added, just empty or a string
    }//from  w  w  w. j a  v a  2s.c  o m

    Object obj = node.getUserObject();
    if (obj instanceof DataObjDataFieldWrapper) {
        DataObjDataFieldWrapper wrapper = (DataObjDataFieldWrapper) obj;
        String sep = sepText.getText();
        if (StringUtils.isNotEmpty(sep)) {
            try {
                DefaultStyledDocument doc = (DefaultStyledDocument) formatEditor.getStyledDocument();
                if (doc.getLength() > 0) {
                    doc.insertString(doc.getLength(), sep, null);
                }
            } catch (BadLocationException ble) {
            }

        }
        insertFieldIntoTextEditor(wrapper);
        setHasChanged(true);
    }
}

From source file:org.netxilia.server.rest.HomeResource.java

/**
 * walk the tree and dump the node to the tree
 * //  ww  w .  j a v  a  2s  .c om
 * @param node
 * @param treeview
 */
@SuppressWarnings("unchecked")
private void buildTreeView(DefaultMutableTreeNode node, StringBuilder treeview) {
    // <ul id="example" class="filetree">
    // <li><span class="folder">Folder 1</span>
    // <ul>
    // <li><span class="file">Item 1.1</span></li>
    // </ul>
    // </li>
    // <li><span class="folder">Folder 2</span>

    TreeViewData viewData = (TreeViewData) node.getUserObject();
    if (node.isLeaf()) {
        if (viewData != null) {
            treeview.append("<li><span id='").append(viewData.getId()).append("' class='")
                    .append(viewData.getCssClass()).append("'>").append(viewData.getName())
                    .append("</span></li>");
        }
    } else {
        if (viewData != null) {
            if (viewData.isCollapsed()) {
                treeview.append("<li class='closed'>");
            } else {
                treeview.append("<li>");
            }
            treeview.append("<span class='folder ").append(viewData.getCssClass()).append("'>")
                    .append(viewData.getName()).append("</span><ul>");
        }
        Enumeration<DefaultMutableTreeNode> childrenEnum = node.children();
        while (childrenEnum.hasMoreElements()) {
            buildTreeView(childrenEnum.nextElement(), treeview);
        }
        if (viewData != null) {
            treeview.append("</ul></li>");
        }
    }
}

From source file:net.sf.jabref.gui.FindUnlinkedFilesDialog.java

/**
 * Creates a list of {@link File}s for all leaf nodes in the tree structure
 * <code>node</code>, which have been marked as <i>selected</i>. <br>
 * <br>/*ww  w  .  ja v  a 2  s .  co  m*/
 * <code>Selected</code> nodes correspond to those entries in the tree,
 * whose checkbox is <code>checked</code>.
 *
 * SIDE EFFECT: The checked nodes are removed from the tree.
 *
 * @param node
 *            The root node representing a tree structure.
 * @return A list of files of all checked leaf nodes.
 */
private List<File> getFileListFromNode(CheckableTreeNode node) {
    List<File> filesList = new ArrayList<>();
    Enumeration<CheckableTreeNode> children = node.depthFirstEnumeration();
    List<CheckableTreeNode> nodesToRemove = new ArrayList<>();
    for (CheckableTreeNode child : Collections.list(children)) {
        if (child.isLeaf() && child.isSelected()) {
            File nodeFile = ((FileNodeWrapper) child.getUserObject()).file;
            if ((nodeFile != null) && nodeFile.isFile()) {
                filesList.add(nodeFile);
                nodesToRemove.add(child);
            }
        }
    }

    // remove imported files from tree
    DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
    for (CheckableTreeNode nodeToRemove : nodesToRemove) {
        DefaultMutableTreeNode parent = (DefaultMutableTreeNode) nodeToRemove.getParent();
        model.removeNodeFromParent(nodeToRemove);

        // remove empty parent node
        while ((parent != null) && parent.isLeaf()) {
            DefaultMutableTreeNode pp = (DefaultMutableTreeNode) parent.getParent();
            if (pp != null) {
                model.removeNodeFromParent(parent);
            }
            parent = pp;
        }
        // TODO: update counter / see: getTreeCellRendererComponent for label generation
    }
    tree.invalidate();
    tree.repaint();

    return filesList;
}