mirror of
https://github.com/angryip/ipscan.git
synced 2025-10-26 11:18:17 +00:00
* NamedListConfig is now Iterable, itrerateNames() renamed to iterator()
* OpenersConfig and FavoritesConfig are now properly injected to all places where they are used git-svn-id: https://ipscan.svn.sourceforge.net/svnroot/ipscan/trunk@239 375186e5-ef17-0410-b0b6-91563547dcda
This commit is contained in:
parent
b1367b0065
commit
035c7504c8
2
TODO
2
TODO
@ -1,3 +1,5 @@
|
||||
* More openers: IP info, etc
|
||||
|
||||
Before 3.0:
|
||||
|
||||
* command-line scanning start
|
||||
|
||||
@ -31,3 +31,4 @@ placeholder
|
||||
firewall
|
||||
registry
|
||||
combo
|
||||
config
|
||||
|
||||
@ -57,16 +57,16 @@ public final class Config {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Favorites config (quick access);
|
||||
* @return Favorites config (only local access)
|
||||
*/
|
||||
public static NamedListConfig getFavoritesConfig() {
|
||||
static NamedListConfig getFavoritesConfig() {
|
||||
return favoritesConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Openers config (quick access);
|
||||
* @return Openers config (only local access);
|
||||
*/
|
||||
public static OpenersConfig getOpenersConfig() {
|
||||
static OpenersConfig getOpenersConfig() {
|
||||
return openersConfig;
|
||||
}
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ import java.util.prefs.Preferences;
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
public class NamedListConfig {
|
||||
public class NamedListConfig implements Iterable<String> {
|
||||
|
||||
protected String preferenceName;
|
||||
protected Preferences preferences;
|
||||
@ -83,7 +83,7 @@ public class NamedListConfig {
|
||||
/**
|
||||
* @return an Iterator for iterating names of available items
|
||||
*/
|
||||
public Iterator<String> iterateNames() {
|
||||
public Iterator<String> iterator() {
|
||||
return namedList.keySet().iterator();
|
||||
}
|
||||
|
||||
|
||||
@ -3,11 +3,8 @@
|
||||
*/
|
||||
package net.azib.ipscan.gui;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.azib.ipscan.config.Config;
|
||||
import net.azib.ipscan.config.FavoritesConfig;
|
||||
import net.azib.ipscan.config.Labels;
|
||||
import net.azib.ipscan.config.NamedListConfig;
|
||||
import net.azib.ipscan.gui.util.LayoutHelper;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
@ -27,9 +24,11 @@ import org.eclipse.swt.widgets.Shell;
|
||||
*/
|
||||
public class EditFavoritesDialog extends AbstractModalDialog {
|
||||
|
||||
private final FavoritesConfig favoritesConfig;
|
||||
private List favoritesList;
|
||||
|
||||
public EditFavoritesDialog() {
|
||||
public EditFavoritesDialog(FavoritesConfig favoritesConfig) {
|
||||
this.favoritesConfig = favoritesConfig;
|
||||
createShell();
|
||||
}
|
||||
|
||||
@ -49,8 +48,7 @@ public class EditFavoritesDialog extends AbstractModalDialog {
|
||||
|
||||
favoritesList = new List(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
|
||||
favoritesList.setLayoutData(LayoutHelper.formData(330, 200, new FormAttachment(0), null, new FormAttachment(messageLabel), null));
|
||||
for (Iterator<String> i = Config.getFavoritesConfig().iterateNames(); i.hasNext();) {
|
||||
String name = i.next();
|
||||
for (String name : favoritesConfig) {
|
||||
favoritesList.add(name);
|
||||
}
|
||||
|
||||
@ -91,11 +89,9 @@ public class EditFavoritesDialog extends AbstractModalDialog {
|
||||
shell.close();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void saveFavorites() {
|
||||
NamedListConfig favoritesConfig = Config.getFavoritesConfig();
|
||||
favoritesConfig.update(favoritesList.getItems());
|
||||
favoritesConfig.store();
|
||||
}
|
||||
|
||||
@ -4,9 +4,7 @@
|
||||
package net.azib.ipscan.gui;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.azib.ipscan.config.Config;
|
||||
import net.azib.ipscan.config.Labels;
|
||||
import net.azib.ipscan.config.OpenersConfig;
|
||||
import net.azib.ipscan.config.Platform;
|
||||
@ -36,7 +34,9 @@ import org.eclipse.swt.widgets.Text;
|
||||
*/
|
||||
public class EditOpenersDialog extends AbstractModalDialog {
|
||||
|
||||
private FetcherRegistry fetcherRegistry;
|
||||
private final FetcherRegistry fetcherRegistry;
|
||||
private final OpenersConfig openersConfig;
|
||||
|
||||
private List openersList;
|
||||
private Group editFieldsGroup;
|
||||
private Text openerNameText;
|
||||
@ -45,8 +45,9 @@ public class EditOpenersDialog extends AbstractModalDialog {
|
||||
private Button isInTerminalCheckbox;
|
||||
private int currentSelectionIndex;
|
||||
|
||||
public EditOpenersDialog(FetcherRegistry fetcherRegistry) {
|
||||
public EditOpenersDialog(FetcherRegistry fetcherRegistry, OpenersConfig openersConfig) {
|
||||
this.fetcherRegistry = fetcherRegistry;
|
||||
this.openersConfig = openersConfig;
|
||||
createShell();
|
||||
}
|
||||
|
||||
@ -68,8 +69,7 @@ public class EditOpenersDialog extends AbstractModalDialog {
|
||||
editFieldsGroup = new Group(shell, SWT.NONE);
|
||||
|
||||
openersList.setLayoutData(LayoutHelper.formData(135, 200, null, null, new FormAttachment(messageLabel, 10), new FormAttachment(editFieldsGroup, 0, SWT.BOTTOM)));
|
||||
for (Iterator<String> i = Config.getOpenersConfig().iterateNames(); i.hasNext();) {
|
||||
String name = i.next();
|
||||
for (String name : openersConfig) {
|
||||
openersList.add(name);
|
||||
}
|
||||
openersList.addListener(SWT.Selection, new ItemSelectListener());
|
||||
@ -161,7 +161,6 @@ public class EditOpenersDialog extends AbstractModalDialog {
|
||||
saveCurrentFields();
|
||||
|
||||
// now save everything else (order, etc)
|
||||
OpenersConfig openersConfig = Config.getOpenersConfig();
|
||||
openersConfig.update(openersList.getItems());
|
||||
openersConfig.store();
|
||||
}
|
||||
@ -172,7 +171,7 @@ public class EditOpenersDialog extends AbstractModalDialog {
|
||||
return;
|
||||
|
||||
File workingDir = workingDirText.getText().length() > 0 ? new File(workingDirText.getText()) : null;
|
||||
Config.getOpenersConfig().add(openerName, new OpenersConfig.Opener(openerStringText.getText(), isInTerminalCheckbox.getSelection(), workingDir));
|
||||
openersConfig.add(openerName, new OpenersConfig.Opener(openerStringText.getText(), isInTerminalCheckbox.getSelection(), workingDir));
|
||||
openersList.setItem(currentSelectionIndex, openerName);
|
||||
}
|
||||
|
||||
@ -180,7 +179,7 @@ public class EditOpenersDialog extends AbstractModalDialog {
|
||||
currentSelectionIndex = openersList.getSelectionIndex();
|
||||
String openerName = openersList.getItem(currentSelectionIndex);
|
||||
editFieldsGroup.setText(openerName);
|
||||
Opener opener = Config.getOpenersConfig().getOpener(openerName);
|
||||
Opener opener = openersConfig.getOpener(openerName);
|
||||
openerNameText.setText(openerName);
|
||||
openerStringText.setText(opener.execString);
|
||||
workingDirText.setText(opener.workingDir != null ? opener.workingDir.toString() : "");
|
||||
|
||||
@ -7,11 +7,10 @@ package net.azib.ipscan.gui.actions;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.azib.ipscan.config.CommentsConfig;
|
||||
import net.azib.ipscan.config.Config;
|
||||
import net.azib.ipscan.config.Labels;
|
||||
import net.azib.ipscan.config.OpenersConfig;
|
||||
import net.azib.ipscan.config.OpenersConfig.Opener;
|
||||
import net.azib.ipscan.core.ScanningResultList;
|
||||
import net.azib.ipscan.core.UserErrorException;
|
||||
@ -154,8 +153,10 @@ public class CommandsActions {
|
||||
public static final class ShowOpenersMenu implements Listener {
|
||||
|
||||
private final Listener openersSelectListener;
|
||||
private final OpenersConfig openersConfig;
|
||||
|
||||
public ShowOpenersMenu(SelectOpener selectOpener) {
|
||||
public ShowOpenersMenu(OpenersConfig openersConfig, SelectOpener selectOpener) {
|
||||
this.openersConfig = openersConfig;
|
||||
this.openersSelectListener = selectOpener;
|
||||
}
|
||||
|
||||
@ -168,9 +169,8 @@ public class CommandsActions {
|
||||
|
||||
// update menu items
|
||||
int index = 0;
|
||||
for (Iterator<String> i = Config.getOpenersConfig().iterateNames(); i.hasNext();) {
|
||||
for (String name : openersConfig) {
|
||||
MenuItem menuItem = new MenuItem(openersMenu, SWT.CASCADE);
|
||||
String name = i.next();
|
||||
|
||||
index++;
|
||||
if (index <= 9) {
|
||||
@ -226,14 +226,16 @@ public class CommandsActions {
|
||||
|
||||
public static final class EditOpeners implements Listener {
|
||||
|
||||
FetcherRegistry fetcherRegistry;
|
||||
private final FetcherRegistry fetcherRegistry;
|
||||
private final OpenersConfig openersConfig;
|
||||
|
||||
public EditOpeners(FetcherRegistry fetcherRegistry) {
|
||||
public EditOpeners(FetcherRegistry fetcherRegistry, OpenersConfig openersConfig) {
|
||||
this.fetcherRegistry = fetcherRegistry;
|
||||
this.openersConfig = openersConfig;
|
||||
}
|
||||
|
||||
public void handleEvent(Event event) {
|
||||
new EditOpenersDialog(fetcherRegistry).open();
|
||||
new EditOpenersDialog(fetcherRegistry, openersConfig).open();
|
||||
}
|
||||
}
|
||||
|
||||
@ -242,8 +244,10 @@ public class CommandsActions {
|
||||
private final StatusBar statusBar;
|
||||
private final ResultTable resultTable;
|
||||
private final OpenerLauncher openerLauncher;
|
||||
private final OpenersConfig openersConfig;
|
||||
|
||||
public SelectOpener(StatusBar statusBar, ResultTable resultTable, OpenerLauncher openerLauncher) {
|
||||
public SelectOpener(OpenersConfig openersConfig, StatusBar statusBar, ResultTable resultTable, OpenerLauncher openerLauncher) {
|
||||
this.openersConfig = openersConfig;
|
||||
this.statusBar = statusBar;
|
||||
this.resultTable = resultTable;
|
||||
this.openerLauncher = openerLauncher;
|
||||
@ -256,7 +260,7 @@ public class CommandsActions {
|
||||
if (indexOf >= 0) {
|
||||
name = name.substring(0, indexOf);
|
||||
}
|
||||
Opener opener = Config.getOpenersConfig().getOpener(name);
|
||||
Opener opener = openersConfig.getOpener(name);
|
||||
|
||||
int selectedItem = resultTable.getSelectionIndex();
|
||||
if (selectedItem < 0) {
|
||||
|
||||
@ -5,11 +5,8 @@
|
||||
*/
|
||||
package net.azib.ipscan.gui.actions;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.azib.ipscan.config.Config;
|
||||
import net.azib.ipscan.config.FavoritesConfig;
|
||||
import net.azib.ipscan.config.Labels;
|
||||
import net.azib.ipscan.config.NamedListConfig;
|
||||
import net.azib.ipscan.config.Version;
|
||||
import net.azib.ipscan.core.UserErrorException;
|
||||
import net.azib.ipscan.gui.EditFavoritesDialog;
|
||||
@ -31,8 +28,10 @@ public class FavoritesActions {
|
||||
|
||||
public static final class Add implements Listener {
|
||||
private final FeederGUIRegistry feederRegistry;
|
||||
private final FavoritesConfig favoritesConfig;
|
||||
|
||||
public Add(FeederGUIRegistry feederRegistry) {
|
||||
public Add(FavoritesConfig favoritesConfig, FeederGUIRegistry feederRegistry) {
|
||||
this.favoritesConfig = favoritesConfig;
|
||||
this.feederRegistry = feederRegistry;
|
||||
}
|
||||
|
||||
@ -44,7 +43,6 @@ public class FavoritesActions {
|
||||
String favoriteName = inputDialog.open(feederInfo);
|
||||
|
||||
if (favoriteName != null) {
|
||||
NamedListConfig favoritesConfig = Config.getFavoritesConfig();
|
||||
if (favoritesConfig.get(favoriteName) != null) {
|
||||
throw new UserErrorException("favorite.alreadyExists");
|
||||
}
|
||||
@ -57,14 +55,16 @@ public class FavoritesActions {
|
||||
|
||||
public static final class Select implements Listener {
|
||||
private final FeederGUIRegistry feederRegistry;
|
||||
private final FavoritesConfig favoritesConfig;
|
||||
|
||||
public Select(FeederGUIRegistry feederRegistry) {
|
||||
public Select(FavoritesConfig favoritesConfig, FeederGUIRegistry feederRegistry) {
|
||||
this.favoritesConfig = favoritesConfig;
|
||||
this.feederRegistry = feederRegistry;
|
||||
}
|
||||
|
||||
public void handleEvent(Event event) {
|
||||
MenuItem menuItem = (MenuItem) event.widget;
|
||||
String serializedFeeder = Config.getFavoritesConfig().get(menuItem.getText());
|
||||
String serializedFeeder = favoritesConfig.get(menuItem.getText());
|
||||
|
||||
int indexOf = serializedFeeder.indexOf('\t');
|
||||
String feederName = serializedFeeder.substring(0, indexOf);
|
||||
@ -77,25 +77,32 @@ public class FavoritesActions {
|
||||
}
|
||||
|
||||
public static final class Edit implements Listener {
|
||||
private final FavoritesConfig favoritesConfig;
|
||||
|
||||
public Edit(FavoritesConfig favoritesConfig) {
|
||||
this.favoritesConfig = favoritesConfig;
|
||||
}
|
||||
|
||||
public void handleEvent(Event event) {
|
||||
new EditFavoritesDialog().open();
|
||||
new EditFavoritesDialog(favoritesConfig).open();
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ShowMenu implements Listener {
|
||||
private final Listener favoritesSelectListener;
|
||||
private final FavoritesConfig favoritesConfig;
|
||||
|
||||
public ShowMenu(Select favoritesSelectListener) {
|
||||
public ShowMenu(FavoritesConfig favoritesConfig, Select favoritesSelectListener) {
|
||||
this.favoritesConfig = favoritesConfig;
|
||||
// the listener for favorites selections from the menu
|
||||
this.favoritesSelectListener = favoritesSelectListener;
|
||||
}
|
||||
|
||||
public void handleEvent(Event event) {
|
||||
Menu favoritesMenu = (Menu) event.widget;
|
||||
// populate favorites in the menu
|
||||
NamedListConfig favoritesConfig = Config.getFavoritesConfig();
|
||||
|
||||
// populate favorites in the menu
|
||||
// note: 3 is the number of items in the menu when no favorites exist
|
||||
|
||||
// dispose old favorites
|
||||
MenuItem[] menuItems = favoritesMenu.getItems();
|
||||
for (int i = 3; i < menuItems.length; i++) {
|
||||
@ -103,9 +110,9 @@ public class FavoritesActions {
|
||||
}
|
||||
|
||||
// update favorites menu items
|
||||
for (Iterator<String> i = favoritesConfig.iterateNames(); i.hasNext();) {
|
||||
for (String name : favoritesConfig) {
|
||||
MenuItem menuItem = new MenuItem(favoritesMenu, SWT.CASCADE);
|
||||
menuItem.setText(i.next());
|
||||
menuItem.setText(name);
|
||||
menuItem.addListener(SWT.Selection, favoritesSelectListener);
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ public class FeederGUIRegistry implements Iterable<AbstractFeederGUI> {
|
||||
}
|
||||
}
|
||||
// if not found
|
||||
throw new FeederException("No such feeder found: " + feederName);
|
||||
throw new FeederException("Feeder not found: " + feederName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -59,7 +59,7 @@ public class NamedListConfigTest {
|
||||
preferences.put(PREFERENCE_NAME, "aa###aaa###bb###bbb###cc###ccc");
|
||||
NamedListConfig config = new NamedListConfig(preferences, PREFERENCE_NAME);
|
||||
|
||||
Iterator namesIterator = config.iterateNames();
|
||||
Iterator namesIterator = config.iterator();
|
||||
assertEquals("aa", namesIterator.next());
|
||||
assertEquals("bb", namesIterator.next());
|
||||
assertEquals("cc", namesIterator.next());
|
||||
@ -84,7 +84,7 @@ public class NamedListConfigTest {
|
||||
|
||||
config.update(new String[] {"x", "z"});
|
||||
|
||||
Iterator i = config.iterateNames();
|
||||
Iterator i = config.iterator();
|
||||
assertEquals("xxx", config.get((String)i.next()));
|
||||
assertEquals("zzz", config.get((String)i.next()));
|
||||
assertFalse(i.hasNext());
|
||||
|
||||
@ -93,7 +93,7 @@ public class OpenersConfigTest {
|
||||
preferences.put(PREFERENCE_NAME, "aa###aaa@@@1@@@###bb###bbb@@@1@@@");
|
||||
OpenersConfig config = new OpenersConfig(preferences);
|
||||
|
||||
Iterator namesIterator = config.iterateNames();
|
||||
Iterator namesIterator = config.iterator();
|
||||
assertEquals("aa", namesIterator.next());
|
||||
assertEquals("bb", namesIterator.next());
|
||||
assertFalse(namesIterator.hasNext());
|
||||
@ -119,7 +119,7 @@ public class OpenersConfigTest {
|
||||
|
||||
config.update(new String[] {"x", "z"});
|
||||
|
||||
Iterator i = config.iterateNames();
|
||||
Iterator i = config.iterator();
|
||||
assertEquals("x", i.next());
|
||||
assertEquals("z", i.next());
|
||||
assertFalse(i.hasNext());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user