View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.xnap.plugin.laf.looks;
21  
22  import javax.swing.UIManager;
23  
24  import java.util.Iterator;
25  
26  import com.jgoodies.plaf.Options;
27  import com.jgoodies.plaf.plastic.PlasticLookAndFeel;
28  import com.jgoodies.plaf.plastic.PlasticTheme;
29  
30  import org.xnap.gui.XNapFrame;
31  import org.xnap.gui.theme.MetalThemeWrapper;
32  import org.xnap.gui.theme.ThemeManager;
33  import org.xnap.gui.util.GUIHelper;
34  import org.xnap.plugin.AbstractLAFPlugin;
35  import org.xnap.util.AbstractPluginPreferences;
36  import org.xnap.util.Preferences;
37  
38  public class LooksPlugin extends AbstractLAFPlugin
39  {
40  
41      //--- Constructor(s) ---
42      
43      public LooksPlugin()
44      {
45      }
46  
47      //--- Method(s) ---
48  
49      public void installLookAndFeel()
50      {
51  		// install look & feels
52  		UIManager.installLookAndFeel
53  			("Extended Windows", 
54  			 "com.jgoodies.plaf.windows.ExtWindowsLookAndFeel");
55  		UIManager.installLookAndFeel
56  			("Plastic", 
57  			 "com.jgoodies.plaf.plastic.PlasticLookAndFeel");
58  		UIManager.installLookAndFeel
59  			("Plastic 3D", 
60  			 "com.jgoodies.plaf.plastic.Plastic3DLookAndFeel");
61  		UIManager.installLookAndFeel
62  			("Plastic XP", 
63  			 "com.jgoodies.plaf.plastic.PlasticXPLookAndFeel");
64  
65  		// install themes
66  		for (Iterator it = PlasticLookAndFeel.getInstalledThemes().iterator(); 
67  			 it.hasNext();) {
68  			Object theme = it.next();
69  			if (theme instanceof PlasticTheme) {
70  				ThemeManager.addTheme(new MyTheme((PlasticTheme)theme));
71  			}
72  		}
73  
74  //  		if (XNap.isRunFromCvs()) {
75  //  			ClearLookManager.setMode(ClearLookMode.DEBUG);
76  //  		}
77  
78  		// set Plastic L&F as default if enabled for the first time
79  		LooksPreferences looksPrefs = new LooksPreferences();
80  		if (looksPrefs.getBoolean("firstLaunch")) {
81  			Preferences.getInstance().setTheme
82  				("com.jgoodies.plaf.plastic.theme.DesertBluer");
83  			Preferences.getInstance().setLookAndFeel
84  				("com.jgoodies.plaf.plastic.PlasticXPLookAndFeel");
85  			looksPrefs.set("firstLaunch", "false");
86  		}
87  	}
88  
89  	public void startGUI()
90  	{
91  		super.startGUI();
92  
93  		XNapFrame.getInstance().getPane().putTabClientProperty
94  			(Options.EMBEDDED_TABS_KEY, Boolean.TRUE);
95   		XNapFrame.getInstance().getPane().putTabClientProperty
96   			(Options.NO_CONTENT_BORDER_KEY, Boolean.TRUE);
97  
98  		if (XNapFrame.getInstance().getChatPanel() != null) {
99  			XNapFrame.getInstance().getChatPanel().getPane().putClientProperty
100 				(Options.EMBEDDED_TABS_KEY, Boolean.TRUE);
101 			XNapFrame.getInstance().getChatPanel().getPane().putClientProperty
102 				(Options.NO_CONTENT_BORDER_KEY, Boolean.TRUE);
103 		}
104 
105 		if (XNapFrame.getInstance().getSearchPanel() != null) {
106 			XNapFrame.getInstance().getSearchPanel().getSearchResultPanel()
107 				.putClientProperty(Options.EMBEDDED_TABS_KEY, Boolean.TRUE);
108 			XNapFrame.getInstance().getSearchPanel().getSearchResultPanel()
109 				.setBorder(GUIHelper.createEmptyBorder());
110 
111 			XNapFrame.getInstance().getSearchPanel().getTransferPanel()
112 				.putClientProperty(Options.EMBEDDED_TABS_KEY, Boolean.TRUE);
113 			XNapFrame.getInstance().getSearchPanel().getTransferPanel()
114 				.setBorder(GUIHelper.createEmptyBorder());
115 		}
116 	}
117 
118 	//--- Inner Classes ---
119 
120 	private static class MyTheme extends MetalThemeWrapper {
121 
122 		public MyTheme(PlasticTheme theme)
123 		{
124 			super(theme);
125 		}
126 
127 		public void install()
128 		{
129 			PlasticLookAndFeel.setMyCurrentTheme((PlasticTheme)getTheme());
130 		}
131 
132 	}
133 
134 	private static class LooksPreferences extends AbstractPluginPreferences {
135 		
136 		public static final int VERSION = 1;
137 
138 		public LooksPreferences()
139 		{
140 			super("plugin.looks", VERSION);
141 
142 			setDefault("firstLaunch", "true");
143 		}
144 
145 	}
146 
147 }