Author: jflesch
Date: 2007-05-14 16:03:56 +0000 (Mon, 14 May 2007)
New Revision: 13249
Modified:
trunk/apps/Thaw/src/thaw/core/Core.java
trunk/apps/Thaw/src/thaw/plugins/ThemeSelector.java
Log:
Fix the exception throwed when the user change the theme
Modified: trunk/apps/Thaw/src/thaw/core/Core.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/Core.java 2007-05-14 12:41:37 UTC (rev
13248)
+++ trunk/apps/Thaw/src/thaw/core/Core.java 2007-05-14 16:03:56 UTC (rev
13249)
@@ -358,6 +358,66 @@
}
+
+ private static class LnFSetter implements Runnable {
+ private Core core;
+ private String theme;
+
+ public LnFSetter(Core c, String t) {
+ core = c;
+ theme = t;
+ }
+
+ public void run() {
+ try {
+ UIManager.setLookAndFeel(theme);
+ } catch(ClassNotFoundException e) {
+ Logger.error(this, "Theme '"+theme+"' not found
! : "+e.toString());
+ } catch(InstantiationException e) {
+ Logger.error(this, "(1) Error while loading
theme '"+theme+"' : "+e.toString());
+ } catch(IllegalAccessException e) {
+ Logger.error(this, "(2) Error while loading
theme '"+theme+"' : "+e.toString());
+ } catch(javax.swing.UnsupportedLookAndFeelException e) {
+ Logger.error(this, "(3) Error while loading
theme '"+theme+"' : "+e.toString());
+ }
+
+ if (core.getMainWindow() != null)
+
javax.swing.SwingUtilities.updateComponentTreeUI(core.getMainWindow().getMainFrame());
+ if (core.getConfigWindow() != null)
+
javax.swing.SwingUtilities.updateComponentTreeUI(core.getConfigWindow().getFrame());
+ }
+ }
+
+
+ public static void setTheme(Core core, String theme) {
+ if (theme == null) {
+ if (core.getConfig() != null)
+ theme =
core.getConfig().getValue("lookAndFeel");
+
+ if (theme == null)
+ theme =
UIManager.getSystemLookAndFeelClassName();
+ }
+
+ if (theme == null)
+ return;
+
+ Logger.notice(core, "Setting theme : "+ theme);
+
+ LnFSetter s = new LnFSetter(core, theme);
+
+ try {
+ javax.swing.SwingUtilities.invokeAndWait(s);
+ } catch(InterruptedException e) {
+ Logger.error(s, "Interrupted while setting theme
'"+theme+"' !");
+ Logger.error(s, "Interrupted because: "+e.toString());
+ } catch(java.lang.reflect.InvocationTargetException e) {
+ Logger.error(s, "Error while setting theme :
"+e.toString());
+ }
+ }
+
+
+
+
/**
* This method sets the look and feel specified with setLookAndFeel().
* If none was specified, the System Look and Feel is set.
@@ -368,15 +428,7 @@
JDialog.setDefaultLookAndFeelDecorated(false);
try {
- if (Core.lookAndFeel == null) {
- if (config != null
- && config.getValue("lookAndFeel") != null)
-
UIManager.setLookAndFeel(config.getValue("lookAndFeel"));
- else
-
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
- } else {
- UIManager.setLookAndFeel(Core.lookAndFeel);
- }
+ setTheme(this, Core.lookAndFeel);
if (splashScreen != null)
splashScreen.rebuild();
Modified: trunk/apps/Thaw/src/thaw/plugins/ThemeSelector.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/ThemeSelector.java 2007-05-14 12:41:37 UTC
(rev 13248)
+++ trunk/apps/Thaw/src/thaw/plugins/ThemeSelector.java 2007-05-14 16:03:56 UTC
(rev 13249)
@@ -104,7 +104,8 @@
if (theme == null)
theme = UIManager.getSystemLookAndFeelClassName();
- setTheme(core, theme);
+ Thread th = new Thread(new ThemeSetter(theme));
+ th.start();
}
@@ -130,21 +131,24 @@
}
- 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());
+ private class ThemeSetter implements Runnable {
+ private String theme;
+
+ public ThemeSetter(String t) {
+ theme = t;
}
+
+ public void run() {
+ Core.setTheme(core, theme);
+ }
}
+
public void valueChanged(ListSelectionEvent e) {
if (e.getFirstIndex() >= 0
&& themes.get(e.getFirstIndex()) != null) {
- setTheme(core, ((String)themeList.getSelectedValue()));
+ Thread th = new Thread(new
ThemeSetter((String)themeList.getSelectedValue()));
+ th.start();
}
}
}