PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/options/GutterOptionPane.java

#
Java | 394 lines | 262 code | 44 blank | 88 comment | 6 complexity | 6b0dd6e094fef51630fb7551f10936bd 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 javax.swing.event.ChangeEvent;
  27. import javax.swing.event.ChangeListener;
  28. import java.awt.*;
  29. import org.gjt.sp.jedit.gui.*;
  30. import org.gjt.sp.jedit.textarea.JEditTextArea;
  31. import org.gjt.sp.jedit.*;
  32. //}}}
  33. import org.gjt.sp.util.SyntaxUtilities;
  34. public class GutterOptionPane extends AbstractOptionPane
  35. {
  36. //{{{ GutterOptionPane constructor
  37. public GutterOptionPane()
  38. {
  39. super("gutter");
  40. } //}}}
  41. //{{{ _init() method
  42. public void _init()
  43. {
  44. /* Gutter enable */
  45. gutterEnabled = new JCheckBox(jEdit.getProperty(
  46. "options.gutter.enabled"));
  47. gutterEnabled.setSelected(isGutterEnabled());
  48. addComponent(gutterEnabled);
  49. /* Gutter components frame */
  50. GridBagConstraints cons = new GridBagConstraints();
  51. cons.gridheight = 1;
  52. cons.gridwidth = GridBagConstraints.REMAINDER;
  53. cons.fill = GridBagConstraints.HORIZONTAL;
  54. cons.anchor = GridBagConstraints.WEST;
  55. cons.weightx = 1.0f;
  56. cons.ipadx = 0;
  57. cons.ipady = 0;
  58. cons.insets = new Insets(0,0,0,0);
  59. gutterComponents = new JPanel(new GridBagLayout());
  60. gutterComponents.setBorder(BorderFactory.createTitledBorder(
  61. jEdit.getProperty("options.gutter.optionalComponents")));
  62. IntegerInputVerifier integerInputVerifier = new IntegerInputVerifier();
  63. /* Line numbering */
  64. lineNumbersEnabled = new JCheckBox(jEdit.getProperty(
  65. "options.gutter.lineNumbers"));
  66. lineNumbersEnabled.setSelected(jEdit.getBooleanProperty(
  67. "view.gutter.lineNumbers"));
  68. gutterComponents.add(lineNumbersEnabled, cons);
  69. minLineNumberDigits = new JTextField(String.valueOf(
  70. getMinLineNumberDigits()),1);
  71. minLineNumberDigits.setInputVerifier(integerInputVerifier);
  72. JPanel minLineNumberDigitsPanel = new JPanel();
  73. minLineNumberDigitsPanel.add(new JLabel(
  74. jEdit.getProperty("options.gutter.minLineNumberDigits")));
  75. minLineNumberDigitsPanel.add(minLineNumberDigits);
  76. cons.gridy = 1;
  77. gutterComponents.add(minLineNumberDigitsPanel, cons);
  78. /* Selection area enable */
  79. selectionAreaEnabled = new JCheckBox(jEdit.getProperty(
  80. "options.gutter.selectionAreaEnabled"));
  81. selectionAreaEnabled.setSelected(isSelectionAreaEnabled());
  82. cons.gridy = 2;
  83. gutterComponents.add(selectionAreaEnabled, cons);
  84. addComponent(gutterComponents);
  85. // Disable gutter components when 'show gutter' is unchecked
  86. setGutterComponentsEnabledState();
  87. gutterEnabled.addChangeListener(new ChangeListener()
  88. {
  89. public void stateChanged(ChangeEvent e)
  90. {
  91. setGutterComponentsEnabledState();
  92. }
  93. });
  94. /* Selection area background color */
  95. addComponent(jEdit.getProperty("options.gutter.selectionAreaBgColor"),
  96. selectionAreaBgColor = new ColorWellButton(
  97. getSelectionAreaBackground()), GridBagConstraints.VERTICAL);
  98. /* Selection area width */
  99. selectionAreaWidth = new JTextField(String.valueOf(
  100. getSelectionAreaWidth()),DEFAULT_SELECTION_GUTTER_WIDTH);
  101. selectionAreaWidth.setInputVerifier(integerInputVerifier);
  102. addComponent(jEdit.getProperty("options.gutter.selectionAreaWidth"),
  103. selectionAreaWidth);
  104. /* Text font */
  105. gutterFont = new FontSelector(
  106. jEdit.getFontProperty("view.gutter.font",
  107. new Font("Monospaced",Font.PLAIN,10)));
  108. addComponent(jEdit.getProperty("options.gutter.font"),gutterFont);
  109. /* Text color */
  110. addComponent(jEdit.getProperty("options.gutter.foreground"),
  111. gutterForeground = new ColorWellButton(
  112. jEdit.getColorProperty("view.gutter.fgColor")),
  113. GridBagConstraints.VERTICAL);
  114. /* Background color */
  115. addComponent(jEdit.getProperty("options.gutter.background"),
  116. gutterBackground = new ColorWellButton(
  117. jEdit.getColorProperty("view.gutter.bgColor")),
  118. GridBagConstraints.VERTICAL);
  119. /* Border width */
  120. /* gutterBorderWidth = new JTextField(jEdit.getProperty(
  121. "view.gutter.borderWidth"));
  122. addComponent(jEdit.getProperty("options.gutter.borderWidth"),
  123. gutterBorderWidth); */
  124. /* Number alignment */
  125. /* String[] alignments = new String[] {
  126. "Left", "Center", "Right"
  127. };
  128. gutterNumberAlignment = new JComboBox(alignments);
  129. String alignment = jEdit.getProperty("view.gutter.numberAlignment");
  130. if("right".equals(alignment))
  131. gutterNumberAlignment.setSelectedIndex(2);
  132. else if("center".equals(alignment))
  133. gutterNumberAlignment.setSelectedIndex(1);
  134. else
  135. gutterNumberAlignment.setSelectedIndex(0);
  136. addComponent(jEdit.getProperty("options.gutter.numberAlignment"),
  137. gutterNumberAlignment); */
  138. /* Current line highlight */
  139. gutterCurrentLineHighlightEnabled = new JCheckBox(jEdit.getProperty(
  140. "options.gutter.currentLineHighlight"));
  141. gutterCurrentLineHighlightEnabled.setSelected(jEdit.getBooleanProperty(
  142. "view.gutter.highlightCurrentLine"));
  143. addComponent(gutterCurrentLineHighlightEnabled,
  144. gutterCurrentLineHighlight = new ColorWellButton(
  145. jEdit.getColorProperty("view.gutter.currentLineColor")),
  146. GridBagConstraints.VERTICAL);
  147. /* Highlight interval and color */
  148. gutterHighlightInterval = new JTextField(jEdit.getProperty(
  149. "view.gutter.highlightInterval"),3);
  150. Box gutterHighlightBox = new Box(BoxLayout.X_AXIS);
  151. gutterHighlightBox.add(new JLabel(jEdit.getProperty(
  152. "options.gutter.interval-1")));
  153. gutterHighlightBox.add(Box.createHorizontalStrut(3));
  154. gutterHighlightBox.add(gutterHighlightInterval);
  155. gutterHighlightBox.add(Box.createHorizontalStrut(3));
  156. gutterHighlightBox.add(new JLabel(jEdit.getProperty(
  157. "options.gutter.interval-2")));
  158. gutterHighlightBox.add(Box.createHorizontalStrut(12));
  159. addComponent(gutterHighlightBox,gutterHighlightColor
  160. = new ColorWellButton(jEdit.getColorProperty(
  161. "view.gutter.highlightColor")),
  162. GridBagConstraints.VERTICAL);
  163. /* Structure highlight */
  164. gutterStructureHighlightEnabled = new JCheckBox(jEdit.getProperty(
  165. "options.gutter.structureHighlight"));
  166. gutterStructureHighlightEnabled.setSelected(jEdit.getBooleanProperty(
  167. "view.gutter.structureHighlight"));
  168. addComponent(gutterStructureHighlightEnabled,
  169. gutterStructureHighlight = new ColorWellButton(
  170. jEdit.getColorProperty("view.gutter.structureHighlightColor")),
  171. GridBagConstraints.VERTICAL);
  172. /* Marker highlight */
  173. gutterMarkerHighlightEnabled = new JCheckBox(jEdit.getProperty(
  174. "options.gutter.markerHighlight"));
  175. gutterMarkerHighlightEnabled.setSelected(jEdit.getBooleanProperty(
  176. "view.gutter.markerHighlight"));
  177. addComponent(gutterMarkerHighlightEnabled,
  178. gutterMarkerHighlight = new ColorWellButton(
  179. jEdit.getColorProperty("view.gutter.markerColor")),
  180. GridBagConstraints.VERTICAL);
  181. /* Fold marker color */
  182. addComponent(jEdit.getProperty("options.gutter.foldColor"),
  183. gutterFoldMarkers = new ColorWellButton(
  184. jEdit.getColorProperty("view.gutter.foldColor")),
  185. GridBagConstraints.VERTICAL);
  186. /* Focused border color */
  187. addComponent(jEdit.getProperty("options.gutter.focusBorderColor"),
  188. gutterFocusBorder = new ColorWellButton(
  189. jEdit.getColorProperty("view.gutter.focusBorderColor")),
  190. GridBagConstraints.VERTICAL);
  191. /* unfocused border color */
  192. addComponent(jEdit.getProperty("options.gutter.noFocusBorderColor"),
  193. gutterNoFocusBorder = new ColorWellButton(
  194. jEdit.getColorProperty("view.gutter.noFocusBorderColor")),
  195. GridBagConstraints.VERTICAL);
  196. addFoldStyleChooser();
  197. } //}}}
  198. //{{{ _save() method
  199. public void _save()
  200. {
  201. jEdit.setBooleanProperty("view.gutter.lineNumbers", lineNumbersEnabled
  202. .isSelected());
  203. jEdit.setIntegerProperty("view.gutter.minDigitCount",
  204. Integer.valueOf(minLineNumberDigits.getText()));
  205. jEdit.setFontProperty("view.gutter.font",gutterFont.getFont());
  206. jEdit.setColorProperty("view.gutter.fgColor",gutterForeground
  207. .getSelectedColor());
  208. jEdit.setColorProperty("view.gutter.bgColor",gutterBackground
  209. .getSelectedColor());
  210. /* jEdit.setProperty("view.gutter.borderWidth",
  211. gutterBorderWidth.getText());
  212. String alignment = null;
  213. switch(gutterNumberAlignment.getSelectedIndex())
  214. {
  215. case 2:
  216. alignment = "right";
  217. break;
  218. case 1:
  219. alignment = "center";
  220. break;
  221. case 0: default:
  222. alignment = "left";
  223. }
  224. jEdit.setProperty("view.gutter.numberAlignment", alignment); */
  225. jEdit.setBooleanProperty("view.gutter.highlightCurrentLine",
  226. gutterCurrentLineHighlightEnabled.isSelected());
  227. jEdit.setColorProperty("view.gutter.currentLineColor",
  228. gutterCurrentLineHighlight.getSelectedColor());
  229. jEdit.setProperty("view.gutter.highlightInterval",
  230. gutterHighlightInterval.getText());
  231. jEdit.setColorProperty("view.gutter.highlightColor",
  232. gutterHighlightColor.getSelectedColor());
  233. jEdit.setBooleanProperty("view.gutter.structureHighlight",
  234. gutterStructureHighlightEnabled.isSelected());
  235. jEdit.setColorProperty("view.gutter.structureHighlightColor",
  236. gutterStructureHighlight.getSelectedColor());
  237. jEdit.setBooleanProperty("view.gutter.markerHighlight",
  238. gutterMarkerHighlightEnabled.isSelected());
  239. jEdit.setColorProperty("view.gutter.markerColor",
  240. gutterMarkerHighlight.getSelectedColor());
  241. jEdit.setColorProperty("view.gutter.foldColor",
  242. gutterFoldMarkers.getSelectedColor());
  243. jEdit.setProperty(JEditTextArea.FOLD_PAINTER_PROPERTY,
  244. painters[foldPainter.getSelectedIndex()]);
  245. jEdit.setColorProperty("view.gutter.focusBorderColor",
  246. gutterFocusBorder.getSelectedColor());
  247. jEdit.setColorProperty("view.gutter.noFocusBorderColor",
  248. gutterNoFocusBorder.getSelectedColor());
  249. jEdit.setBooleanProperty(GUTTER_ENABLED_PROPERTY,
  250. gutterEnabled.isSelected());
  251. jEdit.setBooleanProperty(SELECTION_AREA_ENABLED_PROPERTY,
  252. selectionAreaEnabled.isSelected());
  253. jEdit.setColorProperty(SELECTION_AREA_BGCOLOR_PROPERTY,
  254. selectionAreaBgColor.getSelectedColor());
  255. jEdit.setIntegerProperty("view.gutter.selectionAreaWidth",
  256. Integer.valueOf(selectionAreaWidth.getText()));
  257. } //}}}
  258. //{{{ setGutterComponentsEnabledState
  259. private void setGutterComponentsEnabledState()
  260. {
  261. GUIUtilities.setEnabledRecursively(gutterComponents,
  262. gutterEnabled.isSelected());
  263. } //}}}
  264. //{{{ addFoldStyleChooser() method
  265. private void addFoldStyleChooser()
  266. {
  267. painters = ServiceManager.getServiceNames(JEditTextArea.FOLD_PAINTER_SERVICE);
  268. foldPainter = new JComboBox();
  269. String current = JEditTextArea.getFoldPainterName();
  270. int selected = 0;
  271. for (int i = 0; i < painters.length; i++)
  272. {
  273. String painter = painters[i];
  274. foldPainter.addItem(jEdit.getProperty(
  275. "options.gutter.foldStyleNames." + painter, painter));
  276. if (painter.equals(current))
  277. selected = i;
  278. }
  279. foldPainter.setSelectedIndex(selected);
  280. addComponent(new JLabel(jEdit.getProperty("options.gutter.foldStyle.label")), foldPainter);
  281. } //}}}
  282. //{{{ isGutterEnabled() method
  283. public static boolean isGutterEnabled()
  284. {
  285. return jEdit.getBooleanProperty(GUTTER_ENABLED_PROPERTY);
  286. } //}}}
  287. //{{{ getMinLineNumberDigits() method
  288. public static int getMinLineNumberDigits()
  289. {
  290. int n = jEdit.getIntegerProperty("view.gutter.minDigitCount", 2);
  291. if (n < 0)
  292. n = 2;
  293. return n;
  294. } //}}}
  295. //{{{ isSelectionAreaEnabled() method
  296. public static boolean isSelectionAreaEnabled()
  297. {
  298. return jEdit.getBooleanProperty(SELECTION_AREA_ENABLED_PROPERTY);
  299. } //}}}
  300. //{{{ getSelectionAreaBgColor() method
  301. public static Color getSelectionAreaBackground()
  302. {
  303. String color = jEdit.getProperty(SELECTION_AREA_BGCOLOR_PROPERTY);
  304. if (color == null)
  305. return jEdit.getColorProperty("view.gutter.bgColor");
  306. return SyntaxUtilities.parseColor(color, Color.black);
  307. } //}}}
  308. //{{{ getSelectionAreaWidth() method
  309. public static int getSelectionAreaWidth()
  310. {
  311. int n = jEdit.getIntegerProperty("view.gutter.selectionAreaWidth",
  312. DEFAULT_SELECTION_GUTTER_WIDTH);
  313. if (n < 0)
  314. n = DEFAULT_SELECTION_GUTTER_WIDTH;
  315. return n;
  316. } //}}}
  317. //{{{ Private members
  318. private static final String GUTTER_ENABLED_PROPERTY =
  319. "view.gutter.enabled";
  320. private static final String SELECTION_AREA_ENABLED_PROPERTY =
  321. "view.gutter.selectionAreaEnabled";
  322. private static final String SELECTION_AREA_BGCOLOR_PROPERTY =
  323. "view.gutter.selectionAreaBgColor";
  324. private static final int DEFAULT_SELECTION_GUTTER_WIDTH = 12;
  325. private FontSelector gutterFont;
  326. private ColorWellButton gutterForeground;
  327. private ColorWellButton gutterBackground;
  328. private JTextField gutterHighlightInterval;
  329. private ColorWellButton gutterHighlightColor;
  330. private JCheckBox lineNumbersEnabled;
  331. private JCheckBox gutterCurrentLineHighlightEnabled;
  332. private ColorWellButton gutterCurrentLineHighlight;
  333. private JCheckBox gutterStructureHighlightEnabled;
  334. private ColorWellButton gutterStructureHighlight;
  335. private JCheckBox gutterMarkerHighlightEnabled;
  336. private ColorWellButton gutterMarkerHighlight;
  337. private ColorWellButton gutterFoldMarkers;
  338. private JComboBox foldPainter;
  339. private ColorWellButton gutterFocusBorder;
  340. private ColorWellButton gutterNoFocusBorder;
  341. private String [] painters;
  342. private JCheckBox gutterEnabled;
  343. private JPanel gutterComponents;
  344. private JTextField minLineNumberDigits;
  345. private JCheckBox selectionAreaEnabled;
  346. private ColorWellButton selectionAreaBgColor;
  347. private JTextField selectionAreaWidth;
  348. //}}}
  349. }