Example usage for javax.swing.tree DefaultMutableTreeNode getChildCount

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

Introduction

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

Prototype

public int getChildCount() 

Source Link

Document

Returns the number of children of this node.

Usage

From source file:DynamicTreeDemo.java

public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent, Object child, boolean shouldBeVisible) {
    DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child);

    if (parent == null) {
        parent = rootNode;//  w  w  w  .j  a v a  2s .c  o  m
    }

    // It is key to invoke this on the TreeModel, and NOT DefaultMutableTreeNode
    treeModel.insertNodeInto(childNode, parent, parent.getChildCount());

    // Make sure the user can see the lovely new node.
    if (shouldBeVisible) {
        tree.scrollPathToVisible(new TreePath(childNode.getPath()));
    }
    return childNode;
}

From source file:ListAlgorithmsBC.java

private ListAlgorithmsBC() {
    super("JCE Algorithms");
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Providers");
    DefaultTreeModel treeModel = new DefaultTreeModel(root);
    for (Provider provider : java.security.Security.getProviders()) {
        DefaultMutableTreeNode providerNode = new DefaultMutableTreeNode(provider);
        root.add(providerNode);//from w w  w.ja v a 2  s . c  om
        Set<Provider.Service> used = new HashSet<Provider.Service>();

        getNodes(providerNode, provider, used, "Cipher", "cipher");
        getNodes(providerNode, provider, used, "Key Agreement", "keyagreement");
        getNodes(providerNode, provider, used, "Key Generator", "keygenerator");
        getNodes(providerNode, provider, used, "Key Pair Generator", "keypairgenerator");
        getNodes(providerNode, provider, used, "Key Factory", "keyfactory");
        getNodes(providerNode, provider, used, "Secret Key Factory", "secretkeyfactory");
        getNodes(providerNode, provider, used, "Mac", "mac");
        getNodes(providerNode, provider, used, "Message Digest", "messagedigest");
        getNodes(providerNode, provider, used, "Signature", "signature");
        getNodes(providerNode, provider, used, "Algorithm Paramater", "algorithmparameters");
        getNodes(providerNode, provider, used, "Algorithm Paramater Generator", "algorithmparametergenerator");
        getNodes(providerNode, provider, used, "Key Store", "keystore");
        getNodes(providerNode, provider, used, "Secure Random", "securerandom");
        getNodes(providerNode, provider, used, "Certificate Factory", "certificatefactory");
        getNodes(providerNode, provider, used, "Certificate Store", "certstore");
        getNodes(providerNode, provider, used, "Key Manager Factory", "KeyManagerFactory");
        getNodes(providerNode, provider, used, "Trust Manager Factory", "TrustManagerFactory");
        getNodes(providerNode, provider, used, "SSL Context", "SSLContext");
        getNodes(providerNode, provider, used, "Sasl Server Factory", "SaslServerFactory");
        getNodes(providerNode, provider, used, "Sasl Client Factory", "SaslClientFactory");
        {
            DefaultMutableTreeNode node = new DefaultMutableTreeNode("Other");
            for (Provider.Service service : provider.getServices()) {
                if (!used.contains(service)) {
                    DefaultMutableTreeNode serviceNode = new DefaultMutableTreeNode(
                            service.getType() + " : " + service.getAlgorithm());
                    node.add(serviceNode);
                    serviceNode.add(new DefaultMutableTreeNode("class : " + service.getClassName()));
                }
            }
            if (node.getChildCount() != 0)
                providerNode.add(node);
        }
    }

    JTree tree = new JTree(treeModel);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setEditable(false);
    JScrollPane pane = new JScrollPane(tree);
    pane.setPreferredSize(new Dimension(200, 200));

    getContentPane().add(pane);

    pack();
}

From source file:TreeUtil.java

public void addNode(String name, Object obj) {
    itsMap.put(name, obj);/* ww w.  j  a va  2  s .  c  o  m*/
    DefaultMutableTreeNode tempNode = itsRootNode;
    StringTokenizer tok = new StringTokenizer(name, ".");
    String currentName = null;
    while (tok.hasMoreTokens()) {
        String myTok = tok.nextToken();
        currentName = (currentName == null) ? myTok : currentName + "." + myTok;
        boolean createNew = true;
        for (int j = 0; j < tempNode.getChildCount(); j++) {
            DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) tempNode.getChildAt(j);
            if (childNode.toString().equals(myTok)) {
                tempNode = childNode;
                createNew = false;
                break;
            }
        }
        if (createNew) {
            DefaultMutableTreeNode aNode = new DefaultMutableTreeNode(myTok);
            itsTreeMap.put(currentName, aNode);
            // Let's give some consideration to where in the tree we place
            // the new node.
            // We want any nodes with children to be listed first, in
            // alphabetical order.
            // Then come nodes with no children, in alphabetical order.
            if (tok.hasMoreTokens()) {
                // This node is not a leaf node
                int targeti;
                for (targeti = 0; targeti < tempNode.getChildCount(); targeti++) {
                    TreeNode bNode = tempNode.getChildAt(targeti);
                    if (bNode.isLeaf() || bNode.toString().compareToIgnoreCase(myTok) > 0) {
                        break;
                    }
                }
                tempNode.insert(aNode, targeti);
            } else {
                // This node is a leaf node
                int targeti;
                for (targeti = 0; targeti < tempNode.getChildCount(); targeti++) {
                    TreeNode bNode = tempNode.getChildAt(targeti);
                    if (bNode.isLeaf() && bNode.toString().compareToIgnoreCase(myTok) > 0) {
                        break;
                    }
                }
                tempNode.insert(aNode, targeti);
            }
            tempNode = aNode;
        }
    }
}

From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.BeanInspectorPanel.java

private void jTree1MouseClicked1(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTree1MouseClicked1

    if (evt.getClickCount() == 2 && evt.getButton() == MouseEvent.BUTTON1) {
        DefaultMutableTreeNode tn = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();

        if (tn.getChildCount() > 0)
            return;

        /*if (!jTree1.isCollapsed( jTree1.getSelectionPath() ))
        {/*  w ww .  j a v  a  2  s.  co m*/
        jTree1.collapsePath( jTree1.getSelectionPath() );
        return;
        }
         *
         */
        if (tn.getUserObject() instanceof TreeJRField) {
            TreeJRField jrf = (TreeJRField) tn.getUserObject();
            if (!jrf.getObj().isPrimitive() && !jrf.getObj().getName().startsWith("java.lang.")) {
                exploreBean(tn, jrf.getObj().getName(),
                        isPathOnDescription() ? Misc.nvl(jrf.getField().getDescription(), "")
                                : Misc.nvl(jrf.getField().getName(), ""));
            }
        }
    }

}

From source file:uk.co.markfrimston.tasktree.TaskTree.java

protected void addChildElementsFromTasks(Document doc, Element parent, DefaultMutableTreeNode treeNode,
        int indent) {
    for (int i = 0; i < treeNode.getChildCount(); i++) {
        DefaultMutableTreeNode treeChild = (DefaultMutableTreeNode) treeNode.getChildAt(i);
        String indentText = "\n";
        for (int j = 0; j < indent + 1; j++) {
            indentText += "\t";
        }/*from w  w w  .j a  v a2s.  c o m*/
        parent.appendChild(doc.createTextNode(indentText));
        Element childEl = doc.createElement("task");
        childEl.setAttribute("label", (String) treeChild.getUserObject());
        parent.appendChild(childEl);
        addChildElementsFromTasks(doc, childEl, treeChild, indent + 1);
    }
    if (treeNode.getChildCount() > 0) {
        String indentText = "\n";
        for (int i = 0; i < indent; i++) {
            indentText += "\t";
        }
        parent.appendChild(doc.createTextNode(indentText));
    }
}

From source file:uk.co.markfrimston.tasktree.Main.java

public Main(TaskTree taskTree) {
    super();/* w  w w  .j  av  a  2s .  c  o m*/

    this.taskTree = taskTree;

    this.setTitle("Task Tree");
    this.setSize(new Dimension(300, 500));
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel quickInPanel = new JPanel(new BorderLayout());
    this.quickIn = new JTextArea();
    this.quickIn.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent arg0) {
            if (arg0.getKeyCode() == KeyEvent.VK_ENTER) {
                String newText = quickIn.getText().trim();
                if (newText != null && newText.length() > 0) {
                    addTask(Main.this.taskTree.getRoot(), 0, newText, true);
                    try {
                        Main.this.taskTree.changesMade();
                    } catch (Exception e) {
                        error(e.getMessage());
                    }
                }
                quickIn.setText("");
            }
        }
    });
    this.quickIn.setPreferredSize(new Dimension(300, 75));
    this.quickIn.setBorder(BorderFactory.createTitledBorder("Quick Input"));
    quickInPanel.add(this.quickIn, BorderLayout.CENTER);
    this.syncButton = new JButton("Sync");
    this.syncButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            new SyncThread(Main.this).start();
        }
    });
    quickInPanel.add(this.syncButton, BorderLayout.EAST);
    this.getContentPane().add(quickInPanel, BorderLayout.NORTH);

    this.tree = new JTree(taskTree.getTreeModel());
    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer() {
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
                boolean expanded, boolean leaf, int row, boolean hasFocus) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
            Object newVal = htmlFilter(String.valueOf(node.getUserObject()));
            if (node.getChildCount() > 0 && !tree.isExpanded(new TreePath(node.getPath()))) {
                DefaultMutableTreeNode firstLeaf = (DefaultMutableTreeNode) node.getFirstLeaf();
                newVal = htmlFilter(String.valueOf(node.getUserObject()))
                        + " <span style='color:silver;font-style:italic'>" + "("
                        + String.valueOf(firstLeaf.getUserObject()) + ")</span>";
            }
            newVal = "<html>" + newVal + "</html>";

            return super.getTreeCellRendererComponent(tree, newVal, selected, expanded, leaf, row, hasFocus);
        }
    };
    ImageIcon bulletIcon = new ImageIcon(Main.class.getResource("bullet.gif"));
    renderer.setLeafIcon(bulletIcon);
    renderer.setOpenIcon(bulletIcon);
    renderer.setClosedIcon(bulletIcon);
    renderer.setBorder(BorderFactory.createEmptyBorder(4, 0, 4, 0));
    this.tree.setCellRenderer(renderer);
    this.tree.setRootVisible(false);
    this.tree.setShowsRootHandles(true);
    this.tree.addMouseListener(new MouseAdapter() {
        protected void doSelectRow(MouseEvent arg0) {
            int row = tree.getRowForLocation(arg0.getX(), arg0.getY());
            if (row != -1) {
                tree.setSelectionRow(row);
                if (arg0.isPopupTrigger()) {
                    popup.show(tree, arg0.getX(), arg0.getY());
                }
            }
        }

        public void mousePressed(MouseEvent arg0) {
            doSelectRow(arg0);
        }

        public void mouseReleased(MouseEvent arg0) {
            doSelectRow(arg0);
        }
    });
    JScrollPane treeScroll = new JScrollPane(tree);
    treeScroll.setBorder(BorderFactory.createTitledBorder("Task List"));
    this.getContentPane().add(treeScroll, BorderLayout.CENTER);

    this.popup = new JPopupMenu();
    JMenuItem addBefore = new JMenuItem("Add Before");
    addBefore.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DefaultMutableTreeNode selected = getSelectedNode();
            DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent();
            int pos = parent.getIndex(selected);
            promptAndInsert(parent, pos);
            try {
                Main.this.taskTree.changesMade();
            } catch (Exception ex) {
                error(ex.getMessage());
            }
        }
    });
    this.popup.add(addBefore);
    JMenuItem addAfter = new JMenuItem("Add After");
    addAfter.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DefaultMutableTreeNode selected = getSelectedNode();
            DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent();
            int pos = parent.getIndex(selected) + 1;
            promptAndInsert(parent, pos);
            try {
                Main.this.taskTree.changesMade();
            } catch (Exception ex) {
                error(ex.getMessage());
            }
        }
    });
    this.popup.add(addAfter);
    JMenuItem addNested = new JMenuItem("Add Nested");
    addNested.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DefaultMutableTreeNode selected = getSelectedNode();
            int pos = selected.getChildCount();
            promptAndInsert(selected, pos);
            try {
                Main.this.taskTree.changesMade();
            } catch (Exception ex) {
                ex.getMessage();
            }
        }
    });
    this.popup.add(addNested);
    this.popup.add(new JSeparator());
    JMenuItem moveTop = new JMenuItem("Move to Top");
    moveTop.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DefaultMutableTreeNode selected = getSelectedNode();
            DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent();
            moveTask(selected, parent, 0);
            try {
                Main.this.taskTree.changesMade();
            } catch (Exception ex) {
                error(ex.getMessage());
            }
        }
    });
    this.popup.add(moveTop);
    JMenuItem moveUp = new JMenuItem("Move Up");
    moveUp.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DefaultMutableTreeNode selected = getSelectedNode();
            DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent();
            int pos = Math.max(parent.getIndex(selected) - 1, 0);
            moveTask(selected, parent, pos);
            try {
                Main.this.taskTree.changesMade();
            } catch (Exception ex) {
                error(ex.getMessage());
            }
        }
    });
    this.popup.add(moveUp);
    JMenuItem moveDown = new JMenuItem("Move Down");
    moveDown.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DefaultMutableTreeNode selected = getSelectedNode();
            DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent();
            int pos = Math.min(parent.getIndex(selected) + 1, parent.getChildCount() - 1);
            moveTask(selected, parent, pos);
            try {
                Main.this.taskTree.changesMade();
            } catch (Exception ex) {
                error(ex.getMessage());
            }
        }
    });
    this.popup.add(moveDown);
    JMenuItem moveBottom = new JMenuItem("Move to Bottom");
    moveBottom.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DefaultMutableTreeNode selected = getSelectedNode();
            DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent();
            moveTask(selected, parent, parent.getChildCount() - 1);
            try {
                Main.this.taskTree.changesMade();
            } catch (Exception ex) {
                error(ex.getMessage());
            }
        }
    });
    this.popup.add(moveBottom);
    this.popup.add(new JSeparator());
    JMenuItem rename = new JMenuItem("Edit");
    rename.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DefaultMutableTreeNode selected = getSelectedNode();
            String newText = prompt((String) selected.getUserObject());
            if (newText != null && newText.length() > 0) {
                selected.setUserObject(newText);
                Main.this.taskTree.getTreeModel().reload(selected);
                try {
                    Main.this.taskTree.changesMade();
                } catch (Exception ex) {
                    error(ex.getMessage());
                }
            }
        }
    });
    this.popup.add(rename);
    JMenuItem delete = new JMenuItem("Delete");
    delete.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            promptAndRemove(getSelectedNode());
            try {
                Main.this.taskTree.changesMade();
            } catch (Exception ex) {
                error(ex.getMessage());
            }
        }
    });
    this.popup.add(delete);

    this.setVisible(true);

    loadConfig();
    load();

    syncButton.setVisible(this.taskTree.hasSyncCapability());
}

From source file:com.edduarte.protbox.ui.windows.RestoreFileWindow.java

private RestoreFileWindow(final PReg registry) {
    super();/* w  ww .  j a va  2 s  . co  m*/
    setLayout(null);

    final JTextField searchField = new JTextField();
    searchField.setLayout(null);
    searchField.setBounds(2, 2, 301, 26);
    searchField.setBorder(new LineBorder(Color.lightGray));
    searchField.setFont(Constants.FONT);
    add(searchField);

    final JLabel noBackupFilesLabel = new JLabel("<html>No backups files were found!<br><br>"
            + "<font color=\"gray\">If you think there is a problem with the<br>"
            + "backup system, please create an issue here:<br>"
            + "<a href=\"#\">https://github.com/com.edduarte/protbox/issues</a></font></html>");
    noBackupFilesLabel.setLayout(null);
    noBackupFilesLabel.setBounds(20, 50, 300, 300);
    noBackupFilesLabel.setFont(Constants.FONT.deriveFont(14f));
    noBackupFilesLabel.addMouseListener((OnMouseClick) e -> {
        String urlPath = "https://github.com/com.edduarte/protbox/issues";

        try {

            if (Desktop.isDesktopSupported()) {
                Desktop.getDesktop().browse(new URI(urlPath));

            } else {
                if (SystemUtils.IS_OS_WINDOWS) {
                    Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + urlPath);

                } else {
                    java.util.List<String> browsers = Lists.newArrayList("firefox", "opera", "safari",
                            "mozilla", "chrome");

                    for (String browser : browsers) {
                        if (Runtime.getRuntime().exec(new String[] { "which", browser }).waitFor() == 0) {

                            Runtime.getRuntime().exec(new String[] { browser, urlPath });
                            break;
                        }
                    }
                }
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    });

    DefaultMutableTreeNode rootTreeNode = registry.buildEntryTree();
    final JTree tree = new JTree(rootTreeNode);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    if (rootTreeNode.getChildCount() == 0) {
        searchField.setEnabled(false);
        add(noBackupFilesLabel);
    }
    expandTree(tree);
    tree.setLayout(null);
    tree.setRootVisible(false);
    tree.setEditable(false);
    tree.setCellRenderer(new SearchableTreeCellRenderer(searchField));
    searchField.addKeyListener((OnKeyReleased) e -> {

        // update and expand tree
        DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
        model.nodeStructureChanged((TreeNode) model.getRoot());
        expandTree(tree);
    });
    final JScrollPane scroll = new JScrollPane(tree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scroll.setBorder(new DropShadowBorder());
    scroll.setBorder(new LineBorder(Color.lightGray));
    scroll.setBounds(2, 30, 334, 360);
    add(scroll);

    JLabel close = new JLabel(new ImageIcon(Constants.getAsset("close.png")));
    close.setLayout(null);
    close.setBounds(312, 7, 18, 18);
    close.setFont(Constants.FONT);
    close.setForeground(Color.gray);
    close.addMouseListener((OnMouseClick) e -> dispose());
    add(close);

    final JLabel permanentDeleteButton = new JLabel(new ImageIcon(Constants.getAsset("permanent.png")));
    permanentDeleteButton.setLayout(null);
    permanentDeleteButton.setBounds(91, 390, 40, 39);
    permanentDeleteButton.setBackground(Color.black);
    permanentDeleteButton.setEnabled(false);
    permanentDeleteButton.addMouseListener((OnMouseClick) e -> {
        if (permanentDeleteButton.isEnabled()) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
            PbxEntry entry = (PbxEntry) node.getUserObject();

            if (JOptionPane.showConfirmDialog(null,
                    "Are you sure you wish to permanently delete '" + entry.realName()
                            + "'?\nThis file and its "
                            + "backup copies will be deleted immediately. You cannot undo this action.",
                    "Confirm Cancel", JOptionPane.YES_NO_OPTION,
                    JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) {

                registry.permanentDelete(entry);
                dispose();
                RestoreFileWindow.getInstance(registry);

            } else {
                setVisible(true);
            }
        }
    });
    add(permanentDeleteButton);

    final JLabel configBackupsButton = new JLabel(new ImageIcon(Constants.getAsset("config.png")));
    configBackupsButton.setLayout(null);
    configBackupsButton.setBounds(134, 390, 40, 39);
    configBackupsButton.setBackground(Color.black);
    configBackupsButton.setEnabled(false);
    configBackupsButton.addMouseListener((OnMouseClick) e -> {
        if (configBackupsButton.isEnabled()) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
            PbxEntry entry = (PbxEntry) node.getUserObject();
            if (entry instanceof PbxFile) {
                PbxFile pbxFile = (PbxFile) entry;

                JFrame frame = new JFrame("Choose backup policy");
                Object option = JOptionPane.showInputDialog(frame,
                        "Choose below the backup policy for this file:", "Choose backup",
                        JOptionPane.QUESTION_MESSAGE, null, PbxFile.BackupPolicy.values(),
                        pbxFile.getBackupPolicy());

                if (option == null) {
                    setVisible(true);
                    return;
                }
                PbxFile.BackupPolicy pickedPolicy = PbxFile.BackupPolicy.valueOf(option.toString());
                pbxFile.setBackupPolicy(pickedPolicy);
            }
            setVisible(true);
        }
    });
    add(configBackupsButton);

    final JLabel restoreBackupButton = new JLabel(new ImageIcon(Constants.getAsset("restore.png")));
    restoreBackupButton.setLayout(null);
    restoreBackupButton.setBounds(3, 390, 85, 39);
    restoreBackupButton.setBackground(Color.black);
    restoreBackupButton.setEnabled(false);
    restoreBackupButton.addMouseListener((OnMouseClick) e -> {
        if (restoreBackupButton.isEnabled()) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
            PbxEntry entry = (PbxEntry) node.getUserObject();
            if (entry instanceof PbxFolder) {
                registry.restoreFolderFromEntry((PbxFolder) entry);

            } else if (entry instanceof PbxFile) {
                PbxFile pbxFile = (PbxFile) entry;
                java.util.List<String> snapshots = pbxFile.snapshotsToString();
                if (snapshots.isEmpty()) {
                    setVisible(true);
                    return;
                }

                JFrame frame = new JFrame("Choose backup");
                Object option = JOptionPane.showInputDialog(frame,
                        "Choose below what backup snapshot would you like restore:", "Choose backup",
                        JOptionPane.QUESTION_MESSAGE, null, snapshots.toArray(), snapshots.get(0));

                if (option == null) {
                    setVisible(true);
                    return;
                }
                int pickedIndex = snapshots.indexOf(option.toString());
                registry.restoreFileFromEntry((PbxFile) entry, pickedIndex);
            }
            dispose();
        }
    });
    add(restoreBackupButton);

    tree.addMouseListener((OnMouseClick) e -> {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
        if (node != null) {
            PbxEntry entry = (PbxEntry) node.getUserObject();
            if ((entry instanceof PbxFolder && entry.areNativeFilesDeleted())) {
                permanentDeleteButton.setEnabled(true);
                restoreBackupButton.setEnabled(true);
                configBackupsButton.setEnabled(false);

            } else if (entry instanceof PbxFile) {
                permanentDeleteButton.setEnabled(true);
                restoreBackupButton.setEnabled(true);
                configBackupsButton.setEnabled(true);

            } else {
                permanentDeleteButton.setEnabled(false);
                restoreBackupButton.setEnabled(false);
                configBackupsButton.setEnabled(false);
            }
        }
    });

    final JLabel cancel = new JLabel(new ImageIcon(Constants.getAsset("cancel.png")));
    cancel.setLayout(null);
    cancel.setBounds(229, 390, 122, 39);
    cancel.setBackground(Color.black);
    cancel.addMouseListener((OnMouseClick) e -> dispose());
    add(cancel);

    addWindowFocusListener(new WindowFocusListener() {
        private boolean gained = false;

        @Override
        public void windowGainedFocus(WindowEvent e) {
            gained = true;
        }

        @Override
        public void windowLostFocus(WindowEvent e) {
            if (gained) {
                dispose();
            }
        }
    });

    setSize(340, 432);
    setUndecorated(true);
    getContentPane().setBackground(Color.white);
    setResizable(false);
    getRootPane().setBorder(BorderFactory.createLineBorder(new Color(100, 100, 100)));
    Utils.setComponentLocationOnCenter(this);
    setVisible(true);
}

From source file:com.enderville.enderinstaller.ui.Installer.java

private void buildInstallingPane() {

    getNextButton().setEnabled(false);//w  w w. j  a v a2s. com
    getCancelButton().setEnabled(false);
    getMainPane().removeAll();
    getMainPane().setLayout(new MigLayout(new LC().fill()));
    final JTextArea text = new JTextArea();
    text.setEditable(false);
    getMainPane().add(new JScrollPane(text), new CC().grow().spanY().wrap());
    getMainPane().validate();
    getMainPane().repaint();
    SwingWorker<Object, String> worker = new SwingWorker<Object, String>() {

        @Override
        protected Object doInBackground() throws Exception {
            try {
                List<String> mods = new ArrayList<String>();
                CheckBoxTreeSelectionModel select = getModTree().getCheckBoxTreeSelectionModel();
                TreePath[] paths = select.getSelectionPaths();
                if (paths != null && paths.length > 0) {
                    for (TreePath path : paths) {
                        DefaultMutableTreeNode node = ((DefaultMutableTreeNode) path.getLastPathComponent());
                        String mod = (String) node.getUserObject();
                        if (mod == null) {
                            for (int i = 0; i < node.getChildCount(); i++) {
                                DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(i);
                                mods.add((String) child.getUserObject());
                            }
                        } else {
                            mods.add(mod);
                        }
                    }
                }
                InstallScript.guiInstall(mods, text, getProgressBar());
            } catch (Exception e) {
                LOGGER.error("Error while trying to install mods", e);
                JOptionPane.showMessageDialog(Installer.this,
                        "Unexpected error while installing mods:\n" + e.getMessage(), "Error",
                        JOptionPane.ERROR_MESSAGE);
                setVisible(false);
                dispose();
            }
            return null;
        }

        @Override
        public void done() {
            getNextButton().removeActionListener(Installer.this);
            getNextButton().setText("Done");
            getNextButton().addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    setVisible(false);
                    dispose();
                }
            });
            getNextButton().setEnabled(true);
        }
    };

    worker.execute();
}

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

/**
 * Add an child object to a parent object.
 *
 * @param parent//from   w w w. j  a v a2 s. com
 *            the parent object.
 * @param child
 *            the child object.
 * @param shouldBeVisible
 *            if <code>true</code> the object should be visible.
 * @return Returns a <code>DefaultMutableTreeNode</code>
 */
public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent, Object child, boolean shouldBeVisible) {
    DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child);

    if (parent == null) {
        parent = rootNode;
    }

    treeModel.insertNodeInto(childNode, parent, parent.getChildCount());

    // Make sure the user can see the lovely new node.
    if (shouldBeVisible) {
        tree.scrollPathToVisible(new TreePath(childNode.getPath()));
    }
    return childNode;
}

From source file:edu.ku.brc.specify.tasks.subpane.security.NavigationTreeContextMenuMgr.java

/**
 * @param node/*from  w  w  w .java 2 s .c o  m*/
 */
private void addToAdminGroup(final DefaultMutableTreeNode node) {
    if (node != null) {
        Object userObject = node.getUserObject();
        if (userObject != null) {
            FormDataObjIFace dmObject = ((DataModelObjBaseWrapper) userObject).getDataObj();
            if (dmObject != null && dmObject instanceof SpecifyUser) {
                SpPrincipal adminPrin = null;
                DataProviderSessionIFace session = null;
                try {
                    session = DataProviderFactory.getInstance().createSession();
                    adminPrin = (SpPrincipal) session.getData(SpPrincipal.class, "name", "Administrator",
                            DataProviderSessionIFace.CompareType.Equals);
                    if (adminPrin != null) {
                        SpecifyUser spUser = session.get(SpecifyUser.class, ((SpecifyUser) dmObject).getId());
                        spUser.addUserToSpPrincipalGroup(adminPrin);

                        session.beginTransaction();
                        session.saveOrUpdate(spUser);
                        session.saveOrUpdate(adminPrin);
                        session.commit();

                        DefaultMutableTreeNode adminNode = getAdminTreeNode(
                                (DefaultMutableTreeNode) treeMgr.getTree().getModel().getRoot());
                        DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(
                                new DataModelObjBaseWrapper(spUser));

                        DefaultTreeModel model = (DefaultTreeModel) getTree().getModel();
                        model.insertNodeInto(newNode, adminNode, adminNode.getChildCount());
                        model.nodeChanged(adminNode);
                        model.nodeChanged(newNode);
                        getTree().repaint();

                        getTree().setSelectionPath(new TreePath(newNode.getPath()));

                        lastClickComp = null;
                        updateBtnUI();
                    }

                } catch (final Exception e1) {
                    e1.printStackTrace();

                    edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                    edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(NavigationTreeMgr.class, e1);
                    session.rollback();

                } finally {
                    if (session != null) {
                        session.close();
                    }
                }
            }
        }
    }
}