Search Box Pane Cleanup

This commit is contained in:
Konloch 2021-07-04 19:06:15 -07:00
parent 72597102f4
commit 6efbc39ff6

View file

@ -55,7 +55,6 @@ import the.bytecode.club.bytecodeviewer.util.FileContainer;
@SuppressWarnings("rawtypes")
public class SearchBoxPane extends VisibleComponent
{
private static final long serialVersionUID = -1098524689236993932L;
public static final SearchRadius[] SEARCH_RADII = SearchRadius.values();
public static final SearchType[] SEARCH_TYPES = SearchType.values();
@ -68,15 +67,11 @@ public class SearchBoxPane extends VisibleComponent
public final JComboBox searchRadiusBox;
public JButton search = new JButton("Search");
BackgroundSearchThread t = new BackgroundSearchThread(true) {
@Override
public void search() {
// empty
}
};
public BackgroundSearchThread performSearchThread;
@SuppressWarnings("unchecked")
public SearchBoxPane() {
public SearchBoxPane()
{
super("Search");
final JPanel optionPanel = new JPanel(new BorderLayout());
@ -86,9 +81,9 @@ public class SearchBoxPane extends VisibleComponent
searchRadiusOpt.add(new JLabel("Search from "), BorderLayout.WEST);
DefaultComboBoxModel model = new DefaultComboBoxModel();
for (final SearchRadius st : SEARCH_RADII) {
for (final SearchRadius st : SEARCH_RADII)
model.addElement(st);
}
searchRadiusBox = new JComboBox(model);
searchRadiusOpt.add(searchRadiusBox, BorderLayout.CENTER);
@ -137,13 +132,14 @@ public class SearchBoxPane extends VisibleComponent
getContentPane().add(new JScrollPane(optionPanel), BorderLayout.NORTH);
getContentPane().add(new JScrollPane(tree), BorderLayout.CENTER);
this.tree.addTreeSelectionListener(arg0 -> {
if (arg0.getPath().getPathComponent(0).equals("Results"))
this.tree.addTreeSelectionListener(selectionEvent ->
{
if (selectionEvent.getPath().getPathComponent(0).equals("Results"))
return;
arg0.getPath().getPathComponent(1);
selectionEvent.getPath().getPathComponent(1);
String path = arg0.getPath().getPathComponent(1).toString();
String path = selectionEvent.getPath().getPathComponent(1).toString();
String containerName = path.split(">", 2)[0];
String className = path.split(">", 2)[1].split("\\.")[0];
@ -151,43 +147,51 @@ public class SearchBoxPane extends VisibleComponent
final ClassNode fN = Objects.requireNonNull(container).getClassNode(className);
if (fN != null) {
if (fN != null)
BytecodeViewer.viewer.openClassFile(container, className + ".class", fN);
}
});
this.setVisible(true);
}
public void search() {
public void search()
{
treeRoot.removeAllChildren();
searchType = (SearchType) typeBox.getSelectedItem();
final SearchRadius radius = (SearchRadius) searchRadiusBox
.getSelectedItem();
final SearchRadius radius = (SearchRadius) searchRadiusBox.getSelectedItem();
final SearchResultNotifier srn = debug -> treeRoot.add(new DefaultMutableTreeNode(debug));
if (radius == SearchRadius.All_Classes) {
if (t.finished) {
t = new PerformSearch(this, srn);
Objects.requireNonNull(MainViewerGUI.getComponent(SearchBoxPane.class))
.search.setEnabled(false);
Objects.requireNonNull(MainViewerGUI.getComponent(SearchBoxPane.class))
.search.setText("Searching, please wait..");
t.start();
} else { // this should really never be called.
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, srn);
performSearchThread.start();
}
else
{ // this should really never be called.
BytecodeViewer.showMessage("You currently have a search performing in the background, please wait for that to finish.");
}
} else if (radius == SearchRadius.Current_Class) {
}
else if (radius == SearchRadius.Current_Class)
{
final ResourceViewer cv = Objects.requireNonNull(MainViewerGUI.getComponent(WorkPaneMainComponent.class)).getCurrentViewer();
if (cv != null) {
if (cv != null)
{
searchType.details.search(cv.container, cv.cn, srn, exact.isSelected());
}
}
}
public void resetWorkspace() {
public void resetWorkspace()
{
treeRoot.removeAllChildren();
tree.updateUI();
}
}
private static final long serialVersionUID = -1098524689236993932L;
}