Search in sources :

Example 71 with TreeSelectionListener

use of javax.swing.event.TreeSelectionListener in project Course_Generator by patrovite.

the class CheckBoxTree method main.

public static void main(final String[] args) {
    final DefaultMutableTreeNode root = new DefaultMutableTreeNode(new CheckBoxNodeData("Root", true));
    final DefaultMutableTreeNode accessibility = add(root, "Accessibility", true);
    add(accessibility, "Move system caret with focus/selection changes", false);
    add(accessibility, "Always expand alt text for images", true);
    root.add(accessibility);
    final DefaultMutableTreeNode browsing = new DefaultMutableTreeNode(new CheckBoxNodeData("Browsing", null));
    add(browsing, "Notify when downloads complete", true);
    add(browsing, "Disable script debugging", true);
    add(browsing, "Use AutoComplete", true);
    add(browsing, "Browse in a new process", false);
    root.add(browsing);
    final CheckBoxTree tree = new CheckBoxTree(root);
    ((DefaultMutableTreeNode) tree.getModel().getRoot()).add(new DefaultMutableTreeNode(new CheckBoxNodeData("gggg", null)));
    ((DefaultTreeModel) tree.getModel()).reload();
    // listen for changes in the selection
    tree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(final TreeSelectionEvent e) {
        // System.out.println("selection changed");
        }
    });
    // show the tree on screen
    final JFrame frame = new JFrame("CheckBox Tree");
    final JScrollPane scrollPane = new JScrollPane(tree);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(300, 150);
    frame.setVisible(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) JFrame(javax.swing.JFrame) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 72 with TreeSelectionListener

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

the class TranscodingTab method buildLeft.

public JComponent buildLeft() {
    String colSpec = FormLayoutUtil.getColSpec(LEFT_COL_SPEC, orientation);
    FormLayout layout = new FormLayout(colSpec, LEFT_ROW_SPEC);
    PanelBuilder builder = new PanelBuilder(layout);
    builder.border(Borders.EMPTY);
    builder.opaque(false);
    CellConstraints cc = new CellConstraints();
    CustomJButton but = new CustomJButton(LooksFrame.readImageIcon("button-arrow-down.png"));
    but.setToolTipText(Messages.getString("TrTab2.6"));
    but.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            TreePath path = tree.getSelectionModel().getSelectionPath();
            if (path != null && path.getLastPathComponent() instanceof TreeNodeSettings) {
                TreeNodeSettings node = ((TreeNodeSettings) path.getLastPathComponent());
                if (node.getPlayer() != null) {
                    // get the tree model
                    DefaultTreeModel dtm = (DefaultTreeModel) tree.getModel();
                    // now get the index of the selected node in the DefaultTreeModel
                    int index = dtm.getIndexOfChild(node.getParent(), node);
                    // if selected node is first, return (can't move it up)
                    if (index < node.getParent().getChildCount() - 1) {
                        // move the node
                        dtm.insertNodeInto(node, (DefaultMutableTreeNode) node.getParent(), index + 1);
                        dtm.reload();
                        for (int i = 0; i < tree.getRowCount(); i++) {
                            tree.expandRow(i);
                        }
                        tree.getSelectionModel().setSelectionPath(new TreePath(node.getPath()));
                        updateEngineModel();
                    }
                }
            }
        }
    });
    builder.add(but, FormLayoutUtil.flip(cc.xy(2, 3), colSpec, orientation));
    CustomJButton but2 = new CustomJButton(LooksFrame.readImageIcon("button-arrow-up.png"));
    but2.setToolTipText(Messages.getString("TrTab2.6"));
    but2.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            TreePath path = tree.getSelectionModel().getSelectionPath();
            if (path != null && path.getLastPathComponent() instanceof TreeNodeSettings) {
                TreeNodeSettings node = ((TreeNodeSettings) path.getLastPathComponent());
                if (node.getPlayer() != null) {
                    // get the tree model
                    DefaultTreeModel dtm = (DefaultTreeModel) tree.getModel();
                    // now get the index of the selected node in the DefaultTreeModel
                    int index = dtm.getIndexOfChild(node.getParent(), node);
                    // if selected node is first, return (can't move it up)
                    if (index != 0) {
                        // move the node
                        dtm.insertNodeInto(node, (DefaultMutableTreeNode) node.getParent(), index - 1);
                        dtm.reload();
                        for (int i = 0; i < tree.getRowCount(); i++) {
                            tree.expandRow(i);
                        }
                        tree.getSelectionModel().setSelectionPath(new TreePath(node.getPath()));
                        updateEngineModel();
                    }
                }
            }
        }
    });
    builder.add(but2, FormLayoutUtil.flip(cc.xy(3, 3), colSpec, orientation));
    CustomJButton but3 = new CustomJButton(LooksFrame.readImageIcon("button-toggleengine.png"));
    but3.setToolTipText(Messages.getString("TrTab2.0"));
    but3.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            TreePath path = tree.getSelectionModel().getSelectionPath();
            if (path != null && path.getLastPathComponent() instanceof TreeNodeSettings && ((TreeNodeSettings) path.getLastPathComponent()).getPlayer() != null) {
                ((TreeNodeSettings) path.getLastPathComponent()).setEnable(!((TreeNodeSettings) path.getLastPathComponent()).isEnable());
                updateEngineModel();
                tree.updateUI();
            }
        }
    });
    builder.add(but3, FormLayoutUtil.flip(cc.xy(4, 3), colSpec, orientation));
    DefaultMutableTreeNode root = new DefaultMutableTreeNode(Messages.getString("TrTab2.11"));
    TreeNodeSettings commonEnc = new TreeNodeSettings(Messages.getString("TrTab2.5"), null, buildCommon());
    commonEnc.getConfigPanel().addComponentListener(new ComponentAdapter() {

        @Override
        public void componentShown(ComponentEvent e) {
            handleCardComponentChange(e.getComponent());
        }
    });
    tabbedPanel.add(commonEnc.id(), commonEnc.getConfigPanel());
    root.add(commonEnc);
    parent = new DefaultMutableTreeNode[5];
    parent[0] = new DefaultMutableTreeNode(Messages.getString("TrTab2.14"));
    parent[1] = new DefaultMutableTreeNode(Messages.getString("TrTab2.15"));
    parent[2] = new DefaultMutableTreeNode(Messages.getString("TrTab2.16"));
    parent[3] = new DefaultMutableTreeNode(Messages.getString("TrTab2.17"));
    parent[4] = new DefaultMutableTreeNode(Messages.getString("TrTab2.18"));
    root.add(parent[0]);
    root.add(parent[1]);
    root.add(parent[2]);
    root.add(parent[3]);
    root.add(parent[4]);
    tree = new JTree(new DefaultTreeModel(root)) {

        private static final long serialVersionUID = -6703434752606636290L;
    };
    tree.setRootVisible(false);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            if (e.getNewLeadSelectionPath() != null && e.getNewLeadSelectionPath().getLastPathComponent() instanceof TreeNodeSettings) {
                TreeNodeSettings tns = (TreeNodeSettings) e.getNewLeadSelectionPath().getLastPathComponent();
                cl.show(tabbedPanel, tns.id());
            }
        }
    });
    tree.setRequestFocusEnabled(false);
    tree.setCellRenderer(new TreeRenderer());
    JScrollPane pane = new JScrollPane(tree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    builder.add(pane, FormLayoutUtil.flip(cc.xyw(2, 1, 4), colSpec, orientation));
    builder.addLabel(Messages.getString("TrTab2.19"), FormLayoutUtil.flip(cc.xyw(2, 5, 4), colSpec, orientation));
    builder.addLabel(Messages.getString("TrTab2.20"), FormLayoutUtil.flip(cc.xyw(2, 7, 4), colSpec, orientation));
    JPanel panel = builder.getPanel();
    // Apply the orientation to the panel and all components in it
    panel.applyComponentOrientation(orientation);
    return panel;
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) PanelBuilder(com.jgoodies.forms.builder.PanelBuilder) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) CustomJButton(net.pms.newgui.components.CustomJButton) TreePath(javax.swing.tree.TreePath) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) CellConstraints(com.jgoodies.forms.layout.CellConstraints)

Example 73 with TreeSelectionListener

use of javax.swing.event.TreeSelectionListener in project CCDD by nasa.

the class CcddTableTreeHandler method createTreePanel.

/**
 ********************************************************************************************
 * Create a table tree panel. The table tree is placed in a scroll pane. A check box is added
 * that allows tree expansion/collapse
 *
 * @param label
 *            table tree title
 *
 * @param selectionMode
 *            tree item selection mode (single versus multiple)
 *
 * @param parent
 *            GUI component calling this method
 *
 * @return JPanel containing the table tree components
 ********************************************************************************************
 */
protected JPanel createTreePanel(String label, int selectionMode, final Component parent) {
    // Create an empty border
    Border emptyBorder = BorderFactory.createEmptyBorder();
    // Set the initial layout manager characteristics
    GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2, 0), 0, 0);
    // Set the table tree selection mode
    getSelectionModel().setSelectionMode(selectionMode);
    // Create a panel to contain the table tree
    JPanel treePnl = new JPanel(new GridBagLayout());
    treePnl.setBorder(emptyBorder);
    // Check if a label is provided
    if (label != null && !label.isEmpty()) {
        // Create the tree labels
        JLabel treeLbl = new JLabel(label);
        treeLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
        treeLbl.setForeground(ModifiableColorInfo.SPECIAL_LABEL_TEXT.getColor());
        treePnl.add(treeLbl, gbc);
        gbc.gridy++;
    }
    // Create the tree scroll pane
    JScrollPane treeScroll = new JScrollPane(this);
    treeScroll.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED, Color.LIGHT_GRAY, Color.GRAY), BorderFactory.createEmptyBorder(ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing())));
    // Add the tree to the panel
    gbc.weighty = 1.0;
    treePnl.add(treeScroll, gbc);
    // Set the table tree font and number of rows to display
    setFont(ModifiableFontInfo.TREE_NODE.getFont());
    setVisibleRowCount(10);
    // Add a listener for changes to the table tree
    addTreeSelectionListener(new TreeSelectionListener() {

        /**
         ************************************************************************************
         * Handle a change to the table tree selection
         ************************************************************************************
         */
        @Override
        public void valueChanged(TreeSelectionEvent lse) {
            // tree selection value changes that should not be processed
            if (!isBuilding) {
                // Update the groups based on the tables selected
                updateTableSelection();
            }
        }
    });
    // Add a listener for table tree expand and collapse events
    addTreeExpansionListener(new TreeExpansionListener() {

        /**
         ************************************************************************************
         * Handle an expansion of the table tree
         ************************************************************************************
         */
        @Override
        public void treeExpanded(TreeExpansionEvent tee) {
            // Update the table selection based on the selected group
            updateGroupSelection();
        }

        /**
         ************************************************************************************
         * Handle a collapse of the table tree
         ************************************************************************************
         */
        @Override
        public void treeCollapsed(TreeExpansionEvent tee) {
            // Update the table selection based on the selected group
            updateGroupSelection();
        }
    });
    // Create a tree expansion check box
    expandChkBx = new JCheckBox("Expand all");
    expandChkBx.setBorder(emptyBorder);
    expandChkBx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
    expandChkBx.setSelected(false);
    // Check if this is the last component to add
    if (!showGroupFilter && !showTypeFilter && !addHiddenCheckBox) {
        gbc.insets.bottom = 0;
    }
    gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
    gbc.weighty = 0.0;
    gbc.gridy++;
    treePnl.add(expandChkBx, gbc);
    // Create a listener for changes in selection of the tree expansion check box
    expandChkBx.addActionListener(new ActionListener() {

        /**
         ************************************************************************************
         * Handle a change to the tree expansion check box selection
         ************************************************************************************
         */
        @Override
        public void actionPerformed(ActionEvent ae) {
            setTreeExpansion(expandChkBx.isSelected());
        }
    });
    // Check if instance tables are displayed in the tree
    if (treeType != TableTreeType.PROTOTYPE_TABLES) {
        // Create a hide data type check box
        final JCheckBox hideTypeChkBx = new JCheckBox("Hide data type");
        hideTypeChkBx.setBorder(emptyBorder);
        hideTypeChkBx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
        hideTypeChkBx.setSelected(false);
        // Check if this is the last component to add
        if (!showGroupFilter && !showTypeFilter && !addHiddenCheckBox) {
            gbc.insets.bottom = 0;
        }
        gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
        gbc.weighty = 0.0;
        gbc.gridy++;
        treePnl.add(hideTypeChkBx, gbc);
        // Create a listener for changes in selection of the hide data type check box
        hideTypeChkBx.addActionListener(new ActionListener() {

            /**
             ********************************************************************************
             * Handle a change to the hide data type check box selection
             ********************************************************************************
             */
            @Override
            public void actionPerformed(ActionEvent ae) {
                setEnableDataType(!hideTypeChkBx.isSelected());
                // Store the tree's current expansion state
                String expState = getExpansionState();
                // Force the root node to draw with the node additions
                ((DefaultTreeModel) treeModel).nodeStructureChanged(root);
                setExpansionState(expState);
            }
        });
    }
    // Create the filtering node prefix storage and check boxes
    final List<String> prefixes = new ArrayList<String>();
    final JCheckBox groupFilterChkBx = new JCheckBox("Filter by group");
    final JCheckBox typeFilterChkBx = new JCheckBox("Filter by type");
    // table/variable divisions (e.g., 'Prototype', 'Parents & Children')
    for (int index = 0; index < root.getChildCount(); index++) {
        // Add the child node name with its path to the prefix list
        prefixes.add("[" + root.getUserObject() + ", " + ((ToolTipTreeNode) root.getChildAt(index)).getUserObject());
    }
    // Check if the group check box is valid for this tree type
    if (showGroupFilter) {
        // Create a group filter check box
        groupFilterChkBx.setBorder(emptyBorder);
        groupFilterChkBx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
        groupFilterChkBx.setSelected(false);
        groupFilterChkBx.setEnabled(!groupHandler.getGroupInformation().isEmpty());
        // Check if this is the last component to add
        if (!showTypeFilter && !addHiddenCheckBox) {
            gbc.insets.bottom = 0;
        }
        gbc.gridy++;
        treePnl.add(groupFilterChkBx, gbc);
        // Create a listener for changes in selection of the group filter check box
        groupFilterChkBx.addActionListener(new ActionListener() {

            /**
             ********************************************************************************
             * Handle a change to the group filter check box selection
             ********************************************************************************
             */
            @Override
            public void actionPerformed(ActionEvent ae) {
                // Set the filter by group flag based on the check box status
                isByGroup = groupFilterChkBx.isSelected();
                // Store the tree's current expansion state
                String expState = getExpansionState();
                // Rebuild the tree based on the filter selection
                buildTableTree(expandChkBx.isSelected(), rateName, rateFilter, parent);
                // Adjust the expansion state to account for the change in filtering, then
                // restore the expansion state
                expState = adjustExpansionState(expState, groupFilterChkBx.isSelected(), true, typeFilterChkBx.isSelected(), false, false, prefixes, groupHandler, tableTypeHandler);
                setExpansionState(expState);
            }
        });
    }
    // Check if the type check box is valid for this tree type
    if (showTypeFilter) {
        // Create a type filter check box
        typeFilterChkBx.setBorder(emptyBorder);
        typeFilterChkBx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
        typeFilterChkBx.setSelected(false);
        // Check if this is the last component to add
        if (!addHiddenCheckBox) {
            gbc.insets.bottom = 0;
        }
        gbc.gridy++;
        treePnl.add(typeFilterChkBx, gbc);
        // Create a listener for changes in selection of the type filter check box
        typeFilterChkBx.addActionListener(new ActionListener() {

            /**
             ********************************************************************************
             * Handle a change to the type filter check box selection
             ********************************************************************************
             */
            @Override
            public void actionPerformed(ActionEvent ae) {
                // Set the filter by type flag based on the check box status
                isByType = typeFilterChkBx.isSelected();
                // Store the tree's current expansion state
                String expState = getExpansionState();
                // Rebuild the tree based on the filter selection
                buildTableTree(expandChkBx.isSelected(), rateName, rateFilter, parent);
                // Adjust the expansion state to account for the change in filtering, then
                // restore the expansion state
                expState = adjustExpansionState(expState, groupFilterChkBx.isSelected(), false, typeFilterChkBx.isSelected(), true, false, prefixes, groupHandler, tableTypeHandler);
                setExpansionState(expState);
            }
        });
    }
    // tree panel. Check if the flag is set to add this check box
    if (addHiddenCheckBox) {
        // Create the hidden check box. To prevent display of the check box components an empty
        // panel is placed over it
        JPanel hiddenPnl = new JPanel(new FlowLayout(FlowLayout.LEFT));
        hiddenPnl.setBorder(emptyBorder);
        JCheckBox hiddenChkBx = new JCheckBox(" ");
        hiddenChkBx.setBorder(emptyBorder);
        gbc.insets.bottom = 0;
        gbc.gridy++;
        treePnl.add(hiddenPnl, gbc);
        hiddenChkBx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
        hiddenChkBx.setFocusable(false);
        hiddenChkBx.setDisabledIcon(null);
        hiddenChkBx.setEnabled(false);
        treePnl.add(hiddenChkBx, gbc);
    }
    return treePnl;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) TreeExpansionListener(javax.swing.event.TreeExpansionListener) Insets(java.awt.Insets) FlowLayout(java.awt.FlowLayout) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) JLabel(javax.swing.JLabel) TreeSelectionListener(javax.swing.event.TreeSelectionListener) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) Border(javax.swing.border.Border) BevelBorder(javax.swing.border.BevelBorder) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent) ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode)

Example 74 with TreeSelectionListener

use of javax.swing.event.TreeSelectionListener in project keystore-explorer by kaikramer.

the class DViewCertificate method initComponents.

private void initComponents(X509Certificate[] certs) throws CryptoException {
    jlHierarchy = new JLabel(res.getString("DViewCertificate.jlHierarchy.text"));
    jtrHierarchy = new JTree(createCertificateNodes(certs));
    jtrHierarchy.setRowHeight(Math.max(18, jtrHierarchy.getRowHeight()));
    jtrHierarchy.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    ToolTipManager.sharedInstance().registerComponent(jtrHierarchy);
    jtrHierarchy.setCellRenderer(new CertificateTreeCellRend());
    jtrHierarchy.setRootVisible(false);
    TreeNode topNode = (TreeNode) jtrHierarchy.getModel().getRoot();
    expandTree(jtrHierarchy, new TreePath(topNode));
    jtrHierarchy.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DViewCertificate.this);
                populateDetails();
            } finally {
                CursorUtil.setCursorFree(DViewCertificate.this);
            }
        }
    });
    jspHierarchy = PlatformUtil.createScrollPane(jtrHierarchy, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    jspHierarchy.setPreferredSize(new Dimension(100, 75));
    jpHierarchy = new JPanel(new BorderLayout(5, 5));
    jpHierarchy.add(jlHierarchy, BorderLayout.NORTH);
    jpHierarchy.add(jspHierarchy, BorderLayout.CENTER);
    jpHierarchy.setBorder(new EmptyBorder(5, 5, 5, 5));
    GridBagConstraints gbcLbl = new GridBagConstraints();
    gbcLbl.gridx = 0;
    gbcLbl.gridwidth = 1;
    gbcLbl.gridheight = 1;
    gbcLbl.insets = new Insets(5, 5, 5, 5);
    gbcLbl.anchor = GridBagConstraints.EAST;
    GridBagConstraints gbcCtrl = new GridBagConstraints();
    gbcCtrl.gridx = 1;
    gbcCtrl.gridwidth = 1;
    gbcCtrl.gridheight = 1;
    gbcCtrl.insets = new Insets(5, 5, 5, 5);
    gbcCtrl.anchor = GridBagConstraints.WEST;
    jlVersion = new JLabel(res.getString("DViewCertificate.jlVersion.text"));
    GridBagConstraints gbc_jlVersion = (GridBagConstraints) gbcLbl.clone();
    gbc_jlVersion.gridy = 0;
    jtfVersion = new JTextField(3);
    jtfVersion.setEditable(false);
    jtfVersion.setToolTipText(res.getString("DViewCertificate.jtfVersion.tooltip"));
    GridBagConstraints gbc_jtfVersion = (GridBagConstraints) gbcCtrl.clone();
    gbc_jtfVersion.gridy = 0;
    jlSubject = new JLabel(res.getString("DViewCertificate.jlSubject.text"));
    GridBagConstraints gbc_jlSubject = (GridBagConstraints) gbcLbl.clone();
    gbc_jlSubject.gridy = 1;
    jdnSubject = new JDistinguishedName(res.getString("DViewCertificate.Subject.Title"), 40, false);
    jdnSubject.setToolTipText(res.getString("DViewCertificate.jdnSubject.tooltip"));
    GridBagConstraints gbc_jdnSubject = (GridBagConstraints) gbcCtrl.clone();
    gbc_jdnSubject.gridy = 1;
    jlIssuer = new JLabel(res.getString("DViewCertificate.jlIssuer.text"));
    GridBagConstraints gbc_jlIssuer = (GridBagConstraints) gbcLbl.clone();
    gbc_jlIssuer.gridy = 2;
    jdnIssuer = new JDistinguishedName(res.getString("DViewCertificate.Issuer.Title"), 40, false);
    jdnIssuer.setToolTipText(res.getString("DViewCertificate.jdnIssuer.tooltip"));
    GridBagConstraints gbc_jdnIssuer = (GridBagConstraints) gbcCtrl.clone();
    gbc_jdnIssuer.gridy = 2;
    jlSerialNumber = new JLabel(res.getString("DViewCertificate.jlSerialNumber.text"));
    GridBagConstraints gbc_jlSerialNumber = (GridBagConstraints) gbcLbl.clone();
    gbc_jlSerialNumber.gridy = 3;
    jtfSerialNumber = new JTextField(30);
    jtfSerialNumber.setEditable(false);
    jtfSerialNumber.setToolTipText(res.getString("DViewCertificate.jtfSerialNumber.tooltip"));
    GridBagConstraints gbc_jtfSerialNumber = (GridBagConstraints) gbcCtrl.clone();
    gbc_jtfSerialNumber.gridy = 3;
    jlValidFrom = new JLabel(res.getString("DViewCertificate.jlValidFrom.text"));
    GridBagConstraints gbc_jlValidFrom = (GridBagConstraints) gbcLbl.clone();
    gbc_jlValidFrom.gridy = 4;
    jtfValidFrom = new JTextField(30);
    jtfValidFrom.setEditable(false);
    jtfValidFrom.setToolTipText(res.getString("DViewCertificate.jtfValidFrom.tooltip"));
    GridBagConstraints gbc_jtfValidFrom = (GridBagConstraints) gbcCtrl.clone();
    gbc_jtfValidFrom.gridy = 4;
    jlValidUntil = new JLabel(res.getString("DViewCertificate.jlValidUntil.text"));
    GridBagConstraints gbc_jlValidUntil = (GridBagConstraints) gbcLbl.clone();
    gbc_jlValidUntil.gridy = 5;
    jtfValidUntil = new JTextField(30);
    jtfValidUntil.setEditable(false);
    jtfValidUntil.setToolTipText(res.getString("DViewCertificate.jtfValidUntil.tooltip"));
    GridBagConstraints gbc_jtfValidUntil = (GridBagConstraints) gbcCtrl.clone();
    gbc_jtfValidUntil.gridy = 5;
    jlPublicKey = new JLabel(res.getString("DViewCertificate.jlPublicKey.text"));
    GridBagConstraints gbc_jlPublicKey = (GridBagConstraints) gbcLbl.clone();
    gbc_jlPublicKey.gridy = 6;
    jtfPublicKey = new JTextField(15);
    jtfPublicKey.setEditable(false);
    jtfPublicKey.setToolTipText(res.getString("DViewCertificate.jtfPublicKey.tooltip"));
    jbViewPublicKeyDetails = new JButton();
    jbViewPublicKeyDetails.setToolTipText(res.getString("DViewCertificate.jbViewPublicKeyDetails.tooltip"));
    jbViewPublicKeyDetails.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource(res.getString("DViewCertificate.jbViewPublicKeyDetails.image")))));
    jbViewPublicKeyDetails.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DViewCertificate.this);
                pubKeyDetailsPressed();
            } finally {
                CursorUtil.setCursorFree(DViewCertificate.this);
            }
        }
    });
    jpPublicKey = new JPanel(new GridBagLayout());
    GridBagConstraints gbc_jpPublicKey = (GridBagConstraints) gbcCtrl.clone();
    gbc_jpPublicKey.gridy = 6;
    GridBagConstraints gbc_jtfPublicKey = new GridBagConstraints();
    gbc_jtfPublicKey.gridwidth = 1;
    gbc_jtfPublicKey.gridheight = 1;
    gbc_jtfPublicKey.gridx = 0;
    gbc_jtfPublicKey.gridy = 0;
    gbc_jtfPublicKey.insets = new Insets(0, 0, 0, 5);
    GridBagConstraints gbc_jbViewPublicKeyDetails = new GridBagConstraints();
    gbc_jbViewPublicKeyDetails.gridwidth = 1;
    gbc_jbViewPublicKeyDetails.gridheight = 1;
    gbc_jbViewPublicKeyDetails.gridx = 1;
    gbc_jbViewPublicKeyDetails.gridy = 0;
    gbc_jbViewPublicKeyDetails.insets = new Insets(0, 5, 0, 0);
    jpPublicKey.add(jtfPublicKey, gbc_jtfPublicKey);
    jpPublicKey.add(jbViewPublicKeyDetails, gbc_jbViewPublicKeyDetails);
    jlSignatureAlgorithm = new JLabel(res.getString("DViewCertificate.jlSignatureAlgorithm.text"));
    GridBagConstraints gbc_jlSignatureAlgorithm = (GridBagConstraints) gbcLbl.clone();
    gbc_jlSignatureAlgorithm.gridy = 7;
    jtfSignatureAlgorithm = new JTextField(15);
    jtfSignatureAlgorithm.setEditable(false);
    jtfSignatureAlgorithm.setToolTipText(res.getString("DViewCertificate.jtfSignatureAlgorithm.tooltip"));
    GridBagConstraints gbc_jtfSignatureAlgorithm = (GridBagConstraints) gbcCtrl.clone();
    gbc_jtfSignatureAlgorithm.gridy = 7;
    jlFingerprint = new JLabel(res.getString("DViewCertificate.jlFingerprint.text"));
    GridBagConstraints gbc_jlFingerprint = (GridBagConstraints) gbcLbl.clone();
    gbc_jlFingerprint.gridy = 8;
    jcfFingerprint = new JCertificateFingerprint(30);
    GridBagConstraints gbc_jcfFingerprint = (GridBagConstraints) gbcCtrl.clone();
    gbc_jcfFingerprint.gridy = 8;
    jbExtensions = new JButton(res.getString("DViewCertificate.jbExtensions.text"));
    PlatformUtil.setMnemonic(jbExtensions, res.getString("DViewCertificate.jbExtensions.mnemonic").charAt(0));
    jbExtensions.setToolTipText(res.getString("DViewCertificate.jbExtensions.tooltip"));
    jbExtensions.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DViewCertificate.this);
                extensionsPressed();
            } finally {
                CursorUtil.setCursorFree(DViewCertificate.this);
            }
        }
    });
    jbPem = new JButton(res.getString("DViewCertificate.jbPem.text"));
    PlatformUtil.setMnemonic(jbPem, res.getString("DViewCertificate.jbPem.mnemonic").charAt(0));
    jbPem.setToolTipText(res.getString("DViewCertificate.jbPem.tooltip"));
    jbPem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DViewCertificate.this);
                pemEncodingPressed();
            } finally {
                CursorUtil.setCursorFree(DViewCertificate.this);
            }
        }
    });
    jbAsn1 = new JButton(res.getString("DViewCertificate.jbAsn1.text"));
    PlatformUtil.setMnemonic(jbAsn1, res.getString("DViewCertificate.jbAsn1.mnemonic").charAt(0));
    jbAsn1.setToolTipText(res.getString("DViewCertificate.jbAsn1.tooltip"));
    jbAsn1.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DViewCertificate.this);
                asn1DumpPressed();
            } finally {
                CursorUtil.setCursorFree(DViewCertificate.this);
            }
        }
    });
    if (importExport == IMPORT) {
        jbImportExport = new JButton(res.getString("DViewCertificate.jbImportExport.import.text"));
        jbImportExport.setToolTipText(res.getString("DViewCertificate.jbImportExport.import.tooltip"));
    } else {
        jbImportExport = new JButton(res.getString("DViewCertificate.jbImportExport.export.text"));
        jbImportExport.setToolTipText(res.getString("DViewCertificate.jbImportExport.export.tooltip"));
    }
    PlatformUtil.setMnemonic(jbImportExport, res.getString("DViewCertificate.jbImportExport.mnemonic").charAt(0));
    jbImportExport.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DViewCertificate.this);
                importExportPressed();
            } finally {
                CursorUtil.setCursorFree(DViewCertificate.this);
            }
        }
    });
    jpButtons = new JPanel();
    if (importExport != NONE) {
        jpButtons.add(jbImportExport);
    }
    jpButtons.add(jbExtensions);
    jpButtons.add(jbPem);
    jpButtons.add(jbAsn1);
    GridBagConstraints gbc_jpButtons = new GridBagConstraints();
    gbc_jpButtons.gridx = 0;
    gbc_jpButtons.gridy = 9;
    gbc_jpButtons.gridwidth = 2;
    gbc_jpButtons.gridheight = 1;
    gbc_jpButtons.anchor = GridBagConstraints.EAST;
    jpDetail = new JPanel(new GridBagLayout());
    jpDetail.setBorder(new EmptyBorder(5, 5, 5, 5));
    jpDetail.add(jlVersion, gbc_jlVersion);
    jpDetail.add(jtfVersion, gbc_jtfVersion);
    jpDetail.add(jlSubject, gbc_jlSubject);
    jpDetail.add(jdnSubject, gbc_jdnSubject);
    jpDetail.add(jlIssuer, gbc_jlIssuer);
    jpDetail.add(jdnIssuer, gbc_jdnIssuer);
    jpDetail.add(jlSerialNumber, gbc_jlSerialNumber);
    jpDetail.add(jtfSerialNumber, gbc_jtfSerialNumber);
    jpDetail.add(jlValidFrom, gbc_jlValidFrom);
    jpDetail.add(jtfValidFrom, gbc_jtfValidFrom);
    jpDetail.add(jlValidUntil, gbc_jlValidUntil);
    jpDetail.add(jtfValidUntil, gbc_jtfValidUntil);
    jpDetail.add(jlPublicKey, gbc_jlPublicKey);
    jpDetail.add(jpPublicKey, gbc_jpPublicKey);
    jpDetail.add(jlSignatureAlgorithm, gbc_jlSignatureAlgorithm);
    jpDetail.add(jtfSignatureAlgorithm, gbc_jtfSignatureAlgorithm);
    jpDetail.add(jlFingerprint, gbc_jlFingerprint);
    jpDetail.add(jcfFingerprint, gbc_jcfFingerprint);
    jpDetail.add(jpButtons, gbc_jpButtons);
    jpCertificates = new JPanel(new BorderLayout(0, 0));
    jpCertificates.setBorder(new CompoundBorder(new EmptyBorder(5, 5, 5, 5), new EtchedBorder()));
    jpCertificates.add(jpHierarchy, BorderLayout.NORTH);
    jpCertificates.add(jpDetail, BorderLayout.CENTER);
    jbOK = new JButton(res.getString("DViewCertificate.jbOK.text"));
    jbOK.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            okPressed();
        }
    });
    jpOK = PlatformUtil.createDialogButtonPanel(jbOK, false);
    getContentPane().add(jpCertificates, BorderLayout.CENTER);
    getContentPane().add(jpOK, BorderLayout.SOUTH);
    jtrHierarchy.setSelectionRow(0);
    setResizable(false);
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent evt) {
            closeDialog();
        }
    });
    getRootPane().setDefaultButton(jbOK);
    pack();
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            jbOK.requestFocus();
        }
    });
}
Also used : JPanel(javax.swing.JPanel) ImageIcon(javax.swing.ImageIcon) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) WindowAdapter(java.awt.event.WindowAdapter) TreeSelectionListener(javax.swing.event.TreeSelectionListener) JTextField(javax.swing.JTextField) JDistinguishedName(org.kse.gui.crypto.JDistinguishedName) BorderLayout(java.awt.BorderLayout) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode) CompoundBorder(javax.swing.border.CompoundBorder) EmptyBorder(javax.swing.border.EmptyBorder) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) JTree(javax.swing.JTree) EtchedBorder(javax.swing.border.EtchedBorder) TreePath(javax.swing.tree.TreePath) ActionListener(java.awt.event.ActionListener) WindowEvent(java.awt.event.WindowEvent) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) JCertificateFingerprint(org.kse.gui.crypto.JCertificateFingerprint)

Example 75 with TreeSelectionListener

use of javax.swing.event.TreeSelectionListener in project airavata by apache.

the class ComponentSelector method initGUI.

private void initGUI() {
    this.treeModel = new ComponentTreeModel(new ComponentTreeNode("Components"));
    this.tree = new JTree(this.treeModel);
    // Add a tool tip.
    ToolTipManager.sharedInstance().registerComponent(this.tree);
    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer() {

        @Override
        public java.awt.Component getTreeCellRendererComponent(JTree t, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean focus) {
            super.getTreeCellRendererComponent(t, value, sel, expanded, leaf, row, focus);
            ComponentTreeNode node = (ComponentTreeNode) value;
            if (node.getComponentReference() == null) {
                setToolTipText(null);
            } else {
                setToolTipText("Drag a component to the composer to add");
            }
            return this;
        }
    };
    // Change icons
    try {
        renderer.setOpenIcon(SwingUtil.createImageIcon("opened.gif"));
        renderer.setClosedIcon(SwingUtil.createImageIcon("closed.gif"));
        renderer.setLeafIcon(SwingUtil.createImageIcon("leaf.gif"));
    } catch (RuntimeException e) {
        logger.warn("Failed to load image icons.  " + "It will use the default icons instead.", e);
    }
    this.tree.setCellRenderer(renderer);
    this.tree.setShowsRootHandles(true);
    this.tree.setEditable(false);
    this.tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    this.tree.addTreeSelectionListener(new TreeSelectionListener() {

        public void valueChanged(TreeSelectionEvent event) {
            // update.
            if (event.isAddedPath()) {
                TreePath path = event.getPath();
                select(path);
            }
        }
    });
    // Drag and dtop
    DragGestureListener dragGestureListener = new DragGestureListener() {

        public void dragGestureRecognized(DragGestureEvent event) {
            ComponentSelector.this.dragGestureRecognized(event);
        }
    };
    DragSource dragSource = DragSource.getDefaultDragSource();
    dragSource.createDefaultDragGestureRecognizer(this.tree, DnDConstants.ACTION_COPY_OR_MOVE, dragGestureListener);
    this.dragSourceListener = new DragSourceAdapter() {
    };
    // Popup
    this.tree.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent event) {
            if (event.isPopupTrigger()) {
                showPopupIfNecessary(event);
            }
        }
    });
    createNodePopupMenu();
}
Also used : DragSourceAdapter(java.awt.dnd.DragSourceAdapter) MouseEvent(java.awt.event.MouseEvent) DragGestureEvent(java.awt.dnd.DragGestureEvent) DragGestureListener(java.awt.dnd.DragGestureListener) MouseAdapter(java.awt.event.MouseAdapter) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DragSource(java.awt.dnd.DragSource) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) JTree(javax.swing.JTree) WorkflowRuntimeException(org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException) TreePath(javax.swing.tree.TreePath) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Aggregations

TreeSelectionListener (javax.swing.event.TreeSelectionListener)87 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)82 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)36 TreePath (javax.swing.tree.TreePath)33 JTree (javax.swing.JTree)27 JScrollPane (javax.swing.JScrollPane)25 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 BorderLayout (java.awt.BorderLayout)14 Dimension (java.awt.Dimension)14 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)10 KeyAdapter (java.awt.event.KeyAdapter)9 KeyEvent (java.awt.event.KeyEvent)9