PageRenderTime 37ms CodeModel.GetById 26ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre14/org/gjt/sp/jedit/options/AppearanceOptionPane.java

#
Java | 227 lines | 156 code | 27 blank | 44 comment | 12 complexity | 20cd9c608ccf2a499645b3627c012210 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.*;
 32import org.gjt.sp.util.Log;
 33//}}}
 34
 35public 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[] names = new String[lfs.length];
 51		String 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		updateEnabled();
 86
 87		/* History count */
 88		history = new JTextField(jEdit.getProperty("history"));
 89		addComponent(jEdit.getProperty("options.appearance.history"),history);
 90
 91		/* Menu spillover count */
 92		menuSpillover = new JTextField(jEdit.getProperty("menu.spillover"));
 93		addComponent(jEdit.getProperty("options.appearance.menuSpillover"),menuSpillover);
 94
 95		addSeparator("options.appearance.startup.label");
 96
 97		/* Show splash screen */
 98		showSplash = new JCheckBox(jEdit.getProperty(
 99			"options.appearance.showSplash"));
100		String settingsDirectory = jEdit.getSettingsDirectory();
101		if(settingsDirectory == null)
102			showSplash.setSelected(true);
103		else
104			showSplash.setSelected(!new File(settingsDirectory,"nosplash").exists());
105		addComponent(showSplash);
106
107		/* Show tip of the day */
108		showTips = new JCheckBox(jEdit.getProperty(
109			"options.appearance.showTips"));
110		showTips.setSelected(jEdit.getBooleanProperty("tip.show"));
111		addComponent(showTips);
112
113		addSeparator("options.appearance.experimental.label");
114		addComponent(GUIUtilities.createMultilineLabel(
115			jEdit.getProperty("options.appearance.experimental.caption")));
116
117		/* Use jEdit colors in all text components */
118		textColors = new JCheckBox(jEdit.getProperty(
119			"options.appearance.textColors"));
120		textColors.setSelected(jEdit.getBooleanProperty("textColors"));
121		addComponent(textColors);
122
123		/* Decorate frames with look and feel (JDK 1.4 only) */
124		decorateFrames = new JCheckBox(jEdit.getProperty(
125			"options.appearance.decorateFrames"));
126		decorateFrames.setSelected(jEdit.getBooleanProperty("decorate.frames"));
127
128		/* Decorate dialogs with look and feel (JDK 1.4 only) */
129		decorateDialogs = new JCheckBox(jEdit.getProperty(
130			"options.appearance.decorateDialogs"));
131		decorateDialogs.setSelected(jEdit.getBooleanProperty("decorate.dialogs"));
132
133		if(OperatingSystem.hasJava14())
134		{
135			addComponent(decorateFrames);
136			addComponent(decorateDialogs);
137		}
138	} //}}}
139
140	//{{{ _save() method
141	protected void _save()
142	{
143		String lf = lfs[lookAndFeel.getSelectedIndex()].getClassName();
144		jEdit.setProperty("lookAndFeel",lf);
145		jEdit.setFontProperty("metal.primary.font",primaryFont.getFont());
146		jEdit.setFontProperty("metal.secondary.font",secondaryFont.getFont());
147		jEdit.setProperty("history",history.getText());
148		jEdit.setProperty("menu.spillover",menuSpillover.getText());
149		jEdit.setBooleanProperty("tip.show",showTips.isSelected());
150
151		// this is handled a little differently from other jEdit settings
152		// as the splash screen flag needs to be known very early in the
153		// startup sequence, before the user properties have been loaded
154		String settingsDirectory = jEdit.getSettingsDirectory();
155		if(settingsDirectory != null)
156		{
157			File file = new File(settingsDirectory,"nosplash");
158			if(showSplash.isSelected())
159				file.delete();
160			else
161			{
162				FileOutputStream out = null;
163				try
164				{
165					out = new FileOutputStream(file);
166					out.write('\n');
167					out.close();
168				}
169				catch(IOException io)
170				{
171					Log.log(Log.ERROR,this,io);
172				}
173				finally
174				{
175					try
176					{
177						if(out != null)
178							out.close();
179					}
180					catch(IOException e)
181					{
182					}
183				}
184			}
185		}
186		jEdit.setBooleanProperty("textColors",textColors.isSelected());
187		jEdit.setBooleanProperty("decorate.frames",decorateFrames.isSelected());
188		jEdit.setBooleanProperty("decorate.dialogs",decorateDialogs.isSelected());
189	} //}}}
190
191	//{{{ Private members
192
193	//{{{ Instance variables
194	private UIManager.LookAndFeelInfo[] lfs;
195	private JComboBox lookAndFeel;
196	private FontSelector primaryFont;
197	private FontSelector secondaryFont;
198	private JTextField history;
199	private JTextField menuSpillover;
200	private JCheckBox showTips;
201	private JCheckBox showSplash;
202	private JCheckBox textColors;
203	private JCheckBox decorateFrames;
204	private JCheckBox decorateDialogs;
205	//}}}
206
207	//{{{ updateEnabled() method
208	private void updateEnabled()
209	{
210		String className = lfs[lookAndFeel.getSelectedIndex()]
211			.getClassName();
212
213		if(className.equals("javax.swing.plaf.metal.MetalLookAndFeel")
214			|| className.equals("com.incors.plaf.kunststoff.KunststoffLookAndFeel"))
215		{
216			primaryFont.setEnabled(true);
217			secondaryFont.setEnabled(true);
218		}
219		else
220		{
221			primaryFont.setEnabled(false);
222			secondaryFont.setEnabled(false);
223		}
224	} //}}}
225
226	//}}}
227}