From 196cf483721c833cf3b99f4f152d0bee4fa5a891 Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Thu, 5 May 2016 16:39:41 +0000 Subject: [PATCH] DTG: Remove Swing DesktopguiConfigurationFrame as it's completely inconsistent with the AWT SystemTray menus; move to the AWT menu as a submenu. This was the last of the Swing UI elements, mathias ripped out the all of them in Nov. 2010, but then added this one in Feb. 2011. Remove LookAndFeel setting, only works for Swing. --- .../i2p/desktopgui/ExternalTrayManager.java | 4 +- .../i2p/desktopgui/InternalTrayManager.java | 31 +++- .../src/net/i2p/desktopgui/Main.java | 35 +---- .../src/net/i2p/desktopgui/TrayManager.java | 4 +- .../gui/DesktopguiConfigurationFrame.java | 135 ------------------ 5 files changed, 33 insertions(+), 176 deletions(-) delete mode 100644 apps/desktopgui/src/net/i2p/desktopgui/gui/DesktopguiConfigurationFrame.java diff --git a/apps/desktopgui/src/net/i2p/desktopgui/ExternalTrayManager.java b/apps/desktopgui/src/net/i2p/desktopgui/ExternalTrayManager.java index e15e5c08b5..cf97d255b7 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 90017c0353..70fb2c553b 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 4592ae7b16..76e5f2c573 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 ac0242dd67..31b7569d3c 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 285b63927b..0000000000 --- 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 - -} -- GitLab