Example usage for javax.swing.tree DefaultMutableTreeNode getUserObject

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

Introduction

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

Prototype

public Object getUserObject() 

Source Link

Document

Returns this node's user object.

Usage

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

/**
 * //from   www.  jav a2s.co m
 */
public void updateBtnUI() {
    if (lastClickComp != null) {
        Object userObject = lastClickComp.getUserObject();
        FormDataObjIFace dmObject = ((DataModelObjBaseWrapper) userObject).getDataObj();

        if (dmObject instanceof SpecifyUser) {
            SpecifyUser specifyUser = (SpecifyUser) dmObject;

            addUserBtn.setEnabled(false);
            addExtUserBtn.setEnabled(false);

            String sqlFmt = "SELECT COUNT(*) FROM spprincipal Inner Join specifyuser_spprincipal ON spprincipal.SpPrincipalID = specifyuser_spprincipal.SpPrincipalID "
                    + "Inner Join specifyuser ON specifyuser_spprincipal.SpecifyUserID = specifyuser.SpecifyUserID WHERE GroupSubClass = '%s'";

            boolean isLastAdminUser = false;
            boolean isParentMgrGrp = false;
            boolean isParentAdmGrp = false;

            String sql = String.format(sqlFmt, AdminPrincipal.class.getCanonicalName());
            sql += " AND specifyuser.SpecifyUserID = " + specifyUser.getId();
            boolean isUserInAdmGrp = BasicSQLUtils.getCountAsInt(sql) > 0;

            sql = String.format(sqlFmt, AdminPrincipal.class.getCanonicalName());
            int allAdminUsersCnt = BasicSQLUtils.getCountAsInt(sql); // count of all adminusers

            sql = String.format(sqlFmt, GroupPrincipal.class.getCanonicalName());
            sql += " AND specifyuser.SpecifyUserID = " + specifyUser.getId();
            int grpUserCnt = BasicSQLUtils.getCountAsInt(sql); // count of groups for this user

            DefaultMutableTreeNode parentTreeNode = (DefaultMutableTreeNode) lastClickComp.getParent();
            if (parentTreeNode != null) {
                DataModelObjBaseWrapper pWrapper = (DataModelObjBaseWrapper) (parentTreeNode
                        .getUserObject() instanceof DataModelObjBaseWrapper ? parentTreeNode.getUserObject()
                                : null);
                if (pWrapper != null) {
                    SpPrincipal parentsPrin = (SpPrincipal) (pWrapper.getDataObj() instanceof SpPrincipal
                            ? pWrapper.getDataObj()
                            : null);
                    if (parentsPrin != null) {
                        isLastAdminUser = allAdminUsersCnt == 1;
                        isParentMgrGrp = parentsPrin.getGroupType() != null
                                && parentsPrin.getGroupType().equals("Manager");
                        isParentAdmGrp = parentsPrin.getGroupSubClass()
                                .equals(AdminPrincipal.class.getCanonicalName());
                    }
                }
            }

            addToAdminBtn.setEnabled(isParentMgrGrp && !isUserInAdmGrp);

            String toolTip = "";
            boolean canDelUser = !isUserInAdmGrp && grpUserCnt == 1;
            boolean canRemUser;
            if (isUserInAdmGrp && isParentAdmGrp) {
                canRemUser = allAdminUsersCnt > 1 && (grpUserCnt > 1 || !isLastAdminUser);

            } else {
                canRemUser = grpUserCnt > 1;
                if (canRemUser && dmObject instanceof SpecifyUser) {
                    SpecifyUser spUser = AppContextMgr.getInstance().getClassObject(SpecifyUser.class);
                    canRemUser = !((SpecifyUser) dmObject).getId().equals(spUser.getId());
                }
            }

            if (canDelUser) {
                toolTip = "SEC_DEL_USR_GRP";

            } else if (canRemUser) {
                toolTip = "SEC_RM_USR_GRP";
            }
            delUserBtn.setEnabled(canDelUser || canRemUser);
            delUserBtn.setToolTipText(StringUtils.isNotEmpty(toolTip) ? getResourceString(toolTip) : null);

        } else if (dmObject instanceof SpPrincipal) {
            boolean enable = getTreeMgr().canAddNewUser(lastClickComp);
            addUserBtn.setEnabled(enable);
            addExtUserBtn.setEnabled(enable);
            delUserBtn.setEnabled(false);

        } else //if (dmObject instanceof Collection)
        {
            // object is a collection: offer to add new group and to delete the collection
            boolean enable = getTreeMgr().canAddNewUser(lastClickComp);
            addUserBtn.setEnabled(enable);
            addExtUserBtn.setEnabled(enable);
            delUserBtn.setEnabled(false);
        }
    } else {
        addUserBtn.setEnabled(treeMgr.canAddNewUser(lastClickComp));
        addExtUserBtn.setEnabled(treeMgr.canAddNewUser(lastClickComp));
        delUserBtn.setEnabled(treeMgr.canDeleteUser(lastClickComp));
        addToAdminBtn.setEnabled(treeMgr.canAddToAdmin(lastClickComp));
    }
}

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

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

    if (this.form.getHiveTree() != null) {
        this.form.getHiveTree().clearSelection();
    }/*from  w w w. ja v  a  2  s.  com*/
    if (this.form.getInstagramTree() != null) {
        this.form.getInstagramTree().clearSelection();
    }

    if (node.isLeaf()) {
        this.form.setCursor(new Cursor(Cursor.WAIT_CURSOR));
        SSNAlbumNode fnode = null;
        try {
            if (((SSNIconData) node.getUserObject()).getObject() instanceof SSNAlbumNode)
                fnode = (SSNAlbumNode) ((SSNIconData) node.getUserObject()).getObject();
        } catch (ClassCastException ee) {
            ee.printStackTrace();
            this.form.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }
        String facebookDirPath = SSNHelper.getFacebookPhotosDirPath();
        if (fnode != null)
            fileTree.m_display.setText(facebookDirPath + File.separator + fnode);

        SSNIconData iconData = (SSNIconData) node.getUserObject();
        SSNAlbumNode albumNode = (SSNAlbumNode) iconData.getObject();

        MediaOperations mediaOperations = facebook.mediaOperations();

        List<Photo> listPhoto, completePhotoList = new ArrayList<Photo>();
        do {
            PagingParameters pagingParameters = new PagingParameters(100, completePhotoList.size(), null,
                    Calendar.getInstance().getTimeInMillis());
            listPhoto = mediaOperations.getPhotos(albumNode.getAlbum().getId(), pagingParameters);
            completePhotoList.addAll(listPhoto);

        } while (listPhoto.size() > 0);

        createComponents(this.form, completePhotoList, albumNode);
    }

}

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

public Main(TaskTree taskTree) {
    super();/*from  www .j a v  a2s  .  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: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 {/* ww  w.  j a  v a 2  s .c  o  m*/
            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.edduarte.protbox.ui.windows.RestoreFileWindow.java

private RestoreFileWindow(final PReg registry) {
    super();//from w ww  . j  a v a  2 s . c  o 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 .  jav  a  2 s. co m
    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:gui.GraphsPanel.java

/** detectWeakEdges().
 * //from  w  w  w.j a  v  a2s  .c  o  m
 */
public void detectWeakEdges(TreeNode root, float sensitivity) {
    Color customColor = Color.WHITE;

    // TV get a snapshot of original colors for each node with singleton
    Color prevColor = null;

    @SuppressWarnings("unchecked")
    Enumeration<DefaultMutableTreeNode> en = ((DefaultMutableTreeNode) root).breadthFirstEnumeration();
    while (en.hasMoreElements()) {
        DefaultMutableTreeNode node = en.nextElement();
        DenNode dNode = (DenNode) node.getUserObject();
        Integer level = node.getLevel();

        if (prevColor == null) {
            prevColor = dNode.getColor();
        }

        if (level == 0) {
            dNode.setColor(customColor);
        } else if (level != 0) {
            DenNode pdNode = (DenNode) ((DefaultMutableTreeNode) (node.getParent())).getUserObject();
            if ((dNode.getSimilarity() > this.getThreshold()) && (pdNode.getColor().equals(Color.WHITE))) {
                dNode.setColor(
                        Color.getHSBColor((float) (Math.cos(dNode.getSimilarity() * 90) * 360), 0.8f, 0.8f));
            } else {
                dNode.setColor(pdNode.getColor());
            }
            dNode.resetEdgeColor();
            if (((dNode.getSimilarity() - pdNode.getSimilarity()) > sensitivity)) {
                dNode.setEdgeColor(Color.RED);
            }
        }
    }
}

From source file:dotaSoundEditor.Controls.EditorPanel.java

/**
 * @param oldTree The tree that was previously in use
 * @param scriptFilePath A File object pointing to or containing a script.
 * @return The merged tree.// w  w  w.j a va  2  s .  c  o m
 */
TreeModel mergeNewChanges(TreeModel oldTree, File scriptFilePath) {
    //Look for any modified wavestrings. Save their nodes, and note their indices.
    //Parse in updated script tree, replace nodes at indices with saved nodes.   
    //Return merged tree
    System.out.println("Running a merge operation!");

    TreeNode oldRoot = (TreeNode) oldTree.getRoot();
    ArrayList<DefaultMutableTreeNode> savedNodeList = new ArrayList<>();
    for (Enumeration e = ((DefaultMutableTreeNode) oldRoot).depthFirstEnumeration(); e.hasMoreElements()
            && oldRoot != null;) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
        if (node.getUserObject().toString().contains("custom\\")
                || node.getUserObject().toString().contains("custom/")) {
            savedNodeList.add(node);
        }
    }
    ScriptParser parser = new ScriptParser(scriptFilePath);
    TreeModel newTree = parser.getTreeModel();
    TreeNode newRoot = (TreeNode) newTree.getRoot();
    for (DefaultMutableTreeNode savedNode : savedNodeList) {
        int rndwaveIndex = -1;
        int childIndex = -1;
        int parentIndex = -1;
        DefaultMutableTreeNode parent = (DefaultMutableTreeNode) savedNode.getParent();
        if (parent.getUserObject().toString().contains("rndwave")) {
            rndwaveIndex = parent.getParent().getIndex(parent);
            childIndex = parent.getIndex(savedNode);
            parent = (DefaultMutableTreeNode) parent.getParent();
            parentIndex = parent.getParent().getIndex(parent);
        } else {
            parentIndex = parent.getParent().getIndex(parent);
            childIndex = parent.getIndex(savedNode);
        }

        TreeNode newParentNode = newRoot.getChildAt(parentIndex);
        TreeNode newChildNode;
        if (rndwaveIndex != -1) {
            newChildNode = newParentNode.getChildAt(rndwaveIndex);
            newChildNode = newChildNode.getChildAt(childIndex);
        } else {
            newChildNode = newParentNode.getChildAt(childIndex);
        }
        newChildNode = savedNode;
    }
    return newTree;
}

From source file:gui.GraphsPanel.java

/** TODO: re-implement the algorithm from vertexColor.
 * Vertice Coloring algorithm executed before the vertexColor Transformer is
 * called//  ww  w .  j a  va 2 s.  c o  m
 * TV same algorithm initially set as a vertexColor Transformer COPY FROM
 * PROCESSCLUSTERRESULTS
 */
public void colorizeTree(TreeNode root, float threshold) {
    // System.out.println("___GraphsPanel: COLORIZE TREE!");
    Color customColor = Color.WHITE;

    // int groupCount =
    // cluster.getAvLnkDendrogram().getGroupCount(threshold);
    // int counter = groupCount;

    // traverese the tree
    // Enumeration en =
    // ((DefaultMutableTreeNode)root).depthFirstEnumeration();
    @SuppressWarnings("unchecked")
    Enumeration<DefaultMutableTreeNode> en = ((DefaultMutableTreeNode) root).breadthFirstEnumeration();
    while (en.hasMoreElements()) {
        // Unfortunately the enumeration isn't genericised so we need to
        // downcast
        // when calling nextElement():
        DefaultMutableTreeNode node = en.nextElement();
        DenNode dNode = (DenNode) node.getUserObject();
        Integer level = node.getLevel();

        if (level == 0) {
            dNode.setColor(customColor);
        } else if (level != 0) {
            DenNode pdNode = (DenNode) ((DefaultMutableTreeNode) (node.getParent())).getUserObject();
            if ((dNode.getSimilarity() > threshold) && (pdNode.getColor().equals(Color.WHITE))) {
                dNode.setColor(
                        Color.getHSBColor((float) (Math.cos(dNode.getSimilarity() * 90) * 360), 0.8f, 0.8f));
            } else {
                dNode.setColor(pdNode.getColor());
            }
            // TV
            if (((dNode.getSimilarity() - pdNode.getSimilarity()) > this.getSensitivity())) {
                dNode.setEdgeColor(Color.BLACK);
            }
        }
    }
}

From source file:dotaSoundEditor.Controls.EditorPanel.java

protected void playSelectedTreeSound(TreePath selPath, Path vpkToPlayFrom) {
    try {/*from w w  w.  j a  v a 2  s  .c om*/
        DefaultMutableTreeNode selectedFile = ((DefaultMutableTreeNode) selPath.getLastPathComponent());
        String waveString = selectedFile.getUserObject().toString();
        File soundFile = createSoundFileFromWaveString(waveString, vpkToPlayFrom);
        soundPlayer.loadSound(soundFile.getAbsolutePath());
        soundPlayer.playSound();
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, "The selected node does not represent a valid sound file.", "Error",
                JOptionPane.ERROR_MESSAGE);
    }
}