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