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