PageRenderTime 38ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/options/GutterOptionPane.java

#
Java | 290 lines | 178 code | 36 blank | 76 comment | 6 complexity | 30d2bea2db3a25e329d616503351bfd7 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. * GutterOptionPane.java - Gutter options panel
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2000 mike dillon
  7. * Portions copyright (C) 2001, 2002 Slava Pestov
  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 org.gjt.sp.jedit.options;
  24. //{{{ Imports
  25. import javax.swing.*;
  26. import java.awt.*;
  27. import org.gjt.sp.jedit.gui.*;
  28. import org.gjt.sp.jedit.*;
  29. //}}}
  30. public class GutterOptionPane extends AbstractOptionPane
  31. {
  32. //{{{ GutterOptionPane constructor
  33. public GutterOptionPane()
  34. {
  35. super("gutter");
  36. } //}}}
  37. //{{{ _init() method
  38. public void _init()
  39. {
  40. /* Line numbering */
  41. lineNumbersEnabled = new JCheckBox(jEdit.getProperty(
  42. "options.gutter.lineNumbers"));
  43. lineNumbersEnabled.setSelected(jEdit.getBooleanProperty(
  44. "view.gutter.lineNumbers"));
  45. addComponent(lineNumbersEnabled);
  46. /* Text font */
  47. gutterFont = new FontSelector(
  48. jEdit.getFontProperty("view.gutter.font",
  49. new Font("Monospaced",Font.PLAIN,10)));
  50. addComponent(jEdit.getProperty("options.gutter.font"),gutterFont);
  51. /* Text color */
  52. addComponent(jEdit.getProperty("options.gutter.foreground"),
  53. gutterForeground = new ColorWellButton(
  54. jEdit.getColorProperty("view.gutter.fgColor")),
  55. GridBagConstraints.VERTICAL);
  56. /* Background color */
  57. addComponent(jEdit.getProperty("options.gutter.background"),
  58. gutterBackground = new ColorWellButton(
  59. jEdit.getColorProperty("view.gutter.bgColor")),
  60. GridBagConstraints.VERTICAL);
  61. /* Border width */
  62. /* gutterBorderWidth = new JTextField(jEdit.getProperty(
  63. "view.gutter.borderWidth"));
  64. addComponent(jEdit.getProperty("options.gutter.borderWidth"),
  65. gutterBorderWidth); */
  66. /* Number alignment */
  67. /* String[] alignments = new String[] {
  68. "Left", "Center", "Right"
  69. };
  70. gutterNumberAlignment = new JComboBox(alignments);
  71. String alignment = jEdit.getProperty("view.gutter.numberAlignment");
  72. if("right".equals(alignment))
  73. gutterNumberAlignment.setSelectedIndex(2);
  74. else if("center".equals(alignment))
  75. gutterNumberAlignment.setSelectedIndex(1);
  76. else
  77. gutterNumberAlignment.setSelectedIndex(0);
  78. addComponent(jEdit.getProperty("options.gutter.numberAlignment"),
  79. gutterNumberAlignment); */
  80. /* Current line highlight */
  81. gutterCurrentLineHighlightEnabled = new JCheckBox(jEdit.getProperty(
  82. "options.gutter.currentLineHighlight"));
  83. gutterCurrentLineHighlightEnabled.setSelected(jEdit.getBooleanProperty(
  84. "view.gutter.highlightCurrentLine"));
  85. addComponent(gutterCurrentLineHighlightEnabled,
  86. gutterCurrentLineHighlight = new ColorWellButton(
  87. jEdit.getColorProperty("view.gutter.currentLineColor")),
  88. GridBagConstraints.VERTICAL);
  89. /* Highlight interval and color */
  90. gutterHighlightInterval = new JTextField(jEdit.getProperty(
  91. "view.gutter.highlightInterval"),3);
  92. Box gutterHighlightBox = new Box(BoxLayout.X_AXIS);
  93. gutterHighlightBox.add(new JLabel(jEdit.getProperty(
  94. "options.gutter.interval-1")));
  95. gutterHighlightBox.add(Box.createHorizontalStrut(3));
  96. gutterHighlightBox.add(gutterHighlightInterval);
  97. gutterHighlightBox.add(Box.createHorizontalStrut(3));
  98. gutterHighlightBox.add(new JLabel(jEdit.getProperty(
  99. "options.gutter.interval-2")));
  100. gutterHighlightBox.add(Box.createHorizontalStrut(12));
  101. addComponent(gutterHighlightBox,gutterHighlightColor
  102. = new ColorWellButton(jEdit.getColorProperty(
  103. "view.gutter.highlightColor")),
  104. GridBagConstraints.VERTICAL);
  105. /* Structure highlight */
  106. gutterStructureHighlightEnabled = new JCheckBox(jEdit.getProperty(
  107. "options.gutter.structureHighlight"));
  108. gutterStructureHighlightEnabled.setSelected(jEdit.getBooleanProperty(
  109. "view.gutter.structureHighlight"));
  110. addComponent(gutterStructureHighlightEnabled,
  111. gutterStructureHighlight = new ColorWellButton(
  112. jEdit.getColorProperty("view.gutter.structureHighlightColor")),
  113. GridBagConstraints.VERTICAL);
  114. /* Marker highlight */
  115. gutterMarkerHighlightEnabled = new JCheckBox(jEdit.getProperty(
  116. "options.gutter.markerHighlight"));
  117. gutterMarkerHighlightEnabled.setSelected(jEdit.getBooleanProperty(
  118. "view.gutter.markerHighlight"));
  119. addComponent(gutterMarkerHighlightEnabled,
  120. gutterMarkerHighlight = new ColorWellButton(
  121. jEdit.getColorProperty("view.gutter.markerColor")),
  122. GridBagConstraints.VERTICAL);
  123. /* Fold marker color */
  124. addComponent(jEdit.getProperty("options.gutter.foldColor"),
  125. gutterFoldMarkers = new ColorWellButton(
  126. jEdit.getColorProperty("view.gutter.foldColor")),
  127. GridBagConstraints.VERTICAL);
  128. /* Focused border color */
  129. addComponent(jEdit.getProperty("options.gutter.focusBorderColor"),
  130. gutterFocusBorder = new ColorWellButton(
  131. jEdit.getColorProperty("view.gutter.focusBorderColor")),
  132. GridBagConstraints.VERTICAL);
  133. /* unfocused border color */
  134. addComponent(jEdit.getProperty("options.gutter.noFocusBorderColor"),
  135. gutterNoFocusBorder = new ColorWellButton(
  136. jEdit.getColorProperty("view.gutter.noFocusBorderColor")),
  137. GridBagConstraints.VERTICAL);
  138. /* Mouse actions */
  139. addSeparator("options.gutter.actions");
  140. int c = clickActionKeys.length;
  141. String[] clickActionNames = new String[c];
  142. for(int i = 0; i < c; i++)
  143. {
  144. clickActionNames[i] = jEdit.getProperty(
  145. "options.gutter."+clickActionKeys[i]);
  146. }
  147. c = clickModifierKeys.length;
  148. String[] clickModifierNames = new String[c];
  149. for(int i = 0; i < c; i++)
  150. {
  151. clickModifierNames[i] = jEdit.getProperty(
  152. "options.gutter."+clickModifierKeys[i]);
  153. }
  154. gutterClickActions = new JComboBox[c];
  155. for(int i = 0; i < c; i++)
  156. {
  157. JComboBox cb = new JComboBox(clickActionNames);
  158. gutterClickActions[i] = cb;
  159. String val = jEdit.getProperty("view.gutter."+clickModifierKeys[i]);
  160. for(int j = 0; j < clickActionKeys.length; j++)
  161. {
  162. if(val.equals(clickActionKeys[j]))
  163. {
  164. cb.setSelectedIndex(j);
  165. }
  166. }
  167. addComponent(clickModifierNames[i],cb);
  168. }
  169. } //}}}
  170. //{{{ _save() method
  171. public void _save()
  172. {
  173. jEdit.setBooleanProperty("view.gutter.lineNumbers", lineNumbersEnabled
  174. .isSelected());
  175. jEdit.setFontProperty("view.gutter.font",gutterFont.getFont());
  176. jEdit.setColorProperty("view.gutter.fgColor",gutterForeground
  177. .getSelectedColor());
  178. jEdit.setColorProperty("view.gutter.bgColor",gutterBackground
  179. .getSelectedColor());
  180. /* jEdit.setProperty("view.gutter.borderWidth",
  181. gutterBorderWidth.getText());
  182. String alignment = null;
  183. switch(gutterNumberAlignment.getSelectedIndex())
  184. {
  185. case 2:
  186. alignment = "right";
  187. break;
  188. case 1:
  189. alignment = "center";
  190. break;
  191. case 0: default:
  192. alignment = "left";
  193. }
  194. jEdit.setProperty("view.gutter.numberAlignment", alignment); */
  195. jEdit.setBooleanProperty("view.gutter.highlightCurrentLine",
  196. gutterCurrentLineHighlightEnabled.isSelected());
  197. jEdit.setColorProperty("view.gutter.currentLineColor",
  198. gutterCurrentLineHighlight.getSelectedColor());
  199. jEdit.setProperty("view.gutter.highlightInterval",
  200. gutterHighlightInterval.getText());
  201. jEdit.setColorProperty("view.gutter.highlightColor",
  202. gutterHighlightColor.getSelectedColor());
  203. jEdit.setBooleanProperty("view.gutter.structureHighlight",
  204. gutterStructureHighlightEnabled.isSelected());
  205. jEdit.setColorProperty("view.gutter.structureHighlightColor",
  206. gutterStructureHighlight.getSelectedColor());
  207. jEdit.setBooleanProperty("view.gutter.markerHighlight",
  208. gutterMarkerHighlightEnabled.isSelected());
  209. jEdit.setColorProperty("view.gutter.markerColor",
  210. gutterMarkerHighlight.getSelectedColor());
  211. jEdit.setColorProperty("view.gutter.foldColor",
  212. gutterFoldMarkers.getSelectedColor());
  213. jEdit.setColorProperty("view.gutter.focusBorderColor",
  214. gutterFocusBorder.getSelectedColor());
  215. jEdit.setColorProperty("view.gutter.noFocusBorderColor",
  216. gutterNoFocusBorder.getSelectedColor());
  217. int c = clickModifierKeys.length;
  218. for(int i = 0; i < c; i++)
  219. {
  220. int idx = gutterClickActions[i].getSelectedIndex();
  221. jEdit.setProperty("view.gutter."+clickModifierKeys[i],
  222. clickActionKeys[idx]);
  223. }
  224. } //}}}
  225. //{{{ Private members
  226. private FontSelector gutterFont;
  227. private ColorWellButton gutterForeground;
  228. private ColorWellButton gutterBackground;
  229. private JTextField gutterBorderWidth;
  230. private JTextField gutterHighlightInterval;
  231. private ColorWellButton gutterHighlightColor;
  232. private JComboBox gutterNumberAlignment;
  233. private JCheckBox lineNumbersEnabled;
  234. private JCheckBox gutterCurrentLineHighlightEnabled;
  235. private ColorWellButton gutterCurrentLineHighlight;
  236. private JCheckBox gutterStructureHighlightEnabled;
  237. private ColorWellButton gutterStructureHighlight;
  238. private JCheckBox gutterMarkerHighlightEnabled;
  239. private ColorWellButton gutterMarkerHighlight;
  240. private ColorWellButton gutterFoldMarkers;
  241. private ColorWellButton gutterFocusBorder;
  242. private ColorWellButton gutterNoFocusBorder;
  243. private JComboBox[] gutterClickActions;
  244. // simplified these settings a little...
  245. private static final String[] clickActionKeys = new String[] {
  246. "toggle-fold",
  247. "toggle-fold-fully"
  248. };
  249. private static final String[] clickModifierKeys = new String[] {
  250. "foldClick",
  251. "SfoldClick"
  252. }; //}}}
  253. }