Search in sources :

Example 81 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent in project android-classyshark by google.

the class FilesTree method configureJTree.

private void configureJTree(final JTree jTree) {
    jTree.setRootVisible(false);
    DefaultTreeCellRenderer cellRenderer = (DefaultTreeCellRenderer) jTree.getCellRenderer();
    cellRenderer.setFont(new Font("Monospaced", Font.PLAIN, 20));
    jTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    jTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            Object selection = jTree.getLastSelectedPathComponent();
            if (selection == null)
                return;
            DefaultMutableTreeNode defaultMutableTreeNode = (DefaultMutableTreeNode) selection;
            if (selection.toString().endsWith(".dex")) {
                FilesTree.this.viewerController.onSelectedClassName((String) defaultMutableTreeNode.getUserObject());
                return;
            }
            if (selection.toString().endsWith(".jar")) {
                FilesTree.this.viewerController.onSelectedClassName((String) defaultMutableTreeNode.getUserObject());
                return;
            }
            if (selection.toString().endsWith(".apk")) {
                FilesTree.this.viewerController.onSelectedClassName((String) defaultMutableTreeNode.getUserObject());
                return;
            }
            if (selection.toString().endsWith(".so")) {
                FilesTree.this.viewerController.onSelectedClassName((String) defaultMutableTreeNode.getUserObject());
                return;
            }
            if (!defaultMutableTreeNode.isLeaf())
                return;
            if (FilesTree.this.viewerController != null) {
                if (defaultMutableTreeNode.getUserObject() instanceof String) {
                    FilesTree.this.viewerController.onSelectedClassName((String) defaultMutableTreeNode.getUserObject());
                } else {
                    FilesTree.this.viewerController.onSelectedClassName(((NodeInfo) defaultMutableTreeNode.getUserObject()).fullname);
                }
            }
        }
    });
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) Font(java.awt.Font)

Example 82 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent in project android-classyshark by google.

the class MethodsCountPanel method setup.

private void setup() {
    this.setLayout(new BorderLayout());
    treeModel = new DefaultTreeModel(new DefaultMutableTreeNode(null));
    jTree = new JTree(treeModel);
    jTree.setRootVisible(false);
    jTree.setCellRenderer(new CellRenderer());
    theme.applyTo(jTree);
    DefaultTreeCellRenderer cellRenderer = (DefaultTreeCellRenderer) jTree.getCellRenderer();
    cellRenderer.setFont(new Font("Monospaced", Font.PLAIN, 20));
    jTree.setCellRenderer(cellRenderer);
    jTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            Object selection = jTree.getLastSelectedPathComponent();
            DefaultMutableTreeNode defaultMutableTreeNode = (DefaultMutableTreeNode) selection;
            ClassNode node = (ClassNode) defaultMutableTreeNode.getUserObject();
            viewerController.onSelectedMethodCount(node);
        }
    });
    JScrollPane jScrollPane = new JScrollPane(jTree);
    this.setBorder(new EmptyBorder(0, 0, 0, 0));
    this.add(jScrollPane, BorderLayout.CENTER);
    theme.applyTo(jScrollPane);
    jTree.setDragEnabled(true);
    jTree.setTransferHandler(new FileTransferHandler(viewerController));
}
Also used : JScrollPane(javax.swing.JScrollPane) ClassNode(com.google.classyshark.silverghost.methodscounter.ClassNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) CellRenderer(com.google.classyshark.gui.panel.tree.CellRenderer) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) FileTransferHandler(com.google.classyshark.gui.panel.FileTransferHandler) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) Font(java.awt.Font) JTree(javax.swing.JTree) BorderLayout(java.awt.BorderLayout) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) EmptyBorder(javax.swing.border.EmptyBorder)

Example 83 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent in project qi4j-sdk by Qi4j.

the class EntityViewer method initUI.

private void initUI() {
    propertiesPanel = new PropertiesPanel();
    propertiesPanel.initializeQi4J(qi4jspi);
    propertiesAreaPane.add(propertiesPanel, BorderLayout.CENTER);
    treePanel = new TreePanel();
    treePanel.initializeQi4J(qi4jspi, model);
    treePanel.reload();
    splitPane.setLeftComponent(treePanel);
    splitPane.setDividerLocation(200);
    DefaultComboBoxModel entityComboModel = new DefaultComboBoxModel();
    entitiesCombo.setModel(entityComboModel);
    entitiesCombo.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent evt) {
            entitiesComboItemStateChanged(evt);
        }
    });
    treePanel.getTreeComponent().addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent evt) {
            treePanelValueChanged(evt);
        }
    });
    initEntityCombo(entityComboModel);
}
Also used : ItemEvent(java.awt.event.ItemEvent) ItemListener(java.awt.event.ItemListener) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 84 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent in project qi4j-sdk by Qi4j.

the class TreeModelPane method initQi4J.

/**
 * Initialize Qi4J for this component
 *
 * @param descriptor the Application descriptor
 */
public void initQi4J(ApplicationDetailDescriptor descriptor) {
    this.descriptor = descriptor;
    // Application Application = (Application) application;
    // ApplicationDetailDescriptor descriptor = ApplicationDetailDescriptorBuilder.createApplicationDetailDescriptor( Application );
    // traverse the model and build JTree representation
    MutableTreeNode rootNode1 = StructureModelBuilder.build(descriptor);
    MutableTreeNode rootNode2 = TypeModelBuilder.build(descriptor);
    structureTree.setModel(new DefaultTreeModel(rootNode1));
    typeTree.setModel(new DefaultTreeModel(rootNode2));
    structureTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent evt) {
            structureTreeValueChanged();
        }
    });
    typeTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent evt) {
            typeTreeValueChanged();
        }
    });
}
Also used : TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 85 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent in project java-swing-tips by aterai.

the class BackgroundTask method valueChanged.

@Override
public void valueChanged(TreeSelectionEvent e) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath().getLastPathComponent();
    if (!node.isLeaf()) {
        return;
    }
    File parent = (File) node.getUserObject();
    if (!parent.isDirectory()) {
        return;
    }
    JTree tree = (JTree) e.getSource();
    DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
    new BackgroundTask(fileSystemView, parent) {

        @Override
        protected void process(List<File> chunks) {
            if (isCancelled()) {
                return;
            }
            if (!tree.isDisplayable()) {
                cancel(true);
                return;
            }
            chunks.stream().map(DefaultMutableTreeNode::new).forEach(child -> model.insertNodeInto(child, node, node.getChildCount()));
        // model.reload(node);
        }
    }.execute();
}
Also used : TreeExpansionEvent(javax.swing.event.TreeExpansionEvent) TreePath(javax.swing.tree.TreePath) ExpandVetoException(javax.swing.tree.ExpandVetoException) File(java.io.File) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) java.awt(java.awt) List(java.util.List) FileSystemView(javax.swing.filechooser.FileSystemView) Stream(java.util.stream.Stream) TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeWillExpandListener(javax.swing.event.TreeWillExpandListener) javax.swing(javax.swing) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) File(java.io.File)

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