001: /*
002: * AppearanceOptionPane.java - Appearance options panel
003: * :tabSize=8:indentSize=8:noTabs=false:
004: * :folding=explicit:collapseFolds=1:
005: *
006: * Copyright (C) 2001, 2004 Slava Pestov
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: */
022:
023: package org.gjt.sp.jedit.options;
024:
025: //{{{ Imports
026: import javax.swing.*;
027: import java.awt.event.*;
028: import java.io.*;
029: import org.gjt.sp.jedit.gui.FontSelector;
030: import org.gjt.sp.jedit.*;
031: import org.gjt.sp.util.Log;
032: import org.gjt.sp.util.IOUtilities;
033:
034: //}}}
035:
036: public class AppearanceOptionPane extends AbstractOptionPane {
037: //{{{ AppearanceOptionPane constructor
038: public AppearanceOptionPane() {
039: super ("appearance");
040: } //}}}
041:
042: //{{{ _init() method
043: protected void _init() {
044: /* Look and feel */
045: addComponent(new JLabel(jEdit
046: .getProperty("options.appearance.lf.note")));
047:
048: lfs = UIManager.getInstalledLookAndFeels();
049: String[] names = new String[lfs.length];
050: String lf = UIManager.getLookAndFeel().getClass().getName();
051: int index = 0;
052: for (int i = 0; i < names.length; i++) {
053: names[i] = lfs[i].getName();
054: if (lf.equals(lfs[i].getClassName()))
055: index = i;
056: }
057:
058: lookAndFeel = new JComboBox(names);
059: lookAndFeel.setSelectedIndex(index);
060: lookAndFeel.addActionListener(new ActionListener() {
061: public void actionPerformed(ActionEvent evt) {
062: updateEnabled();
063: }
064: });
065:
066: addComponent(jEdit.getProperty("options.appearance.lf"),
067: lookAndFeel);
068:
069: /* Primary Metal L&F font */
070: primaryFont = new FontSelector(jEdit
071: .getFontProperty("metal.primary.font"));
072: addComponent(jEdit
073: .getProperty("options.appearance.primaryFont"),
074: primaryFont);
075:
076: /* Secondary Metal L&F font */
077: secondaryFont = new FontSelector(jEdit
078: .getFontProperty("metal.secondary.font"));
079: addComponent(jEdit
080: .getProperty("options.appearance.secondaryFont"),
081: secondaryFont);
082:
083: /*
084: antiAliasExtras = new JComboBox(AntiAlias.comboChoices);
085: antiAliasExtras.setSelectedIndex(AntiAlias.appearance().val());
086: antiAliasExtras.setToolTipText(jEdit.getProperty("options.textarea.antiAlias.tooltip"));
087: addComponent(jEdit.getProperty("options.appearance.fonts.antialias"), antiAliasExtras);
088: */
089: updateEnabled();
090:
091: /* History count */
092: history = new JTextField(jEdit.getProperty("history"));
093: addComponent(jEdit.getProperty("options.appearance.history"),
094: history);
095:
096: /* Menu spillover count */
097: menuSpillover = new JTextField(jEdit
098: .getProperty("menu.spillover"));
099: addComponent(jEdit
100: .getProperty("options.appearance.menuSpillover"),
101: menuSpillover);
102:
103: continuousLayout = new JCheckBox(
104: jEdit
105: .getProperty("options.appearance.continuousLayout.label"));
106: continuousLayout.setSelected(jEdit
107: .getBooleanProperty("appearance.continuousLayout"));
108: addComponent(continuousLayout);
109:
110: addSeparator("options.appearance.startup.label");
111:
112: /* Show splash screen */
113: showSplash = new JCheckBox(jEdit
114: .getProperty("options.appearance.showSplash"));
115: String settingsDirectory = jEdit.getSettingsDirectory();
116: if (settingsDirectory == null)
117: showSplash.setSelected(true);
118: else
119: showSplash.setSelected(!new File(settingsDirectory,
120: "nosplash").exists());
121: addComponent(showSplash);
122:
123: /* Show tip of the day */
124: showTips = new JCheckBox(jEdit
125: .getProperty("options.appearance.showTips"));
126: showTips.setSelected(jEdit.getBooleanProperty("tip.show"));
127: addComponent(showTips);
128:
129: addSeparator("options.appearance.experimental.label");
130: addComponent(GUIUtilities
131: .createMultilineLabel(jEdit
132: .getProperty("options.appearance.experimental.caption")));
133:
134: /* Use jEdit colors in all text components */
135: textColors = new JCheckBox(jEdit
136: .getProperty("options.appearance.textColors"));
137: textColors.setSelected(jEdit.getBooleanProperty("textColors"));
138: addComponent(textColors);
139:
140: /* Decorate frames with look and feel (JDK 1.4 only) */
141: decorateFrames = new JCheckBox(jEdit
142: .getProperty("options.appearance.decorateFrames"));
143: decorateFrames.setSelected(jEdit
144: .getBooleanProperty("decorate.frames"));
145: addComponent(decorateFrames);
146:
147: /* Decorate dialogs with look and feel (JDK 1.4 only) */
148: decorateDialogs = new JCheckBox(jEdit
149: .getProperty("options.appearance.decorateDialogs"));
150: decorateDialogs.setSelected(jEdit
151: .getBooleanProperty("decorate.dialogs"));
152: addComponent(decorateDialogs);
153: } //}}}
154:
155: //{{{ _save() method
156: protected void _save() {
157: String lf = lfs[lookAndFeel.getSelectedIndex()].getClassName();
158: jEdit.setProperty("lookAndFeel", lf);
159: jEdit.setFontProperty("metal.primary.font", primaryFont
160: .getFont());
161: jEdit.setFontProperty("metal.secondary.font", secondaryFont
162: .getFont());
163: jEdit.setProperty("history", history.getText());
164: jEdit.setProperty("menu.spillover", menuSpillover.getText());
165: jEdit.setBooleanProperty("tip.show", showTips.isSelected());
166: jEdit.setBooleanProperty("appearance.continuousLayout",
167: continuousLayout.isSelected());
168:
169: /* AntiAlias nv = AntiAlias.appearance();
170: int idx = antiAliasExtras.getSelectedIndex();
171: nv.set(idx);
172: primaryFont.setAntiAliasEnabled(idx > 0);
173: secondaryFont.setAntiAliasEnabled(idx > 0);
174: primaryFont.repaint();
175: secondaryFont.repaint(); */
176:
177: // this is handled a little differently from other jEdit settings
178: // as the splash screen flag needs to be known very early in the
179: // startup sequence, before the user properties have been loaded
180: String settingsDirectory = jEdit.getSettingsDirectory();
181: if (settingsDirectory != null) {
182: File file = new File(settingsDirectory, "nosplash");
183: if (showSplash.isSelected())
184: file.delete();
185: else {
186: FileOutputStream out = null;
187: try {
188: out = new FileOutputStream(file);
189: out.write('\n');
190: out.close();
191: } catch (IOException io) {
192: Log.log(Log.ERROR, this , io);
193: } finally {
194: IOUtilities.closeQuietly(out);
195: }
196: }
197: }
198: jEdit.setBooleanProperty("textColors", textColors.isSelected());
199: jEdit.setBooleanProperty("decorate.frames", decorateFrames
200: .isSelected());
201: jEdit.setBooleanProperty("decorate.dialogs", decorateDialogs
202: .isSelected());
203: } //}}}
204:
205: //{{{ Private members
206:
207: //{{{ Instance variables
208: private UIManager.LookAndFeelInfo[] lfs;
209: private JComboBox lookAndFeel;
210: private FontSelector primaryFont;
211: private FontSelector secondaryFont;
212: private JTextField history;
213: private JTextField menuSpillover;
214: private JCheckBox showTips;
215: private JCheckBox continuousLayout;
216: private JCheckBox showSplash;
217: private JCheckBox textColors;
218: private JCheckBox decorateFrames;
219: private JCheckBox decorateDialogs;
220: private JComboBox antiAliasExtras;
221:
222: //}}}
223:
224: //{{{ updateEnabled() method
225: private void updateEnabled() {
226: String className = lfs[lookAndFeel.getSelectedIndex()]
227: .getClassName();
228:
229: if (className.equals("javax.swing.plaf.metal.MetalLookAndFeel")
230: || className
231: .equals("com.incors.plaf.kunststoff.KunststoffLookAndFeel")) {
232: primaryFont.setEnabled(true);
233: secondaryFont.setEnabled(true);
234: } else {
235: primaryFont.setEnabled(false);
236: secondaryFont.setEnabled(false);
237: }
238: } //}}}
239:
240: //}}}
241: }
|