Search in sources :

Example 41 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent in project sldeditor by robward-scisys.

the class GeoServerStyleTree method createUI.

/**
 * Creates the ui.
 */
private void createUI() {
    setLayout(new BorderLayout());
    styleCardPanel = new JPanel();
    styleCardPanel.setLayout(new CardLayout(0, 0));
    add(styleCardPanel, BorderLayout.CENTER);
    JPanel styleTreePanel = new JPanel();
    styleTreePanel.setLayout(new BorderLayout());
    styleCardPanel.add(styleTreePanel, STYLE_PANEL);
    tree = new JTree(treeModel);
    tree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            if (!populating) {
                setButtonState(true);
            }
        }
    });
    JScrollPane scrollPane = new JScrollPane(tree);
    styleTreePanel.add(scrollPane, BorderLayout.CENTER);
    JPanel styleButtonsPanel = new JPanel();
    styleTreePanel.add(styleButtonsPanel, BorderLayout.SOUTH);
    btnApply = new JButton(Localisation.getString(GeoServerStyleTree.class, "common.apply"));
    btnApply.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            apply();
        }
    });
    styleButtonsPanel.add(btnApply);
    btnRevert = new JButton(Localisation.getString(GeoServerStyleTree.class, "common.revert"));
    btnRevert.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            revert();
        }
    });
    styleButtonsPanel.add(btnRevert);
    // 
    // Empty panel
    // 
    JPanel emptyPanel = new JPanel();
    emptyPanel.setLayout(new BorderLayout());
    styleCardPanel.add(emptyPanel, EMPTY_PANEL);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) CardLayout(java.awt.CardLayout) JTree(javax.swing.JTree) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 42 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent in project android by JetBrains.

the class LicenseAgreementStep method createTreeSelectionListener.

private TreeSelectionListener createTreeSelectionListener() {
    return new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            DefaultMutableTreeNode selected = (DefaultMutableTreeNode) myChangeTree.getLastSelectedPathComponent();
            if (selected != null && selected.isRoot()) {
                return;
            }
            if (selected != null && !selected.isLeaf()) {
                License license = (License) selected.getUserObject();
                myLicenseTextField.setText(license.getValue());
                myCurrentLicense = license.getId();
            } else if (selected != null && !selected.isRoot()) {
                Change change = (Change) selected.getUserObject();
                myLicenseTextField.setText(change.license.getValue());
                myCurrentLicense = change.license.getId();
            }
            if (myAcceptances.get(myCurrentLicense)) {
                myAcceptRadioButton.setSelected(true);
            } else {
                myDeclineRadioButton.setSelected(true);
            }
            myLicenseTextField.setCaretPosition(0);
        }
    };
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) License(com.android.repository.api.License) TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 43 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent in project android by JetBrains.

the class LicenseAgreementStep method init.

@Override
public void init() {
    super.init();
    myChangeTree.setModel(myTreeModel);
    myChangeTree.setShowsRootHandles(false);
    myLicenseTextField.setEditable(false);
    // Initialize radio buttons
    ButtonGroup group = new ButtonGroup();
    group.add(myDeclineRadioButton);
    group.add(myAcceptRadioButton);
    myDeclineRadioButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            myAcceptances.put(myCurrentLicense, Boolean.FALSE);
            invokeUpdate(null);
            myChangeTree.repaint();
        }
    });
    myAcceptRadioButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            myAcceptances.put(myCurrentLicense, Boolean.TRUE);
            invokeUpdate(null);
            myChangeTree.repaint();
        }
    });
    myChangeTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            DefaultMutableTreeNode selected = (DefaultMutableTreeNode) myChangeTree.getLastSelectedPathComponent();
            if (selected != null && selected.isRoot()) {
                return;
            }
            if (selected != null && !selected.isLeaf()) {
                License license = (License) selected.getUserObject();
                myLicenseTextField.setText(license.getValue());
                myCurrentLicense = license.getId();
            } else if (selected != null && !selected.isRoot()) {
                Change change = (Change) selected.getUserObject();
                myLicenseTextField.setText(change.license.getValue());
                myCurrentLicense = change.license.getId();
            }
            if (myAcceptances.get(myCurrentLicense)) {
                myAcceptRadioButton.setSelected(true);
            } else {
                myDeclineRadioButton.setSelected(true);
            }
            myLicenseTextField.setCaretPosition(0);
        }
    });
    myChangeTree.setCellRenderer(new ColoredTreeCellRenderer() {

        @Override
        public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            if (row == 0) {
                append("Licenses", SimpleTextAttributes.REGULAR_ATTRIBUTES);
                return;
            }
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
            if (!leaf) {
                License license = (License) node.getUserObject();
                appendLicenseText(license, license.getId());
            } else {
                Change change = (Change) node.getUserObject();
                if (change == null) {
                    return;
                }
                appendLicenseText(change.license, change.toString());
                setIcon(change.getIcon());
            }
        }

        private void appendLicenseText(@Nullable License license, String text) {
            boolean notAccepted = license != null && !myAcceptances.get(license.getId());
            if (notAccepted) {
                append("*", SimpleTextAttributes.ERROR_ATTRIBUTES);
                append(text, SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
            } else {
                append(text, SimpleTextAttributes.REGULAR_ATTRIBUTES);
            }
        }
    });
    setChanges(createChangesList());
}
Also used : ColoredTreeCellRenderer(com.intellij.ui.ColoredTreeCellRenderer) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ActionEvent(java.awt.event.ActionEvent) TreeSelectionListener(javax.swing.event.TreeSelectionListener) ActionListener(java.awt.event.ActionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 44 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent in project intellij-community by JetBrains.

the class ModulesDependenciesPanel method installLeftTreeListeners.

private void installLeftTreeListeners() {
    myLeftTree.addTreeExpansionListener(new TreeExpansionListener() {

        @Override
        public void treeCollapsed(TreeExpansionEvent event) {
        }

        @Override
        public void treeExpanded(TreeExpansionEvent event) {
            DefaultMutableTreeNode expandedNode = (DefaultMutableTreeNode) event.getPath().getLastPathComponent();
            for (int i = 0; i < expandedNode.getChildCount(); i++) {
                DefaultMutableTreeNode child = (DefaultMutableTreeNode) expandedNode.getChildAt(i);
                if (child.getChildCount() == 0 && !isLooped(event.getPath(), child)) {
                    Module module = ((MyUserObject) child.getUserObject()).myModule;
                    for (Module dependency : getModuleDependencies(module)) {
                        child.add(new DefaultMutableTreeNode(new MyUserObject(isInCycle(dependency), dependency)));
                    }
                    TreeUtil.sortRecursively(child, NODE_COMPARATOR);
                }
            }
        }

        private boolean isLooped(TreePath path, DefaultMutableTreeNode child) {
            for (Object o : path.getPath()) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) o;
                if (node != child && Comparing.equal(node.getUserObject(), child.getUserObject())) {
                    return true;
                }
            }
            return false;
        }
    });
    myLeftTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            TreePath selectionPath = myLeftTree.getSelectionPath();
            if (selectionPath != null) {
                myPathField.setText(StringUtil.join(selectionPath.getPath(), o -> {
                    Object userObject = ((DefaultMutableTreeNode) o).getUserObject();
                    return userObject instanceof MyUserObject ? ((MyUserObject) userObject).myModule.getName() : "";
                }, " : "));
                DefaultMutableTreeNode selection = (DefaultMutableTreeNode) selectionPath.getLastPathComponent();
                if (selection != null) {
                    updateRightTree(((MyUserObject) selection.getUserObject()).myModule);
                }
            }
        }
    });
}
Also used : TreeExpansionListener(javax.swing.event.TreeExpansionListener) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) Module(com.intellij.openapi.module.Module) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent)

Example 45 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent in project intellij-community by JetBrains.

the class SMTestRunnerResultsForm method addEventsListener.

public void addEventsListener(final EventsListener listener) {
    myEventListeners.add(listener);
    addTestsTreeSelectionListener(new TreeSelectionListener() {

        public void valueChanged(final TreeSelectionEvent e) {
            //We should fire event only if it was generated by this component,
            //e.g. it is focused. Otherwise it is side effect of selecting proxy in
            //try by other component
            //if (myTreeView.isFocusOwner()) {
            @Nullable final SMTestProxy selectedProxy = (SMTestProxy) getTreeView().getSelectedTest();
            listener.onSelected(selectedProxy, SMTestRunnerResultsForm.this, SMTestRunnerResultsForm.this);
        //}
        }
    });
}
Also used : TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Aggregations

TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)85 TreeSelectionListener (javax.swing.event.TreeSelectionListener)82 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)34 TreePath (javax.swing.tree.TreePath)32 JTree (javax.swing.JTree)27 ActionEvent (java.awt.event.ActionEvent)23 JScrollPane (javax.swing.JScrollPane)23 JPanel (javax.swing.JPanel)22 ActionListener (java.awt.event.ActionListener)20 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)18 MouseEvent (java.awt.event.MouseEvent)15 BorderLayout (java.awt.BorderLayout)14 Dimension (java.awt.Dimension)13 GridBagConstraints (java.awt.GridBagConstraints)12 GridBagLayout (java.awt.GridBagLayout)12 Insets (java.awt.Insets)12 JButton (javax.swing.JButton)11 Tree (com.intellij.ui.treeStructure.Tree)9 KeyAdapter (java.awt.event.KeyAdapter)9 KeyEvent (java.awt.event.KeyEvent)9