Example usage for javax.swing.tree TreePath TreePath

List of usage examples for javax.swing.tree TreePath TreePath

Introduction

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

Prototype

public TreePath(Object lastPathComponent) 

Source Link

Document

Creates a TreePath containing a single element.

Usage

From source file:com.mirth.connect.client.ui.DashboardPanel.java

private void addChannelNodeExpansionStates(MutableTreeTableNode parent, Set<String> expandedIds,
        Set<String> collapsedIds) {
    DashboardTreeTableModel model = (DashboardTreeTableModel) dashboardTable.getTreeTableModel();

    for (Enumeration<? extends MutableTreeTableNode> channelNodes = parent.children(); channelNodes
            .hasMoreElements();) {//w  w w .j  ava2s  . co  m
        AbstractDashboardTableNode channelNode = (AbstractDashboardTableNode) channelNodes.nextElement();

        if (dashboardTable.isExpanded(new TreePath(model.getPathToRoot(channelNode)))) {
            expandedIds.add(channelNode.getChannelId());
        } else {
            collapsedIds.add(channelNode.getChannelId());
        }
    }
}

From source file:com.pironet.tda.TDA.java

/**
 * navigate to the currently selected dump in logfile
 *///  ww w  . j  a v  a 2  s .  co  m
private void navigateToDumpInLogfile() {
    Object userObject = ((DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent())
            .getUserObject();
    if (userObject instanceof ThreadDumpInfo) {
        ThreadDumpInfo ti = (ThreadDumpInfo) userObject;
        int lineNumber = ti.getLogLine();

        // find log file node.
        TreePath selPath = tree.getSelectionPath();
        while (selPath != null && !checkNameFromNode((DefaultMutableTreeNode) selPath.getLastPathComponent(),
                File.separator)) {

            selPath = selPath.getParentPath();
        }

        tree.setSelectionPath(selPath);
        tree.scrollPathToVisible(selPath);
        if (selPath == null) {
            return;
        }

        Enumeration childs = ((DefaultMutableTreeNode) selPath.getLastPathComponent()).children();
        boolean found = false;
        DefaultMutableTreeNode logfileContent = null;
        while (!found && childs.hasMoreElements()) {
            logfileContent = (DefaultMutableTreeNode) childs.nextElement();
            found = logfileContent.getUserObject() instanceof LogFileContent;
        }

        if (found) {
            TreePath monitorPath = new TreePath(logfileContent.getPath());
            tree.setSelectionPath(monitorPath);
            tree.scrollPathToVisible(monitorPath);
            displayLogFileContent(logfileContent.getUserObject());
            jeditPane.setFirstLine(lineNumber - 1);
        }
    }
}

From source file:com.mirth.connect.client.ui.DashboardPanel.java

private void restoreTableState(TableState tableState) {
    DashboardTreeTableModel model = (DashboardTreeTableModel) dashboardTable.getTreeTableModel();
    MutableTreeTableNode root = (MutableTreeTableNode) model.getRoot();

    if (model.isGroupModeEnabled()) {
        for (Enumeration<? extends MutableTreeTableNode> groupNodes = root.children(); groupNodes
                .hasMoreElements();) {//from   ww  w.  j a  v  a 2  s .  c  om
            AbstractDashboardTableNode groupNode = (AbstractDashboardTableNode) groupNodes.nextElement();
            String groupId = groupNode.getGroupStatus().getGroup().getId();

            if (tableState.getExpandedIds().contains(groupId)
                    || !tableState.getCollapsedIds().contains(groupId)) {
                dashboardTable.expandPath(new TreePath(new Object[] { root, groupNode }));
            } else if (tableState.getCollapsedIds().contains(groupId)) {
                dashboardTable.collapsePath(new TreePath(new Object[] { root, groupNode }));
            }

            setChannelNodeExpansionStates(groupNode, tableState);
        }
    } else {
        setChannelNodeExpansionStates(root, tableState);
    }

    final List<TreePath> selectionPaths = new ArrayList<TreePath>();

    if (model.isGroupModeEnabled()) {
        for (Enumeration<? extends MutableTreeTableNode> groupNodes = root.children(); groupNodes
                .hasMoreElements();) {
            AbstractDashboardTableNode groupNode = (AbstractDashboardTableNode) groupNodes.nextElement();

            if (tableState.getSelectedIds().contains(groupNode.getGroupStatus().getGroup().getId())) {
                selectionPaths.add(new TreePath(new Object[] { root, groupNode }));
            }

            selectChannelNodes(groupNode, tableState, selectionPaths);
        }
    } else {
        selectChannelNodes(root, tableState, selectionPaths);
    }

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            dashboardTable.getTreeSelectionModel()
                    .setSelectionPaths(selectionPaths.toArray(new TreePath[selectionPaths.size()]));
        }
    });
}

From source file:com.SE.myPlayer.MusicPlayerGUI.java

private void folder_Playlist_TreeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_folder_Playlist_TreeMouseClicked
        DefaultMutableTreeNode selectedNode;

        if (evt.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(evt)) {
            selectedNode = (DefaultMutableTreeNode) folder_Playlist_Tree.getSelectionPath().getLastPathComponent();
            getSongTable(selectedNode.toString());
            lastOpen = selectedNode.toString();
            for (ObjectBean list1 : list) {
                if (list1.getTitle().equals("library")) {
                    list1.setLastOpen(lastOpen);
                }/*  w  ww . j a v  a2 s.co m*/
            }
        } else if (SwingUtilities.isRightMouseButton(evt)) {
            DefaultTreeModel myModel = (DefaultTreeModel) folder_Playlist_Tree.getModel();
            DefaultMutableTreeNode root = (DefaultMutableTreeNode) myModel.getRoot();

            TreeNode[] nodes = myModel.getPathToRoot(root);
            TreePath treepath = new TreePath(nodes);
            folder_Playlist_Tree.setSelectionPath(treepath);
            folder_Playlist_Tree.scrollPathToVisible(treepath);

            TreePath path = folder_Playlist_Tree.getPathForLocation(evt.getX(), evt.getY());
            folder_Playlist_Tree.setSelectionPath(path);
            folder_Playlist_Tree.scrollPathToVisible(path);
            if (!folder_Playlist_Tree.isSelectionEmpty()) {
                selectedNode = (DefaultMutableTreeNode) folder_Playlist_Tree.getSelectionPath()
                        .getLastPathComponent();
                if (!"playlist".equals(selectedNode.toString()) && !"library".equals(selectedNode.toString())) {
                    folderTree_PopUp.show(folder_Playlist_Tree, evt.getX(), evt.getY());
                }
            }
        }
    }

From source file:com.mirth.connect.client.ui.codetemplate.CodeTemplatePanel.java

public void doNewCodeTemplate() {
    stopTableEditing();/*from w w  w  .j  av  a 2s  .  c o  m*/
    updateCurrentNode();
    updateCurrentNode.set(false);
    setSaveEnabled(true);
    AbstractSortableTreeTableNode parentNode;

    int selectedRow = templateTreeTable.getSelectedRow();
    if (selectedRow >= 0) {
        parentNode = (AbstractSortableTreeTableNode) templateTreeTable.getPathForRow(selectedRow)
                .getLastPathComponent();
        if (parentNode instanceof CodeTemplateTreeTableNode) {
            parentNode = (AbstractSortableTreeTableNode) parentNode.getParent();
        }
    } else {
        return;
    }

    String name;
    int index = 1;
    do {
        name = "Template " + index++;
    } while (!checkCodeTemplateName(name));

    CodeTemplate codeTemplate = CodeTemplate.getDefaultCodeTemplate(name);
    CodeTemplateTreeTableNode codeTemplateNode = new CodeTemplateTreeTableNode(codeTemplate);

    CodeTemplateTreeTableModel model = (CodeTemplateTreeTableModel) templateTreeTable.getTreeTableModel();
    model.insertNodeInto(codeTemplateNode, parentNode);

    if (model.getRoot() != fullModel.getRoot()) {
        fullModel.insertNodeInto(new CodeTemplateTreeTableNode(codeTemplate), findFullNode(parentNode));
    }

    TreePath selectedPath = new TreePath(model.getPathToRoot(codeTemplateNode));
    selectTemplatePath(selectedPath);
    updateFilterNotification();
    updateCurrentNode.set(true);
}

From source file:com.mirth.connect.client.ui.codetemplate.CodeTemplatePanel.java

public void doNewLibrary() {
    stopTableEditing();//from w w  w . java2 s  . c  o m
    updateCurrentNode();
    updateCurrentNode.set(false);
    setSaveEnabled(true);

    String name;
    int index = 1;
    do {
        name = "Library " + index++;
    } while (!checkLibraryName(name));

    CodeTemplateLibrary library = new CodeTemplateLibrary();
    library.setName(name);
    CodeTemplateLibraryTreeTableNode libraryNode = new CodeTemplateLibraryTreeTableNode(library);

    CodeTemplateTreeTableModel model = (CodeTemplateTreeTableModel) templateTreeTable.getTreeTableModel();
    model.insertNodeInto(libraryNode, (AbstractSortableTreeTableNode) model.getRoot());

    if (model.getRoot() != fullModel.getRoot()) {
        fullModel.insertNodeInto(new CodeTemplateLibraryTreeTableNode(library),
                (AbstractSortableTreeTableNode) fullModel.getRoot());
    }

    final TreePath selectedPath = new TreePath(model.getPathToRoot(libraryNode));
    selectTemplatePath(selectedPath);

    updateLibrariesComboBox();
    updateFilterNotification();

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            selectTemplatePath(selectedPath);
            updateCurrentNode.set(true);
        }
    });
}

From source file:ru.apertum.qsystem.client.forms.FAdmin.java

/**
     *   ??.//ww  w.  ja v a 2  s  . c o  m
     */
    private void loadConfig() {
        listUsers.setModel(QUserList.getInstance());
        listResponse.setModel(QResponseList.getInstance());
        listResults.setModel(QResultList.getInstance());
        treeServices.setModel(QServiceTree.getInstance());
        treeInfo.setModel(QInfoTree.getInstance());
        listSchedule.setModel(QScheduleList.getInstance());
        listBreaks.setModel(QBreaksList.getInstance());
        listCalendar.setModel(QCalendarList.getInstance());
        listReposts.setModel(QReportsList.getInstance());

        spinnerPropServerPort.setValue(ServerProps.getInstance().getProps().getServerPort());
        spinnerPropClientPort.setValue(ServerProps.getInstance().getProps().getClientPort());
        spinnerWebServerPort.setValue(ServerProps.getInstance().getProps().getWebServerPort());
        textFieldStartTime.setText(Uses.format_HH_mm.format(ServerProps.getInstance().getProps().getStartTime()));
        textFieldFinishTime.setText(Uses.format_HH_mm.format(ServerProps.getInstance().getProps().getFinishTime()));
        textFieldURLWebService.setText(ServerProps.getInstance().getProps().getSkyServerUrl());

        spinnerWaitMax.setValue(ServerProps.getInstance().getStandards().getWaitMax());
        spinnerWorkMax.setValue(ServerProps.getInstance().getStandards().getWorkMax());
        spinnerDowntimeNax.setValue(ServerProps.getInstance().getStandards().getDowntimeMax());
        spinnerLineServiceMax.setValue(ServerProps.getInstance().getStandards().getLineServiceMax());
        spinnerLineTotalMax.setValue(ServerProps.getInstance().getStandards().getLineTotalMax());
        spinnerRelocation.setValue(ServerProps.getInstance().getStandards().getRelocation());

        textFieldZonBoadrServAddr.setText(ServerProps.getInstance().getProps().getZoneBoardServAddr());
        spinnerZonBoadrServPort.setValue(ServerProps.getInstance().getProps().getZoneBoardServPort());

        spinnerBranchId.setValue(ServerProps.getInstance().getProps().getBranchOfficeId());
        spinnerFirstNumber.setValue(ServerProps.getInstance().getProps().getFirstNumber());
        spinnerLastNumber.setValue(ServerProps.getInstance().getProps().getLastNumber());
        rbKindCommon.setSelected(!ServerProps.getInstance().getProps().getNumering());
        rbKindPersonal.setSelected(ServerProps.getInstance().getProps().getNumering());
        spinnerRemoveRecall.getModel().setValue(ServerProps.getInstance().getProps().getLimitRecall());
        chBoxBtnFreeDsn.setSelected(ServerProps.getInstance().getProps().getButtonFreeDesign());
        switch (ServerProps.getInstance().getProps().getPoint()) {
        case 0:
            rbPointOffice.setSelected(true);
            break;
        case 1:
            rbPointWindow.setSelected(true);
            break;
        case 2:
            rbPointStoika.setSelected(true);
            break;
        }
        switch (ServerProps.getInstance().getProps().getSound()) {
        case 0:
            rbNotificationNo.setSelected(true);
            break;
        case 1:
            rbNotificationGong.setSelected(true);
            break;
        case 2:
            rbNotificationGongOrVoice.setSelected(true);
            break;
        case 3:
            rbNotificationGongVoice.setSelected(true);
            break;
        }
        comboBoxVoices.setSelectedIndex(ServerProps.getInstance().getProps().getVoice());
        spinnerBlackListTimeMin.setValue(ServerProps.getInstance().getProps().getBlackTime());
        rbNotificationGongVoiceActionPerformed(null);

        // ?    ??
        if (listUsers.getLastVisibleIndex() != -1) {
            listUsers.setSelectedIndex(0);
        }

        if (listResponse.getLastVisibleIndex() != -1) {
            listResponse.setSelectedIndex(0);
        }

        if (listSchedule.getLastVisibleIndex() != -1) {
            listSchedule.setSelectedIndex(0);
        }

        if (listCalendar.getLastVisibleIndex() != -1) {
            listCalendar.setSelectedIndex(0);
        }

        if (treeServices.getModel().getRoot() != null) {
            treeServices.setSelectionPath(new TreePath(treeServices.getModel().getRoot()));
        }

        if (treeInfo.getModel().getRoot() != null) {
            treeInfo.setSelectionPath(new TreePath(treeInfo.getModel().getRoot()));
        }

        if (listUserService.getLastVisibleIndex() != -1) {
            listUserService.setSelectedIndex(0);
        }

    }

From source file:com.mirth.connect.client.ui.DashboardPanel.java

private void setChannelNodeExpansionStates(MutableTreeTableNode parent, TableState tableState) {
    DashboardTreeTableModel model = (DashboardTreeTableModel) dashboardTable.getTreeTableModel();

    for (Enumeration<? extends MutableTreeTableNode> channelNodes = parent.children(); channelNodes
            .hasMoreElements();) {/*from  w  ww  .  j  a  v a2s. com*/
        AbstractDashboardTableNode channelNode = (AbstractDashboardTableNode) channelNodes.nextElement();
        String channelId = channelNode.getChannelId();

        if (tableState.getExpandedIds().contains(channelId)) {
            dashboardTable.expandPath(new TreePath(model.getPathToRoot(channelNode)));
        } else if (tableState.getCollapsedIds().contains(channelId)) {
            dashboardTable.collapsePath(new TreePath(model.getPathToRoot(channelNode)));
        }
    }
}

From source file:com.pironet.tda.TDA.java

/**
 * navigate to monitor//from w  w  w .j  av a 2 s  . c  o  m
 *
 * @param monitorLink the monitor link to navigate to
 */
private void navigateToMonitor(String monitorLink) {
    String monitor = monitorLink.substring(monitorLink.lastIndexOf('/') + 1);

    // find monitor node for this thread info
    DefaultMutableTreeNode dumpNode;
    if (monitorLink.indexOf("Dump No.") > 0) {
        dumpNode = getDumpRootNode(
                monitorLink.substring(monitorLink.indexOf('/') + 1, monitorLink.lastIndexOf('/')),
                (DefaultMutableTreeNode) tree.getLastSelectedPathComponent());
    } else {
        dumpNode = getDumpRootNode((DefaultMutableTreeNode) tree.getLastSelectedPathComponent());
    }
    final Enumeration children = dumpNode.children();
    DefaultMutableTreeNode monitorNode = null;
    DefaultMutableTreeNode monitorWithoutLocksNode = null;
    while (children.hasMoreElements()) {
        DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement();
        if (child.getUserObject() instanceof TreeCategory) {
            if (((TreeCategory) child.getUserObject()).getName().startsWith("Monitors (")) {
                monitorNode = child;
            } else if (((TreeCategory) child.getUserObject()).getName().startsWith("Monitors without")) {
                monitorWithoutLocksNode = child;
            }
        }
    }

    // highlight chosen monitor
    JTree searchTree = (JTree) ((TreeCategory) monitorNode.getUserObject()).getCatComponent(this);
    TreePath searchPath = searchTree.getNextMatch(monitor, 0, Position.Bias.Forward);
    if ((searchPath == null) && (monitorWithoutLocksNode != null)) {
        searchTree = (JTree) ((TreeCategory) monitorWithoutLocksNode.getUserObject()).getCatComponent(this);
        searchPath = searchTree.getNextMatch(monitor, 0, Position.Bias.Forward);
        monitorNode = monitorWithoutLocksNode;
    }

    if (searchPath != null) {
        TreePath monitorPath = new TreePath(monitorNode.getPath());
        tree.setSelectionPath(monitorPath);
        tree.scrollPathToVisible(monitorPath);

        displayCategory(monitorNode.getUserObject());

        TreePath threadInMonitor = searchPath
                .pathByAddingChild(((DefaultMutableTreeNode) searchPath.getLastPathComponent()).getLastChild());
        searchTree.setSelectionPath(threadInMonitor);
        searchTree.scrollPathToVisible(searchPath);
        searchTree.setSelectionPath(searchPath);
    }
}

From source file:com.SE.myPlayer.MusicPlayerGUI.java

private void createPlaylistActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createPlaylistActionPerformed
        String input = JOptionPane.showInputDialog("Enter playlist Name: ");
        if (input == null) {
        } else if (!input.equals("")) {
            int validInput = sd.newTreeNode(input);
            if (validInput == 1) {
                treeReferesh();//from www. ja v a2s .c  o m
                DefaultTreeModel model = (DefaultTreeModel) folder_Playlist_Tree.getModel();
                DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
                DefaultMutableTreeNode playlist = (DefaultMutableTreeNode) model.getChild(root, 1);
                DefaultMutableTreeNode newPlaylist = (DefaultMutableTreeNode) model.getChild(playlist,
                        model.getChildCount(playlist) - 1);

                getSongTable(newPlaylist.toString());

                TreeNode[] nodes = model.getPathToRoot(newPlaylist);
                TreePath treepath = new TreePath(nodes);

                folder_Playlist_Tree.setExpandsSelectedPaths(true);
                folder_Playlist_Tree.setSelectionPath(treepath);
                folder_Playlist_Tree.scrollPathToVisible(treepath);

                addJMenuItemsToPopUP();

                lastOpen = input;
                for (ObjectBean list1 : list) {
                    if (list1.getTitle().equals("library")) {
                        list1.setLastOpen(lastOpen);
                    }
                }
            } else {
                createPlaylistActionPerformed(evt);
            }
        } else {
            JOptionPane.showMessageDialog(null, "Please Enter Valid Playlist Name", "Error in Name",
                    JOptionPane.ERROR_MESSAGE);
            createPlaylistActionPerformed(evt);
        }
    }