* Switch to I2P logging.
* Add javadoc where necessary. * Add javadoc build target. * Some code cleanup.
This commit is contained in:
@ -6,12 +6,14 @@
|
|||||||
<property name="dist" location="dist"/>
|
<property name="dist" location="dist"/>
|
||||||
<property name="jar" value="desktopgui.jar"/>
|
<property name="jar" value="desktopgui.jar"/>
|
||||||
<property name="resources" value="resources"/>
|
<property name="resources" value="resources"/>
|
||||||
|
<property name="javadoc" value="javadoc"/>
|
||||||
|
|
||||||
<property name="javac.compilerargs" value=""/>
|
<property name="javac.compilerargs" value=""/>
|
||||||
|
|
||||||
<target name="init">
|
<target name="init">
|
||||||
<mkdir dir="${build}"/>
|
<mkdir dir="${build}"/>
|
||||||
<mkdir dir="${build}/${resources}"/>
|
<mkdir dir="${build}/${resources}"/>
|
||||||
|
<mkdir dir="${build}/${javadoc}"/>
|
||||||
<mkdir dir="${dist}"/>
|
<mkdir dir="${dist}"/>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
@ -44,6 +46,22 @@
|
|||||||
</jar>
|
</jar>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
|
<target name="javadoc">
|
||||||
|
<mkdir dir="${build}" />
|
||||||
|
<mkdir dir="${build}/${javadoc}" />
|
||||||
|
<javadoc
|
||||||
|
sourcepath="${src}" destdir="${build}/${javadoc}"
|
||||||
|
packagenames="*"
|
||||||
|
use="true"
|
||||||
|
splitindex="true"
|
||||||
|
windowtitle="Desktopgui">
|
||||||
|
<classpath>
|
||||||
|
<pathelement location="../../router/java/build/router.jar" />
|
||||||
|
<pathelement location="../../core/java/build/i2p.jar" />
|
||||||
|
</classpath>
|
||||||
|
</javadoc>
|
||||||
|
</target>
|
||||||
|
|
||||||
<target name="dist" depends="jar" />
|
<target name="dist" depends="jar" />
|
||||||
<target name="all" depends="jar" />
|
<target name="all" depends="jar" />
|
||||||
</project>
|
</project>
|
||||||
|
@ -7,37 +7,40 @@ package net.i2p.desktopgui;
|
|||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.UnsupportedLookAndFeelException;
|
import javax.swing.UnsupportedLookAndFeelException;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
import net.i2p.desktopgui.util.*;
|
import net.i2p.desktopgui.util.*;
|
||||||
|
import net.i2p.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main class of the application.
|
* The main class of the application.
|
||||||
*/
|
*/
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
|
///Manages the lifetime of the tray icon.
|
||||||
|
private TrayManager trayManager = null;
|
||||||
|
private final static Log log = new Log(Main.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start the tray icon code (loads tray icon in the tray area).
|
* Start the tray icon code (loads tray icon in the tray area).
|
||||||
*/
|
*/
|
||||||
private void startUp() {
|
private void startUp() {
|
||||||
trayManager = new TrayManager();
|
trayManager = TrayManager.getInstance();
|
||||||
|
trayManager.startManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main method launching the application.
|
* Main method launching the application.
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.setProperty("java.awt.headless", "false"); //Make sure I2P is running in GUI mode for our application
|
|
||||||
try {
|
try {
|
||||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||||
} catch (ClassNotFoundException ex) {
|
} catch (ClassNotFoundException ex) {
|
||||||
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
|
log.log(Log.ERROR, null, ex);
|
||||||
} catch (InstantiationException ex) {
|
} catch (InstantiationException ex) {
|
||||||
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
|
log.log(Log.ERROR, null, ex);
|
||||||
} catch (IllegalAccessException ex) {
|
} catch (IllegalAccessException ex) {
|
||||||
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
|
log.log(Log.ERROR, null, ex);
|
||||||
} catch (UnsupportedLookAndFeelException ex) {
|
} catch (UnsupportedLookAndFeelException ex) {
|
||||||
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
|
log.log(Log.ERROR, null, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigurationManager.getInstance().loadArguments(args);
|
ConfigurationManager.getInstance().loadArguments(args);
|
||||||
@ -78,6 +81,4 @@ public class Main {
|
|||||||
t.start();
|
t.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
///Manages the lifetime of the tray icon.
|
|
||||||
private TrayManager trayManager = null;
|
|
||||||
}
|
}
|
||||||
|
@ -9,43 +9,54 @@ import java.awt.SystemTray;
|
|||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
import java.awt.TrayIcon;
|
import java.awt.TrayIcon;
|
||||||
import java.awt.Desktop.Action;
|
import java.awt.Desktop.Action;
|
||||||
import java.awt.TrayIcon.MessageType;
|
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import javax.swing.SwingWorker;
|
import javax.swing.SwingWorker;
|
||||||
|
|
||||||
import net.i2p.desktopgui.router.RouterManager;
|
import net.i2p.desktopgui.router.RouterManager;
|
||||||
import net.i2p.desktopgui.util.*;
|
import net.i2p.desktopgui.util.ConfigurationManager;
|
||||||
import net.i2p.router.Router;
|
import net.i2p.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages the tray icon life.
|
* Manages the tray icon life.
|
||||||
*/
|
*/
|
||||||
public class TrayManager {
|
public class TrayManager {
|
||||||
|
|
||||||
|
private static TrayManager instance = null;
|
||||||
///The tray area, or null if unsupported
|
///The tray area, or null if unsupported
|
||||||
private SystemTray tray = null;
|
private SystemTray tray = null;
|
||||||
///Our tray icon, or null if unsupported
|
///Our tray icon, or null if unsupported
|
||||||
private TrayIcon trayIcon = null;
|
private TrayIcon trayIcon = null;
|
||||||
|
private final static Log log = new Log(TrayManager.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiate tray icon and add it to the system tray.
|
* Instantiate tray manager.
|
||||||
*/
|
*/
|
||||||
public TrayManager() {
|
private TrayManager() {}
|
||||||
|
|
||||||
|
public static TrayManager getInstance() {
|
||||||
|
if(instance == null) {
|
||||||
|
instance = new TrayManager();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the tray icon to the system tray and start everything up.
|
||||||
|
*/
|
||||||
|
public void startManager() {
|
||||||
if(SystemTray.isSupported()) {
|
if(SystemTray.isSupported()) {
|
||||||
tray = SystemTray.getSystemTray();
|
tray = SystemTray.getSystemTray();
|
||||||
trayIcon = new TrayIcon(getTrayImage(), "I2P", getMainMenu());
|
trayIcon = new TrayIcon(getTrayImage(), "I2P", getMainMenu());
|
||||||
try {
|
try {
|
||||||
tray.add(trayIcon);
|
tray.add(trayIcon);
|
||||||
} catch (AWTException e) {
|
} catch (AWTException e) {
|
||||||
// TODO Auto-generated catch block
|
log.log(Log.WARN, "Problem creating system tray icon!", e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,11 +89,9 @@ public class TrayManager {
|
|||||||
try {
|
try {
|
||||||
desktop.browse(new URI("http://localhost:7657"));
|
desktop.browse(new URI("http://localhost:7657"));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO Auto-generated catch block
|
log.log(Log.WARN, "Failed to open browser!", e);
|
||||||
e.printStackTrace();
|
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
// TODO Auto-generated catch block
|
log.log(Log.WARN, "Failed to open browser!", e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -5,9 +5,17 @@ import java.io.IOException;
|
|||||||
import net.i2p.desktopgui.util.ConfigurationManager;
|
import net.i2p.desktopgui.util.ConfigurationManager;
|
||||||
import net.i2p.router.Router;
|
import net.i2p.router.Router;
|
||||||
import net.i2p.router.RouterContext;
|
import net.i2p.router.RouterContext;
|
||||||
|
import net.i2p.util.Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle communications with the router instance.
|
||||||
|
* @author mathias
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class RouterManager {
|
public class RouterManager {
|
||||||
|
|
||||||
|
private final static Log log = new Log(RouterManager.class);
|
||||||
|
|
||||||
private static Router getRouter() {
|
private static Router getRouter() {
|
||||||
return RouterContext.listContexts().get(0).router();
|
return RouterContext.listContexts().get(0).router();
|
||||||
}
|
}
|
||||||
@ -27,8 +35,7 @@ public class RouterManager {
|
|||||||
//TODO: crossplatform
|
//TODO: crossplatform
|
||||||
Runtime.getRuntime().exec(location + "/i2psvc " + location + "/wrapper.config");
|
Runtime.getRuntime().exec(location + "/i2psvc " + location + "/wrapper.config");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO Auto-generated catch block
|
log.log(Log.WARN, "Failed to start I2P", e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package net.i2p.desktopgui.util;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manage the configuration of desktopgui.
|
* Manage the configuration of desktopgui.
|
||||||
@ -53,16 +52,31 @@ public class ConfigurationManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a boolean configuration.
|
||||||
|
* @param arg The key we wish to add as a configuration.
|
||||||
|
*/
|
||||||
public void loadBooleanConfiguration(String arg) {
|
public void loadBooleanConfiguration(String arg) {
|
||||||
booleanConfigurations.put(arg, Boolean.TRUE);
|
booleanConfigurations.put(arg, Boolean.TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a String configuration which consists a key and a value.
|
||||||
|
* @param arg String of the form substring1=substring2.
|
||||||
|
* @param equalsPosition Position of the '=' element.
|
||||||
|
*/
|
||||||
public void loadStringConfiguration(String arg, int equalsPosition) {
|
public void loadStringConfiguration(String arg, int equalsPosition) {
|
||||||
String key = arg.substring(0, equalsPosition);
|
String key = arg.substring(0, equalsPosition);
|
||||||
String value = arg.substring(equalsPosition+1);
|
String value = arg.substring(equalsPosition+1);
|
||||||
stringConfigurations.put(key, value);
|
stringConfigurations.put(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a specific boolean configuration exists.
|
||||||
|
* @param arg The key for the configuration.
|
||||||
|
* @param defaultValue If the configuration is not found, we use a default value.
|
||||||
|
* @return The value of a configuration: true if found, defaultValue if not found.
|
||||||
|
*/
|
||||||
public boolean getBooleanConfiguration(String arg, boolean defaultValue) {
|
public boolean getBooleanConfiguration(String arg, boolean defaultValue) {
|
||||||
Boolean value = ((Boolean) booleanConfigurations.get("startWithI2P"));
|
Boolean value = ((Boolean) booleanConfigurations.get("startWithI2P"));
|
||||||
System.out.println(value);
|
System.out.println(value);
|
||||||
@ -72,6 +86,12 @@ public class ConfigurationManager {
|
|||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a specific String configuration.
|
||||||
|
* @param arg The key for the configuration.
|
||||||
|
* @param defaultValue If the configuration is not found, we use a default value.
|
||||||
|
* @return The value of the configuration, or the defaultValue.
|
||||||
|
*/
|
||||||
public String getStringConfiguration(String arg, String defaultValue) {
|
public String getStringConfiguration(String arg, String defaultValue) {
|
||||||
String value = stringConfigurations.get(arg);
|
String value = stringConfigurations.get(arg);
|
||||||
System.out.println(value);
|
System.out.println(value);
|
||||||
|
Reference in New Issue
Block a user