PageRenderTime 54ms CodeModel.GetById 44ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Java | 215 lines | 144 code | 27 blank | 44 comment | 10 complexity | a15bfac94d086a9b84424776404a045a 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, 2003 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				try
163				{
164					FileOutputStream out = new FileOutputStream(file);
165					out.write('\n');
166					out.close();
167				}
168				catch(IOException io)
169				{
170					Log.log(Log.ERROR,this,io);
171				}
172			}
173		}
174		jEdit.setBooleanProperty("textColors",textColors.isSelected());
175		jEdit.setBooleanProperty("decorate.frames",decorateFrames.isSelected());
176		jEdit.setBooleanProperty("decorate.dialogs",decorateDialogs.isSelected());
177	} //}}}
178
179	//{{{ Private members
180
181	//{{{ Instance variables
182	private UIManager.LookAndFeelInfo[] lfs;
183	private JComboBox lookAndFeel;
184	private FontSelector primaryFont;
185	private FontSelector secondaryFont;
186	private JTextField history;
187	private JTextField menuSpillover;
188	private JCheckBox showTips;
189	private JCheckBox showSplash;
190	private JCheckBox textColors;
191	private JCheckBox decorateFrames;
192	private JCheckBox decorateDialogs;
193	//}}}
194
195	//{{{ updateEnabled() method
196	private void updateEnabled()
197	{
198		String className = lfs[lookAndFeel.getSelectedIndex()]
199			.getClassName();
200
201		if(className.equals("javax.swing.plaf.metal.MetalLookAndFeel")
202			|| className.equals("com.incors.plaf.kunststoff.KunststoffLookAndFeel"))
203		{
204			primaryFont.setEnabled(true);
205			secondaryFont.setEnabled(true);
206		}
207		else
208		{
209			primaryFont.setEnabled(false);
210			secondaryFont.setEnabled(false);
211		}
212	} //}}}
213
214	//}}}
215}