diff --git a/config/logging.properties b/config/logging.properties index 6a8f298e..0e3a56f5 100755 --- a/config/logging.properties +++ b/config/logging.properties @@ -5,4 +5,4 @@ handlers = java.util.logging.ConsoleHandler java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter java.util.logging.ConsoleHandler.level = ALL -.level = FINE +.level = FINER diff --git a/src/net/azib/ipscan/Main.java b/src/net/azib/ipscan/Main.java index 1692673a..b85c82ec 100755 --- a/src/net/azib/ipscan/Main.java +++ b/src/net/azib/ipscan/Main.java @@ -35,18 +35,25 @@ public class Main { public static void main(String[] args) { + long startTime = System.currentTimeMillis(); + initSystemProperties(); - Display display = Display.getDefault(); + Display display = Display.getDefault(); + LOG.finer("SWT initialized after " + (System.currentTimeMillis() - startTime)); // initalize Labels instance - Labels.initialize(new Locale("en")); // TODO: retrieve locale normally - + Labels.initialize(new Locale("en")); // TODO: retrieve locale normally // initialize Config instance - Config.initialize(); + Config.initialize(); + LOG.finer("Labels and Config initialized after " + (System.currentTimeMillis() - startTime)); + + ComponentRegistry componentRegistry = new ComponentRegistry(); + LOG.finer("ComponentRegistry initialized after " + (System.currentTimeMillis() - startTime)); // create the main window using dependency injection - MainWindow mainWindow = new ComponentRegistry().createMainWindow(); + MainWindow mainWindow = componentRegistry.createMainWindow(); + LOG.fine("Startup time: " + (System.currentTimeMillis() - startTime)); while (!mainWindow.isDisposed()) { try { diff --git a/src/net/azib/ipscan/gui/AbstractModalDialog.java b/src/net/azib/ipscan/gui/AbstractModalDialog.java index a309226d..369ea5bb 100755 --- a/src/net/azib/ipscan/gui/AbstractModalDialog.java +++ b/src/net/azib/ipscan/gui/AbstractModalDialog.java @@ -91,8 +91,8 @@ public abstract class AbstractModalDialog { } public void handleEvent(Event event) { - if (list.isSelected(0)) { - // do not move anything if the first item is selected + if (list.getSelectionCount() == 0 || list.isSelected(0)) { + // do not move anything if either nothing is selected or only the first item is selected return; } @@ -121,8 +121,8 @@ public abstract class AbstractModalDialog { } public void handleEvent(Event event) { - if (list.isSelected(list.getItemCount() - 1)) { - // do not move anything if the last items is selected + if (list.getSelectionCount() == 0 || list.isSelected(list.getItemCount() - 1)) { + // do not move anything if either nothing is selected or only the last item is selected return; } diff --git a/src/net/azib/ipscan/gui/InputDialog.java b/src/net/azib/ipscan/gui/InputDialog.java index 3e0f4540..5d44c9fa 100755 --- a/src/net/azib/ipscan/gui/InputDialog.java +++ b/src/net/azib/ipscan/gui/InputDialog.java @@ -71,6 +71,8 @@ public class InputDialog extends AbstractModalDialog { shell.dispose(); } }); + + text.setFocus(); } private void setText(String text) { diff --git a/src/net/azib/ipscan/gui/MainMenu.java b/src/net/azib/ipscan/gui/MainMenu.java index 0d827510..c4adda03 100755 --- a/src/net/azib/ipscan/gui/MainMenu.java +++ b/src/net/azib/ipscan/gui/MainMenu.java @@ -108,7 +108,7 @@ public class MainMenu { initMenuItem(menu, "menu.commands.details", null, null, initListener(CommandsActions.Details.class)); initMenuItem(menu, null, null, null, null); initMenuItem(menu, "menu.commands.rescan", "Ctrl+R", new Integer(SWT.MOD1 | 'R'), null); - initMenuItem(menu, "menu.commands.delete", "Del", new Integer(SWT.DEL), initListener(CommandsActions.Delete.class)); + initMenuItem(menu, "menu.commands.delete", "Del", null, initListener(CommandsActions.Delete.class)); initMenuItem(menu, null, null, null, null); initMenuItem(menu, "menu.commands.copy", "Ctrl+C", new Integer(SWT.MOD1 | 'C'), initListener(CommandsActions.CopyIP.class)); initMenuItem(menu, "menu.commands.copyDetails", null, null, initListener(CommandsActions.CopyIPDetails.class)); diff --git a/src/net/azib/ipscan/gui/ResultTable.java b/src/net/azib/ipscan/gui/ResultTable.java index 28a239a5..20eb3711 100755 --- a/src/net/azib/ipscan/gui/ResultTable.java +++ b/src/net/azib/ipscan/gui/ResultTable.java @@ -75,6 +75,7 @@ public class ResultTable extends Table implements FetcherRegistryUpdateListener }; addListener(SWT.Traverse, detailsListener); addListener(SWT.MouseDoubleClick, detailsListener); + addListener(SWT.KeyDown, new CommandsActions.Delete(this)); addListener(SWT.SetData, new SetDataListener()); } diff --git a/src/net/azib/ipscan/gui/actions/CommandsActions.java b/src/net/azib/ipscan/gui/actions/CommandsActions.java index 574ac7a5..3b8539ad 100755 --- a/src/net/azib/ipscan/gui/actions/CommandsActions.java +++ b/src/net/azib/ipscan/gui/actions/CommandsActions.java @@ -54,6 +54,9 @@ public class CommandsActions { } public void handleEvent(Event event) { + // ignore other keys if this is a KeyDown event + if (event.type == SWT.KeyDown && event.keyCode != SWT.DEL) + return; checkSelection(resultTable); int firstSelection = resultTable.getSelectionIndex(); resultTable.remove(resultTable.getSelectionIndices()); diff --git a/src/net/azib/ipscan/gui/feeders/RandomFeederGUI.java b/src/net/azib/ipscan/gui/feeders/RandomFeederGUI.java index 80f8bc84..e9a5e480 100755 --- a/src/net/azib/ipscan/gui/feeders/RandomFeederGUI.java +++ b/src/net/azib/ipscan/gui/feeders/RandomFeederGUI.java @@ -5,8 +5,10 @@ package net.azib.ipscan.gui.feeders; import java.net.InetAddress; import java.net.UnknownHostException; +import java.util.logging.Logger; import net.azib.ipscan.config.Labels; +import net.azib.ipscan.config.LoggerFactory; import net.azib.ipscan.config.Platform; import net.azib.ipscan.core.InetAddressUtils; import net.azib.ipscan.feeders.Feeder; @@ -31,7 +33,9 @@ import org.eclipse.swt.widgets.Text; * @author anton */ public class RandomFeederGUI extends AbstractFeederGUI { - + + private static final Logger LOG = LoggerFactory.getLogger(); + private Label ipPrototypeLabel; private Text ipPrototypeText; @@ -104,12 +108,6 @@ public class RandomFeederGUI extends AbstractFeederGUI { ipMaskCombo.setLayoutData(formData); FeederActions.HostnameButton hostnameSelectionListener = new FeederActions.HostnameButton(hostnameText, ipPrototypeText); - try { - hostnameText.setText(InetAddress.getLocalHost().getHostName()); - } - catch (UnknownHostException e1) { - // leave hostnameText empty - } hostnameText.addTraverseListener(hostnameSelectionListener); formData = new FormData(105, SWT.DEFAULT); formData.top = new FormAttachment(ipPrototypeText); @@ -146,13 +144,20 @@ public class RandomFeederGUI extends AbstractFeederGUI { formData.right = new FormAttachment(ipMaskCombo, 0, SWT.RIGHT); countSpinner.setLayoutData(formData); - // fill the IP text with local IP address - try { - ipPrototypeText.setText(InetAddressUtils.getAddressByName(hostnameText.getText())); - } - catch (UnknownHostException e) { - // don't report any errors on initialization - } + // do this stuff asynchronously (to show GUI faster) + getDisplay().asyncExec(new Runnable() { + public void run() { + // fill the IP and hostname fields with local hostname and IP addresses + try { + hostnameText.setText(InetAddress.getLocalHost().getHostName()); + ipPrototypeText.setText(InetAddressUtils.getAddressByName(hostnameText.getText())); + } + catch (UnknownHostException e) { + // don't report any errors on initialization, leave fields empty + LOG.fine(e.toString()); + } + } + }); pack(); } diff --git a/src/net/azib/ipscan/gui/feeders/RangeFeederGUI.java b/src/net/azib/ipscan/gui/feeders/RangeFeederGUI.java index 299d7b3d..aa9ae4ee 100755 --- a/src/net/azib/ipscan/gui/feeders/RangeFeederGUI.java +++ b/src/net/azib/ipscan/gui/feeders/RangeFeederGUI.java @@ -100,13 +100,7 @@ public class RangeFeederGUI extends AbstractFeederGUI { formData.left = new FormAttachment(startIPText); formData.top = new FormAttachment(startIPText, 0, SWT.CENTER); toLabel.setLayoutData(formData); - - try { - endIPText.setText(InetAddress.getLocalHost().getHostAddress()); - } - catch (UnknownHostException e) { - // leave endIPText empty - } + formData = new FormData(105 + (Platform.MAC_OS ? 35 : 0), SWT.DEFAULT); formData.left = new FormAttachment(toLabel); endIPText.setLayoutData(formData); @@ -122,12 +116,7 @@ public class RangeFeederGUI extends AbstractFeederGUI { super.widgetSelected(event); } }; - try { - hostnameText.setText(InetAddress.getLocalHost().getHostName()); - } - catch (UnknownHostException e1) { - // leave hostnameText empty - } + hostnameText.addTraverseListener(hostnameListener); formData = new FormData(105, SWT.DEFAULT); formData.top = new FormAttachment(startIPText); @@ -173,16 +162,22 @@ public class RangeFeederGUI extends AbstractFeederGUI { formData.bottom = new FormAttachment(hostnameText, 0, SWT.BOTTOM); netmaskCombo.setLayoutData(formData); netmaskCombo.setToolTipText(Labels.getLabel("feeder.range.netmask.tooltip")); - - // fill the IP text with local IP address - try { - startIPText.setText(InetAddressUtils.getAddressByName(hostnameText.getText())); - endIPText.setText(startIPText.getText()); - } - catch (UnknownHostException e) { - // don't report any errors on initialization - LOG.fine(e.toString()); - } + + // do this stuff asynchronously (to show GUI faster) + getDisplay().asyncExec(new Runnable() { + public void run() { + // fill the IP and hostname fields with local hostname and IP addresses + try { + hostnameText.setText(InetAddress.getLocalHost().getHostName()); + startIPText.setText(InetAddressUtils.getAddressByName(hostnameText.getText())); + endIPText.setText(startIPText.getText()); + } + catch (UnknownHostException e) { + // don't report any errors on initialization, leave fields empty + LOG.fine(e.toString()); + } + } + }); pack(); }