Author: jflesch
Date: 2007-03-28 17:07:32 +0000 (Wed, 28 Mar 2007)
New Revision: 12415

Added:
   trunk/apps/Thaw/images/lookAndFeel.png
   trunk/apps/Thaw/images/min-lookAndFeel.png
   trunk/apps/Thaw/src/thaw/plugins/ThemeSelector.java
Modified:
   trunk/apps/Thaw/src/thaw/core/Core.java
   trunk/apps/Thaw/src/thaw/core/PluginManager.java
   trunk/apps/Thaw/src/thaw/gui/IconBox.java
   trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
   trunk/apps/Thaw/src/thaw/i18n/thaw.properties
   trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
   trunk/apps/Thaw/src/thaw/plugins/peerMonitor/PeerMonitorPanel.java
Log:
Implement a theme selector

Added: trunk/apps/Thaw/images/lookAndFeel.png
===================================================================
(Binary files differ)


Property changes on: trunk/apps/Thaw/images/lookAndFeel.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/apps/Thaw/images/min-lookAndFeel.png
===================================================================
(Binary files differ)


Property changes on: trunk/apps/Thaw/images/min-lookAndFeel.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: trunk/apps/Thaw/src/thaw/core/Core.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/Core.java     2007-03-28 16:01:36 UTC (rev 
12414)
+++ trunk/apps/Thaw/src/thaw/core/Core.java     2007-03-28 17:07:32 UTC (rev 
12415)
@@ -338,7 +338,11 @@

                try {
                        if (Core.lookAndFeel == null) {
-                               
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+                               if (config != null
+                                   && config.getValue("lookAndFeel") != null)
+                                       
UIManager.setLookAndFeel(config.getValue("lookAndFeel"));
+                               else
+                                       
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                        } else {
                                UIManager.setLookAndFeel(Core.lookAndFeel);
                        }

Modified: trunk/apps/Thaw/src/thaw/core/PluginManager.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/PluginManager.java    2007-03-28 16:01:36 UTC 
(rev 12414)
+++ trunk/apps/Thaw/src/thaw/core/PluginManager.java    2007-03-28 17:07:32 UTC 
(rev 12415)
@@ -13,6 +13,7 @@
                "thaw.plugins.FetchPlugin",
                "thaw.plugins.InsertPlugin",
                "thaw.plugins.StatusBar",
+               "thaw.plugins.ThemeSelector",
                "thaw.plugins.Hsqldb",
                "thaw.plugins.IndexBrowser",
                "thaw.plugins.IndexExporter"
@@ -24,6 +25,7 @@
                "thaw.plugins.FetchPlugin",
                "thaw.plugins.InsertPlugin",
                "thaw.plugins.StatusBar",
+               "thaw.plugins.ThemeSelector",
                "thaw.plugins.Hsqldb",
                "thaw.plugins.IndexBrowser",
                "thaw.plugins.IndexExporter",

Modified: trunk/apps/Thaw/src/thaw/gui/IconBox.java
===================================================================
--- trunk/apps/Thaw/src/thaw/gui/IconBox.java   2007-03-28 16:01:36 UTC (rev 
12414)
+++ trunk/apps/Thaw/src/thaw/gui/IconBox.java   2007-03-28 17:07:32 UTC (rev 
12415)
@@ -89,7 +89,10 @@
        public static ImageIcon identity;
        public static ImageIcon peers;

+       public static ImageIcon lookAndFeel;
+       public static ImageIcon minLookAndFeel;

+
        /**
         * Not really used
         */
@@ -174,6 +177,8 @@
                IconBox.computer            = IconBox.loadIcon("computer.png");
                IconBox.identity            = IconBox.loadIcon("identity.png");
                IconBox.peers               = IconBox.loadIcon("peers.png");
+               IconBox.lookAndFeel         = 
IconBox.loadIcon("lookAndFeel.png");
+               IconBox.minLookAndFeel      = 
IconBox.loadIcon("min-lookAndFeel.png");
        }

 }

Modified: trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties     2007-03-28 
16:01:36 UTC (rev 12414)
+++ trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties     2007-03-28 
17:07:32 UTC (rev 12415)
@@ -339,7 +339,12 @@
 thaw.plugin.peerMonitor.infos.nodeMemory=Memoire du noeud
 thaw.plugin.peerMonitor.infos.thawMemory=Memoire de Thaw

+thaw.plugin.themeSelector.themeSelector=S?lecteur de th?me
+thaw.plugin.themeSelector.selectATheme=Selectionnez un th?me:
+thaw.plugin.themeSelector.theme=Th?me

+# Zeroconf
+
 thaw.zeroconf.searchingNode=Recherche de noeuds Freenet ...
 thaw.zeroconf.nodeList=Noeuds trouv?s :


Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2007-03-28 16:01:36 UTC 
(rev 12414)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2007-03-28 17:07:32 UTC 
(rev 12415)
@@ -333,6 +333,11 @@
 thaw.plugin.peerMonitor.infos.nodeMemory=Node memory
 thaw.plugin.peerMonitor.infos.thawMemory=Thaw memory

+thaw.plugin.themeSelector.themeSelector=Theme selector
+thaw.plugin.themeSelector.selectATheme=Select a theme:
+thaw.plugin.themeSelector.theme=Theme

+# ZeroConf
+
 thaw.zeroconf.searchingNode=Searching freenet nodes ...
 thaw.zeroconf.nodeList=Nodes found:

Modified: trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties    2007-03-28 16:01:36 UTC 
(rev 12414)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties    2007-03-28 17:07:32 UTC 
(rev 12415)
@@ -339,7 +339,12 @@
 thaw.plugin.peerMonitor.infos.nodeMemory=Memoire du noeud
 thaw.plugin.peerMonitor.infos.thawMemory=Memoire de Thaw

+thaw.plugin.themeSelector.themeSelector=S\u00e9lecteur de th\u00e8me
+thaw.plugin.themeSelector.selectATheme=Selectionnez un th\u00e8me:
+thaw.plugin.themeSelector.theme=Th\u00e8me

+# Zeroconf
+
 thaw.zeroconf.searchingNode=Recherche de noeuds Freenet ...
 thaw.zeroconf.nodeList=Noeuds trouv\u00e9s :


Added: trunk/apps/Thaw/src/thaw/plugins/ThemeSelector.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/ThemeSelector.java                         
(rev 0)
+++ trunk/apps/Thaw/src/thaw/plugins/ThemeSelector.java 2007-03-28 17:07:32 UTC 
(rev 12415)
@@ -0,0 +1,150 @@
+package thaw.plugins;
+
+import javax.swing.JPanel;
+import javax.swing.JList;
+import javax.swing.JLabel;
+import javax.swing.JScrollPane;
+
+import javax.swing.event.ListSelectionListener;
+import javax.swing.event.ListSelectionEvent;
+
+import javax.swing.UIManager;
+
+import java.awt.BorderLayout;
+
+import java.util.Observer;
+import java.util.Observable;
+
+import java.util.Vector;
+
+import thaw.core.I18n;
+import thaw.core.Logger;
+import thaw.core.Core;
+
+
+public class ThemeSelector implements thaw.core.Plugin, Observer, 
ListSelectionListener {
+
+       private Core core;
+
+       private JPanel panel = null;
+       private JList themeList = null;
+       private Vector themes = null;
+
+       public ThemeSelector() {
+
+       }
+
+       public Vector getPossibleThemes() {
+               Vector list = new Vector();
+
+               final UIManager.LookAndFeelInfo[] feels =
+                       UIManager.getInstalledLookAndFeels();
+
+               for (int i = 0; i < feels.length; i++) {
+                       list.add(feels[i].getClassName());
+               }
+
+               return list;
+       }
+
+       public boolean run(Core core) {
+               this.core = core;
+
+               panel = new JPanel(new BorderLayout(5, 5));
+               themeList = new JList(themes = getPossibleThemes());
+               JLabel label = new 
JLabel(I18n.getMessage("thaw.plugin.themeSelector.selectATheme"));
+
+               themeList.addListSelectionListener(this);
+
+               panel.add(label, BorderLayout.NORTH);
+               panel.add(new JScrollPane(themeList), BorderLayout.CENTER);
+
+               resetSelection();
+
+               core.getConfigWindow().addObserver(this);
+
+               
core.getConfigWindow().addTab(I18n.getMessage("thaw.plugin.themeSelector.theme"),
+                                             thaw.gui.IconBox.minLookAndFeel,
+                                             panel);
+
+               return true;
+       }
+
+
+       public boolean stop() {
+               core.getConfigWindow().removeTab(panel);
+
+               return false;
+       }
+
+       public String getNameForUser() {
+               return 
I18n.getMessage("thaw.plugin.themeSelector.themeSelector");
+       }
+
+
+       public javax.swing.ImageIcon getIcon() {
+               return thaw.gui.IconBox.lookAndFeel;
+       }
+
+
+       public void resetSelection() {
+               String theme = core.getConfig().getValue("lookAndFeel");
+
+               if (theme == null)
+                       theme = UIManager.getSystemLookAndFeelClassName();
+
+               themeList.setSelectedValue(theme, true);
+       }
+
+       public void resetTheme() {
+               String theme = core.getConfig().getValue("lookAndFeel");
+
+               if (theme == null)
+                       theme = UIManager.getSystemLookAndFeelClassName();
+
+               setTheme(core, theme);
+       }
+
+
+       public void update(Observable o, Object arg) {
+               if (o == core.getConfigWindow()) {
+
+                       if (arg == core.getConfigWindow().getOkButton()) {
+                               if (themeList.getSelectedValue() != null) {
+                                       core.getConfig().setValue("lookAndFeel",
+                                                                 
((String)themeList.getSelectedValue()));
+
+                                       resetSelection();
+                               }
+
+                               return;
+                       }
+
+                       if (arg == core.getConfigWindow().getCancelButton()) {
+                               resetSelection();
+                               resetTheme();
+                               return;
+                       }
+               }
+       }
+
+
+       public static void setTheme(Core core, String theme) {
+               try {
+                       Logger.notice(core, "Setting theme : "+ theme);
+                       UIManager.setLookAndFeel(theme);
+                       
javax.swing.SwingUtilities.updateComponentTreeUI(core.getMainWindow().getMainFrame());
+                       
javax.swing.SwingUtilities.updateComponentTreeUI(core.getConfigWindow().getFrame());
+               } catch(Exception exc) {
+                       Logger.error(new ThemeSelector(), "Error while changing 
theme : "+exc.toString());
+               }
+       }
+
+       public void valueChanged(ListSelectionEvent e) {
+               if (e.getFirstIndex() >= 0
+                   && themes.get(e.getFirstIndex()) != null) {
+                       setTheme(core, ((String)themeList.getSelectedValue()));
+               }
+       }
+}
+

Modified: trunk/apps/Thaw/src/thaw/plugins/peerMonitor/PeerMonitorPanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/peerMonitor/PeerMonitorPanel.java  
2007-03-28 16:01:36 UTC (rev 12414)
+++ trunk/apps/Thaw/src/thaw/plugins/peerMonitor/PeerMonitorPanel.java  
2007-03-28 17:07:32 UTC (rev 12415)
@@ -491,10 +491,15 @@
                if (e.getFirstIndex() == 0) {
                        
displayInfos(I18n.getMessage("thaw.plugin.peerMonitor.nodeInfos"), nodeInfos);
                } else {
-                       String peerName = 
peers.get(e.getFirstIndex()).toString();
+                       Peer peer;

-                       
displayInfos(I18n.getMessage("thaw.plugin.peerMonitor.peerInfos") + " '" + 
peerName + "':",
-                                    
((Peer)peers.get(e.getFirstIndex())).getParameters());
+                       if ((peer = ((Peer)peerList.getSelectedValue())) != 
null) {
+
+                               String peerName = peer.toString();
+
+                               
displayInfos(I18n.getMessage("thaw.plugin.peerMonitor.peerInfos") + " '" + 
peerName + "':",
+                                            peer.getParameters());
+                       }
                }

                setChanged();


Reply via email to