Search in sources :

Example 1 with JClass

use of jadx.gui.treemodel.JClass in project jadx by skylot.

the class MainWindow method initUI.

private void initUI() {
    mainPanel = new JPanel(new BorderLayout());
    JSplitPane splitPane = new JSplitPane();
    splitPane.setResizeWeight(SPLIT_PANE_RESIZE_WEIGHT);
    mainPanel.add(splitPane);
    DefaultMutableTreeNode treeRoot = new DefaultMutableTreeNode(NLS.str("msg.open_file"));
    treeModel = new DefaultTreeModel(treeRoot);
    tree = new JTree(treeModel);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            treeClickAction();
        }
    });
    tree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                treeClickAction();
            }
        }
    });
    tree.setCellRenderer(new DefaultTreeCellRenderer() {

        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean isLeaf, int row, boolean focused) {
            Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, isLeaf, row, focused);
            if (value instanceof JNode) {
                setIcon(((JNode) value).getIcon());
            }
            return c;
        }
    });
    tree.addTreeWillExpandListener(new TreeWillExpandListener() {

        @Override
        public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
            TreePath path = event.getPath();
            Object node = path.getLastPathComponent();
            if (node instanceof JClass) {
                JClass cls = (JClass) node;
                cls.getRootClass().load();
            }
        }

        @Override
        public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
        }
    });
    progressPane = new ProgressPanel(this, true);
    JPanel leftPane = new JPanel(new BorderLayout());
    leftPane.add(new JScrollPane(tree), BorderLayout.CENTER);
    leftPane.add(progressPane, BorderLayout.PAGE_END);
    splitPane.setLeftComponent(leftPane);
    tabbedPane = new TabbedPane(this);
    splitPane.setRightComponent(tabbedPane);
    dropTarget = new DropTarget(this, DnDConstants.ACTION_COPY, new MainDropTarget(this));
    setContentPane(mainPanel);
    setTitle(DEFAULT_TITLE);
}
Also used : JPanel(javax.swing.JPanel) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) KeyAdapter(java.awt.event.KeyAdapter) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) ExpandVetoException(javax.swing.tree.ExpandVetoException) KeyEvent(java.awt.event.KeyEvent) BorderLayout(java.awt.BorderLayout) JNode(jadx.gui.treemodel.JNode) Component(java.awt.Component) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent) TreeWillExpandListener(javax.swing.event.TreeWillExpandListener) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) JClass(jadx.gui.treemodel.JClass) MouseAdapter(java.awt.event.MouseAdapter) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) CacheObject(jadx.gui.utils.CacheObject) DropTarget(java.awt.dnd.DropTarget) JSplitPane(javax.swing.JSplitPane)

Example 2 with JClass

use of jadx.gui.treemodel.JClass in project jadx by skylot.

the class MainWindow method treeClickAction.

private void treeClickAction() {
    try {
        Object obj = tree.getLastSelectedPathComponent();
        if (obj instanceof JResource) {
            JResource res = (JResource) obj;
            ResourceFile resFile = res.getResFile();
            if (resFile != null && JResource.isSupportedForView(resFile.getType())) {
                tabbedPane.showResource(res);
            }
        } else if (obj instanceof JNode) {
            JNode node = (JNode) obj;
            JClass cls = node.getRootClass();
            if (cls != null) {
                tabbedPane.codeJump(new Position(cls, node.getLine()));
            }
        }
    } catch (Exception e) {
        LOG.error("Content loading error", e);
    }
}
Also used : ResourceFile(jadx.api.ResourceFile) Position(jadx.gui.utils.Position) JResource(jadx.gui.treemodel.JResource) JClass(jadx.gui.treemodel.JClass) CacheObject(jadx.gui.utils.CacheObject) JNode(jadx.gui.treemodel.JNode) ExpandVetoException(javax.swing.tree.ExpandVetoException)

Aggregations

JClass (jadx.gui.treemodel.JClass)2 JNode (jadx.gui.treemodel.JNode)2 CacheObject (jadx.gui.utils.CacheObject)2 ExpandVetoException (javax.swing.tree.ExpandVetoException)2 ResourceFile (jadx.api.ResourceFile)1 JResource (jadx.gui.treemodel.JResource)1 Position (jadx.gui.utils.Position)1 BorderLayout (java.awt.BorderLayout)1 Component (java.awt.Component)1 DropTarget (java.awt.dnd.DropTarget)1 KeyAdapter (java.awt.event.KeyAdapter)1 KeyEvent (java.awt.event.KeyEvent)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 JSplitPane (javax.swing.JSplitPane)1 JTree (javax.swing.JTree)1 TreeExpansionEvent (javax.swing.event.TreeExpansionEvent)1 TreeWillExpandListener (javax.swing.event.TreeWillExpandListener)1