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.gui.theme;
21  
22  import java.awt.Component;
23  import java.awt.Font;
24  
25  import javax.swing.plaf.FontUIResource;
26  import javax.swing.*;
27  
28  import org.xnap.*;
29  import org.xnap.gui.component.FontChooserDialog;
30  import org.xnap.util.Preferences;
31  
32  /***
33   * This class provides a theme that makes use of a custom font. A font chooser
34   * is provided as the configuration dialog.
35   */
36  public class DefaultTheme extends AbstractTheme {
37  
38      //--- Constant(s) ---
39  
40      //--- Data field(s) ---    
41  
42      private Object[] properties;
43  
44      //--- Constructor(s) ---
45  
46      public DefaultTheme(String name)
47      {
48  		super(name);
49      }
50  
51  	public DefaultTheme()
52  	{
53  		this(XNap.tr("Default"));
54  	}
55  
56      //--- Method(s) ---
57  
58      public boolean isConfigurable()
59      {
60  		return true;
61      }
62  
63      public Font getFont()
64      {
65  		return Preferences.getInstance().getFont("defaultThemeFont");
66      }
67  
68      public Object[] getProperties()
69      {
70  		if (properties == null) {
71  			properties = createProperties(new FontUIResource(getFont()));
72  		}
73  		return properties;
74      }
75  
76  	/***
77  	 * Installs the theme. Sets the UIManager defaults.
78  	 *
79  	 * @see #getProperties()
80  	 */
81  	public void install()
82  	{
83  		UIManager.getDefaults().putDefaults(getProperties());
84  	}
85  
86      public void setFont(Font newValue)
87      {
88  		Preferences.getInstance().set("defaultThemeFont", newValue);
89  		properties = createProperties(new FontUIResource(getFont()));
90      }
91  
92      public boolean showConfigurationDialog(Component parent)
93      {
94  		Font f = FontChooserDialog.showDialog(parent, getFont());
95  		if (f != null) {
96  			setFont(f);
97  			return true;
98  		}
99  
100 		return false;
101     }
102 
103 }