* 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="jar" value="desktopgui.jar"/>
|
||||
<property name="resources" value="resources"/>
|
||||
<property name="javadoc" value="javadoc"/>
|
||||
|
||||
<property name="javac.compilerargs" value=""/>
|
||||
|
||||
<target name="init">
|
||||
<mkdir dir="${build}"/>
|
||||
<mkdir dir="${build}/${resources}"/>
|
||||
<mkdir dir="${build}/${javadoc}"/>
|
||||
<mkdir dir="${dist}"/>
|
||||
</target>
|
||||
|
||||
@ -44,6 +46,22 @@
|
||||
</jar>
|
||||
</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="all" depends="jar" />
|
||||
</project>
|
||||
|
@ -7,37 +7,40 @@ package net.i2p.desktopgui;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.UnsupportedLookAndFeelException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import net.i2p.desktopgui.util.*;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
* The main class of the application.
|
||||
*/
|
||||
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).
|
||||
*/
|
||||
private void startUp() {
|
||||
trayManager = new TrayManager();
|
||||
trayManager = TrayManager.getInstance();
|
||||
trayManager.startManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* Main method launching the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
System.setProperty("java.awt.headless", "false"); //Make sure I2P is running in GUI mode for our application
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
} catch (ClassNotFoundException ex) {
|
||||
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
|
||||
log.log(Log.ERROR, null, ex);
|
||||
} catch (InstantiationException ex) {
|
||||
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
|
||||
log.log(Log.ERROR, null, ex);
|
||||
} catch (IllegalAccessException ex) {
|
||||
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
|
||||
log.log(Log.ERROR, null, ex);
|
||||
} catch (UnsupportedLookAndFeelException ex) {
|
||||
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
|
||||
log.log(Log.ERROR, null, ex);
|
||||
}
|
||||
|
||||
ConfigurationManager.getInstance().loadArguments(args);
|
||||
@ -78,6 +81,4 @@ public class Main {
|
||||
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.TrayIcon;
|
||||
import java.awt.Desktop.Action;
|
||||
import java.awt.TrayIcon.MessageType;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.swing.SwingWorker;
|
||||
|
||||
import net.i2p.desktopgui.router.RouterManager;
|
||||
import net.i2p.desktopgui.util.*;
|
||||
import net.i2p.router.Router;
|
||||
import net.i2p.desktopgui.util.ConfigurationManager;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
* Manages the tray icon life.
|
||||
*/
|
||||
public class TrayManager {
|
||||
|
||||
private static TrayManager instance = null;
|
||||
///The tray area, or null if unsupported
|
||||
private SystemTray tray = null;
|
||||
///Our tray icon, or null if unsupported
|
||||
private TrayIcon trayIcon = null;
|
||||
private final static Log log = new Log(TrayManager.class);
|
||||
|
||||
/**
|
||||
* Instantiate tray manager.
|
||||
*/
|
||||
private TrayManager() {}
|
||||
|
||||
public static TrayManager getInstance() {
|
||||
if(instance == null) {
|
||||
instance = new TrayManager();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate tray icon and add it to the system tray.
|
||||
* Add the tray icon to the system tray and start everything up.
|
||||
*/
|
||||
public TrayManager() {
|
||||
public void startManager() {
|
||||
if(SystemTray.isSupported()) {
|
||||
tray = SystemTray.getSystemTray();
|
||||
trayIcon = new TrayIcon(getTrayImage(), "I2P", getMainMenu());
|
||||
try {
|
||||
tray.add(trayIcon);
|
||||
} catch (AWTException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
log.log(Log.WARN, "Problem creating system tray icon!", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -78,11 +89,9 @@ public class TrayManager {
|
||||
try {
|
||||
desktop.browse(new URI("http://localhost:7657"));
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
log.log(Log.WARN, "Failed to open browser!", e);
|
||||
} catch (URISyntaxException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
log.log(Log.WARN, "Failed to open browser!", e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -5,9 +5,17 @@ import java.io.IOException;
|
||||
import net.i2p.desktopgui.util.ConfigurationManager;
|
||||
import net.i2p.router.Router;
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
* Handle communications with the router instance.
|
||||
* @author mathias
|
||||
*
|
||||
*/
|
||||
public class RouterManager {
|
||||
|
||||
private final static Log log = new Log(RouterManager.class);
|
||||
|
||||
private static Router getRouter() {
|
||||
return RouterContext.listContexts().get(0).router();
|
||||
}
|
||||
@ -27,8 +35,7 @@ public class RouterManager {
|
||||
//TODO: crossplatform
|
||||
Runtime.getRuntime().exec(location + "/i2psvc " + location + "/wrapper.config");
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
log.log(Log.WARN, "Failed to start I2P", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package net.i2p.desktopgui.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
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) {
|
||||
String key = arg.substring(0, equalsPosition);
|
||||
String value = arg.substring(equalsPosition+1);
|
||||
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) {
|
||||
Boolean value = ((Boolean) booleanConfigurations.get("startWithI2P"));
|
||||
System.out.println(value);
|
||||
@ -72,6 +86,12 @@ public class ConfigurationManager {
|
||||
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) {
|
||||
String value = stringConfigurations.get(arg);
|
||||
System.out.println(value);
|
||||
|
Reference in New Issue
Block a user