big refactoring to start using dependency injection (using the PicoContainer)

git-svn-id: https://ipscan.svn.sourceforge.net/svnroot/ipscan/ipscan@36 375186e5-ef17-0410-b0b6-91563547dcda
This commit is contained in:
angryziber 2006-10-26 20:34:10 +00:00
parent 6c82a149fe
commit 5e2cd54c5d
16 changed files with 549 additions and 256 deletions

View File

@ -14,6 +14,7 @@ import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import net.azib.ipscan.config.Config;
import net.azib.ipscan.config.GUIComponentContainer;
import net.azib.ipscan.config.Labels;
import net.azib.ipscan.gui.MainWindow;
import net.azib.ipscan.gui.UserErrorException;
@ -41,7 +42,9 @@ public class Main {
// initialize Config instance
Config.initialize();
MainWindow mainWindow = new MainWindow();
// create the main window using dependency injection
MainWindow mainWindow = new GUIComponentContainer().createMainWindow();
while (!mainWindow.isDisposed()) {
try {
if (!display.readAndDispatch())

View File

@ -0,0 +1,92 @@
/**
*
*/
package net.azib.ipscan.config;
import net.azib.ipscan.core.ScanningResultList;
import net.azib.ipscan.gui.MainMenu;
import net.azib.ipscan.gui.MainWindow;
import net.azib.ipscan.gui.ResultTable;
import net.azib.ipscan.gui.StatusBar;
import net.azib.ipscan.gui.actions.OpenerLauncher;
import net.azib.ipscan.gui.feeders.FeederGUIRegistry;
import net.azib.ipscan.gui.feeders.FileFeederGUI;
import net.azib.ipscan.gui.feeders.RandomFeederGUI;
import net.azib.ipscan.gui.feeders.RangeFeederGUI;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.picocontainer.MutablePicoContainer;
import org.picocontainer.Parameter;
import org.picocontainer.PicoContainer;
import org.picocontainer.defaults.BasicComponentParameter;
import org.picocontainer.defaults.ConstantParameter;
import org.picocontainer.defaults.DefaultPicoContainer;
/**
* This class is a dependency injection configuration
* using the Pico Container.
*
* @author anton
*/
public class GUIComponentContainer {
private PicoContainer container;
public GUIComponentContainer() {
MutablePicoContainer container = new DefaultPicoContainer();
this.container = container;
container.registerComponentInstance(container);
// non-GUI
container.registerComponentImplementation(ScanningResultList.class);
// GUI follows
// Some "shared" GUI components
container.registerComponentImplementation("mainShell", Shell.class);
container.registerComponentImplementation("feederArea", Composite.class, new Parameter[] {
new BasicComponentParameter("mainShell"),
new ConstantParameter(new Integer(SWT.NONE))});
container.registerComponentImplementation("controlsArea", Composite.class, new Parameter[] {
new BasicComponentParameter("mainShell"),
new ConstantParameter(new Integer(SWT.NONE))});
container.registerComponentImplementation("feederSelectionCombo", Combo.class, new Parameter[] {
new BasicComponentParameter("controlsArea"),
new ConstantParameter(new Integer(SWT.READ_ONLY))});
// GUI Feeders
container.registerComponentImplementation(FeederGUIRegistry.class);
Parameter[] feederGUIParameters = new Parameter[] {new BasicComponentParameter("feederArea")};
container.registerComponentImplementation(RangeFeederGUI.class, RangeFeederGUI.class, feederGUIParameters);
container.registerComponentImplementation(RandomFeederGUI.class, RandomFeederGUI.class, feederGUIParameters);
container.registerComponentImplementation(FileFeederGUI.class, FileFeederGUI.class, feederGUIParameters);
container.registerComponentImplementation(OpenerLauncher.class);
container.registerComponentImplementation(MainWindow.class, MainWindow.class, new Parameter[] {
new BasicComponentParameter("mainShell"),
new BasicComponentParameter("feederArea"),
new BasicComponentParameter("controlsArea"),
new BasicComponentParameter("feederSelectionCombo"),
BasicComponentParameter.BASIC_DEFAULT,
BasicComponentParameter.BASIC_DEFAULT,
BasicComponentParameter.BASIC_DEFAULT,
BasicComponentParameter.BASIC_DEFAULT});
container.registerComponentImplementation(ResultTable.class, ResultTable.class, new Parameter[] {
new BasicComponentParameter("mainShell"),
BasicComponentParameter.BASIC_DEFAULT});
container.registerComponentImplementation(StatusBar.class, StatusBar.class, new Parameter[] {
new BasicComponentParameter("mainShell")});
container.registerComponentImplementation(MainMenu.class, MainMenu.class, new Parameter[] {
new BasicComponentParameter("mainShell"),
BasicComponentParameter.BASIC_DEFAULT});
}
public MainWindow createMainWindow() {
return (MainWindow) container.getComponentInstance(MainWindow.class);
}
}

View File

@ -4,6 +4,8 @@
package net.azib.ipscan.core;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
@ -22,6 +24,7 @@ public class ScanningResultList {
private List fetchers;
private List scanningResults = new ArrayList(1024);
private ResultsComparator resultsComparator = new ResultsComparator();
public synchronized int add(String name) {
int index = scanningResults.size();
@ -101,5 +104,31 @@ public class ScanningResultList {
scanningResults.remove(i);
}
}
/**
* Sorts by the specified column index.
* @param columnIndex
*/
public void sort(int columnIndex) {
resultsComparator.index = columnIndex;
Collections.sort(scanningResults, resultsComparator);
}
private static class ResultsComparator implements Comparator {
private int index;
public int compare(Object o1, Object o2) {
if (!(o1 instanceof ScanningResult))
return -1;
if (!(o2 instanceof ScanningResult))
return 1;
Object val1 = ((ScanningResult)o1).getValues().get(index);
Object val2 = ((ScanningResult)o2).getValues().get(index);
return val1.toString().compareTo(val2.toString());
}
}
}

View File

@ -4,7 +4,6 @@
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;
@ -14,10 +13,14 @@ import net.azib.ipscan.gui.actions.HelpActions;
import net.azib.ipscan.gui.actions.ToolsActions;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Decorations;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.picocontainer.MutablePicoContainer;
import org.picocontainer.PicoContainer;
import org.picocontainer.defaults.DefaultPicoContainer;
/**
* MainMenu
@ -26,18 +29,25 @@ import org.eclipse.swt.widgets.Shell;
*/
public class MainMenu {
private MainWindow mainWindow;
private MutablePicoContainer container;
private Menu mainMenu;
private Menu resultsContextMenu;
private Menu favoritesMenu;
private Menu columnsMenu;
private Menu openersMenu;
private ResultsContextMenu resultsContextMenu;
private FavoritesMenu favoritesMenu;
private ColumnsMenu columnsMenu;
private OpenersMenu openersMenu;
public MainMenu(MainWindow mainWindow) {
public MainMenu(Shell shell, PicoContainer parentContainer) {
this.mainWindow = mainWindow;
Shell shell = mainWindow.getShell();
// create the menu-specific child container
this.container = new DefaultPicoContainer(parentContainer);
// register some components not registered in the main menu
container.registerComponentImplementation(CommandsActions.SelectOpener.class);
container.registerComponentImplementation(CommandsActions.ShowOpenersMenu.class);
container.registerComponentImplementation(FavoritesActions.ShowMenu.class);
container.registerComponentImplementation(FavoritesActions.Select.class);
mainMenu = new Menu(shell, SWT.BAR);
shell.setMenuBar(mainMenu);
@ -46,11 +56,13 @@ public class MainMenu {
// generate the menu from the definition
generateMenu(shell, menuDefinition, mainMenu);
openersMenu = new Menu(shell, SWT.DROP_DOWN);
openersMenu = new OpenersMenu(shell);
container.registerComponentInstance(OpenersMenu.class, openersMenu);
MenuItem openersMenuItem = new MenuItem(mainMenu.getItem(2).getMenu(), SWT.CASCADE);
openersMenuItem.setText(Labels.getInstance().getString("menu.commands.open"));
openersMenuItem.setMenu(openersMenu);
CommandsActions.ShowOpenersMenu showOpenersMenuListener = new CommandsActions.ShowOpenersMenu(mainWindow, openersMenu);
Listener showOpenersMenuListener = (Listener) container.getComponentInstance(CommandsActions.ShowOpenersMenu.class);
openersMenu.addListener(SWT.Show, showOpenersMenuListener);
MenuItem menuItem = new MenuItem(openersMenu, SWT.PUSH);
menuItem.setText(Labels.getInstance().getString("menu.commands.open.edit"));
@ -62,15 +74,16 @@ public class MainMenu {
// retrieve results context menu, that is the same as "commands" menu
// note: the index of 2 is hardcoded and may theoretically change
// TODO: probably something better should be done here
resultsContextMenu = new Menu(shell, SWT.POP_UP);
resultsContextMenu = new ResultsContextMenu(shell);
generateSubMenu((Object[]) ((Object[]) menuDefinition[2])[1], resultsContextMenu);
// retrieve favoritesMenu, which is 3
favoritesMenu = mainMenu.getItem(3).getMenu();
favoritesMenu.addListener(SWT.Show, new FavoritesActions.ShowMenu(mainWindow, favoritesMenu));
// retrieve favoritesMenu, which is 3 (TODO: ugly hardcode of favorites menu retrieval)
favoritesMenu = (FavoritesMenu) mainMenu.getItem(3).getMenu();
container.registerComponentInstance("favoritesMenu", favoritesMenu);
favoritesMenu.addListener(SWT.Show, (Listener) container.getComponentInstance(FavoritesActions.ShowMenu.class));
// this is the menu when clicking on a column header
columnsMenu = new Menu(shell, SWT.POP_UP);
columnsMenu = new ColumnsMenu(shell);
generateSubMenu(createColumnsMenuDefinition(), columnsMenu);
}
@ -79,47 +92,47 @@ public class MainMenu {
Object[] menuDefinition = new Object[] {
new Object[] {"menu.file",
new Object[] {
new Object[] {"menu.file.saveAll", new Integer(SWT.CONTROL | 'S'), new FileActions.SaveResults(mainWindow, false)},
new Object[] {"menu.file.saveSelection", null, new FileActions.SaveResults(mainWindow, true)},
new Object[] {"menu.file.saveAll", new Integer(SWT.CONTROL | 'S'), FileActions.SaveAll.class},
new Object[] {"menu.file.saveSelection", null, FileActions.SaveSelection.class},
null,
new Object[] {"menu.file.exportOptions", null, null},
new Object[] {"menu.file.importOptions", null, null},
null,
new Object[] {"menu.file.exit", null, new FileActions.Exit()},
new Object[] {"menu.file.exit", null, FileActions.Exit.class},
}
},
new Object[] {"menu.goto",
new Object[] {
new Object[] {"menu.goto.aliveHost", new Integer(SWT.CONTROL | SWT.SHIFT | 'H'), new GotoActions.NextHost(mainWindow, ScanningSubject.RESULT_TYPE_ALIVE)},
new Object[] {"menu.goto.deadHost", new Integer(SWT.CONTROL | SWT.SHIFT | 'D'), new GotoActions.NextHost(mainWindow, ScanningSubject.RESULT_TYPE_DEAD)},
new Object[] {"menu.goto.openPort", new Integer(SWT.CONTROL | SWT.SHIFT | 'P'), new GotoActions.NextHost(mainWindow, ScanningSubject.RESULT_TYPE_ADDITIONAL_INFO)},
new Object[] {"menu.goto.aliveHost", new Integer(SWT.CONTROL | SWT.SHIFT | 'H'), GotoActions.NextAliveHost.class},
new Object[] {"menu.goto.deadHost", new Integer(SWT.CONTROL | SWT.SHIFT | 'D'), GotoActions.NextDeadHost.class},
new Object[] {"menu.goto.openPort", new Integer(SWT.CONTROL | SWT.SHIFT | 'P'), GotoActions.NextHostWithInfo.class},
null,
new Object[] {"menu.goto.find", new Integer(SWT.CONTROL | 'F'), new GotoActions.Find(mainWindow)},
new Object[] {"menu.goto.find", new Integer(SWT.CONTROL | 'F'), GotoActions.Find.class},
}
},
new Object[] {"menu.commands",
new Object[] {
new Object[] {"menu.commands.details", null, new CommandsActions.Details(mainWindow.getResultTable())},
new Object[] {"menu.commands.details", null, CommandsActions.Details.class},
null,
new Object[] {"menu.commands.rescan", new Integer(SWT.CONTROL | 'R'), null},
new Object[] {"menu.commands.delete", new Integer(SWT.DEL), new CommandsActions.Delete(mainWindow.getResultTable())},
new Object[] {"menu.commands.delete", new Integer(SWT.DEL), CommandsActions.Delete.class},
null,
new Object[] {"menu.commands.copy", new Integer(SWT.CONTROL | 'C'), new CommandsActions.CopyIP(mainWindow.getResultTable())},
new Object[] {"menu.commands.copyDetails", null, new CommandsActions.CopyIPDetails(mainWindow.getResultTable())},
new Object[] {"menu.commands.copy", new Integer(SWT.CONTROL | 'C'), CommandsActions.CopyIP.class},
new Object[] {"menu.commands.copyDetails", null, CommandsActions.CopyIPDetails.class},
null,
//new Object[] {"menu.commands.show", null, null},
}
},
new Object[] {"menu.favorites",
new Object[] {
new Object[] {"menu.favorites.add", new Integer(SWT.CONTROL | 'D'), new FavoritesActions.Add(mainWindow)},
new Object[] {"menu.favorites.edit", null, new FavoritesActions.Edit()},
new Object[] {"menu.favorites.add", new Integer(SWT.CONTROL | 'D'), FavoritesActions.Add.class},
new Object[] {"menu.favorites.edit", null, FavoritesActions.Edit.class},
null,
}
},
new Object[] {"menu.tools",
new Object[] {
new Object[] {"menu.tools.options", new Integer(SWT.CONTROL | 'O'), new ToolsActions.Options()},
new Object[] {"menu.tools.options", new Integer(SWT.CONTROL | 'O'), ToolsActions.Options.class},
new Object[] {"menu.tools.fetchers", null, null},
null,
new Object[] {"menu.tools.delete", null, null},
@ -128,17 +141,17 @@ public class MainMenu {
},
new Object[] {"menu.help",
new Object[] {
new Object[] {"menu.help.gettingStarted", new Integer(SWT.F1), new HelpActions.GettingStarted()},
new Object[] {"menu.help.gettingStarted", new Integer(SWT.F1), HelpActions.GettingStarted.class},
null,
new Object[] {"menu.help.website", null, new HelpActions.Website()},
new Object[] {"menu.help.forum", null, new HelpActions.Forum()},
new Object[] {"menu.help.plugins", null, new HelpActions.Plugins()},
new Object[] {"menu.help.website", null, HelpActions.Website.class},
new Object[] {"menu.help.forum", null, HelpActions.Forum.class},
new Object[] {"menu.help.plugins", null, HelpActions.Plugins.class},
null,
new Object[] {"menu.help.cmdLine", null, null},
null,
new Object[] {"menu.help.checkVersion", null, new HelpActions.CheckVersion(mainWindow)},
new Object[] {"menu.help.checkVersion", null, HelpActions.CheckVersion.class},
null,
new Object[] {"menu.help.about", new Integer(SWT.F12), new HelpActions.About()},
new Object[] {"menu.help.about", new Integer(SWT.F12), HelpActions.About.class},
}
},
};
@ -148,7 +161,7 @@ public class MainMenu {
private Object[] createColumnsMenuDefinition() {
// a shortened version of menu definition
Object[] menuDefinition = new Object[] {
new Object[] {"menu.columns.sortBy", null, new ColumnsActions.SortBy()},
new Object[] {"menu.columns.sortBy", null, ColumnsActions.SortBy.class},
new Object[] {"menu.columns.info", null, null},
new Object[] {"menu.columns.options", null, null},
};
@ -172,7 +185,8 @@ public class MainMenu {
menuItem.setText(labels.getString((String) topMenuDef[0]));
Object[] subMenuDef = (Object[]) topMenuDef[1];
Menu subMenu = new Menu(shell, SWT.DROP_DOWN);
// TODO: ugly hardcode of FavoritesMenu creation
Menu subMenu = i == 3 ? new FavoritesMenu(shell) : new Menu(shell, SWT.DROP_DOWN);
menuItem.setMenu(subMenu);
generateSubMenu(subMenuDef, subMenu);
@ -196,12 +210,20 @@ public class MainMenu {
else {
MenuItem subItem = new MenuItem(menu, SWT.PUSH);
subItem.setText(labels.getString((String) menuDef[0]));
if (menuDef[1] != null)
subItem.setAccelerator(((Integer)menuDef[1]).intValue());
if (menuDef[2] != null)
subItem.addListener(SWT.Selection, (Listener) menuDef[2]);
else
if (menuDef[2] != null) {
// register the component if it is not registered yet
if (container.getComponentAdapter(menuDef[2]) == null)
container.registerComponentImplementation((Class) menuDef[2]);
// .. and create the instance, satisfying all the dependencies
subItem.addListener(SWT.Selection, (Listener) container.getComponentInstance(menuDef[2]));
}
else {
subItem.setEnabled(false);
}
}
}
}
@ -214,8 +236,48 @@ public class MainMenu {
return favoritesMenu;
}
public Menu getColumnsPopupMenu() {
public ColumnsMenu getColumnsPopupMenu() {
return columnsMenu;
}
/**
* OpenersMenu wrapper for type-safety
*/
public static class OpenersMenu extends Menu {
public OpenersMenu(Decorations parent) {
super(parent, SWT.DROP_DOWN);
}
protected void checkSubclass() { } // allow extending of Menu class
}
/**
* ResultsContextMenu wrapper for type-safety
*/
public static class ResultsContextMenu extends Menu {
public ResultsContextMenu(Decorations parent) {
super(parent, SWT.POP_UP);
}
protected void checkSubclass() { } // allow extending of Menu class
}
/**
* FavoritesMenu wrapper for type-safety
*/
public static class FavoritesMenu extends Menu {
public FavoritesMenu(Decorations parent) {
super(parent, SWT.DROP_DOWN);
}
protected void checkSubclass() { } // allow extending of Menu class
}
/**
* ColumnsMenu wrapper for type-safety
*/
public static class ColumnsMenu extends Menu {
public ColumnsMenu(Decorations parent) {
super(parent, SWT.POP_UP);
}
protected void checkSubclass() { } // allow extending of Menu class
}
}

View File

@ -3,26 +3,20 @@
*/
package net.azib.ipscan.gui;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.azib.ipscan.config.Config;
import net.azib.ipscan.config.Labels;
import net.azib.ipscan.config.Version;
import net.azib.ipscan.feeders.FeederException;
import net.azib.ipscan.gui.actions.StartStopScanningAction;
import net.azib.ipscan.gui.feeders.AbstractFeederGUI;
import net.azib.ipscan.gui.feeders.FileFeederGUI;
import net.azib.ipscan.gui.feeders.RandomFeederGUI;
import net.azib.ipscan.gui.feeders.RangeFeederGUI;
import net.azib.ipscan.gui.feeders.FeederGUIRegistry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
@ -32,9 +26,7 @@ import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
/**
@ -47,64 +39,62 @@ import org.eclipse.swt.widgets.Shell;
*/
public class MainWindow {
private Shell shell;
private Shell shell;
private Composite feederArea;
private ResultTable resultTable;
private MainMenu mainMenu;
private Combo feederSelectionCombo;
private List feederGUIList;
private Composite feederArea;
private AbstractFeederGUI feederGUI;
private FeederGUIRegistry feederRegistry;
private Composite controlsArea;
private Composite statusBar;
private ProgressBar progressBar;
private Label statusText;
private Label threadsText;
private StatusBar statusBar;
/**
* Creates and initializes the main window.
*/
public MainWindow() {
createShell();
public MainWindow(Shell shell, Composite feederArea, Composite controlsArea, Combo feederSelectionCombo, ResultTable resultTable, StatusBar statusBar, MainMenu mainMenu, FeederGUIRegistry feederGUIRegistry) {
this.shell = shell;
this.feederArea = feederArea;
this.controlsArea = controlsArea;
this.feederSelectionCombo = feederSelectionCombo;
this.resultTable = resultTable;
this.statusBar = statusBar;
this.mainMenu = mainMenu;
this.feederRegistry = feederGUIRegistry;
populateShell();
createControls();
initTable();
shell.setBounds(Config.getDimensionsConfig().getWindowBounds());
shell.setMaximized(Config.getDimensionsConfig().isWindowMaximized);
shell.open();
}
/**
* This method initializes shell
*/
private void createShell() {
private void populateShell() {
FormLayout formLayout = new FormLayout();
shell = new Shell();
shell.setLayout(formLayout);
shell.setText(Version.FULL_NAME);
// load and set icon
Image image = new Image(shell.getDisplay(), Labels.getInstance().getImageAsStream("icon"));
shell.setImage(image);
resultTable = new ResultTable(shell);
createMenu();
createControls();
createStatusBar();
initTable();
shell.setBounds(Config.getDimensionsConfig().getWindowBounds());
shell.setMaximized(Config.getDimensionsConfig().isWindowMaximized);
shell.addListener(SWT.Close, new Listener() {
public void handleEvent(Event event) {
// save dimensions!
Config.getDimensionsConfig().setWindowBounds(shell.getBounds(), shell.getMaximized());
}
});
shell.open();
}
private void createMenu() {
mainMenu = new MainMenu(this);
}
public Shell getShell() {
@ -114,46 +104,31 @@ public class MainWindow {
public boolean isDisposed() {
return shell.isDisposed();
}
/**
* @deprecated use FeederGUIRegistry instead
*/
public AbstractFeederGUI getFeederGUI() {
return feederGUI;
return feederRegistry.current();
}
/**
* Selects the appropriate feeder by it's name
* @deprecated
*/
public void selectFeederGUI(String feederName) {
String[] items = feederSelectionCombo.getItems();
for (int i = 0; i < items.length; i++) {
if (items[i].equals(feederName)) {
// select the feeder if found
feederSelectionCombo.select(i);
feederSelectionCombo.notifyListeners(SWT.Selection, null);
return;
}
}
// if not found
throw new FeederException("No such feeder found: " + feederName);
}
public ResultTable getResultTable() {
return resultTable;
}
public Label getStatusText() {
return statusText;
}
/**
* This method initializes resultTable
*/
private void initTable() {
resultTable.setColumnsMenu(mainMenu.getColumnsPopupMenu());
resultTable.initialize(mainMenu.getColumnsPopupMenu());
FormData formData = new FormData();
formData.top = new FormAttachment(feederArea);
formData.left = new FormAttachment(0);
formData.right = new FormAttachment(100);
formData.bottom = new FormAttachment(statusBar, 0);
formData.bottom = new FormAttachment(statusBar.getComposite(), -3);
resultTable.setLayoutData(formData);
resultTable.setMenu(mainMenu.getResultsContextMenu());
}
@ -164,26 +139,11 @@ public class MainWindow {
private void createControls() {
// feederArea is the placeholder for the visible feeder
feederArea = new Composite(shell, SWT.NONE);
FormData formData = new FormData();
formData.top = new FormAttachment(0);
formData.left = new FormAttachment(0);
feederArea.setLayoutData(formData);
// create feeder GUIs
// TODO: move this code to a more appropriate place
feederGUIList = new ArrayList();
feederGUI = new RangeFeederGUI(feederArea);
feederGUI.setVisible(false);
feederGUIList.add(feederGUI);
feederGUI = new RandomFeederGUI(feederArea);
feederGUI.setVisible(false);
feederGUIList.add(feederGUI);
feederGUI = new FileFeederGUI(feederArea);
feederGUI.setVisible(false);
feederGUIList.add(feederGUI);
controlsArea = new Composite(shell, SWT.NONE);
formData = new FormData();
formData.top = new FormAttachment(0);
formData.left = new FormAttachment(feederArea);
@ -202,9 +162,8 @@ public class MainWindow {
button.addSelectionListener(new StartStopScanningAction(this, button));
// feeder selection combobox
feederSelectionCombo = new Combo(controlsArea, SWT.READ_ONLY);
feederSelectionCombo.setLayoutData(new RowData(SWT.DEFAULT, 23));
for (Iterator i = feederGUIList.iterator(); i.hasNext();) {
for (Iterator i = feederRegistry.iterator(); i.hasNext();) {
AbstractFeederGUI feederGUI = (AbstractFeederGUI) i.next();
feederSelectionCombo.add(feederGUI.getFeederName());
}
@ -218,54 +177,26 @@ public class MainWindow {
((RowData)button.getLayoutData()).height = feederSelectionCombo.getBounds().height;
((RowData)button.getLayoutData()).width = feederSelectionCombo.getBounds().width;
}
/**
* This method initializes status bar and it's controls
* @deprecated use statusBar instead
*/
private void createStatusBar() {
statusBar = new Composite(shell, SWT.NONE);
FormData formData = new FormData();
formData.left = new FormAttachment(0);
formData.right = new FormAttachment(100);
formData.height = 18;
formData.bottom = new FormAttachment(100);
statusBar.setLayoutData(formData);
RowLayout rowLayout = new RowLayout();
rowLayout.fill = true;
rowLayout.wrap = false;
rowLayout.spacing = 0;
statusBar.setLayout(/*rowLayout*/ new FillLayout());
statusText = new Label(statusBar, SWT.BORDER);
//statusText.setLayoutData(new RowData(150, SWT.DEFAULT));
setStatusText(null);
threadsText = new Label(statusBar, SWT.BORDER);
//threadsText.setLayoutData(new RowData(50, SWT.DEFAULT));
threadsText.setText(Labels.getInstance().getString("text.threads") + "0");
progressBar = new ProgressBar(statusBar, SWT.BORDER);
//progressBar.setLayoutData(new RowData());
progressBar.setSelection(0);
}
public void setStatusText(String statusText) {
if (statusText == null) {
statusText = Labels.getInstance().getString("state.ready");
}
if (!this.statusText.isDisposed())
this.statusText.setText(statusText);
statusBar.setStatusText(statusText);
}
/**
* @deprecated use statusBar instead
*/
public void setRunningThreads(int runningThreads) {
if (!threadsText.isDisposed())
// TODO: make this more efficient
threadsText.setText(Labels.getInstance().getString("text.threads") + runningThreads);
statusBar.setRunningThreads(runningThreads);
}
/**
* @deprecated use statusBar instead
*/
public void setProgress(int progress) {
if (!progressBar.isDisposed())
progressBar.setSelection(progress);
statusBar.setProgress(progress);
}
/**
@ -277,18 +208,11 @@ public class MainWindow {
}
public void widgetSelected(SelectionEvent e) {
// hide current feeder
feederGUI.setVisible(false);
// get new feeder
int newActiveFeeder = feederSelectionCombo.getSelectionIndex();
feederGUI = (AbstractFeederGUI) feederGUIList.get(newActiveFeeder);
Config.getGlobal().activeFeeder = newActiveFeeder;
// make new feeder visible
feederGUI.setVisible(true);
feederRegistry.select(feederSelectionCombo.getSelectionIndex());
// all this 'magic' is needed in order to resize everything properly
// and accomodate feeders with different sizes
Rectangle bounds = feederGUI.getBounds();
Rectangle bounds = feederRegistry.current().getBounds();
FormData feederAreaLayoutData = ((FormData)feederArea.getLayoutData());
feederAreaLayoutData.height = bounds.height;
feederAreaLayoutData.width = bounds.width;

View File

@ -14,6 +14,7 @@ import net.azib.ipscan.core.ScanningResultList;
import net.azib.ipscan.core.ScanningSubject;
import net.azib.ipscan.fetchers.Fetcher;
import net.azib.ipscan.fetchers.FetcherRegistry;
import net.azib.ipscan.gui.MainMenu.ColumnsMenu;
import net.azib.ipscan.gui.actions.ColumnsActions;
import net.azib.ipscan.gui.actions.CommandsActions;
@ -22,7 +23,6 @@ import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
@ -34,23 +34,18 @@ import org.eclipse.swt.widgets.TableItem;
*/
public class ResultTable extends Table {
private ScanningResultList scanningResults = new ScanningResultList();
private ScanningResultList scanningResults;
private Image[] images = new Image[4];
private String feederInfo;
private Menu columnsMenu;
public ResultTable(Composite parent) {
public ResultTable(Composite parent, ScanningResultList scanningResultList) {
super(parent, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
initialize();
this.scanningResults = scanningResultList;
}
void setColumnsMenu(Menu columnsMenu) {
this.columnsMenu = columnsMenu;
}
private void initialize() {
public void initialize(ColumnsMenu columnsMenu) {
setHeaderVisible(true);
setLinesVisible(true);

View File

@ -0,0 +1,84 @@
/**
*
*/
package net.azib.ipscan.gui;
import net.azib.ipscan.config.Labels;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
/**
* The status bar of the main window.
*
* @author anton
*/
public class StatusBar {
private Composite composite;
private ProgressBar progressBar;
private Label statusText;
private Label threadsText;
public StatusBar(Shell shell) {
composite = new Composite(shell, SWT.NONE);
FormData formData = new FormData();
formData.left = new FormAttachment(0);
formData.right = new FormAttachment(100);
formData.height = 18;
formData.bottom = new FormAttachment(100);
composite.setLayoutData(formData);
RowLayout rowLayout = new RowLayout();
rowLayout.fill = true;
rowLayout.wrap = false;
rowLayout.spacing = 0;
composite.setLayout(/*rowLayout*/ new FillLayout());
statusText = new Label(composite, SWT.BORDER);
//statusText.setLayoutData(new RowData(150, SWT.DEFAULT));
setStatusText(null);
threadsText = new Label(composite, SWT.BORDER);
//threadsText.setLayoutData(new RowData(50, SWT.DEFAULT));
threadsText.setText(Labels.getInstance().getString("text.threads") + "0");
progressBar = new ProgressBar(composite, SWT.BORDER);
//progressBar.setLayoutData(new RowData());
progressBar.setSelection(0);
}
/**
* Used for the positioning of the controls in the MainWindow
*/
Composite getComposite() {
return composite;
}
public void setStatusText(String statusText) {
if (statusText == null) {
statusText = Labels.getInstance().getString("state.ready");
}
if (!this.statusText.isDisposed())
this.statusText.setText(statusText);
}
public void setRunningThreads(int runningThreads) {
if (!threadsText.isDisposed())
// TODO: make this more efficient
threadsText.setText(Labels.getInstance().getString("text.threads") + runningThreads);
}
public void setProgress(int progress) {
if (!progressBar.isDisposed())
progressBar.setSelection(progress);
}
}

View File

@ -4,6 +4,7 @@
package net.azib.ipscan.gui.actions;
import net.azib.ipscan.config.Labels;
import net.azib.ipscan.gui.MainMenu.ColumnsMenu;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
@ -24,7 +25,7 @@ public class ColumnsActions {
private Menu columnsMenu;
public ColumnClick(Menu columnsMenu) {
public ColumnClick(ColumnsMenu columnsMenu) {
this.columnsMenu = columnsMenu;
}
@ -39,7 +40,7 @@ public class ColumnsActions {
sortMenuItem.setText(Labels.getInstance().getString("menu.columns.sortBy") + tableColumn.getText());
}
// remember the clicked column
// remember the clicked column (see SortBy below)
sortMenuItem.setData(tableColumn);
// show the menu
@ -63,6 +64,8 @@ public class ColumnsActions {
else {
table.setSortDirection(table.getSortDirection() == SWT.UP ? SWT.DOWN : SWT.UP);
}
// TODO: execute ScanningResultList.sort() here!!!
}
}

View File

@ -10,9 +10,10 @@ import net.azib.ipscan.config.Labels;
import net.azib.ipscan.config.OpenersConfig.Opener;
import net.azib.ipscan.gui.DetailsWindow;
import net.azib.ipscan.gui.EditOpenersDialog;
import net.azib.ipscan.gui.MainWindow;
import net.azib.ipscan.gui.ResultTable;
import net.azib.ipscan.gui.StatusBar;
import net.azib.ipscan.gui.UserErrorException;
import net.azib.ipscan.gui.MainMenu.OpenersMenu;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.Clipboard;
@ -109,9 +110,9 @@ public class CommandsActions {
private Menu openersMenu;
private Listener openersSelectListener;
public ShowOpenersMenu(MainWindow mainWindow, Menu openersMenu) {
public ShowOpenersMenu(OpenersMenu openersMenu, SelectOpener selectOpener) {
this.openersMenu = openersMenu;
this.openersSelectListener = new SelectOpener(mainWindow);
this.openersSelectListener = selectOpener;
}
public void handleEvent(Event event) {
@ -136,10 +137,8 @@ public class CommandsActions {
menuItem.setData(new Integer(index));
menuItem.addListener(SWT.Selection, openersSelectListener);
}
}
}
public static class EditOpeners implements Listener {
@ -151,12 +150,14 @@ public class CommandsActions {
public static class SelectOpener implements Listener {
private MainWindow mainWindow;
private StatusBar statusBar;
private ResultTable resultTable;
private OpenerLauncher openerLauncher;
public SelectOpener(MainWindow mainWindow) {
this.mainWindow = mainWindow;
this.openerLauncher = new OpenerLauncher(mainWindow);
public SelectOpener(StatusBar statusBar, ResultTable resultTable, OpenerLauncher openerLauncher) {
this.statusBar = statusBar;
this.resultTable = resultTable;
this.openerLauncher = openerLauncher;
}
public void handleEvent(Event event) {
@ -168,13 +169,13 @@ public class CommandsActions {
}
Opener opener = Config.getOpenersConfig().getOpener(name);
int selectedItem = mainWindow.getResultTable().getSelectionIndex();
int selectedItem = resultTable.getSelectionIndex();
if (selectedItem < 0) {
throw new UserErrorException("commands.noSelection");
}
try {
mainWindow.setStatusText(Labels.getInstance().getString("state.opening") + name);
statusBar.setStatusText(Labels.getInstance().getString("state.opening") + name);
openerLauncher.launch(opener, selectedItem);
// wait a bit to make status visible
// TODO: somehow wait until the process is started
@ -182,7 +183,7 @@ public class CommandsActions {
}
catch (InterruptedException e) {}
finally {
mainWindow.setStatusText(null);
statusBar.setStatusText(null);
}
}
}

View File

@ -10,8 +10,9 @@ import net.azib.ipscan.config.Labels;
import net.azib.ipscan.config.NamedListConfig;
import net.azib.ipscan.gui.EditFavoritesDialog;
import net.azib.ipscan.gui.InputDialog;
import net.azib.ipscan.gui.MainWindow;
import net.azib.ipscan.gui.UserErrorException;
import net.azib.ipscan.gui.MainMenu.FavoritesMenu;
import net.azib.ipscan.gui.feeders.FeederGUIRegistry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
@ -27,14 +28,14 @@ import org.eclipse.swt.widgets.MenuItem;
public class FavoritesActions {
public static class Add implements Listener {
private MainWindow mainWindow;
private FeederGUIRegistry feederRegistry;
public Add(MainWindow mainWindow) {
this.mainWindow = mainWindow;
public Add(FeederGUIRegistry feederRegistry) {
this.feederRegistry = feederRegistry;
}
public void handleEvent(Event event) {
String feederInfo = mainWindow.getFeederGUI().getInfo();
String feederInfo = feederRegistry.current().getInfo();
InputDialog inputDialog = new InputDialog(
Labels.getInstance().getString("title.favorite.add"),
Labels.getInstance().getString("text.favorite.add"));
@ -45,19 +46,19 @@ public class FavoritesActions {
if (favoritesConfig.get(favoriteName) != null) {
throw new UserErrorException("favorite.alreadyExists");
}
String serializedFeeder = mainWindow.getFeederGUI().getFeederName() + '\t' + mainWindow.getFeederGUI().serialize();
String serializedFeeder = feederRegistry.current().getFeederName() + '\t' + feederRegistry.current().serialize();
favoritesConfig.add(favoriteName, serializedFeeder);
}
}
}
public static class Select implements Listener {
private MainWindow mainWindow;
private FeederGUIRegistry feederRegistry;
public Select(MainWindow mainWindow) {
this.mainWindow = mainWindow;
public Select(FeederGUIRegistry feederRegistry) {
this.feederRegistry = feederRegistry;
}
public void handleEvent(Event event) {
MenuItem menuItem = (MenuItem) event.widget;
String serializedFeeder = Config.getFavoritesConfig().get(menuItem.getText());
@ -66,8 +67,8 @@ public class FavoritesActions {
String feederName = serializedFeeder.substring(0, indexOf);
serializedFeeder = serializedFeeder.substring(indexOf + 1);
mainWindow.selectFeederGUI(feederName);
mainWindow.getFeederGUI().unserialize(serializedFeeder);
feederRegistry.select(feederName);
feederRegistry.current().unserialize(serializedFeeder);
}
}
@ -81,10 +82,10 @@ public class FavoritesActions {
private Menu favoritesMenu;
private Listener favoritesSelectListener;
public ShowMenu(MainWindow mainWindow, Menu favoritesMenu) {
public ShowMenu(FavoritesMenu favoritesMenu, Select favoritesSelectListener) {
this.favoritesMenu = favoritesMenu;
// the listener for favorites selections from the menu
this.favoritesSelectListener = new Select(mainWindow);
this.favoritesSelectListener = favoritesSelectListener;
}
public void handleEvent(Event event) {

View File

@ -13,8 +13,8 @@ import net.azib.ipscan.exporters.ExportProcessor;
import net.azib.ipscan.exporters.Exporter;
import net.azib.ipscan.exporters.ExporterRegistry;
import net.azib.ipscan.exporters.ExportProcessor.ScanningResultSelector;
import net.azib.ipscan.gui.MainWindow;
import net.azib.ipscan.gui.ResultTable;
import net.azib.ipscan.gui.StatusBar;
import net.azib.ipscan.gui.UserErrorException;
import org.eclipse.swt.SWT;
@ -35,19 +35,19 @@ public class FileActions {
}
}
public static class SaveResults implements Listener {
MainWindow mainWindow;
boolean isSelection;
public SaveResults(MainWindow mainWindow, boolean isSelection) {
this.mainWindow = mainWindow;
private static class SaveResults implements Listener {
private ResultTable resultTable;
private StatusBar statusBar;
private boolean isSelection;
SaveResults(ResultTable resultTable, StatusBar statusBar, boolean isSelection) {
this.resultTable = resultTable;
this.statusBar = statusBar;
// TODO: implement isSelection
this.isSelection = isSelection;
}
public void handleEvent(Event event) {
ResultTable resultTable = mainWindow.getResultTable();
if (resultTable.getItemCount() <= 0) {
throw new UserErrorException("commands.noResults");
}
@ -74,7 +74,7 @@ public class FileActions {
// create exporter instance
Exporter exporter = ExporterRegistry.getInstance().createExporter(fileName);
mainWindow.setStatusText(Labels.getInstance().getString("state.saving"));
statusBar.setStatusText(Labels.getInstance().getString("state.saving"));
ExportProcessor exportProcessor = new ExportProcessor(exporter, fileName);
@ -83,14 +83,14 @@ public class FileActions {
if (isSelection) {
scanningResultSelector = new ScanningResultSelector() {
public boolean isResultSelected(int index, ScanningResult result) {
return mainWindow.getResultTable().isSelected(index);
return resultTable.isSelected(index);
}
};
}
exportProcessor.process(resultTable.getScanningResults(), mainWindow.getResultTable().getFeederInfo(), scanningResultSelector);
exportProcessor.process(resultTable.getScanningResults(), resultTable.getFeederInfo(), scanningResultSelector);
mainWindow.setStatusText(null);
statusBar.setStatusText(null);
}
}
@ -107,5 +107,16 @@ public class FileActions {
sb.append(")");
}
}
public static class SaveAll extends SaveResults {
public SaveAll(ResultTable resultTable, StatusBar statusBar) {
super(resultTable, statusBar, false);
}
}
public static class SaveSelection extends SaveResults {
public SaveSelection(ResultTable resultTable, StatusBar statusBar) {
super(resultTable, statusBar, true);
}
}
}

View File

@ -9,14 +9,16 @@ 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.core.ScanningSubject;
import net.azib.ipscan.gui.InputDialog;
import net.azib.ipscan.gui.MainWindow;
import net.azib.ipscan.gui.ResultTable;
import net.azib.ipscan.gui.StatusBar;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
/**
* GotoActions
@ -25,18 +27,17 @@ import org.eclipse.swt.widgets.MessageBox;
*/
public class GotoActions {
public static class NextHost implements Listener {
private MainWindow mainWindow;
private static class NextHost implements Listener {
private ResultTable resultTable;
private int whatToSearchFor;
public NextHost(MainWindow mainWindow, int whatToSearchFor) {
this.mainWindow = mainWindow;
NextHost(ResultTable resultTable, int whatToSearchFor) {
this.resultTable = resultTable;
this.whatToSearchFor = whatToSearchFor;
}
public void handleEvent(Event event) {
ResultTable resultTable = mainWindow.getResultTable();
ScanningResultList results = resultTable.getScanningResults();
int numElements = resultTable.getItemCount();
@ -61,17 +62,36 @@ public class GotoActions {
}
public static class NextAliveHost extends NextHost {
public NextAliveHost(ResultTable resultTable) {
super(resultTable, ScanningSubject.RESULT_TYPE_ALIVE);
}
}
public static class NextDeadHost extends NextHost {
public NextDeadHost(ResultTable resultTable) {
super(resultTable, ScanningSubject.RESULT_TYPE_DEAD);
}
}
public static class NextHostWithInfo extends NextHost {
public NextHostWithInfo(ResultTable resultTable) {
super(resultTable, ScanningSubject.RESULT_TYPE_ADDITIONAL_INFO);
}
}
public static class Find implements Listener {
private MainWindow mainWindow;
private ResultTable resultTable;
private StatusBar statusBar;
private String lastText = "";
public Find(MainWindow mainWindow) {
this.mainWindow = mainWindow;
public Find(StatusBar statusBar, ResultTable resultTable) {
this.statusBar = statusBar;
this.resultTable = resultTable;
}
public void handleEvent(Event event) {
InputDialog dialog = new InputDialog(Labels.getInstance().getString("title.find"), Labels.getInstance().getString("text.find"));
String text = dialog.open(lastText);
if (text == null) {
@ -80,18 +100,16 @@ public class GotoActions {
lastText = text;
try {
mainWindow.setStatusText(Labels.getInstance().getString("state.searching"));
statusBar.setStatusText(Labels.getInstance().getString("state.searching"));
findText(text);
findText(text, event.display.getActiveShell());
}
finally {
mainWindow.setStatusText(null);
statusBar.setStatusText(null);
}
}
private void findText(String text) {
ResultTable resultTable = mainWindow.getResultTable();
private void findText(String text, Shell activeShell) {
ScanningResultList results = resultTable.getScanningResults();
int numElements = resultTable.getItemCount();
@ -112,28 +130,24 @@ public class GotoActions {
return;
}
}
}
if (startElement > 0) {
MessageBox messageBox = new MessageBox(mainWindow.getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION);
MessageBox messageBox = new MessageBox(activeShell, 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);
findText(text, activeShell);
}
}
else {
MessageBox messageBox = new MessageBox(mainWindow.getShell(), SWT.OK | SWT.ICON_INFORMATION);
MessageBox messageBox = new MessageBox(activeShell, SWT.OK | SWT.ICON_INFORMATION);
messageBox.setText(Labels.getInstance().getString("title.find"));
messageBox.setMessage(Labels.getInstance().getString("text.find.notFound"));
messageBox.open();
}
}
}
}

View File

@ -13,7 +13,7 @@ import net.azib.ipscan.config.Labels;
import net.azib.ipscan.config.Version;
import net.azib.ipscan.gui.AboutWindow;
import net.azib.ipscan.gui.GettingStartedWindow;
import net.azib.ipscan.gui.MainWindow;
import net.azib.ipscan.gui.StatusBar;
import net.azib.ipscan.gui.UserErrorException;
import org.eclipse.swt.SWT;
@ -59,16 +59,16 @@ public class HelpActions {
}
public static class CheckVersion implements Listener {
private MainWindow mainWindow;
private StatusBar statusBar;
public CheckVersion(MainWindow mainWindow) {
this.mainWindow = mainWindow;
public CheckVersion(StatusBar statusBar) {
this.statusBar = statusBar;
}
public void handleEvent(Event event) {
BufferedReader reader = null;
try {
mainWindow.setStatusText(Labels.getInstance().getString("state.retrievingVersion"));
statusBar.setStatusText(Labels.getInstance().getString("state.retrievingVersion"));
URL url = new URL(Version.LATEST_VERSION_URL);
URLConnection conn = url.openConnection();
@ -102,7 +102,7 @@ public class HelpActions {
}
catch (IOException e) {}
mainWindow.setStatusText(null);
statusBar.setStatusText(null);
}
}
}

View File

@ -10,7 +10,7 @@ import java.util.regex.Pattern;
import net.azib.ipscan.config.OpenersConfig.Opener;
import net.azib.ipscan.fetchers.FetcherRegistry;
import net.azib.ipscan.gui.MainWindow;
import net.azib.ipscan.gui.ResultTable;
import net.azib.ipscan.gui.UserErrorException;
/**
@ -20,10 +20,10 @@ import net.azib.ipscan.gui.UserErrorException;
*/
public class OpenerLauncher {
private MainWindow mainWindow;
private ResultTable resultTable;
public OpenerLauncher(MainWindow mainWindow) {
this.mainWindow = mainWindow;
public OpenerLauncher(ResultTable resultTable) {
this.resultTable = resultTable;
}
public void launch(Opener opener, int selectedItem) {
@ -84,6 +84,6 @@ public class OpenerLauncher {
}
String getScannedValue(int selectedItem, int fetcherIndex) {
return (String) mainWindow.getResultTable().getScanningResults().getResult(selectedItem).getValues().get(fetcherIndex);
return (String) resultTable.getScanningResults().getResult(selectedItem).getValues().get(fetcherIndex);
}
}

View File

@ -20,6 +20,7 @@ public abstract class AbstractFeederGUI extends Composite {
public AbstractFeederGUI(Composite parent) {
super(parent, SWT.NONE);
setVisible(false);
initialize();
}

View File

@ -0,0 +1,73 @@
/**
*
*/
package net.azib.ipscan.gui.feeders;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Combo;
import net.azib.ipscan.config.Config;
import net.azib.ipscan.feeders.FeederException;
/**
* FeederGUIRegistry
*
* @author anton
*/
public class FeederGUIRegistry {
private List feederGUIList;
private Combo feederSelectionCombo;
private AbstractFeederGUI currentFeederGUI;
public FeederGUIRegistry(AbstractFeederGUI[] allTheFeeders, Combo feederSelectionCombo) {
this.feederGUIList = Arrays.asList(allTheFeeders);
this.feederSelectionCombo = feederSelectionCombo;
this.currentFeederGUI = allTheFeeders[0];
}
public AbstractFeederGUI current() {
return currentFeederGUI;
}
/**
* Select a new indexed feeder GUI
*/
public void select(int newActiveFeeder) {
// hide current feeder
currentFeederGUI.setVisible(false);
// get new feeder
currentFeederGUI = (AbstractFeederGUI) feederGUIList.get(newActiveFeeder);
Config.getGlobal().activeFeeder = newActiveFeeder;
// make new feeder visible
currentFeederGUI.setVisible(true);
}
public Iterator iterator() {
return feederGUIList.iterator();
}
/**
* Select the Feeder GUI by its name, while updating the GUI
*/
public void select(String feederName) {
String[] items = feederSelectionCombo.getItems();
for (int i = 0; i < items.length; i++) {
if (items[i].equals(feederName)) {
// select the feeder if found
feederSelectionCombo.select(i);
feederSelectionCombo.notifyListeners(SWT.Selection, null);
return;
}
}
// if not found
throw new FeederException("No such feeder found: " + feederName);
}
}