Whitespace cleanup, while we're not yet merged into trunk yet.
This commit is contained in:
@ -13,40 +13,40 @@ import net.i2p.util.Log;
|
||||
|
||||
public class ExternalTrayManager extends TrayManager {
|
||||
|
||||
private final static Log log = new Log(ExternalTrayManager.class);
|
||||
private final static Log log = new Log(ExternalTrayManager.class);
|
||||
|
||||
protected ExternalTrayManager() {}
|
||||
protected ExternalTrayManager() {}
|
||||
|
||||
@Override
|
||||
public PopupMenu getMainMenu() {
|
||||
PopupMenu popup = new PopupMenu();
|
||||
@Override
|
||||
public PopupMenu getMainMenu() {
|
||||
PopupMenu popup = new PopupMenu();
|
||||
MenuItem startItem = new MenuItem(_("Start I2P"));
|
||||
startItem.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
new SwingWorker<Object, Object>() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
new SwingWorker<Object, Object>() {
|
||||
|
||||
@Override
|
||||
protected Object doInBackground() throws Exception {
|
||||
RouterManager.start();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done() {
|
||||
trayIcon.displayMessage(_("Starting"), _("I2P is starting!"), TrayIcon.MessageType.INFO);
|
||||
//Hide the tray icon.
|
||||
//We cannot stop the desktopgui program entirely,
|
||||
//since that risks killing the I2P process as well.
|
||||
tray.remove(trayIcon);
|
||||
}
|
||||
|
||||
}.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object doInBackground() throws Exception {
|
||||
RouterManager.start();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done() {
|
||||
trayIcon.displayMessage(_("Starting"), _("I2P is starting!"), TrayIcon.MessageType.INFO);
|
||||
//Hide the tray icon.
|
||||
//We cannot stop the desktopgui program entirely,
|
||||
//since that risks killing the I2P process as well.
|
||||
tray.remove(trayIcon);
|
||||
}
|
||||
|
||||
}.execute();
|
||||
}
|
||||
|
||||
});
|
||||
popup.add(startItem);
|
||||
return popup;
|
||||
}
|
||||
return popup;
|
||||
}
|
||||
}
|
||||
|
@ -16,13 +16,13 @@ public class InternalTrayManager extends TrayManager {
|
||||
|
||||
private final static Log log = new Log(InternalTrayManager.class);
|
||||
|
||||
protected InternalTrayManager() {}
|
||||
protected InternalTrayManager() {}
|
||||
|
||||
@Override
|
||||
public PopupMenu getMainMenu() {
|
||||
PopupMenu popup = new PopupMenu();
|
||||
|
||||
MenuItem browserLauncher = new MenuItem(_("Launch I2P Browser"));
|
||||
@Override
|
||||
public PopupMenu getMainMenu() {
|
||||
PopupMenu popup = new PopupMenu();
|
||||
|
||||
MenuItem browserLauncher = new MenuItem(_("Launch I2P Browser"));
|
||||
browserLauncher.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
@ -36,11 +36,11 @@ public class InternalTrayManager extends TrayManager {
|
||||
|
||||
@Override
|
||||
protected void done() {
|
||||
try {
|
||||
I2PDesktop.browse("http://localhost:7657");
|
||||
} catch (BrowseException e1) {
|
||||
log.log(Log.WARN, "Failed to open browser!", e1);
|
||||
}
|
||||
try {
|
||||
I2PDesktop.browse("http://localhost:7657");
|
||||
} catch (BrowseException e1) {
|
||||
log.log(Log.WARN, "Failed to open browser!", e1);
|
||||
}
|
||||
}
|
||||
|
||||
}.execute();
|
||||
@ -89,5 +89,5 @@ public class InternalTrayManager extends TrayManager {
|
||||
popup.add(stopItem);
|
||||
|
||||
return popup;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,15 +19,15 @@ import net.i2p.util.I2PProperties.I2PPropertyCallback;
|
||||
* 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).
|
||||
* @throws Exception
|
||||
*/
|
||||
/**
|
||||
* Start the tray icon code (loads tray icon in the tray area).
|
||||
* @throws Exception
|
||||
*/
|
||||
public void startUp() throws Exception {
|
||||
trayManager = TrayManager.getInstance();
|
||||
trayManager.startManager();
|
||||
@ -35,26 +35,26 @@ public class Main {
|
||||
if(RouterManager.inI2P()) {
|
||||
RouterManager.getRouterContext().addPropertyCallback(new I2PPropertyCallback() {
|
||||
|
||||
@Override
|
||||
public void propertyChanged(String arg0, String arg1) {
|
||||
if(arg0.equals(Translate.PROP_LANG)) {
|
||||
trayManager.languageChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void propertyChanged(String arg0, String arg1) {
|
||||
if(arg0.equals(Translate.PROP_LANG)) {
|
||||
trayManager.languageChanged();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
beginStartup(args);
|
||||
beginStartup(args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Main method launching the application.
|
||||
*/
|
||||
public static void beginStartup(String[] args) {
|
||||
System.setProperty("java.awt.headless", "false");
|
||||
System.setProperty("java.awt.headless", "false");
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
} catch (ClassNotFoundException ex) {
|
||||
@ -62,9 +62,9 @@ public class Main {
|
||||
} catch (InstantiationException ex) {
|
||||
log.log(Log.ERROR, null, ex);
|
||||
} catch (IllegalAccessException ex) {
|
||||
log.log(Log.ERROR, null, ex);
|
||||
log.log(Log.ERROR, null, ex);
|
||||
} catch (UnsupportedLookAndFeelException ex) {
|
||||
log.log(Log.ERROR, null, ex);
|
||||
log.log(Log.ERROR, null, ex);
|
||||
}
|
||||
|
||||
ConfigurationManager.getInstance().loadArguments(args);
|
||||
@ -78,10 +78,10 @@ public class Main {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
main.startUp();
|
||||
main.startUp();
|
||||
}
|
||||
catch(Exception e) {
|
||||
log.error("Failed while running desktopgui!", e);
|
||||
log.error("Failed while running desktopgui!", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,8 +30,8 @@ import net.i2p.util.Log;
|
||||
*/
|
||||
public abstract class TrayManager {
|
||||
|
||||
private static TrayManager instance = null;
|
||||
///The tray area, or null if unsupported
|
||||
private static TrayManager instance = null;
|
||||
///The tray area, or null if unsupported
|
||||
protected SystemTray tray = null;
|
||||
///Our tray icon, or null if unsupported
|
||||
protected TrayIcon trayIcon = null;
|
||||
@ -43,16 +43,16 @@ public abstract class TrayManager {
|
||||
protected TrayManager() {}
|
||||
|
||||
protected static TrayManager getInstance() {
|
||||
if(instance == null) {
|
||||
boolean inI2P = RouterManager.inI2P();
|
||||
if(inI2P) {
|
||||
instance = new InternalTrayManager();
|
||||
}
|
||||
else {
|
||||
instance = new ExternalTrayManager();
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
if(instance == null) {
|
||||
boolean inI2P = RouterManager.inI2P();
|
||||
if(inI2P) {
|
||||
instance = new InternalTrayManager();
|
||||
}
|
||||
else {
|
||||
instance = new ExternalTrayManager();
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,13 +65,13 @@ public abstract class TrayManager {
|
||||
try {
|
||||
tray.add(trayIcon);
|
||||
} catch (AWTException e) {
|
||||
log.log(Log.WARN, "Problem creating system tray icon!", e);
|
||||
log.log(Log.WARN, "Problem creating system tray icon!", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void languageChanged() {
|
||||
trayIcon.setPopupMenu(getMainMenu());
|
||||
trayIcon.setPopupMenu(getMainMenu());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,23 +4,23 @@ import net.i2p.I2PAppContext;
|
||||
import net.i2p.util.Translate;
|
||||
|
||||
public class DesktopguiTranslator {
|
||||
|
||||
|
||||
private static final String BUNDLE_NAME = "net.i2p.desktopgui.messages";
|
||||
|
||||
|
||||
private static I2PAppContext ctx;
|
||||
|
||||
private static I2PAppContext getRouterContext() {
|
||||
if(ctx == null) {
|
||||
ctx = I2PAppContext.getCurrentContext();
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
|
||||
|
||||
private static I2PAppContext getRouterContext() {
|
||||
if(ctx == null) {
|
||||
ctx = I2PAppContext.getCurrentContext();
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
|
||||
public static String _(String s) {
|
||||
return Translate.getString(s, getRouterContext(), BUNDLE_NAME);
|
||||
return Translate.getString(s, getRouterContext(), BUNDLE_NAME);
|
||||
}
|
||||
|
||||
public static String _(String s, Object o) {
|
||||
return Translate.getString(s, o, getRouterContext(), BUNDLE_NAME);
|
||||
return Translate.getString(s, o, getRouterContext(), BUNDLE_NAME);
|
||||
}
|
||||
}
|
||||
|
@ -38,61 +38,61 @@ public class RouterManager {
|
||||
try {
|
||||
return getRouterContext().router();
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to get router. Why did we request it if no RouterContext is available?", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start an I2P router instance.
|
||||
* This method has limited knowledge
|
||||
* (there is no I2P instance running to collect information from).
|
||||
*
|
||||
* It determines the I2P location using the I2PAppContext.
|
||||
*/
|
||||
public static void start() {
|
||||
try {
|
||||
//TODO: set/get PID
|
||||
String separator = System.getProperty("file.separator");
|
||||
String location = getAppContext().getBaseDir().getAbsolutePath();
|
||||
|
||||
Runtime.getRuntime().exec(location + separator + "i2psvc " + location + separator + "wrapper.config");
|
||||
} catch (IOException e) {
|
||||
log.log(Log.WARN, "Failed to start I2P", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restart the running I2P instance.
|
||||
*/
|
||||
public static void restart() {
|
||||
if(inI2P()) {
|
||||
getRouter().restart();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the running I2P instance.
|
||||
*/
|
||||
public static void shutDown() {
|
||||
if(inI2P()) {
|
||||
Thread t = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
WrapperManager.signalStopped(Router.EXIT_HARD);
|
||||
}
|
||||
|
||||
});
|
||||
t.start();
|
||||
getRouter().shutdown(Router.EXIT_HARD);
|
||||
}
|
||||
log.error("Failed to get router. Why did we request it if no RouterContext is available?", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start an I2P router instance.
|
||||
* This method has limited knowledge
|
||||
* (there is no I2P instance running to collect information from).
|
||||
*
|
||||
* It determines the I2P location using the I2PAppContext.
|
||||
*/
|
||||
public static void start() {
|
||||
try {
|
||||
//TODO: set/get PID
|
||||
String separator = System.getProperty("file.separator");
|
||||
String location = getAppContext().getBaseDir().getAbsolutePath();
|
||||
|
||||
Runtime.getRuntime().exec(location + separator + "i2psvc " + location + separator + "wrapper.config");
|
||||
} catch (IOException e) {
|
||||
log.log(Log.WARN, "Failed to start I2P", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restart the running I2P instance.
|
||||
*/
|
||||
public static void restart() {
|
||||
if(inI2P()) {
|
||||
getRouter().restart();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the running I2P instance.
|
||||
*/
|
||||
public static void shutDown() {
|
||||
if(inI2P()) {
|
||||
Thread t = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
WrapperManager.signalStopped(Router.EXIT_HARD);
|
||||
}
|
||||
|
||||
});
|
||||
t.start();
|
||||
getRouter().shutdown(Router.EXIT_HARD);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we are running inside I2P.
|
||||
*/
|
||||
public static boolean inI2P() {
|
||||
return context.isRouterContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we are running inside I2P.
|
||||
*/
|
||||
public static boolean inI2P() {
|
||||
return context.isRouterContext();
|
||||
}
|
||||
}
|
||||
|
@ -5,19 +5,19 @@ public class BrowseException extends Exception {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public BrowseException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public BrowseException(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
public BrowseException(String s, Throwable t) {
|
||||
super(s, t);
|
||||
}
|
||||
|
||||
public BrowseException(Throwable t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
super();
|
||||
}
|
||||
|
||||
public BrowseException(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
public BrowseException(String s, Throwable t) {
|
||||
super(s, t);
|
||||
}
|
||||
|
||||
public BrowseException(Throwable t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
}
|
@ -11,11 +11,11 @@ import net.i2p.desktopgui.router.RouterManager;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
public class I2PDesktop {
|
||||
|
||||
private final static Log log = new Log(I2PDesktop.class);
|
||||
|
||||
public static void browse(String url) throws BrowseException {
|
||||
if(Desktop.isDesktopSupported()) {
|
||||
|
||||
private final static Log log = new Log(I2PDesktop.class);
|
||||
|
||||
public static void browse(String url) throws BrowseException {
|
||||
if(Desktop.isDesktopSupported()) {
|
||||
Desktop desktop = Desktop.getDesktop();
|
||||
if(desktop.isSupported(Action.BROWSE)) {
|
||||
try {
|
||||
@ -25,11 +25,11 @@ public class I2PDesktop {
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new BrowseException();
|
||||
throw new BrowseException();
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new BrowseException();
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new BrowseException();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user