use of jadx.gui.treemodel.JPackage in project jadx by skylot.
the class JPackagePopupMenu method makeRenameMenuItem.
@Nullable
private JMenuItem makeRenameMenuItem(JPackage pkg) {
List<String> aliasShortParts = splitPackage(pkg.getName());
int count = aliasShortParts.size();
if (count == 0) {
return null;
}
String rawPackage = getRawPackage(pkg);
if (rawPackage == null) {
return null;
}
List<String> aliasParts = splitPackage(pkg.getFullName());
// can be longer then alias parts
List<String> rawParts = splitPackage(rawPackage);
int start = aliasParts.size() - count;
if (count == 1) {
// single case => no submenu
JPackage renamePkg = new JPackage(concat(rawParts, start), aliasParts.get(start));
JMenuItem pkgItem = new JMenuItem(NLS.str("popup.rename"));
pkgItem.addActionListener(e -> rename(renamePkg));
return pkgItem;
}
JMenuItem renameSubMenu = new JMenu(NLS.str("popup.rename"));
for (int i = start; i < aliasParts.size(); i++) {
String aliasShortPkg = aliasParts.get(i);
JPackage pkgPart = new JPackage(concat(rawParts, i), aliasShortPkg);
JMenuItem pkgPartItem = new JMenuItem(aliasShortPkg);
pkgPartItem.addActionListener(e -> rename(pkgPart));
renameSubMenu.add(pkgPartItem);
}
return renameSubMenu;
}
use of jadx.gui.treemodel.JPackage in project jadx by skylot.
the class RenameDialog method refreshState.
private void refreshState() {
RootNode rootNode = mainWindow.getWrapper().getDecompiler().getRoot();
new RenameVisitor().init(rootNode);
JNodeCache nodeCache = cache.getNodeCache();
JavaNode javaNode = node.getJavaNode();
List<JavaNode> toUpdate = new ArrayList<>();
if (source != null && source != node) {
toUpdate.add(source.getJavaNode());
}
if (javaNode != null) {
toUpdate.add(javaNode);
toUpdate.addAll(javaNode.getUseIn());
if (node instanceof JMethod) {
toUpdate.addAll(((JMethod) node).getJavaMethod().getOverrideRelatedMethods());
}
} else if (node instanceof JPackage) {
processPackage(toUpdate);
} else {
throw new JadxRuntimeException("Unexpected node type: " + node);
}
Set<JClass> updatedTopClasses = toUpdate.stream().map(JavaNode::getTopParentClass).map(nodeCache::makeFrom).filter(Objects::nonNull).collect(Collectors.toSet());
LOG.debug("Classes to update: {}", updatedTopClasses);
refreshTabs(mainWindow.getTabbedPane(), updatedTopClasses);
if (!updatedTopClasses.isEmpty()) {
mainWindow.getBackgroundExecutor().execute("Refreshing", () -> refreshClasses(updatedTopClasses), (status) -> {
if (status == TaskStatus.CANCEL_BY_MEMORY) {
mainWindow.showHeapUsageBar();
UiUtils.errorMessage(this, NLS.str("message.memoryLow"));
}
if (node instanceof JPackage) {
mainWindow.getTreeRoot().update();
}
mainWindow.reloadTree();
});
}
}
use of jadx.gui.treemodel.JPackage in project jadx by skylot.
the class RenameDialog method buildRename.
@NotNull
private JadxCodeRename buildRename(JNode node, String newName, Set<ICodeRename> renames) {
if (node instanceof JMethod) {
JavaMethod javaMethod = ((JMethod) node).getJavaMethod();
List<JavaMethod> relatedMethods = javaMethod.getOverrideRelatedMethods();
if (!relatedMethods.isEmpty()) {
for (JavaMethod relatedMethod : relatedMethods) {
renames.remove(new JadxCodeRename(JadxNodeRef.forMth(relatedMethod), ""));
}
}
return new JadxCodeRename(JadxNodeRef.forMth(javaMethod), newName);
}
if (node instanceof JField) {
return new JadxCodeRename(JadxNodeRef.forFld(((JField) node).getJavaField()), newName);
}
if (node instanceof JClass) {
return new JadxCodeRename(JadxNodeRef.forCls(((JClass) node).getCls()), newName);
}
if (node instanceof JPackage) {
return new JadxCodeRename(JadxNodeRef.forPkg(((JPackage) node).getFullName()), newName);
}
if (node instanceof JVariable) {
JavaVariable javaVar = ((JVariable) node).getJavaVarNode();
return new JadxCodeRename(JadxNodeRef.forMth(javaVar.getMth()), JadxCodeRef.forVar(javaVar), newName);
}
throw new JadxRuntimeException("Failed to build rename node for: " + node);
}
use of jadx.gui.treemodel.JPackage in project jadx by skylot.
the class MainWindow method initUI.
private void initUI() {
setMinimumSize(new Dimension(200, 150));
mainPanel = new JPanel(new BorderLayout());
splitPane = new JSplitPane();
splitPane.setResizeWeight(SPLIT_PANE_RESIZE_WEIGHT);
mainPanel.add(splitPane);
DefaultMutableTreeNode treeRootNode = new DefaultMutableTreeNode(NLS.str("msg.open_file"));
treeModel = new DefaultTreeModel(treeRootNode);
tree = new JTree(treeModel);
ToolTipManager.sharedInstance().registerComponent(tree);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.setFocusable(false);
tree.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
tree.setFocusable(false);
}
});
tree.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if (SwingUtilities.isLeftMouseButton(e)) {
if (!nodeClickAction(getJNodeUnderMouse(e))) {
// click ignored -> switch to focusable mode
tree.setFocusable(true);
tree.requestFocus();
}
} else if (SwingUtilities.isRightMouseButton(e)) {
treeRightClickAction(e);
}
}
});
tree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
nodeClickAction(tree.getLastSelectedPathComponent());
}
}
});
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) {
JNode jNode = (JNode) value;
setText(jNode.makeStringHtml());
setIcon(jNode.getIcon());
setToolTipText(jNode.getTooltip());
} else {
setToolTipText(null);
}
if (value instanceof JPackage) {
setEnabled(((JPackage) value).isEnabled());
}
return c;
}
});
tree.addTreeWillExpandListener(new TreeWillExpandListener() {
@Override
public void treeWillExpand(TreeExpansionEvent event) {
TreePath path = event.getPath();
Object node = path.getLastPathComponent();
if (node instanceof JLoadableNode) {
((JLoadableNode) node).loadNode();
}
if (!treeReloading) {
project.addTreeExpansion(getPathExpansion(event.getPath()));
update();
}
}
@Override
public void treeWillCollapse(TreeExpansionEvent event) {
if (!treeReloading) {
project.removeTreeExpansion(getPathExpansion(event.getPath()));
update();
}
}
});
progressPane = new ProgressPanel(this, true);
IssuesPanel issuesPanel = new IssuesPanel(this);
JPanel leftPane = new JPanel(new BorderLayout());
JScrollPane treeScrollPane = new JScrollPane(tree);
treeScrollPane.setMinimumSize(new Dimension(100, 150));
JPanel bottomPane = new JPanel(new BorderLayout());
bottomPane.add(issuesPanel, BorderLayout.PAGE_START);
bottomPane.add(progressPane, BorderLayout.PAGE_END);
leftPane.add(treeScrollPane, BorderLayout.CENTER);
leftPane.add(bottomPane, BorderLayout.PAGE_END);
splitPane.setLeftComponent(leftPane);
tabbedPane = new TabbedPane(this);
tabbedPane.setMinimumSize(new Dimension(150, 150));
splitPane.setRightComponent(tabbedPane);
new DropTarget(this, DnDConstants.ACTION_COPY, new MainDropTarget(this));
heapUsageBar = new HeapUsageBar();
mainPanel.add(heapUsageBar, BorderLayout.SOUTH);
verticalSplitter = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
verticalSplitter.setTopComponent(splitPane);
verticalSplitter.setResizeWeight(SPLIT_PANE_RESIZE_WEIGHT);
mainPanel.add(verticalSplitter, BorderLayout.CENTER);
setContentPane(mainPanel);
setTitle(DEFAULT_TITLE);
}
use of jadx.gui.treemodel.JPackage in project jadx by skylot.
the class MainWindow method treeRightClickAction.
private void treeRightClickAction(MouseEvent e) {
JNode obj = getJNodeUnderMouse(e);
if (obj instanceof JPackage) {
JPackagePopupMenu menu = new JPackagePopupMenu(this, (JPackage) obj);
menu.show(e.getComponent(), e.getX(), e.getY());
} else if (obj instanceof JClass || obj instanceof JField || obj instanceof JMethod) {
JMenuItem jmi = new JMenuItem(NLS.str("popup.rename"));
jmi.addActionListener(action -> RenameDialog.rename(this, obj));
JPopupMenu menu = new JPopupMenu();
menu.add(jmi);
menu.show(e.getComponent(), e.getX(), e.getY());
}
}
Aggregations