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