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