Example usage for javax.swing.tree TreePath getLastPathComponent

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

Introduction

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

Prototype

public Object getLastPathComponent() 

Source Link

Document

Returns the last element of this path.

Usage

From source file:org.fhaes.gui.AnalysisResultsPanel.java

/**
 * Set up the AnalysisResults GUI/*from   www  . j a v  a2  s.  c o m*/
 */
private void initGUI() {

    setLayout(new BorderLayout(0, 0));
    if (Platform.isOSX())
        setBackground(MainWindow.MAC_BACKGROUND_COLOR);

    ImageIcon iconMultipleTables = Builder.getImageIcon("multipletables16.png");
    ImageIcon iconTable = Builder.getImageIcon("table16.png");

    // ImageIcon iconChart = Builder.getImageIcon("chart16.png");

    // Categories
    rootNode = new FHAESCategoryTreeNode("FHAES analysis results");
    categoryGeneral = new FHAESCategoryTreeNode("Descriptive summaries",
            Builder.getImageIcon("interval16.png"));
    categoryInterval = new FHAESCategoryTreeNode("Interval analysis", Builder.getImageIcon("interval16.png"));
    categorySeasonality = new FHAESCategoryTreeNode("Seasonality", Builder.getImageIcon("seasonality16.png"));
    categoryBinarySummaryMatrices = new FHAESCategoryTreeNode("Binary summary matrices",
            Builder.getImageIcon("matrix16.png"));
    categoryBinaryMatrices = new FHAESCategoryTreeNode("Binary comparison matrices",
            Builder.getImageIcon("matrix16.png"));
    categorySimMatrices = new FHAESCategoryTreeNode("Similarity matrices",
            Builder.getImageIcon("matrix16.png"));
    categoryDisSimMatrices = new FHAESCategoryTreeNode("Dissimilarity matrices",
            Builder.getImageIcon("matrix16.png"));

    // Menu actions

    // Results

    itemJaccard = new FHAESResultTreeNode(FHAESResult.JACCARD_SIMILARITY_MATRIX, iconMultipleTables);
    itemJaccard.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(SJACFile, new CSVFileFilter());
        }
    });

    itemCohen = new FHAESResultTreeNode(FHAESResult.COHEN_SIMILARITITY_MATRIX, iconMultipleTables);
    itemCohen.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(SCOHFile, new CSVFileFilter());
        }
    });

    itemJaccardD = new FHAESResultTreeNode(FHAESResult.JACCARD_SIMILARITY_MATRIX_D, iconMultipleTables);
    itemJaccardD.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(DSJACFile, new CSVFileFilter());
        }
    });

    itemCohenD = new FHAESResultTreeNode(FHAESResult.COHEN_SIMILARITITY_MATRIX_D, iconMultipleTables);
    itemCohenD.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(DSCOHFile, new CSVFileFilter());
        }
    });

    itemIntervalSummary = new FHAESResultTreeNode(FHAESResult.INTERVAL_SUMMARY, iconMultipleTables);
    itemIntervalSummary.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(intervalsSummaryFile, new CSVFileFilter());
        }
    });

    itemExceedence = new FHAESResultTreeNode(FHAESResult.INTERVAL_EXCEEDENCE_TABLE, iconMultipleTables);
    itemExceedence.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(intervalsExceedenceFile, new CSVFileFilter());
        }
    });

    itemSeasonalitySummary = new FHAESResultTreeNode(FHAESResult.SEASONALITY_SUMMARY, iconMultipleTables);
    itemSeasonalitySummary.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(seasonalitySummaryFile, new CSVFileFilter());
        }
    });

    itemBin00 = new FHAESResultTreeNode(FHAESResult.BINARY_MATRIX_00, iconMultipleTables);
    itemBin00.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(bin00File, new CSVFileFilter());
        }
    });

    itemBin01 = new FHAESResultTreeNode(FHAESResult.BINARY_MATRIX_01, iconMultipleTables);
    itemBin01.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(bin01File, new CSVFileFilter());
        }
    });

    itemBin10 = new FHAESResultTreeNode(FHAESResult.BINARY_MATRIX_10, iconMultipleTables);
    itemBin10.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(bin10File, new CSVFileFilter());
        }
    });

    itemBin11 = new FHAESResultTreeNode(FHAESResult.BINARY_MATRIX_11, iconMultipleTables);
    itemBin11.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(bin11File, new CSVFileFilter());
        }
    });

    itemBinSum = new FHAESResultTreeNode(FHAESResult.BINARY_MATRIX_SUM, iconMultipleTables);
    itemBinSum.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(binSumFile, new CSVFileFilter());
        }

    });
    itemBinSiteSummary = new FHAESResultTreeNode(FHAESResult.BINARY_MATRIX_SITE, iconMultipleTables);
    itemBinSiteSummary.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(siteSummaryFile, new CSVFileFilter());
        }
    });
    itemBinSiteSummary.addAction(new FHAESAction("Export to shapefile", "formatshp.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            new ShapeFileDialog(App.mainFrame, fhm);

        }
    });

    itemBinTreeSummary = new FHAESResultTreeNode(FHAESResult.BINARY_MATRIX_TREE, iconMultipleTables);
    itemBinTreeSummary.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(treeSummaryFile, new CSVFileFilter());
        }
    });

    itemNTP = new FHAESResultTreeNode(FHAESResult.BINARY_MATRIX_NTP, iconMultipleTables);
    itemNTP.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(NTPFile, new CSVFileFilter());
        }
    });

    this.itemGeneralSummary = new FHAESResultTreeNode(FHAESResult.GENERAL_SUMMARY, iconMultipleTables);
    itemGeneralSummary.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(generalSummaryFile, new CSVFileFilter());
        }

    });

    this.itemSingleFileSummary = new FHAESResultTreeNode(FHAESResult.SINGLE_FILE_SUMMARY, iconTable);
    itemSingleFileSummary.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(singleFileSummaryFile, new CSVFileFilter());
        }

    });

    this.itemSingleEventSummary = new FHAESResultTreeNode(FHAESResult.SINGLE_EVENT_SUMMARY, iconTable);
    itemSingleEventSummary.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(singleEventSummaryFile, new CSVFileFilter());
        }

    });

    // Add results to categories
    categoryGeneral.add(itemGeneralSummary);
    categoryGeneral.add(itemSingleFileSummary);
    categoryGeneral.add(itemSingleEventSummary);
    categorySimMatrices.add(itemJaccard);
    categorySimMatrices.add(itemCohen);
    categoryDisSimMatrices.add(itemJaccardD);
    categoryDisSimMatrices.add(itemCohenD);
    categoryInterval.add(itemIntervalSummary);
    categoryInterval.add(itemExceedence);
    categorySeasonality.add(itemSeasonalitySummary);
    categoryBinaryMatrices.add(itemBin11);
    categoryBinaryMatrices.add(itemBin01);
    categoryBinaryMatrices.add(itemBin10);
    categoryBinaryMatrices.add(itemBin00);
    categoryBinaryMatrices.add(itemBinSum);
    categoryBinarySummaryMatrices.add(itemBinSiteSummary);
    categoryBinarySummaryMatrices.add(itemBinTreeSummary);
    categoryBinarySummaryMatrices.add(itemNTP);

    // Add categories to root of tree
    rootNode.add(categoryGeneral);
    rootNode.add(categoryInterval);
    rootNode.add(categorySeasonality);
    rootNode.add(categoryBinarySummaryMatrices);
    rootNode.add(categoryBinaryMatrices);
    rootNode.add(categorySimMatrices);
    rootNode.add(categoryDisSimMatrices);

    treeModel = new DefaultTreeModel(rootNode);

    splitPane = new JSplitPane();
    if (Platform.isOSX())
        splitPane.setBackground(MainWindow.MAC_BACKGROUND_COLOR);

    splitPane.setResizeWeight(0.9);
    add(splitPane, BorderLayout.CENTER);

    JPanel panelTree = new JPanel();
    splitPane.setRightComponent(panelTree);
    panelTree.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
    panelTree.setLayout(new BorderLayout(0, 0));

    // Build tree
    treeResults = new JTree();
    panelTree.add(treeResults);
    treeResults.setModel(treeModel);

    treeResults.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    treeResults.setCellRenderer(new FHAESResultTreeRenderer());

    pickResultPanel = new PickResultPanel();
    runAnalysisPanel = new RunAnalysisPanel();

    cards = new JPanel();
    cl = new CardLayout();
    cards.setLayout(cl);
    cards.add(pickResultPanel, PICKRESULTPANEL);
    cards.add(runAnalysisPanel, RUNANALYSIS);
    cards.add(emptyPanel, EMPTYPANEL);

    splitPane.setLeftComponent(cards);

    cl.show(cards, RUNANALYSIS);

    splitPaneResult = new JSplitPane();
    splitPaneResult.setOneTouchExpandable(true);
    splitPaneResult.setOrientation(JSplitPane.VERTICAL_SPLIT);
    cards.add(splitPaneResult, RESULTSPANEL);

    panelResult = new JPanel();

    panelResult.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
    panelResult.setLayout(new BorderLayout(0, 0));

    goldFishPanel = new GoldFishPanel();
    splitPaneResult.setRightComponent(goldFishPanel);

    // Build table
    scrollPane = new JScrollPane();

    panelResult.add(scrollPane);
    table = new JXTable();
    adapter = new JTableSpreadsheetByRowAdapter(table);

    table.setModel(new DefaultTableModel());
    table.setHorizontalScrollEnabled(true);
    scrollPane.setViewportView(table);
    splitPaneResult.setLeftComponent(panelResult);

    // OSX Style hack
    if (Platform.isOSX())
        panelResult.setBackground(MainWindow.MAC_BACKGROUND_COLOR);
    if (Platform.isOSX())
        scrollPane.setBackground(MainWindow.MAC_BACKGROUND_COLOR);

    // Expand all nodes
    for (int i = 0; i < treeResults.getRowCount(); i++) {
        treeResults.expandRow(i);
    }

    treeResults.addTreeSelectionListener(this);

    treeResults.addMouseListener(new MouseListener() {

        @Override
        public void mouseClicked(MouseEvent e) {

            if (SwingUtilities.isRightMouseButton(e)) {
                int x = e.getX();
                int y = e.getY();
                JTree tree = (JTree) e.getSource();
                TreePath path = tree.getPathForLocation(x, y);
                if (path == null)
                    return;
                if (!tree.isEnabled())
                    return;

                tree.setSelectionPath(path);
                Component mc = e.getComponent();

                if (path != null && path.getLastPathComponent() instanceof FHAESResultTreeNode) {
                    FHAESResultTreeNode node = (FHAESResultTreeNode) path.getLastPathComponent();

                    if (!node.isEnabled())
                        return;

                    FHAESResultPopupMenu popupMenu = new FHAESResultPopupMenu(node.getArrayOfActions());
                    popupMenu.show(mc, e.getX(), e.getY());
                }
            }
        }

        @Override
        public void mouseEntered(MouseEvent arg0) {

        }

        @Override
        public void mouseExited(MouseEvent arg0) {

        }

        @Override
        public void mousePressed(MouseEvent arg0) {

        }

        @Override
        public void mouseReleased(MouseEvent arg0) {

        }

    });

    this.splitPaneResult.setDividerLocation(10000);
    this.splitPaneResult.setDividerSize(3);
    this.splitPaneResult.setResizeWeight(1);
}

From source file:org.geopublishing.atlasViewer.GpCoreUtil.java

private final static void expandAll(final JTree tree, final TreePath parent, final boolean expand) {
    // Traverse children
    final TreeNode node = (TreeNode) parent.getLastPathComponent();
    if (node.getChildCount() >= 0) {
        for (final Enumeration<TreeNode> e = node.children(); e.hasMoreElements();) {
            final TreeNode n = e.nextElement();
            final TreePath path = parent.pathByAddingChild(n);
            expandAll(tree, path, expand);
        }/*ww w .  j a v  a  2 s.  c o  m*/
    }

    // Expansion or collapse must be done bottom-up
    if (expand) {
        tree.expandPath(parent);
    } else {
        tree.collapsePath(parent);
    }
}

From source file:org.hippoecm.frontend.plugins.cms.admin.updater.UpdaterPanel.java

private void expandAndSelectNodeInTree(final AjaxRequestTarget target) {
    final JcrNodeModel model = (JcrNodeModel) getDefaultModel();
    final TreePath treePath = treeModel.lookup(model);
    final ITreeState treeState = tree.getTreeState();
    for (Object n : treePath.getPath()) {
        final TreeNode treeNode = (TreeNode) n;
        if (!treeState.isNodeExpanded(treeNode)) {
            treeState.expandNode(treeNode);
        }//from w ww  .  ja  va  2 s . c o  m
    }
    treeState.selectNode(treePath.getLastPathComponent(), true);
    tree.updateTree(target);
}

From source file:org.hippoecm.frontend.plugins.cms.browse.tree.FolderTreePlugin.java

@Override
public void onModelChanged() {
    super.onModelChanged();

    if (tree == null) {
        return;/*w w  w.j  a  v  a  2  s .  c om*/
    }
    JcrNodeModel model = (JcrNodeModel) getDefaultModel();
    ITreeState treeState = tree.getTreeState();
    TreePath treePath = treeModel.lookup(model);
    if (treePath != null) {
        for (Object component : treePath.getPath()) {
            TreeNode treeNode = (TreeNode) component;
            if (!treeState.isNodeExpanded(treeNode)) {
                treeState.expandNode(treeNode);
            }
        }
        treeState.selectNode(treePath.getLastPathComponent(), true);
    }
}

From source file:org.hippoecm.frontend.plugins.console.browser.BrowserPlugin.java

@Override
public void onModelChanged() {
    super.onModelChanged();

    JcrNodeModel model = (JcrNodeModel) getDefaultModel();
    TreePath treePath = treeModel.lookup(model);
    if (treePath != null) {
        ITreeState treeState = tree.getTreeState();
        if (!navigating) {
            for (Object node : treePath.getPath()) {
                TreeNode treeNode = (TreeNode) node;
                if (!treeState.isNodeExpanded(treeNode)) {
                    treeState.expandNode(treeNode);
                }//from   w  w  w .j  a va2 s .c  om
            }
        }
        treeState.selectNode(treePath.getLastPathComponent(), true);
    }
}

From source file:org.isatools.isacreator.filechooser.FileChooserUI.java

/**
 * Create the Navigation Tree panel/*  w w w . ja v a2  s. c  om*/
 *
 * @return @see JPanel containing the navigation tree to browse a file system.
 */
private JPanel createNavTree() {
    JPanel treeContainer = new JPanel(new BorderLayout());
    treeContainer.setBackground(UIHelper.BG_COLOR);
    treeContainer
            .setBorder(new TitledBorder(UIHelper.GREEN_ROUNDED_BORDER, "", TitledBorder.DEFAULT_JUSTIFICATION,
                    TitledBorder.DEFAULT_POSITION, UIHelper.VER_12_BOLD, UIHelper.DARK_GREEN_COLOR));

    JPanel navigationControls = new JPanel();
    navigationControls.setLayout(new BoxLayout(navigationControls, BoxLayout.LINE_AXIS));
    navigationControls.setOpaque(false);

    final JLabel navToParentDir = new JLabel(upIcon);
    navToParentDir.setOpaque(false);
    navToParentDir.addMouseListener(new CommonMouseAdapter() {

        public void mousePressed(MouseEvent event) {
            super.mousePressed(event);
            navToParentDir.setIcon(upIcon);
            try {
                updateTree(fileBrowser.getParentDirectory());
            } catch (IOException e) {
                errorAction("problem occurred!");
            }
        }

        public void mouseEntered(MouseEvent event) {
            super.mouseEntered(event);
            navToParentDir.setIcon(upIconOver);
        }

        public void mouseExited(MouseEvent event) {
            super.mouseExited(event);
            navToParentDir.setIcon(upIcon);
        }
    });

    navigationControls.add(navToParentDir);
    navigationControls.add(Box.createHorizontalStrut(5));

    final JLabel navToHomeDir = new JLabel(homeIcon);
    navToHomeDir.setOpaque(false);
    navToHomeDir.addMouseListener(new CommonMouseAdapter() {

        public void mousePressed(MouseEvent event) {
            super.mousePressed(event);
            navToHomeDir.setIcon(homeIcon);
            try {
                updateTree(fileBrowser.getHomeDirectory());

            } catch (IOException e) {
                if (e instanceof ConnectionException) {
                    status.setText("<html>status: not connected!</html>");
                }
                FileBrowserTreeNode defaultFTPNode = new FileBrowserTreeNode("problem occurred!", false,
                        FileBrowserTreeNode.DIRECTORY);
                updateTree(defaultFTPNode);
            }
        }

        public void mouseEntered(MouseEvent event) {
            super.mouseEntered(event);
            navToHomeDir.setIcon(homeIconOver);
        }

        public void mouseExited(MouseEvent event) {
            super.mouseExited(event);
            navToHomeDir.setIcon(homeIcon);
        }
    });

    navigationControls.add(navToHomeDir);
    navigationControls.add(Box.createGlue());

    treeContainer.add(navigationControls, BorderLayout.NORTH);

    try {
        treeModel = new DefaultTreeModel(fileBrowser.getHomeDirectory());
        directoryTree = new JTree(treeModel);
        directoryTree.setFont(UIHelper.VER_11_PLAIN);
        directoryTree.setCellRenderer(new FileSystemTreeCellRenderer());
    } catch (IOException e) {
        FileBrowserTreeNode defaultFTPNode = new FileBrowserTreeNode("problem occurred!", false,
                FileBrowserTreeNode.DIRECTORY);
        updateTree(defaultFTPNode);
    }

    directoryTree.addMouseListener(new CommonMouseAdapter() {

        public void mousePressed(MouseEvent event) {
            super.mousePressed(event);
            int selRow = directoryTree.getRowForLocation(event.getX(), event.getY());

            TreePath selPath = directoryTree.getPathForLocation(event.getX(), event.getY());

            if (selRow != -1) {
                final FileBrowserTreeNode node = (FileBrowserTreeNode) selPath.getLastPathComponent();

                if (SwingUtilities.isLeftMouseButton(event)) {

                    if (event.getClickCount() == 2) {
                        if ((node.getType() == FileBrowserTreeNode.DIRECTORY) && (node.getLevel() != 0)) {

                            String newPath;
                            if (fileBrowser instanceof LocalBrowser) {
                                newPath = ((File) fileBrowser.getDirFiles().get(node.toString())).getPath();
                            } else {
                                newPath = node.toString();
                            }
                            updateTree(fileBrowser.changeDirectory(newPath));
                        }

                        // else, if a leaf node, then add file to to list
                        if (node.isLeaf() && (node.getType() != FileBrowserTreeNode.DIRECTORY)) {
                            String extension = node.toString().substring(node.toString().lastIndexOf(".") + 1)
                                    .trim().toUpperCase();

                            FileChooserFile toAdd = null;

                            for (Object o : fileBrowser.getFileMap().get(extension)) {
                                String fileName;
                                String filePath;
                                if (fileBrowser instanceof LocalBrowser) {
                                    File file = (File) o;
                                    fileName = file.getName();
                                    filePath = file.getPath();

                                    if (fileName.equals(node.toString())) {
                                        toAdd = new CustomFile(filePath);
                                        break;
                                    }
                                } else {
                                    FTPFile ftpFile = (FTPFile) o;
                                    fileName = ftpFile.getName();
                                    filePath = fileBrowser.getAbsoluteWorkingDirectory() + File.separator
                                            + ftpFile.getName();

                                    if (fileName.equals(node.toString())) {
                                        toAdd = new CustomFTPFile(ftpFile, filePath);
                                        break;
                                    }
                                }

                            }

                            if (toAdd != null && !checkIfInList(toAdd)) {
                                selectedFiles.addFileItem(toAdd);
                            }
                        }
                    }
                } else {
                    if ((node.getType() == FileBrowserTreeNode.DIRECTORY) && (node.getLevel() != 0)) {

                        // show popup to add the directory to the selected files
                        JPopupMenu popup = new JPopupMenu();

                        JMenuItem addDirectory = new JMenuItem("add directory");
                        addDirectory.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent ae) {

                                Object fileToAdd = fileBrowser.getDirFiles().get(node.toString());
                                FileChooserFile toAdd;

                                if (fileToAdd instanceof File) {
                                    toAdd = new CustomFile(((File) fileToAdd).getPath());
                                } else {
                                    FTPFile ftpFile = (FTPFile) fileToAdd;
                                    String filePath = fileBrowser.getAbsoluteWorkingDirectory() + File.separator
                                            + ftpFile.getName();

                                    toAdd = new CustomFTPFile(ftpFile, filePath);
                                }

                                if (!checkIfInList(toAdd)) {
                                    selectedFiles.addDirectoryItem(toAdd);
                                }
                            }
                        });

                        popup.add(addDirectory);
                        popup.show(directoryTree, event.getX(), event.getY());
                    }
                }
            }
        }

    });

    BasicTreeUI ui = new BasicTreeUI() {
        public Icon getCollapsedIcon() {
            return null;
        }

        public Icon getExpandedIcon() {
            return null;
        }
    };

    directoryTree.setUI(ui);
    directoryTree.setFont(UIHelper.VER_12_PLAIN);

    JScrollPane treeScroll = new JScrollPane(directoryTree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    treeScroll.setPreferredSize(new Dimension(300, 200));
    treeScroll.setBorder(new EmptyBorder(0, 0, 0, 0));
    treeContainer.add(treeScroll, BorderLayout.CENTER);

    IAppWidgetFactory.makeIAppScrollPane(treeScroll);

    return treeContainer;
}

From source file:org.kepler.gui.popups.LibraryPopupListener.java

/**
 * //from w w  w.ja  va  2 s  . co m
 * @param selPath
 * @param e
 */
private void handlePopupInsideKar(TreePath selPath, MouseEvent e) {

    Object ob = selPath.getLastPathComponent();
    if (isDebugging)
        log.debug(ob.getClass().getName());

    if (ob instanceof FolderEntityLibrary) {
        // User clicked on a Folder inside of a KAR
        KARFolderPopup kfp = new KARFolderPopup(selPath, _aptree.getParentComponent());
        kfp.initialize();
        _aptree.add(kfp);
        _aptree.setSelectionPath(selPath);
        kfp.show(e.getComponent(), e.getX(), e.getY());

    } else if (!(ob instanceof ptolemy.moml.EntityLibrary)) {
        // User clicked on a Component inside a KAR
        KARComponentPopup kcp = new KARComponentPopup(selPath, _aptree.getParentComponent());
        kcp.initialize();
        _aptree.add(kcp);
        _aptree.setSelectionPath(selPath);
        kcp.show(e.getComponent(), e.getX(), e.getY());

    }
}

From source file:org.kepler.gui.popups.LibraryPopupListener.java

/**
 * //from   w w  w.  ja v a 2  s  . c  o  m
 * @param selPath
 * @param e
 */
private void handlePopupOutsideKar(TreePath selPath, MouseEvent e) {

    Object ob = selPath.getLastPathComponent();
    if (isDebugging)
        log.debug(ob.getClass().getName());

    if (ob instanceof KAREntityLibrary) {
        // User clicked on a KAR
        if (isDebugging)
            log.debug("KAREntityLibrary selected");
        KARPopup kp = new KARPopup(selPath, _aptree.getParentComponent());
        kp.initialize();
        _aptree.add(kp);
        _aptree.setSelectionPath(selPath);
        kp.show(e.getComponent(), e.getX(), e.getY());
    } else if (ob instanceof DownloadableKAREntityLibrary) {
        DownloadableKARPopup kp = new DownloadableKARPopup(selPath, _aptree.getParentComponent());
        kp.initialize();
        _aptree.add(kp);
        _aptree.setSelectionPath(selPath);
        kp.show(e.getComponent(), e.getX(), e.getY());
    } else if (ob instanceof RemoteRepositoryEntityLibrary) {
        //         System.out.println("Context click on RREL");

    } else if (ob instanceof FolderEntityLibrary) {
        // User clicked on a Folder
        FolderPopup fp = new FolderPopup(selPath, _aptree.getParentComponent());
        fp.initialize();
        _aptree.add(fp);
        _aptree.setSelectionPath(selPath);
        fp.show(e.getComponent(), e.getX(), e.getY());

    } else if (ob instanceof OntologyEntityLibrary) {
        // User clicked on an ontology
        OntologyPopup op = new OntologyPopup(selPath, _aptree.getParentComponent());
        op.initialize();
        _aptree.add(op);
        _aptree.setSelectionPath(selPath);
        op.show(e.getComponent(), e.getX(), e.getY());

    } else if (ob instanceof KARErrorEntityLibrary) {
        KARErrorPopup kep = new KARErrorPopup(selPath, _aptree.getParentComponent());
        kep.initialize();
        _aptree.add(kep);
        _aptree.setSelectionPath(selPath);
        kep.show(e.getComponent(), e.getX(), e.getY());

    } else if (ob instanceof RemoteKARErrorEntityLibrary) {
        RemoteKARErrorPopup kep = new RemoteKARErrorPopup(selPath, _aptree.getParentComponent());
        kep.initialize();
        _aptree.add(kep);
        _aptree.setSelectionPath(selPath);
        kep.show(e.getComponent(), e.getX(), e.getY());

    } else if (!(ob instanceof ptolemy.moml.EntityLibrary)) {
        // User clicked on a Component
        if (!(ob instanceof NamedObj)) {
            // Shouldn't happen
            return;
        }
        NamedObj no = (NamedObj) ob;
        String alternateLibraryPopupClassName = _getAlternateLibraryPopupClassName(no);
        if (alternateLibraryPopupClassName == null) {
            //System.out.println("Using default context menu stuff for class: " + ob.getClass().getName());
            OntologyComponentPopup ocp = new OntologyComponentPopup(selPath, _aptree.getParentComponent());
            ocp.initialize();
            _aptree.add(ocp);
            _aptree.setSelectionPath(selPath);
            ocp.show(e.getComponent(), e.getX(), e.getY());
        } else {
            try {
                Class<?> libraryPopupClass = Class.forName(alternateLibraryPopupClassName);
                Object object = libraryPopupClass.newInstance();
                Method getPopupMethod = libraryPopupClass.getMethod("getPopup", JTree.class, MouseEvent.class,
                        TreePath.class, Component.class);
                getPopupMethod.invoke(object, _aptree, e, selPath, _aptree.getParentComponent());
            } catch (Exception w) {
                log.error("Error creating alternateGetLibraryPopup!", w);
            }
        }
    }
}

From source file:org.kepler.gui.popups.LibraryPopupListener.java

/** Handle a double-click action. */
private void handleDoubleClickOutsideKar(TreePath selPath, MouseEvent event) {
    Object ob = selPath.getLastPathComponent();

    if (ob instanceof EntityLibrary) {
        return;/*from ww w .  j a va 2s.c o m*/
    } else {

        int liid = LibraryManager.getLiidFor((ComponentEntity) ob);
        LibItem li = null;
        try {
            li = LibraryManager.getInstance().getPopulatedLibItem(liid);
        } catch (SQLException e) {
            MessageHandler.error("Error accessinc library item.", e);
            return;
        }

        // open it if it's a MoML
        String filePath = li.getAttributeValue(LibIndex.ATT_XMLFILE);
        if (filePath != null) {
            Component component = _aptree.getParentComponent();
            while (component != null && !(component instanceof TableauFrame)) {
                component = component.getParent();
            }
            if (component == null) {
                MessageHandler.error("Could not find TableauFrame.");
                return;
            }
            Configuration configuration = ((TableauFrame) component).getConfiguration();
            try {
                URL url = new File(filePath).toURI().toURL();
                configuration.openModel(url, url, url.toExternalForm());
            } catch (Exception e) {
                MessageHandler.error("Error opening " + filePath, e);
            }

            // if we successfully opened a file, update the history menu and
            // set the last directory.

            // update the history menu
            if (component instanceof KeplerGraphFrame) {
                try {
                    ((KeplerGraphFrame) component).updateHistory(filePath);
                } catch (IOException exception) {
                    MessageHandler.error("Unable to update history menu.", exception);
                }
            }
            if (component instanceof BasicGraphFrame) {
                ((BasicGraphFrame) component).setLastDirectory(new File(filePath).getParentFile());
            }

        } else if (li.getLsid() != null) {
            // if it has an lsid, show the documentation
            Component component = _aptree.getParentComponent();
            while (component != null && !(component instanceof PtolemyFrame)) {
                component = component.getParent();
            }
            if (component == null) {
                MessageHandler.error("Could not find TableauFrame.");
                return;
            }
            ShowDocumentationAction action = new ShowDocumentationAction(selPath, _aptree.getParentComponent());
            action.setLsidToView(li.getLsid());
            action.setPtolemyFrame((PtolemyFrame) component);

            action.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_FIRST, "open"));
        }
    }
}

From source file:org.kepler.gui.popups.LibraryPopupListener.java

/**
 * Description of the Method/*from w  w w  .j  ava 2  s . c  o  m*/
 * 
 *@param e
 *            Description of the Parameter
 */
private void maybeShowPopup(MouseEvent e) {
    if (isDebugging)
        log.debug("maybeShowPopup(" + e.toString() + ")");
    if (e.isPopupTrigger() || _trigger) {
        _trigger = false;
        TreePath selPath = _aptree.getPathForLocation(e.getX(), e.getY());
        if (isDebugging)
            log.debug(selPath.toString());
        if ((selPath != null)) {

            if (isDebugging)
                log.debug(selPath.getLastPathComponent().getClass().getName());

            if (_isPathInsideKAR(selPath)) {
                handlePopupInsideKar(selPath, e);
            } else {
                handlePopupOutsideKar(selPath, e);

            }
        }
        // handle double clicks
    } else if (e.getClickCount() == 2) {
        TreePath selPath = _aptree.getPathForLocation(e.getX(), e.getY());
        if (isDebugging)
            log.debug(selPath.toString());
        if ((selPath != null)) {

            if (isDebugging)
                log.debug(selPath.getLastPathComponent().getClass().getName());

            if (_isPathInsideKAR(selPath)) {
                handlePopupInsideKar(selPath, e);
            } else {
                handleDoubleClickOutsideKar(selPath, e);
            }
        }
    }
}