mirror of
https://github.com/angryip/ipscan.git
synced 2025-10-26 11:18:17 +00:00
git-svn-id: https://ipscan.svn.sourceforge.net/svnroot/ipscan/trunk@407 375186e5-ef17-0410-b0b6-91563547dcda
141 lines
3.9 KiB
Java
Executable File
141 lines
3.9 KiB
Java
Executable File
/**
|
|
* This file is a part of Angry IP Scanner source code,
|
|
* see http://www.azib.net/ for more information.
|
|
* Licensed under GPLv2.
|
|
*/
|
|
package net.azib.ipscan.gui.actions;
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.IOException;
|
|
import java.io.InputStreamReader;
|
|
import java.net.URL;
|
|
import java.net.URLConnection;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
|
|
import net.azib.ipscan.config.Labels;
|
|
import net.azib.ipscan.config.Version;
|
|
import net.azib.ipscan.gui.AboutDialog;
|
|
import net.azib.ipscan.gui.GettingStartedDialog;
|
|
import net.azib.ipscan.gui.StatusBar;
|
|
|
|
import org.eclipse.swt.SWT;
|
|
import org.eclipse.swt.widgets.Display;
|
|
import org.eclipse.swt.widgets.Event;
|
|
import org.eclipse.swt.widgets.Listener;
|
|
import org.eclipse.swt.widgets.MessageBox;
|
|
|
|
/**
|
|
* HelpActions
|
|
*
|
|
* @author Anton Keks
|
|
*/
|
|
public class HelpActions {
|
|
public static final class GettingStarted implements Listener {
|
|
public void handleEvent(Event event) {
|
|
new GettingStartedDialog().open();
|
|
}
|
|
}
|
|
|
|
public static final class About implements Listener {
|
|
private AboutDialog aboutDialog;
|
|
|
|
public About(AboutDialog aboutDialog) {
|
|
super();
|
|
this.aboutDialog = aboutDialog;
|
|
}
|
|
|
|
public void handleEvent(Event event) {
|
|
aboutDialog.open();
|
|
}
|
|
}
|
|
|
|
public static final class Website implements Listener {
|
|
public void handleEvent(Event event) {
|
|
BrowserLauncher.openURL(Version.WEBSITE);
|
|
}
|
|
}
|
|
|
|
public static final class FAQ implements Listener {
|
|
public void handleEvent(Event event) {
|
|
BrowserLauncher.openURL(Version.FAQ_URL);
|
|
}
|
|
}
|
|
|
|
public static final class Plugins implements Listener {
|
|
public void handleEvent(Event event) {
|
|
BrowserLauncher.openURL(Version.PLUGINS_URL);
|
|
}
|
|
}
|
|
|
|
public static final class CheckVersion implements Listener {
|
|
private final StatusBar statusBar;
|
|
|
|
public CheckVersion(StatusBar statusBar) {
|
|
this.statusBar = statusBar;
|
|
}
|
|
|
|
public void handleEvent(final Event event) {
|
|
check();
|
|
}
|
|
|
|
public void check() {
|
|
statusBar.setStatusText(Labels.getLabel("state.retrievingVersion"));
|
|
|
|
Runnable checkVersionCode = new Runnable() {
|
|
public void run() {
|
|
BufferedReader reader = null;
|
|
String message = null;
|
|
int messageStyle = SWT.ICON_WARNING;
|
|
try {
|
|
URL url = new URL(Version.LATEST_VERSION_URL);
|
|
URLConnection conn = url.openConnection();
|
|
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
|
|
|
String latestVersion = reader.readLine();
|
|
latestVersion = latestVersion.substring(latestVersion.indexOf(' ')+1);
|
|
|
|
if (!Version.getVersion().equals(latestVersion)) {
|
|
message = Labels.getLabel("text.version.old");
|
|
message = message.replaceFirst("%LATEST", latestVersion);
|
|
message = message.replaceFirst("%VERSION", Version.getVersion());
|
|
messageStyle = SWT.ICON_QUESTION | SWT.YES | SWT.NO;
|
|
}
|
|
else {
|
|
message = Labels.getLabel("text.version.latest");
|
|
messageStyle = SWT.ICON_INFORMATION;
|
|
}
|
|
}
|
|
catch (Exception e) {
|
|
message = Labels.getLabel("exception.UserErrorException.version.latestFailed");
|
|
Logger.getLogger(getClass().getName()).log(Level.WARNING, message, e);
|
|
}
|
|
finally {
|
|
try {
|
|
if (reader != null)
|
|
reader.close();
|
|
}
|
|
catch (IOException e) {}
|
|
|
|
// show the box in the SWT thread
|
|
final String messageToShow = message;
|
|
final int messageStyleToShow = messageStyle;
|
|
Display.getDefault().asyncExec(new Runnable() {
|
|
public void run() {
|
|
statusBar.setStatusText(null);
|
|
MessageBox messageBox = new MessageBox(statusBar.getShell(), messageStyleToShow);
|
|
messageBox.setText(Version.getFullName());
|
|
messageBox.setMessage(messageToShow);
|
|
if (messageBox.open() == SWT.YES) {
|
|
BrowserLauncher.openURL(Version.DOWNLOAD_URL);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
};
|
|
new Thread(checkVersionCode).start();
|
|
}
|
|
}
|
|
}
|