PageRenderTime 53ms CodeModel.GetById 20ms app.highlight 11ms RepoModel.GetById 20ms app.codeStats 0ms

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

#
Java | 154 lines | 97 code | 20 blank | 37 comment | 5 complexity | 0c96096662e1f87df610b4f31b154ec3 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 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		/* Use jEdit colors in all text components */
 88		textColors = new JCheckBox(jEdit.getProperty(
 89			"options.appearance.textColors"));
 90		textColors.setSelected(jEdit.getBooleanProperty("textColors"));
 91		addComponent(textColors);
 92
 93		/* Decorate frames with look and feel (JDK 1.4 only) */
 94		decorateFrames = new JCheckBox(jEdit.getProperty(
 95			"options.appearance.decorateFrames"));
 96		decorateFrames.setSelected(jEdit.getBooleanProperty("decorate.frames"));
 97
 98		/* Decorate dialogs with look and feel (JDK 1.4 only) */
 99		decorateDialogs = new JCheckBox(jEdit.getProperty(
100			"options.appearance.decorateDialogs"));
101		decorateDialogs.setSelected(jEdit.getBooleanProperty("decorate.dialogs"));
102
103		if(OperatingSystem.hasJava14())
104		{
105			addComponent(decorateFrames);
106			addComponent(decorateDialogs);
107		}
108	} //}}}
109
110	//{{{ _save() method
111	protected void _save()
112	{
113		String lf = lfs[lookAndFeel.getSelectedIndex()].getClassName();
114		jEdit.setProperty("lookAndFeel",lf);
115		jEdit.setFontProperty("metal.primary.font",primaryFont.getFont());
116		jEdit.setFontProperty("metal.secondary.font",secondaryFont.getFont());
117		jEdit.setBooleanProperty("textColors",textColors.isSelected());
118		jEdit.setBooleanProperty("decorate.frames",decorateFrames.isSelected());
119		jEdit.setBooleanProperty("decorate.dialogs",decorateDialogs.isSelected());
120	} //}}}
121
122	//{{{ Private members
123
124	//{{{ Instance variables
125	private UIManager.LookAndFeelInfo[] lfs;
126	private JComboBox lookAndFeel;
127	private FontSelector primaryFont;
128	private FontSelector secondaryFont;
129	private JCheckBox textColors;
130	private JCheckBox decorateFrames;
131	private JCheckBox decorateDialogs;
132	//}}}
133
134	//{{{ updateEnabled() method
135	private void updateEnabled()
136	{
137		String className = lfs[lookAndFeel.getSelectedIndex()]
138			.getClassName();
139
140		if(className.equals("javax.swing.plaf.metal.MetalLookAndFeel")
141			|| className.equals("com.incors.plaf.kunststoff.KunststoffLookAndFeel"))
142		{
143			primaryFont.setEnabled(true);
144			secondaryFont.setEnabled(true);
145		}
146		else
147		{
148			primaryFont.setEnabled(false);
149			secondaryFont.setEnabled(false);
150		}
151	} //}}}
152
153	//}}}
154}