PageRenderTime 94ms CodeModel.GetById 61ms app.highlight 16ms RepoModel.GetById 14ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/options/AppearanceOptionPane.java

#
Java | 239 lines | 155 code | 27 blank | 57 comment | 11 complexity | 081667e986437efffbf4d81f5035eeb8 MD5 | raw file
  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
 23package org.gjt.sp.jedit.options;
 24
 25//{{{ Imports
 26import javax.swing.*;
 27import java.awt.event.*;
 28import java.awt.*;
 29import java.io.*;
 30import org.gjt.sp.jedit.gui.FontSelector;
 31import org.gjt.sp.jedit.textarea.AntiAlias;
 32import org.gjt.sp.jedit.*;
 33import org.gjt.sp.util.Log;
 34//}}}
 35
 36public class AppearanceOptionPane extends AbstractOptionPane
 37{
 38	//{{{ AppearanceOptionPane constructor
 39	public AppearanceOptionPane()
 40	{
 41		super("appearance");
 42	} //}}}
 43
 44	//{{{ _init() method
 45	protected void _init()
 46	{
 47		/* Look and feel */
 48		addComponent(new JLabel(jEdit.getProperty("options.appearance.lf.note")));
 49
 50		lfs = UIManager.getInstalledLookAndFeels();
 51		String[] names = new String[lfs.length];
 52		String lf = UIManager.getLookAndFeel().getClass().getName();
 53		int index = 0;
 54		for(int i = 0; i < names.length; i++)
 55		{
 56			names[i] = lfs[i].getName();
 57			if(lf.equals(lfs[i].getClassName()))
 58				index = i;
 59		}
 60
 61		lookAndFeel = new JComboBox(names);
 62		lookAndFeel.setSelectedIndex(index);
 63		lookAndFeel.addActionListener(new ActionListener()
 64		{
 65			public void actionPerformed(ActionEvent evt)
 66			{
 67				updateEnabled();
 68			}
 69		});
 70
 71		addComponent(jEdit.getProperty("options.appearance.lf"),
 72			lookAndFeel);
 73
 74		/* Primary Metal L&F font */
 75		primaryFont = new FontSelector(jEdit.getFontProperty(
 76			"metal.primary.font"));
 77		addComponent(jEdit.getProperty("options.appearance.primaryFont"),
 78			primaryFont);
 79
 80		/* Secondary Metal L&F font */
 81		secondaryFont = new FontSelector(jEdit.getFontProperty(
 82			"metal.secondary.font"));
 83		addComponent(jEdit.getProperty("options.appearance.secondaryFont"),
 84			secondaryFont);
 85
 86		/*
 87		antiAliasExtras = new JComboBox(AntiAlias.comboChoices);
 88		antiAliasExtras.setSelectedIndex(AntiAlias.appearance().val());
 89		antiAliasExtras.setToolTipText(jEdit.getProperty("options.textarea.antiAlias.tooltip"));
 90		addComponent(jEdit.getProperty("options.appearance.fonts.antialias"), antiAliasExtras);
 91		*/
 92		updateEnabled();
 93
 94		/* History count */
 95		history = new JTextField(jEdit.getProperty("history"));
 96		addComponent(jEdit.getProperty("options.appearance.history"),history);
 97
 98		/* Menu spillover count */
 99		menuSpillover = new JTextField(jEdit.getProperty("menu.spillover"));
100		addComponent(jEdit.getProperty("options.appearance.menuSpillover"),menuSpillover);
101
102		addSeparator("options.appearance.startup.label");
103
104		/* Show splash screen */
105		showSplash = new JCheckBox(jEdit.getProperty(
106			"options.appearance.showSplash"));
107		String settingsDirectory = jEdit.getSettingsDirectory();
108		if(settingsDirectory == null)
109			showSplash.setSelected(true);
110		else
111			showSplash.setSelected(!new File(settingsDirectory,"nosplash").exists());
112		addComponent(showSplash);
113
114		/* Show tip of the day */
115		showTips = new JCheckBox(jEdit.getProperty(
116			"options.appearance.showTips"));
117		showTips.setSelected(jEdit.getBooleanProperty("tip.show"));
118		addComponent(showTips);
119
120		addSeparator("options.appearance.experimental.label");
121		addComponent(GUIUtilities.createMultilineLabel(
122			jEdit.getProperty("options.appearance.experimental.caption")));
123
124		/* Use jEdit colors in all text components */
125		textColors = new JCheckBox(jEdit.getProperty(
126			"options.appearance.textColors"));
127		textColors.setSelected(jEdit.getBooleanProperty("textColors"));
128		addComponent(textColors);
129
130		/* Decorate frames with look and feel (JDK 1.4 only) */
131		decorateFrames = new JCheckBox(jEdit.getProperty(
132			"options.appearance.decorateFrames"));
133		decorateFrames.setSelected(jEdit.getBooleanProperty("decorate.frames"));
134		addComponent(decorateFrames);
135
136		/* Decorate dialogs with look and feel (JDK 1.4 only) */
137		decorateDialogs = new JCheckBox(jEdit.getProperty(
138			"options.appearance.decorateDialogs"));
139		decorateDialogs.setSelected(jEdit.getBooleanProperty("decorate.dialogs"));
140		addComponent(decorateDialogs);
141	} //}}}
142
143	//{{{ _save() method
144	protected void _save()
145	{
146		String lf = lfs[lookAndFeel.getSelectedIndex()].getClassName();
147		jEdit.setProperty("lookAndFeel",lf);
148		jEdit.setFontProperty("metal.primary.font",primaryFont.getFont());
149		jEdit.setFontProperty("metal.secondary.font",secondaryFont.getFont());
150		jEdit.setProperty("history",history.getText());
151		jEdit.setProperty("menu.spillover",menuSpillover.getText());
152		jEdit.setBooleanProperty("tip.show",showTips.isSelected());
153		
154		/* AntiAlias nv = AntiAlias.appearance();
155		 int idx = antiAliasExtras.getSelectedIndex();
156		nv.set(idx);
157		primaryFont.setAntiAliasEnabled(idx > 0);
158		secondaryFont.setAntiAliasEnabled(idx > 0);
159		primaryFont.repaint();
160		secondaryFont.repaint(); */
161
162		// this is handled a little differently from other jEdit settings
163		// as the splash screen flag needs to be known very early in the
164		// startup sequence, before the user properties have been loaded
165		String settingsDirectory = jEdit.getSettingsDirectory();
166		if(settingsDirectory != null)
167		{
168			File file = new File(settingsDirectory,"nosplash");
169			if(showSplash.isSelected())
170				file.delete();
171			else
172			{
173				FileOutputStream out = null;
174				try
175				{
176					out = new FileOutputStream(file);
177					out.write('\n');
178					out.close();
179				}
180				catch(IOException io)
181				{
182					Log.log(Log.ERROR,this,io);
183				}
184				finally
185				{
186					try
187					{
188						if(out != null)
189							out.close();
190					}
191					catch(IOException e)
192					{
193					}
194				}
195			}
196		}
197		jEdit.setBooleanProperty("textColors",textColors.isSelected());
198		jEdit.setBooleanProperty("decorate.frames",decorateFrames.isSelected());
199		jEdit.setBooleanProperty("decorate.dialogs",decorateDialogs.isSelected());
200	} //}}}
201
202	//{{{ Private members
203
204	//{{{ Instance variables
205	private UIManager.LookAndFeelInfo[] lfs;
206	private JComboBox lookAndFeel;
207	private FontSelector primaryFont;
208	private FontSelector secondaryFont;
209	private JTextField history;
210	private JTextField menuSpillover;
211	private JCheckBox showTips;
212	private JCheckBox showSplash;
213	private JCheckBox textColors;
214	private JCheckBox decorateFrames;
215	private JCheckBox decorateDialogs;
216	private JComboBox antiAliasExtras;
217	//}}}
218
219	//{{{ updateEnabled() method
220	private void updateEnabled()
221	{
222		String className = lfs[lookAndFeel.getSelectedIndex()]
223			.getClassName();
224
225		if(className.equals("javax.swing.plaf.metal.MetalLookAndFeel")
226			|| className.equals("com.incors.plaf.kunststoff.KunststoffLookAndFeel"))
227		{
228			primaryFont.setEnabled(true);
229			secondaryFont.setEnabled(true);
230		}
231		else
232		{
233			primaryFont.setEnabled(false);
234			secondaryFont.setEnabled(false);
235		}
236	} //}}}
237
238	//}}}
239}