bcv-vf/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcesearch/SearchBoxPane.java

198 lines
7.7 KiB
Java
Raw Normal View History

package the.bytecode.club.bytecodeviewer.gui.resourcesearch;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
2021-04-12 22:31:22 +00:00
import java.util.Objects;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
2021-07-09 01:58:27 +00:00
import javax.swing.tree.DefaultTreeModel;
import org.objectweb.asm.tree.ClassNode;
2021-04-12 20:19:12 +00:00
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ResourceViewer;
2021-04-12 20:19:12 +00:00
import the.bytecode.club.bytecodeviewer.searching.BackgroundSearchThread;
import the.bytecode.club.bytecodeviewer.searching.LDCSearchTreeNodeResult;
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
import the.bytecode.club.bytecodeviewer.translation.TranslatedComponents;
import the.bytecode.club.bytecodeviewer.translation.components.*;
2021-07-11 09:14:42 +00:00
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
/***************************************************************************
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
* Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
/**
* A pane dedicating to searching the loaded files.
2018-01-31 15:41:24 +00:00
*
* @author Konloch
* @author WaterWolf
2021-07-04 07:03:40 +00:00
* @since 09/29/2011
*/
2021-07-07 10:39:29 +00:00
public class SearchBoxPane extends TranslatedVisibleComponent
{
2021-04-12 22:31:22 +00:00
public static final SearchRadius[] SEARCH_RADII = SearchRadius.values();
public static final SearchType[] SEARCH_TYPES = SearchType.values();
public final JCheckBox exact = new TranslatedJCheckBox("Exact", TranslatedComponents.EXACT);
public final TranslatedDefaultMutableTreeNode treeRoot = new TranslatedDefaultMutableTreeNode("Results", TranslatedComponents.RESULTS);
2021-06-22 18:05:25 +00:00
public final JTree tree;
public final JComboBox<SearchType> typeBox;
2021-06-22 18:05:25 +00:00
public SearchType searchType = null;
public final JComboBox searchRadiusBox;
public JButton search = new TranslatedJButton("Search", TranslatedComponents.SEARCH);
2021-07-05 02:06:15 +00:00
public BackgroundSearchThread performSearchThread;
2018-01-31 15:41:24 +00:00
@SuppressWarnings("unchecked")
2021-07-05 02:06:15 +00:00
public SearchBoxPane()
{
super("Search", TranslatedComponents.SEARCH);
2018-01-31 15:41:24 +00:00
final JPanel optionPanel = new JPanel(new BorderLayout());
final JPanel searchRadiusOpt = new JPanel(new BorderLayout());
final JPanel searchOpts = new JPanel(new GridLayout(2, 1));
searchRadiusOpt.add(new TranslatedJLabel("Search from ", TranslatedComponents.SEARCH_FROM), BorderLayout.WEST);
2018-01-31 15:41:24 +00:00
DefaultComboBoxModel model = new DefaultComboBoxModel();
2021-07-05 02:06:15 +00:00
for (final SearchRadius st : SEARCH_RADII)
2018-01-31 15:41:24 +00:00
model.addElement(st);
searchRadiusBox = new JComboBox(model);
searchRadiusOpt.add(searchRadiusBox, BorderLayout.CENTER);
searchOpts.add(searchRadiusOpt);
model = new DefaultComboBoxModel();
2021-06-22 18:05:25 +00:00
for (final SearchType st : SEARCH_TYPES)
2018-01-31 15:41:24 +00:00
model.addElement(st);
typeBox = new JComboBox<SearchType>(model);
2018-01-31 15:41:24 +00:00
final JPanel searchOptPanel = new JPanel();
2021-04-12 22:31:22 +00:00
final ItemListener il = arg0 -> {
searchOptPanel.removeAll();
searchType = (SearchType) typeBox.getSelectedItem();
searchOptPanel.add(Objects.requireNonNull(searchType).panel.getPanel());
2018-01-31 15:41:24 +00:00
2021-04-12 22:31:22 +00:00
searchOptPanel.revalidate();
searchOptPanel.repaint();
2018-01-31 15:41:24 +00:00
};
typeBox.addItemListener(il);
2019-04-17 06:45:15 +00:00
typeBox.setSelectedItem(SearchType.Strings);
2018-01-31 15:41:24 +00:00
il.itemStateChanged(null);
searchOpts.add(typeBox);
optionPanel.add(searchOpts, BorderLayout.NORTH);
JPanel sharedPanel = new JPanel();
sharedPanel.setLayout(new BorderLayout());
sharedPanel.add(searchOptPanel, BorderLayout.NORTH);
sharedPanel.add(exact, BorderLayout.SOUTH);
2018-01-31 15:41:24 +00:00
optionPanel.add(sharedPanel, BorderLayout.CENTER);
2018-01-31 15:41:24 +00:00
2021-04-12 22:31:22 +00:00
search.addActionListener(arg0 -> search());
2018-01-31 15:41:24 +00:00
optionPanel.add(search, BorderLayout.SOUTH);
this.tree = new JTree(treeRoot);
2021-07-09 01:58:27 +00:00
treeRoot.setTree((DefaultTreeModel) tree.getModel());
2018-01-31 15:41:24 +00:00
getContentPane().setLayout(new BorderLayout());
getContentPane().add(optionPanel, BorderLayout.NORTH);
2018-01-31 15:41:24 +00:00
getContentPane().add(new JScrollPane(tree), BorderLayout.CENTER);
tree.addMouseListener(new MouseAdapter()
2021-07-05 02:06:15 +00:00
{
@Override
public void mouseReleased(MouseEvent e)
{
//TODO right-click context menu
if (e.isMetaDown())
{
}
else if (e.getButton() == MouseEvent.BUTTON1)
{
if(!(tree.getLastSelectedPathComponent() instanceof LDCSearchTreeNodeResult))
return;
LDCSearchTreeNodeResult result = (LDCSearchTreeNodeResult) tree.getLastSelectedPathComponent();
final String name = result.resourceWorkingName;
BytecodeViewer.viewer.workPane.addClassResource(result.container, name);
}
}
2018-01-31 15:41:24 +00:00
});
this.setVisible(true);
}
2021-07-05 02:06:15 +00:00
public void search()
{
2019-04-17 06:45:15 +00:00
treeRoot.removeAllChildren();
searchType = (SearchType) typeBox.getSelectedItem();
2021-07-05 02:06:15 +00:00
final SearchRadius radius = (SearchRadius) searchRadiusBox.getSelectedItem();
if (radius == SearchRadius.All_Classes)
{
if (performSearchThread == null || performSearchThread.finished)
{
BytecodeViewer.viewer.searchBoxPane.search.setEnabled(false);
BytecodeViewer.viewer.searchBoxPane.search.setText("Searching, please wait..");
performSearchThread = new PerformSearch(this);
2021-07-05 02:06:15 +00:00
performSearchThread.start();
}
else
{ // this should really never be called.
2021-06-21 23:37:55 +00:00
BytecodeViewer.showMessage("You currently have a search performing in the background, please wait for that to finish.");
2019-04-17 06:45:15 +00:00
}
2021-07-05 02:06:15 +00:00
}
else if (radius == SearchRadius.Current_Class)
{
2021-07-07 03:05:35 +00:00
final ResourceViewer cv = BytecodeViewer.getActiveResource();
2021-07-05 02:06:15 +00:00
if (cv != null)
searchType.panel.search(cv.resource.container, cv.resource.workingName, cv.resource.getResourceClassNode(), exact.isSelected());
2019-04-17 06:45:15 +00:00
}
}
2021-07-05 02:06:15 +00:00
public void resetWorkspace()
{
2018-01-31 15:41:24 +00:00
treeRoot.removeAllChildren();
tree.updateUI();
}
2021-07-05 02:06:15 +00:00
private static final long serialVersionUID = -1098524689236993932L;
}