KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > options > AppearanceOptionPane


1 /*
2  * AppearanceOptionPane.java - Appearance options panel
3  * :tabSize=8:indentSize=8:noTabs=false:
4  * :folding=explicit:collapseFolds=1:
5  *
6  * Copyright (C) 2001, 2004 Slava Pestov
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  */

22
23 package org.gjt.sp.jedit.options;
24
25 //{{{ Imports
26
import javax.swing.*;
27 import java.awt.event.*;
28 import java.io.*;
29 import org.gjt.sp.jedit.gui.FontSelector;
30 import org.gjt.sp.jedit.*;
31 import org.gjt.sp.util.Log;
32 import org.gjt.sp.util.IOUtilities;
33 //}}}
34

35 public class AppearanceOptionPane extends AbstractOptionPane
36 {
37     //{{{ AppearanceOptionPane constructor
38
public AppearanceOptionPane()
39     {
40         super("appearance");
41     } //}}}
42

43     //{{{ _init() method
44
protected void _init()
45     {
46         /* Look and feel */
47         addComponent(new JLabel(jEdit.getProperty("options.appearance.lf.note")));
48
49         lfs = UIManager.getInstalledLookAndFeels();
50         String JavaDoc[] names = new String JavaDoc[lfs.length];
51         String JavaDoc lf = UIManager.getLookAndFeel().getClass().getName();
52         int index = 0;
53         for(int i = 0; i < names.length; i++)
54         {
55             names[i] = lfs[i].getName();
56             if(lf.equals(lfs[i].getClassName()))
57                 index = i;
58         }
59
60         lookAndFeel = new JComboBox(names);
61         lookAndFeel.setSelectedIndex(index);
62         lookAndFeel.addActionListener(new ActionListener()
63         {
64             public void actionPerformed(ActionEvent evt)
65             {
66                 updateEnabled();
67             }
68         });
69
70         addComponent(jEdit.getProperty("options.appearance.lf"),
71             lookAndFeel);
72
73         /* Primary Metal L&F font */
74         primaryFont = new FontSelector(jEdit.getFontProperty(
75             "metal.primary.font"));
76         addComponent(jEdit.getProperty("options.appearance.primaryFont"),
77             primaryFont);
78
79         /* Secondary Metal L&F font */
80         secondaryFont = new FontSelector(jEdit.getFontProperty(
81             "metal.secondary.font"));
82         addComponent(jEdit.getProperty("options.appearance.secondaryFont"),
83             secondaryFont);
84
85         /*
86         antiAliasExtras = new JComboBox(AntiAlias.comboChoices);
87         antiAliasExtras.setSelectedIndex(AntiAlias.appearance().val());
88         antiAliasExtras.setToolTipText(jEdit.getProperty("options.textarea.antiAlias.tooltip"));
89         addComponent(jEdit.getProperty("options.appearance.fonts.antialias"), antiAliasExtras);
90         */

91         updateEnabled();
92
93         /* History count */
94         history = new JTextField(jEdit.getProperty("history"));
95         addComponent(jEdit.getProperty("options.appearance.history"),history);
96
97         /* Menu spillover count */
98         menuSpillover = new JTextField(jEdit.getProperty("menu.spillover"));
99         addComponent(jEdit.getProperty("options.appearance.menuSpillover"),menuSpillover);
100
101         continuousLayout = new JCheckBox(jEdit.getProperty(
102             "options.appearance.continuousLayout.label"));
103         continuousLayout.setSelected(jEdit.getBooleanProperty("appearance.continuousLayout"));
104         addComponent(continuousLayout);
105
106         addSeparator("options.appearance.startup.label");
107
108         /* Show splash screen */
109         showSplash = new JCheckBox(jEdit.getProperty(
110             "options.appearance.showSplash"));
111         String JavaDoc settingsDirectory = jEdit.getSettingsDirectory();
112         if(settingsDirectory == null)
113             showSplash.setSelected(true);
114         else
115             showSplash.setSelected(!new File(settingsDirectory,"nosplash").exists());
116         addComponent(showSplash);
117
118         /* Show tip of the day */
119         showTips = new JCheckBox(jEdit.getProperty(
120             "options.appearance.showTips"));
121         showTips.setSelected(jEdit.getBooleanProperty("tip.show"));
122         addComponent(showTips);
123
124         addSeparator("options.appearance.experimental.label");
125         addComponent(GUIUtilities.createMultilineLabel(
126             jEdit.getProperty("options.appearance.experimental.caption")));
127
128         /* Use jEdit colors in all text components */
129         textColors = new JCheckBox(jEdit.getProperty(
130             "options.appearance.textColors"));
131         textColors.setSelected(jEdit.getBooleanProperty("textColors"));
132         addComponent(textColors);
133
134         /* Decorate frames with look and feel (JDK 1.4 only) */
135         decorateFrames = new JCheckBox(jEdit.getProperty(
136             "options.appearance.decorateFrames"));
137         decorateFrames.setSelected(jEdit.getBooleanProperty("decorate.frames"));
138         addComponent(decorateFrames);
139
140         /* Decorate dialogs with look and feel (JDK 1.4 only) */
141         decorateDialogs = new JCheckBox(jEdit.getProperty(
142             "options.appearance.decorateDialogs"));
143         decorateDialogs.setSelected(jEdit.getBooleanProperty("decorate.dialogs"));
144         addComponent(decorateDialogs);
145     } //}}}
146

147     //{{{ _save() method
148
protected void _save()
149     {
150         String JavaDoc lf = lfs[lookAndFeel.getSelectedIndex()].getClassName();
151         jEdit.setProperty("lookAndFeel",lf);
152         jEdit.setFontProperty("metal.primary.font",primaryFont.getFont());
153         jEdit.setFontProperty("metal.secondary.font",secondaryFont.getFont());
154         jEdit.setProperty("history",history.getText());
155         jEdit.setProperty("menu.spillover",menuSpillover.getText());
156         jEdit.setBooleanProperty("tip.show",showTips.isSelected());
157         jEdit.setBooleanProperty("appearance.continuousLayout",continuousLayout.isSelected());
158
159         /* AntiAlias nv = AntiAlias.appearance();
160          int idx = antiAliasExtras.getSelectedIndex();
161         nv.set(idx);
162         primaryFont.setAntiAliasEnabled(idx > 0);
163         secondaryFont.setAntiAliasEnabled(idx > 0);
164         primaryFont.repaint();
165         secondaryFont.repaint(); */

166
167         // this is handled a little differently from other jEdit settings
168
// as the splash screen flag needs to be known very early in the
169
// startup sequence, before the user properties have been loaded
170
String JavaDoc settingsDirectory = jEdit.getSettingsDirectory();
171         if(settingsDirectory != null)
172         {
173             File file = new File(settingsDirectory,"nosplash");
174             if(showSplash.isSelected())
175                 file.delete();
176             else
177             {
178                 FileOutputStream out = null;
179                 try
180                 {
181                     out = new FileOutputStream(file);
182                     out.write('\n');
183                     out.close();
184                 }
185                 catch(IOException io)
186                 {
187                     Log.log(Log.ERROR,this,io);
188                 }
189                 finally
190                 {
191                     IOUtilities.closeQuietly(out);
192                 }
193             }
194         }
195         jEdit.setBooleanProperty("textColors",textColors.isSelected());
196         jEdit.setBooleanProperty("decorate.frames",decorateFrames.isSelected());
197         jEdit.setBooleanProperty("decorate.dialogs",decorateDialogs.isSelected());
198     } //}}}
199

200     //{{{ Private members
201

202     //{{{ Instance variables
203
private UIManager.LookAndFeelInfo[] lfs;
204     private JComboBox lookAndFeel;
205     private FontSelector primaryFont;
206     private FontSelector secondaryFont;
207     private JTextField history;
208     private JTextField menuSpillover;
209     private JCheckBox showTips;
210     private JCheckBox continuousLayout;
211     private JCheckBox showSplash;
212     private JCheckBox textColors;
213     private JCheckBox decorateFrames;
214     private JCheckBox decorateDialogs;
215     private JComboBox antiAliasExtras;
216     //}}}
217

218     //{{{ updateEnabled() method
219
private void updateEnabled()
220     {
221         String JavaDoc className = lfs[lookAndFeel.getSelectedIndex()]
222             .getClassName();
223
224         if(className.equals("javax.swing.plaf.metal.MetalLookAndFeel")
225             || className.equals("com.incors.plaf.kunststoff.KunststoffLookAndFeel"))
226         {
227             primaryFont.setEnabled(true);
228             secondaryFont.setEnabled(true);
229         }
230         else
231         {
232             primaryFont.setEnabled(false);
233             secondaryFont.setEnabled(false);
234         }
235     } //}}}
236

237     //}}}
238
}
239
Popular Tags