PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/bundles/plugins-trunk/Console/console/options/GeneralOptionPane.java

#
Java | 207 lines | 140 code | 35 blank | 32 comment | 11 complexity | 600b0283ab9ff41b1053d6550677e53c 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. * GeneralOptionPane.java - General settings
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 1999, 2004 Slava Pestov
  7. * parts Copyright (C) 2010 Eric Le Lay
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. */
  23. package console.options;
  24. //{{{ Imports
  25. import java.awt.Color;
  26. import java.awt.event.ActionEvent;
  27. import java.awt.event.ActionListener;
  28. import java.util.Arrays;
  29. import javax.swing.JButton;
  30. import javax.swing.JCheckBox;
  31. import javax.swing.JColorChooser;
  32. import javax.swing.JComboBox;
  33. import javax.swing.JTextField;
  34. import org.gjt.sp.jedit.AbstractOptionPane;
  35. import org.gjt.sp.jedit.MiscUtilities;
  36. import org.gjt.sp.jedit.jEdit;
  37. import org.gjt.sp.jedit.gui.FontSelector;
  38. import org.gjt.sp.util.StandardUtilities.StringCompare;
  39. import org.gjt.sp.util.StringList;
  40. import org.gjt.sp.jedit.gui.HistoryModel ;
  41. import console.Shell;
  42. import console.gui.Label;
  43. //}}}
  44. public class GeneralOptionPane extends AbstractOptionPane
  45. {
  46. // {{{ data members
  47. private FontSelector font;
  48. private JComboBox encoding;
  49. private JComboBox defaultShell;
  50. private JButton bgColor;
  51. private JButton plainColor;
  52. private JButton caretColor;
  53. private JButton infoColor;
  54. private JButton warningColor;
  55. private JButton errorColor;
  56. private JCheckBox showWelcomeMessage;
  57. private JTextField limit ;
  58. private JTextField limitHistory ;
  59. // }}}
  60. //{{{ GeneralOptionPane constructor
  61. public GeneralOptionPane()
  62. {
  63. super("console.general");
  64. } //}}}
  65. //{{{ _init() method
  66. protected void _init()
  67. {
  68. StringList sl = new StringList(Shell.getShellNames());
  69. int idx = sl.indexOf("System");
  70. if (idx != 0) {
  71. String other = sl.get(0);
  72. sl.set(idx, other);
  73. sl.set(0, "System");
  74. }
  75. sl.add(jEdit.getProperty("options.last-selected"));
  76. defaultShell = new JComboBox(sl.toArray());
  77. String ds = jEdit.getProperty("console.shell.default", "System");
  78. defaultShell.setSelectedItem(ds);
  79. addComponent(jEdit.getProperty("options.console.general.defaultshell", "Default Shell:"),
  80. defaultShell);
  81. showWelcomeMessage = new JCheckBox();
  82. showWelcomeMessage.setText(jEdit.getProperty("options.console.general.welcome"));
  83. showWelcomeMessage.setSelected(jEdit.getBooleanProperty("console.shell.info.toggle"));
  84. addComponent(showWelcomeMessage);
  85. font = new FontSelector(jEdit.getFontProperty("console.font"));
  86. addComponent(jEdit.getProperty("options.console.general.font"), font);
  87. String[] encodings = MiscUtilities.getEncodings(true);
  88. // Arrays.sort(encodings,new MiscUtilities.StringICaseCompare());
  89. Arrays.sort(encodings, new StringCompare<String>(true));
  90. encoding = new JComboBox(encodings);
  91. encoding.setEditable(true);
  92. encoding.setSelectedItem(jEdit.getProperty("console.encoding"));
  93. addComponent(jEdit.getProperty("options.console.general.encoding"),
  94. encoding);
  95. Label limitLabel = new Label("options.console.general.charlimit");
  96. limit = new JTextField(jEdit.getProperty("console.outputLimit"));
  97. addComponent(limitLabel, limit);
  98. Label limitHistoryLabel = new Label("options.console.general.historylimit");
  99. limitHistory = new JTextField(jEdit.getProperty("console.historyLimit",
  100. String.valueOf(HistoryModel.getDefaultMax())));
  101. addComponent(limitHistoryLabel, limitHistory);
  102. addComponent(jEdit.getProperty("options.console.general.bgColor"),
  103. bgColor = createColorButton("console.bgColor"));
  104. bgColor.setToolTipText(jEdit.getProperty("options.console.general.bgColor.tooltip"));
  105. addComponent(jEdit.getProperty("options.console.general.plainColor"),
  106. plainColor = createColorButton("console.plainColor"));
  107. plainColor.setToolTipText(jEdit.getProperty("options.console.general.bgColor.tooltip"));
  108. addComponent(jEdit.getProperty("options.console.general.caretColor"),
  109. caretColor = createColorButton("console.caretColor"));
  110. caretColor.setToolTipText(jEdit.getProperty("options.console.general.bgColor.tooltip"));
  111. addComponent(jEdit.getProperty("options.console.general.infoColor"),
  112. infoColor = createColorButton("console.infoColor"));
  113. addComponent(jEdit.getProperty("options.console.general.warningColor"),
  114. warningColor = createColorButton("console.warningColor"));
  115. addComponent(jEdit.getProperty("options.console.general.errorColor"),
  116. errorColor = createColorButton("console.errorColor"));
  117. } //}}}
  118. //{{{ _save() method
  119. protected void _save()
  120. {
  121. jEdit.setBooleanProperty("console.shell.info.toggle", showWelcomeMessage.isSelected());
  122. jEdit.setFontProperty("console.font",font.getFont());
  123. String limitstr = limit.getText();
  124. if(limitstr != null && limitstr.length() > 0)
  125. jEdit.setProperty("console.outputLimit", limitstr);
  126. else
  127. jEdit.unsetProperty("console.outputLimit");
  128. String limithist = limitHistory.getText();
  129. if(limithist != null && limithist.length() > 0
  130. && !String.valueOf(HistoryModel.getDefaultMax()).equals(limithist))
  131. jEdit.setProperty("console.historyLimit", limithist);
  132. else
  133. jEdit.unsetProperty("console.historyLimit");
  134. jEdit.setProperty("console.encoding",
  135. (String)encoding.getSelectedItem());
  136. jEdit.setProperty("console.shell.default",
  137. (String)defaultShell.getSelectedItem());
  138. jEdit.setColorProperty("console.bgColor",
  139. bgColor.getBackground());
  140. jEdit.setColorProperty("console.plainColor",
  141. plainColor.getBackground());
  142. jEdit.setColorProperty("console.caretColor",
  143. caretColor.getBackground());
  144. jEdit.setColorProperty("console.infoColor",
  145. infoColor.getBackground());
  146. jEdit.setColorProperty("console.warningColor",
  147. warningColor.getBackground());
  148. jEdit.setColorProperty("console.errorColor",
  149. errorColor.getBackground());
  150. }
  151. //}}}
  152. //{{{ createColorButton() method
  153. private JButton createColorButton(String property)
  154. {
  155. final JButton b = new JButton(" ");
  156. b.setBackground(jEdit.getColorProperty(property));
  157. b.addActionListener(new ActionListener()
  158. {
  159. public void actionPerformed(ActionEvent evt)
  160. {
  161. Color c = JColorChooser.showDialog(
  162. GeneralOptionPane.this,
  163. jEdit.getProperty("colorChooser.title"),
  164. b.getBackground());
  165. if(c != null)
  166. b.setBackground(c);
  167. }
  168. });
  169. b.setRequestFocusEnabled(false);
  170. return b;
  171. } //}}}
  172. }