Search in sources :

Example 31 with TreeSelectionListener

use of javax.swing.event.TreeSelectionListener in project sirix by sirixdb.

the class TreeView method refreshUpdate.

@Override
public void refreshUpdate(final Optional<VisualItemAxis> pAxis) {
    // Use our sirix model and renderer.
    dispose();
    final ReadDB db = mGUI.getReadDB();
    mTree.setModel(new TreeModel(db));
    mTree.setCellRenderer(new TreeCellRenderer(db));
    if (mTree.getTreeSelectionListeners().length == 0) {
        // Listen for when the selection changes.
        mTree.addTreeSelectionListener(new TreeSelectionListener() {

            @Override
            public void valueChanged(final TreeSelectionEvent paramE) {
                if (paramE.getNewLeadSelectionPath() != null && paramE.getNewLeadSelectionPath() != paramE.getOldLeadSelectionPath()) {
                    /*
						 * Returns the last path element of the selection. This method is
						 * useful only when the selection model allows a single selection.
						 */
                    final Node node = (Node) paramE.getNewLeadSelectionPath().getLastPathComponent();
                    db.setKey(node.getNodeKey());
                    mNotifier.update(mView, Optional.<VisualItemAxis>absent());
                }
            }
        });
    }
}
Also used : VisualItemAxis(org.sirix.gui.view.VisualItemAxis) Node(org.sirix.node.interfaces.Node) TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) ReadDB(org.sirix.gui.ReadDB)

Example 32 with TreeSelectionListener

use of javax.swing.event.TreeSelectionListener in project selenium_java by sergueik.

the class JSplitPaneClassFile method createAndShowGUI.

private void createAndShowGUI(JFrame top) {
    // Construct class file viewer
    final JTreeClassFile jTreeClassFile = new JTreeClassFile(this.classFile);
    jTreeClassFile.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(final javax.swing.event.TreeSelectionEvent evt) {
            jTreeClassFileSelectionChanged(evt);
        }
    });
    final JPanelForTree panel = new JPanelForTree(jTreeClassFile, top);
    final JTabbedPane tabbedPane = new JTabbedPane();
    // Construct binary viewer
    this.binaryViewer = new JBinaryViewer();
    this.binaryViewer.setData(this.classFile.getClassByteArray());
    this.binaryViewerView = new JScrollPane(this.binaryViewer);
    this.binaryViewerView.getVerticalScrollBar().setValue(0);
    tabbedPane.add("Class File", this.binaryViewerView);
    // Construct opcode viewer
    this.opcode = new JTextPane();
    this.opcode.setAlignmentX(Component.LEFT_ALIGNMENT);
    // this.opcode.setFont(new Font(Font.DIALOG_INPUT, Font.PLAIN, 14));
    this.opcode.setEditable(false);
    this.opcode.setBorder(null);
    this.opcode.setContentType("text/html");
    tabbedPane.add("Opcode", new JScrollPane(this.opcode));
    // Class report
    this.report = new JTextPane();
    this.report.setAlignmentX(Component.LEFT_ALIGNMENT);
    this.report.setEditable(false);
    this.report.setBorder(null);
    this.report.setContentType("text/html");
    tabbedPane.add("Report", new JScrollPane(this.report));
    this.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
    this.setDividerSize(5);
    this.setDividerLocation(280);
    this.setLeftComponent(panel);
    this.setRightComponent(tabbedPane);
    this.binaryViewerView.getVerticalScrollBar().setValue(0);
}
Also used : JScrollPane(javax.swing.JScrollPane) JTextPane(javax.swing.JTextPane) JTabbedPane(javax.swing.JTabbedPane) JPanelForTree(org.freeinternals.commonlib.ui.JPanelForTree) TreeSelectionListener(javax.swing.event.TreeSelectionListener) JBinaryViewer(org.freeinternals.commonlib.ui.JBinaryViewer) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 33 with TreeSelectionListener

use of javax.swing.event.TreeSelectionListener in project Eidolons by IDemiurge.

the class ModelManager method adjustTreeTabSelection.

public static void adjustTreeTabSelection(ObjType type, boolean select) {
    int code = // type.getOBJ_TYPE_ENUM().getCode();
    ListMaster.getIndexString(new ArrayList<>(ArcaneVault.getMainBuilder().getTabBuilder().getTabNames()), type.getOBJ_TYPE(), true);
    ArcaneVault.getMainBuilder().getTabBuilder().getTabbedPane().setSelectedIndex(code);
    // ArcaneVault.getMainBuilder().getEditViewPanel().selectType(type);
    // Class<?> ENUM_CLASS =
    // EnumMaster.findEnumClass(type.getOBJ_TYPE_ENUM().getGroupingKey().getName());
    List<String> list = EnumMaster.findEnumConstantNames(type.getOBJ_TYPE_ENUM().getGroupingKey().getName());
    int index = ListMaster.getIndexString(list, type.getGroupingKey(), true);
    if (type.getOBJ_TYPE_ENUM() == DC_TYPE.SKILLS) {
        if (index > 5) {
            index--;
        }
    }
    TabBuilder tb = ArcaneVault.getMainBuilder().getTabBuilder().getSubTabs(code);
    tb.getTabbedPane().setSelectedIndex(index);
    // getOrCreate path for node? I could keep some map from type to path...
    if (!select) {
        if (tb.getTree().getTreeSelectionListeners().length != 1) {
            return;
        }
        TreeSelectionListener listener = tb.getTree().getTreeSelectionListeners()[0];
        tb.getTree().removeTreeSelectionListener(listener);
        try {
            TreeMaster.collapseTree(tb.getTree());
            DefaultMutableTreeNode node = TreeMaster.findNode(tb.getTree(), type.getName());
            if (node == null) {
                // tb.getTabbedPane().setSelectedIndex(prevIndex);
                return;
            }
            tb.getTree().setSelectionPath(new TreePath(node.getPath()));
        } catch (Exception e) {
            main.system.ExceptionMaster.printStackTrace(e);
        } finally {
            tb.getTree().addTreeSelectionListener(listener);
        }
        return;
    }
    TreeMaster.collapseTree(tb.getTree());
    DefaultMutableTreeNode node = TreeMaster.findNode(tb.getTree(), type.getName());
    tb.getTree().setSelectionPath(new TreePath(node.getPath()));
}
Also used : TabBuilder(main.gui.builders.TabBuilder) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) TreeSelectionListener(javax.swing.event.TreeSelectionListener)

Example 34 with TreeSelectionListener

use of javax.swing.event.TreeSelectionListener in project opennars by opennars.

the class NarseseTemplatePanel method newPanel.

private static JPanel newPanel(List<NarseseTemplate> templates) {
    JPanel p = new JPanel(new BorderLayout());
    JPanel menu = new JPanel(new BorderLayout());
    DefaultMutableTreeNode tree = new DefaultMutableTreeNode();
    for (NarseseTemplate n : templates) {
        DefaultMutableTreeNode nt = new DefaultMutableTreeNode(n);
        tree.add(nt);
    }
    JTree t = new JTree(tree);
    menu.add(t, BorderLayout.CENTER);
    final JComboBox formSelect = new JComboBox();
    formSelect.addItem("en");
    formSelect.addItem("narsese");
    menu.add(formSelect, BorderLayout.NORTH);
    p.add(menu, BorderLayout.WEST);
    ActionListener change = new ActionListener() {

        JPanel r = null;

        @Override
        public void actionPerformed(ActionEvent e) {
            if (t.getSelectionModel().isSelectionEmpty())
                return;
            Object o = ((DefaultMutableTreeNode) t.getSelectionModel().getSelectionPath().getLastPathComponent()).getUserObject();
            if (!(o instanceof NarseseTemplate))
                return;
            if (r != null) {
                p.remove(r);
            }
            r = newPanel((NarseseTemplate) o, formSelect.getSelectedItem().toString());
            p.add(r, BorderLayout.CENTER);
            p.validate();
        }
    };
    formSelect.addActionListener(change);
    t.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            change.actionPerformed(null);
        }
    });
    change.actionPerformed(null);
    return p;
}
Also used : JPanel(javax.swing.JPanel) JTree(javax.swing.JTree) BorderLayout(java.awt.BorderLayout) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) JComboBox(javax.swing.JComboBox) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 35 with TreeSelectionListener

use of javax.swing.event.TreeSelectionListener in project flutter-intellij by flutter.

the class TextOnlyActionWrapper method initToolWindow.

public void initToolWindow(@NotNull ToolWindow toolWindow) {
    final ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
    final ContentManager contentManager = toolWindow.getContentManager();
    final DefaultActionGroup toolbarGroup = new DefaultActionGroup();
    toolbarGroup.add(actionCenter);
    toolbarGroup.add(actionPadding);
    toolbarGroup.add(actionColumn);
    toolbarGroup.add(actionRow);
    toolbarGroup.addSeparator();
    toolbarGroup.add(actionExtractMethod);
    toolbarGroup.addSeparator();
    toolbarGroup.add(actionMoveUp);
    toolbarGroup.add(actionMoveDown);
    toolbarGroup.addSeparator();
    toolbarGroup.add(actionRemove);
    toolbarGroup.add(new ShowOnlyWidgetsAction(AllIcons.General.Filter, "Show only widgets"));
    final Content content = contentFactory.createContent(null, null, false);
    content.setCloseable(false);
    windowPanel = new OutlineComponent(this);
    content.setComponent(windowPanel);
    windowToolbar = ActionManager.getInstance().createActionToolbar("PreviewViewToolbar", toolbarGroup, true);
    windowPanel.setToolbar(windowToolbar.getComponent());
    final DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
    tree = new OutlineTree(rootNode);
    tree.setCellRenderer(new OutlineTreeCellRenderer());
    tree.expandAll();
    initTreePopup();
    // Add collapse all, expand all, and feedback buttons.
    if (toolWindow instanceof ToolWindowEx) {
        final AnAction sendFeedbackAction = new AnAction("Send Feedback", "Send Feedback", FlutterIcons.Feedback) {

            @Override
            public void actionPerformed(AnActionEvent event) {
                BrowserUtil.browse(FEEDBACK_URL);
            }
        };
        final AnAction separator = new AnAction(AllIcons.General.Divider) {

            @Override
            public void actionPerformed(AnActionEvent event) {
            }
        };
        final TreeExpander expander = new DefaultTreeExpander(tree);
        final CommonActionsManager actions = CommonActionsManager.getInstance();
        final AnAction expandAllAction = actions.createExpandAllAction(expander, tree);
        expandAllAction.getTemplatePresentation().setIcon(AllIcons.General.ExpandAll);
        final AnAction collapseAllAction = actions.createCollapseAllAction(expander, tree);
        collapseAllAction.getTemplatePresentation().setIcon(AllIcons.General.CollapseAll);
        ((ToolWindowEx) toolWindow).setTitleActions(sendFeedbackAction, separator, expandAllAction, collapseAllAction);
    }
    new TreeSpeedSearch(tree) {

        @Override
        protected String getElementText(Object element) {
            final TreePath path = (TreePath) element;
            final DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
            final Object object = node.getUserObject();
            if (object instanceof OutlineObject) {
                return ((OutlineObject) object).getSpeedSearchString();
            }
            return null;
        }
    };
    tree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() > 1) {
                final TreePath selectionPath = tree.getSelectionPath();
                if (selectionPath != null) {
                    selectPath(selectionPath, true);
                }
            }
        }
    });
    tree.addTreeSelectionListener(treeSelectionListener);
    scrollPane = ScrollPaneFactory.createScrollPane(tree);
    previewArea = new PreviewArea(new PreviewArea.Listener() {

        @Override
        public void clicked(FlutterOutline outline) {
            final ImmutableList<FlutterOutline> outlines = ImmutableList.of(outline);
            updateActionsForOutlines(outlines);
            applyOutlinesSelectionToTree(outlines);
            jumpToOutlineInEditor(outline, false);
        }

        @Override
        public void doubleClicked(FlutterOutline outline) {
            final ImmutableList<FlutterOutline> outlines = ImmutableList.of(outline);
            updateActionsForOutlines(outlines);
            applyOutlinesSelectionToTree(outlines);
            jumpToOutlineInEditor(outline, true);
        }

        @Override
        public void resized(int width, int height) {
            if (myRenderHelper != null) {
                myRenderHelper.setSize(width, height);
            }
        }
    });
    splitter = new Splitter(true);
    splitter.setProportion(getState().getSplitterProportion());
    getState().addListener(e -> {
        final float newProportion = getState().getSplitterProportion();
        if (splitter.getProportion() != newProportion) {
            splitter.setProportion(newProportion);
        }
    });
    // noinspection Convert2Lambda
    splitter.addPropertyChangeListener("proportion", new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            getState().setSplitterProportion(splitter.getProportion());
        }
    });
    splitter.setFirstComponent(scrollPane);
    windowPanel.setContent(splitter);
    contentManager.addContent(content);
    contentManager.setSelectedContent(content);
}
Also used : PropertyChangeListener(java.beans.PropertyChangeListener) TreeSelectionListener(javax.swing.event.TreeSelectionListener) CaretListener(com.intellij.openapi.editor.event.CaretListener) FlutterOutlineListener(io.flutter.dart.FlutterOutlineListener) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) PropertyChangeListener(java.beans.PropertyChangeListener) ToolWindowEx(com.intellij.openapi.wm.ex.ToolWindowEx) PropertyChangeEvent(java.beans.PropertyChangeEvent) MouseEvent(java.awt.event.MouseEvent) Splitter(com.intellij.openapi.ui.Splitter) ContentManager(com.intellij.ui.content.ContentManager) MouseAdapter(java.awt.event.MouseAdapter) ContentFactory(com.intellij.ui.content.ContentFactory) TreePath(javax.swing.tree.TreePath) Content(com.intellij.ui.content.Content) JsonObject(com.google.gson.JsonObject)

Aggregations

TreeSelectionListener (javax.swing.event.TreeSelectionListener)86 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)81 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)36 TreePath (javax.swing.tree.TreePath)32 JTree (javax.swing.JTree)28 JScrollPane (javax.swing.JScrollPane)26 ActionEvent (java.awt.event.ActionEvent)23 JPanel (javax.swing.JPanel)22 ActionListener (java.awt.event.ActionListener)20 MouseEvent (java.awt.event.MouseEvent)16 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)16 Dimension (java.awt.Dimension)15 BorderLayout (java.awt.BorderLayout)14 GridBagConstraints (java.awt.GridBagConstraints)11 GridBagLayout (java.awt.GridBagLayout)11 Insets (java.awt.Insets)11 JButton (javax.swing.JButton)11 Tree (com.intellij.ui.treeStructure.Tree)10 KeyAdapter (java.awt.event.KeyAdapter)9 KeyEvent (java.awt.event.KeyEvent)9