diff --git a/apps/desktopgui/src/net/i2p/desktopgui/ExternalTrayManager.java b/apps/desktopgui/src/net/i2p/desktopgui/ExternalTrayManager.java index e15e5c08b553de3d177d74f0047a2944f949ffce..cf97d255b79d5b33ee8f79efdc5bef7d3c3a6830 100644 --- a/apps/desktopgui/src/net/i2p/desktopgui/ExternalTrayManager.java +++ b/apps/desktopgui/src/net/i2p/desktopgui/ExternalTrayManager.java @@ -20,8 +20,8 @@ import net.i2p.desktopgui.router.RouterManager; */ class ExternalTrayManager extends TrayManager { - public ExternalTrayManager(I2PAppContext ctx) { - super(ctx); + public ExternalTrayManager(I2PAppContext ctx, Main main) { + super(ctx, main); } @Override diff --git a/apps/desktopgui/src/net/i2p/desktopgui/InternalTrayManager.java b/apps/desktopgui/src/net/i2p/desktopgui/InternalTrayManager.java index 90017c0353222588cfa7bb7c3912c4888944587c..70fb2c553bd537ee84173fcbd0090783191e4552 100644 --- a/apps/desktopgui/src/net/i2p/desktopgui/InternalTrayManager.java +++ b/apps/desktopgui/src/net/i2p/desktopgui/InternalTrayManager.java @@ -6,7 +6,6 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.SwingWorker; -import net.i2p.desktopgui.gui.DesktopguiConfigurationFrame; import net.i2p.desktopgui.router.RouterManager; import net.i2p.desktopgui.util.BrowseException; @@ -24,8 +23,8 @@ class InternalTrayManager extends TrayManager { private final RouterContext _context; private final Log log; - public InternalTrayManager(RouterContext ctx) { - super(ctx); + public InternalTrayManager(RouterContext ctx, Main main) { + super(ctx, main); _context = ctx; log = ctx.logManager().getLog(InternalTrayManager.class); } @@ -58,8 +57,9 @@ class InternalTrayManager extends TrayManager { }.execute(); } }); - MenuItem desktopguiConfigurationLauncher = new MenuItem(_t("Configure desktopgui")); - desktopguiConfigurationLauncher.addActionListener(new ActionListener() { + PopupMenu desktopguiConfigurationLauncher = new PopupMenu(_t("Configure I2P System Tray")); + MenuItem configSubmenu = new MenuItem(_t("Disable")); + configSubmenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { @@ -67,7 +67,7 @@ class InternalTrayManager extends TrayManager { @Override protected Object doInBackground() throws Exception { - new DesktopguiConfigurationFrame(_context).setVisible(true); + configureDesktopgui(false); return null; } @@ -114,6 +114,7 @@ class InternalTrayManager extends TrayManager { popup.add(browserLauncher); popup.addSeparator(); + desktopguiConfigurationLauncher.add(configSubmenu); popup.add(desktopguiConfigurationLauncher); popup.addSeparator(); popup.add(restartItem); @@ -121,4 +122,22 @@ class InternalTrayManager extends TrayManager { return popup; } + + /** + * @since 0.9.26 from removed gui/DesktopguiConfigurationFrame + */ + private void configureDesktopgui(boolean enable) { + String property = "desktopgui.enabled"; + String value = Boolean.toString(enable); + try { + + _context.router().saveConfig(property, value); + if (!enable) { + // TODO popup that explains how to re-enable in console + _main.shutdown(null); + } + } catch (Exception ex) { + log.error("Error saving config", ex); + } + } } diff --git a/apps/desktopgui/src/net/i2p/desktopgui/Main.java b/apps/desktopgui/src/net/i2p/desktopgui/Main.java index 4592ae7b166fcfb03ecaf3cf53b926e7b0ad6d9d..76e5f2c573740b5b09e69c9868ab21b9a3a36d90 100644 --- a/apps/desktopgui/src/net/i2p/desktopgui/Main.java +++ b/apps/desktopgui/src/net/i2p/desktopgui/Main.java @@ -5,8 +5,6 @@ package net.i2p.desktopgui; */ import javax.swing.SwingUtilities; -import javax.swing.UIManager; -import javax.swing.UnsupportedLookAndFeelException; import net.i2p.I2PAppContext; import net.i2p.app.ClientAppManager; @@ -63,9 +61,9 @@ public class Main implements RouterApp { private synchronized void startUp() throws Exception { final TrayManager trayManager; if (_context != null) - trayManager = new InternalTrayManager(_context); + trayManager = new InternalTrayManager(_context, this); else - trayManager = new ExternalTrayManager(_appContext); + trayManager = new ExternalTrayManager(_appContext, this); trayManager.startManager(); _trayManager = trayManager; changeState(RUNNING); @@ -105,34 +103,7 @@ public class Main implements RouterApp { changeState(START_FAILED, "Headless environment: not starting desktopgui!", null); return; } - try { - //UIManager.LookAndFeelInfo[] lafs = UIManager.getInstalledLookAndFeels(); - //for (int i = 0; i < lafs.length; i++) { - // System.out.println("LAF " + i + ": " + lafs[i].getName() + ' ' + lafs[i].getClassName()); - //} - String laf = UIManager.getSystemLookAndFeelClassName(); - //System.out.println("Default: " + laf); - UIManager.setLookAndFeel(laf); - //laf = UIManager.getCrossPlatformLookAndFeelClassName(); - //System.out.println("Cross-Platform: " + laf); - //UIManager.setLookAndFeel(laf); - //UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel"); - } catch (ClassNotFoundException ex) { - log.log(Log.ERROR, null, ex); - } catch (InstantiationException ex) { - log.log(Log.ERROR, null, ex); - } catch (IllegalAccessException ex) { - log.log(Log.ERROR, null, ex); - } catch (UnsupportedLookAndFeelException ex) { - log.log(Log.ERROR, null, ex); - } catch (Error ex) { - // on permissions error (different user) - // Exception in thread "main" java.lang.InternalError: Can't connect to X11 window server using ':0' as the value of the DISPLAY variable. - log.log(Log.ERROR, "No permissions? Different user?", ex); - changeState(START_FAILED, "No permissions? Different user?", new RuntimeException(ex)); - return; - } - + // TODO process args with getopt if needed if (_context == null) diff --git a/apps/desktopgui/src/net/i2p/desktopgui/TrayManager.java b/apps/desktopgui/src/net/i2p/desktopgui/TrayManager.java index ac0242dd67ca417526fac2e35c45492671137723..31b7569d3c2afd901cfcad5c0c67ff6145a06e0a 100644 --- a/apps/desktopgui/src/net/i2p/desktopgui/TrayManager.java +++ b/apps/desktopgui/src/net/i2p/desktopgui/TrayManager.java @@ -18,6 +18,7 @@ import net.i2p.util.SystemVersion; abstract class TrayManager { protected final I2PAppContext _appContext; + protected final Main _main; ///The tray area, or null if unsupported protected SystemTray tray; ///Our tray icon, or null if unsupported @@ -26,8 +27,9 @@ abstract class TrayManager { /** * Instantiate tray manager. */ - protected TrayManager(I2PAppContext ctx) { + protected TrayManager(I2PAppContext ctx, Main main) { _appContext = ctx; + _main = main; } /** diff --git a/apps/desktopgui/src/net/i2p/desktopgui/gui/DesktopguiConfigurationFrame.java b/apps/desktopgui/src/net/i2p/desktopgui/gui/DesktopguiConfigurationFrame.java deleted file mode 100644 index 285b63927b44813751cfc001624ac3b38539fadc..0000000000000000000000000000000000000000 --- a/apps/desktopgui/src/net/i2p/desktopgui/gui/DesktopguiConfigurationFrame.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -/* - * ConfigurationFrame.java - * - * Created on Feb 16, 2011, 8:03:14 AM - */ - -package net.i2p.desktopgui.gui; - -import java.util.logging.Level; -import java.util.logging.Logger; - -import net.i2p.desktopgui.i18n.DesktopguiTranslator; -import net.i2p.desktopgui.router.RouterManager; -import net.i2p.router.RouterContext; - -/** - * - * @author mathias - */ -public class DesktopguiConfigurationFrame extends javax.swing.JFrame { - - private final RouterContext _context; - - /** Creates new form ConfigurationFrame */ - public DesktopguiConfigurationFrame(RouterContext ctx) { - _context = ctx; - initComponents(); - } - - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. - */ - // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents - private void initComponents() { - - desktopguiEnabled = new javax.swing.JCheckBox(); - okButton = new javax.swing.JButton(); - cancelButton = new javax.swing.JButton(); - - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); - setTitle(_t("Tray icon configuration")); - - desktopguiEnabled.setSelected(true); - desktopguiEnabled.setText(_t("Should tray icon be enabled?")); - desktopguiEnabled.setActionCommand("shouldDesktopguiBeEnabled"); - - okButton.setText("OK"); - okButton.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseReleased(java.awt.event.MouseEvent evt) { - okButtonMouseReleased(evt); - } - }); - - cancelButton.setText("Cancel"); - cancelButton.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseReleased(java.awt.event.MouseEvent evt) { - cancelButtonMouseReleased(evt); - } - }); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(desktopguiEnabled) - .addGroup(layout.createSequentialGroup() - .addComponent(okButton) - .addGap(18, 18, 18) - .addComponent(cancelButton))) - .addContainerGap(237, Short.MAX_VALUE)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(desktopguiEnabled) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(okButton) - .addComponent(cancelButton)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - - pack(); - }// </editor-fold>//GEN-END:initComponents - - private void cancelButtonMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cancelButtonMouseReleased - //System.out.println("Cancelling configuration change."); - this.dispose(); - }//GEN-LAST:event_cancelButtonMouseReleased - - private void okButtonMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_okButtonMouseReleased - configureDesktopgui(); - }//GEN-LAST:event_okButtonMouseReleased - - private String _t(String s) { - return DesktopguiTranslator._t(_context, s); - } - - private void configureDesktopgui() { - String property = "desktopgui.enabled"; - String value; - if(!desktopguiEnabled.isSelected()) { - value = "false"; - //System.out.println("Disabling desktopgui"); - } else { - value = "true"; - //System.out.println("Enabling desktopgui"); - } - try { - _context.router().saveConfig(property, value); - } catch (Exception ex) { - Logger.getLogger(DesktopguiConfigurationFrame.class.getName()).log(Level.SEVERE, null, ex); - } - //System.out.println("Applying desktopgui configuration!"); - this.dispose(); - } - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton cancelButton; - private javax.swing.JCheckBox desktopguiEnabled; - private javax.swing.JButton okButton; - // End of variables declaration//GEN-END:variables - -}