From cfc79686941897a9fa104f7f905ddc8bf56d0ddc Mon Sep 17 00:00:00 2001 From: angryziber Date: Mon, 24 Jul 2006 21:16:24 +0000 Subject: [PATCH] Goto functionality implemented (including searching) git-svn-id: https://ipscan.svn.sourceforge.net/svnroot/ipscan/ipscan@3 375186e5-ef17-0410-b0b6-91563547dcda --- .classpath | 2 +- resources/Labels.txt | 6 +- src/net/azib/ipscan/core/ScanningResult.java | 6 + src/net/azib/ipscan/gui/InputDialog.java | 2 +- src/net/azib/ipscan/gui/MainMenu.java | 11 +- .../azib/ipscan/gui/actions/GotoActions.java | 140 ++++++++++++++++++ 6 files changed, 159 insertions(+), 8 deletions(-) create mode 100755 src/net/azib/ipscan/gui/actions/GotoActions.java diff --git a/.classpath b/.classpath index c2030a14..3224d044 100755 --- a/.classpath +++ b/.classpath @@ -9,7 +9,7 @@ - + diff --git a/resources/Labels.txt b/resources/Labels.txt index 537da2b2..d42f2671 100755 --- a/resources/Labels.txt +++ b/resources/Labels.txt @@ -9,7 +9,6 @@ menu.goto=&Go to menu.goto.aliveHost=Next alive &host Ctrl+H menu.goto.deadHost=Next d&ead host Ctrl+E menu.goto.openPort=Next open &port Ctrl+P -menu.goto.closedPort=Next &closed port Ctrl+L menu.goto.find=Find... Ctrl+F menu.commands=&Commands menu.commands.details=&Show details Dbl-Clk @@ -44,6 +43,7 @@ state.scanning=Scanning state.waitForThreads=Wait for all threads to terminate... state.killingThreads=Killing all threads... state.saving=Exporting results... +state.searching=Searching... title.about=About title.options=Options title.options.scanning=Scanning @@ -56,10 +56,14 @@ title.saveSelection=Export Selected Results title.gettingStarted=Getting Started title.favorite.add=Add a favorite title.favorite.edit=Edit favorites +title.find=Find text.ip=IP text.threads=Threads: text.favorite.add=Enter the name of the new favorite text.favorite.edit=Below you can rearrange or delete favorites +text.find=Enter the text to search for +text.find.notFound=Nothing was found. +text.find.restart=Would you like to start from the beginning? text.about=%NAME\n\nVersion %VERSION\n%COPYLEFT\n\n%WEBSITE\n%MAILTO\n\nThis is an Open Source Software released under the GPL. text.gettingStarted1=Angry IP Scanner is an IP address scanner tool.\n\nIt is used for scanning IP addresses for finding alive hosts, gathering any kind of needed information about each host. text.gettingStarted2=Main terminology:\n\nFeeder - generator of IP addresses for scanning. Angry IP Scanner provides various kinds of feeders: IP Range, Random, and IP List File. You can select a feeder using the combo box next to the "Start" button.\n\nFetcher - gathers specific information about a host, e.g. ping time, hostname, open ports. Feeders usually represent columns in the scanning results list. diff --git a/src/net/azib/ipscan/core/ScanningResult.java b/src/net/azib/ipscan/core/ScanningResult.java index e72bcd9b..78f88671 100755 --- a/src/net/azib/ipscan/core/ScanningResult.java +++ b/src/net/azib/ipscan/core/ScanningResult.java @@ -27,10 +27,16 @@ public class ScanningResult { this.type = resultType; } + /** + * @return the scanning results as List, result of each Fetcher is an element + */ public List getValues() { return values; } + /** + * @return the scanning result type, see constants in {@link ScanningSubject} + */ public int getType() { return type; } diff --git a/src/net/azib/ipscan/gui/InputDialog.java b/src/net/azib/ipscan/gui/InputDialog.java index 8907ba22..2606af6d 100755 --- a/src/net/azib/ipscan/gui/InputDialog.java +++ b/src/net/azib/ipscan/gui/InputDialog.java @@ -43,7 +43,7 @@ public class InputDialog { Display currentDisplay = Display.getCurrent(); Shell parent = currentDisplay != null ? currentDisplay.getActiveShell() : null; - shell = new Shell(parent); + shell = new Shell(parent, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM); shell.setSize(new Point(300, 112)); shell.setLayout(null); messageLabel = new Label(shell, SWT.NONE); diff --git a/src/net/azib/ipscan/gui/MainMenu.java b/src/net/azib/ipscan/gui/MainMenu.java index 1da1f5a8..558726d0 100755 --- a/src/net/azib/ipscan/gui/MainMenu.java +++ b/src/net/azib/ipscan/gui/MainMenu.java @@ -4,10 +4,12 @@ package net.azib.ipscan.gui; import net.azib.ipscan.config.Labels; +import net.azib.ipscan.core.ScanningSubject; import net.azib.ipscan.gui.actions.ColumnsActions; import net.azib.ipscan.gui.actions.CommandsActions; import net.azib.ipscan.gui.actions.FavoritesActions; import net.azib.ipscan.gui.actions.FileActions; +import net.azib.ipscan.gui.actions.GotoActions; import net.azib.ipscan.gui.actions.HelpActions; import net.azib.ipscan.gui.actions.ToolsActions; @@ -74,12 +76,11 @@ public class MainMenu { }, new Object[] {"menu.goto", new Object[] { - new Object[] {"menu.goto.aliveHost", new Integer(SWT.CONTROL | 'H'), null}, - new Object[] {"menu.goto.deadHost", new Integer(SWT.CONTROL | 'E'), null}, - new Object[] {"menu.goto.openPort", new Integer(SWT.CONTROL | 'P'), null}, - new Object[] {"menu.goto.closedPort", new Integer(SWT.CONTROL | 'L'), null}, + new Object[] {"menu.goto.aliveHost", new Integer(SWT.CONTROL | 'H'), new GotoActions.NextHost(mainWindow, ScanningSubject.RESULT_TYPE_ALIVE)}, + new Object[] {"menu.goto.deadHost", new Integer(SWT.CONTROL | 'E'), new GotoActions.NextHost(mainWindow, ScanningSubject.RESULT_TYPE_DEAD)}, + new Object[] {"menu.goto.openPort", new Integer(SWT.CONTROL | 'P'), new GotoActions.NextHost(mainWindow, ScanningSubject.RESULT_TYPE_ADDITIONAL_INFO)}, null, - new Object[] {"menu.goto.find", new Integer(SWT.CONTROL | 'F'), null}, + new Object[] {"menu.goto.find", new Integer(SWT.CONTROL | 'F'), new GotoActions.Find(mainWindow)}, } }, new Object[] {"menu.commands", diff --git a/src/net/azib/ipscan/gui/actions/GotoActions.java b/src/net/azib/ipscan/gui/actions/GotoActions.java new file mode 100755 index 00000000..63fa1a8f --- /dev/null +++ b/src/net/azib/ipscan/gui/actions/GotoActions.java @@ -0,0 +1,140 @@ +/** + * + */ +package net.azib.ipscan.gui.actions; + +import java.util.Iterator; +import java.util.List; + +import net.azib.ipscan.config.Labels; +import net.azib.ipscan.core.ScanningResult; +import net.azib.ipscan.core.ScanningResultList; +import net.azib.ipscan.gui.InputDialog; +import net.azib.ipscan.gui.MainWindow; +import net.azib.ipscan.gui.ResultTable; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.MessageBox; + +/** + * GotoActions + * + * @author anton + */ +public class GotoActions { + + public static class NextHost implements Listener { + + private MainWindow mainWindow; + private int whatToSearchFor; + + public NextHost(MainWindow mainWindow, int whatToSearchFor) { + this.mainWindow = mainWindow; + this.whatToSearchFor = whatToSearchFor; + } + + public void handleEvent(Event event) { + ResultTable resultTable = mainWindow.getResultTable(); + ScanningResultList results = resultTable.getScanningResults(); + + int numElements = resultTable.getItemCount(); + int startElement = resultTable.getSelectionIndex() + 1; + + for (int i = startElement; i < numElements; i++) { + ScanningResult scanningResult = results.getResult(i); + + if (scanningResult.getType() == whatToSearchFor) { + resultTable.setSelection(i); + resultTable.setFocus(); + return; + } + + } + + if (startElement > 0) { + resultTable.deselectAll(); + handleEvent(event); + } + } + + } + + public static class Find implements Listener { + + private MainWindow mainWindow; + private String lastText = ""; + + public Find(MainWindow mainWindow) { + this.mainWindow = mainWindow; + } + + public void handleEvent(Event event) { + + InputDialog dialog = new InputDialog(Labels.getInstance().getString("title.find"), Labels.getInstance().getString("text.find")); + dialog.setText(lastText); + String text = dialog.open(); + if (text == null) { + return; + } + lastText = text; + + try { + mainWindow.setStatusText(Labels.getInstance().getString("state.searching")); + + findText(text); + } + finally { + mainWindow.setStatusText(null); + } + } + + private void findText(String text) { + + ResultTable resultTable = mainWindow.getResultTable(); + ScanningResultList results = resultTable.getScanningResults(); + + int numElements = resultTable.getItemCount(); + int startElement = resultTable.getSelectionIndex() + 1; + + for (int i = startElement; i < numElements; i++) { + ScanningResult scanningResult = results.getResult(i); + + List values = scanningResult.getValues(); + + for (Iterator j = values.iterator(); j.hasNext();) { + String value = (String) j.next(); + + // TODO: case-insensitive search + if (value != null && value.indexOf(text) >= 0) { + resultTable.setSelection(i); + resultTable.setFocus(); + return; + } + } + + } + + if (startElement > 0) { + MessageBox messageBox = new MessageBox(mainWindow.getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION); + messageBox.setText(Labels.getInstance().getString("title.find")); + messageBox.setMessage(Labels.getInstance().getString("text.find.notFound") + " " + Labels.getInstance().getString("text.find.restart")); + if (messageBox.open() == SWT.YES) { + resultTable.deselectAll(); + findText(text); + } + } + else { + MessageBox messageBox = new MessageBox(mainWindow.getShell(), SWT.OK | SWT.ICON_INFORMATION); + messageBox.setText(Labels.getInstance().getString("title.find")); + messageBox.setMessage(Labels.getInstance().getString("text.find.notFound")); + messageBox.open(); + } + + } + + } + + +}