/plugins/Highlight/tags/Highlight-1.5.0/src/gatchan/highlight/TextAreaExtensionLayerChooser.java

# · Java · 91 lines · 54 code · 4 blank · 33 comment · 3 complexity · 020b01e89cbe3a2c2f59b6c873555bc9 MD5 · raw file

  1. /*
  2. * TextAreaExtensionLayerChooser.java - A combo to choose a textarea extension
  3. * layer
  4. * :tabSize=8:indentSize=8:noTabs=false:
  5. * :folding=explicit:collapseFolds=1:
  6. *
  7. * Copyright (C) 2007 Matthieu Casanova
  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 gatchan.highlight;
  24. //{{{ imports
  25. import org.gjt.sp.jedit.jEdit;
  26. import org.gjt.sp.jedit.textarea.TextAreaPainter;
  27. import javax.swing.JComboBox;
  28. import java.util.Arrays;
  29. //}}}
  30. /**
  31. * @author Matthieu Casanova
  32. * @version $Id: HighlightPlugin.java,v 1.20 2006/06/21 09:40:32 kpouer Exp $
  33. */
  34. public class TextAreaExtensionLayerChooser extends JComboBox
  35. {
  36. private static Object[] layers = new Object[]{ TextAreaPainter.LOWEST_LAYER + " (LOWEST_LAYER)" ,
  37. TextAreaPainter.BACKGROUND_LAYER + " (BACKGROUND_LAYER)",
  38. TextAreaPainter.LINE_BACKGROUND_LAYER + " (LINE_BACKGROUND_LAYER)",
  39. TextAreaPainter.BELOW_SELECTION_LAYER + " (BELOW_SELECTION_LAYER)",
  40. TextAreaPainter.SELECTION_LAYER + " (SELECTION_LAYER)",
  41. TextAreaPainter.WRAP_GUIDE_LAYER + " (WRAP_GUIDE_LAYER)",
  42. TextAreaPainter.BELOW_MOST_EXTENSIONS_LAYER + " (BELOW_MOST_EXTENSIONS_LAYER)",
  43. TextAreaPainter.DEFAULT_LAYER + " (DEFAULT_LAYER)",
  44. TextAreaPainter.BLOCK_CARET_LAYER + " (BLOCK_CARET_LAYER)",
  45. TextAreaPainter.BRACKET_HIGHLIGHT_LAYER + " (BRACKET_HIGHLIGHT_LAYER)",
  46. TextAreaPainter.TEXT_LAYER + " (TEXT_LAYER)",
  47. TextAreaPainter.CARET_LAYER + " (CARET_LAYER)",
  48. TextAreaPainter.HIGHEST_LAYER + " (HIGHEST_LAYER)"};
  49. //{{{ TextAreaExtensionLayerChooser constructor
  50. /**
  51. * Initialize the plugin. When starting this plugin will add an Highlighter on each text area
  52. */
  53. public TextAreaExtensionLayerChooser(int currentLayer)
  54. {
  55. super(layers);
  56. setEditable(true);
  57. switch (currentLayer)
  58. {
  59. case TextAreaPainter.LOWEST_LAYER :setSelectedIndex(0);break;
  60. case TextAreaPainter.BACKGROUND_LAYER :setSelectedIndex(1);break;
  61. case TextAreaPainter.LINE_BACKGROUND_LAYER :setSelectedIndex(2);break;
  62. case TextAreaPainter.BELOW_SELECTION_LAYER :setSelectedIndex(3);break;
  63. case TextAreaPainter.SELECTION_LAYER :setSelectedIndex(4);break;
  64. case TextAreaPainter.WRAP_GUIDE_LAYER :setSelectedIndex(5);break;
  65. case TextAreaPainter.BELOW_MOST_EXTENSIONS_LAYER :setSelectedIndex(6);break;
  66. case TextAreaPainter.DEFAULT_LAYER :setSelectedIndex(7);break;
  67. case TextAreaPainter.BLOCK_CARET_LAYER :setSelectedIndex(8);break;
  68. case TextAreaPainter.BRACKET_HIGHLIGHT_LAYER :setSelectedIndex(9);break;
  69. case TextAreaPainter.TEXT_LAYER :setSelectedIndex(10);break;
  70. case TextAreaPainter.CARET_LAYER :setSelectedIndex(11);break;
  71. case TextAreaPainter.HIGHEST_LAYER :setSelectedIndex(12);break;
  72. default :setSelectedItem(Integer.toString(currentLayer));
  73. }
  74. } //}}}
  75. //{{{ getLayer() method
  76. public int getLayer() throws NumberFormatException
  77. {
  78. String value = (String) getSelectedItem();
  79. if (Arrays.binarySearch(layers, value) == -1)
  80. {
  81. int layer = Integer.parseInt(value);
  82. return layer;
  83. }
  84. int layer = Integer.parseInt(value.substring(0, value.indexOf(' ')));
  85. return layer;
  86. } //}}}
  87. }