PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre5/org/gjt/sp/jedit/textarea/ExtensionManager.java

#
Java | 140 lines | 92 code | 15 blank | 33 comment | 10 complexity | 286c85e99641ee1010d0a448ee6b10ec 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. * ExtensionManager.java - Handles 'layers'
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2002 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.textarea;
  23. import java.awt.Graphics2D;
  24. import java.util.ArrayList;
  25. import org.gjt.sp.util.Log;
  26. class ExtensionManager
  27. {
  28. //{{{ addExtension() method
  29. void addExtension(int layer, TextAreaExtension ext)
  30. {
  31. Entry entry = new Entry(layer,ext);
  32. for(int i = 0; i < extensions.size(); i++)
  33. {
  34. int _layer = ((Entry)extensions.get(i)).layer;
  35. if(layer < _layer)
  36. {
  37. extensions.add(i,entry);
  38. return;
  39. }
  40. }
  41. extensions.add(entry);
  42. } //}}}
  43. //{{{ removeExtension() method
  44. void removeExtension(TextAreaExtension ext)
  45. {
  46. for(int i = 0; i < extensions.size(); i++)
  47. {
  48. Entry entry = (Entry)extensions.get(i);
  49. if(entry.ext == ext)
  50. {
  51. extensions.remove(i);
  52. return;
  53. }
  54. }
  55. } //}}}
  56. //{{{ paintValidLine() method
  57. void paintValidLine(Graphics2D gfx, int screenLine,
  58. int physicalLine, int start, int end, int y)
  59. {
  60. for(int i = 0; i < extensions.size(); i++)
  61. {
  62. TextAreaExtension ext = ((Entry)extensions.get(i)).ext;
  63. try
  64. {
  65. ext.paintValidLine(gfx,screenLine,
  66. physicalLine,start,end,y);
  67. }
  68. catch(Throwable t)
  69. {
  70. Log.log(Log.ERROR,this,t);
  71. // remove it so editor can continue
  72. // functioning
  73. extensions.remove(i);
  74. i--;
  75. }
  76. }
  77. } //}}}
  78. //{{{ paintInvalidLine() method
  79. void paintInvalidLine(Graphics2D gfx, int screenLine,
  80. int y)
  81. {
  82. for(int i = 0; i < extensions.size(); i++)
  83. {
  84. TextAreaExtension ext = ((Entry)extensions.get(i)).ext;
  85. try
  86. {
  87. ext.paintInvalidLine(gfx,screenLine,y);
  88. }
  89. catch(Throwable t)
  90. {
  91. Log.log(Log.ERROR,this,t);
  92. // remove it so editor can continue
  93. // functioning
  94. extensions.remove(i);
  95. i--;
  96. }
  97. }
  98. } //}}}
  99. //{{{ getToolTipText() method
  100. String getToolTipText(int x, int y)
  101. {
  102. for(int i = 0; i < extensions.size(); i++)
  103. {
  104. TextAreaExtension ext = ((Entry)extensions.get(i)).ext;
  105. String toolTip = ext.getToolTipText(x,y);
  106. if(toolTip != null)
  107. return toolTip;
  108. }
  109. return null;
  110. } //}}}
  111. //{{{ Private members
  112. private ArrayList extensions = new ArrayList();
  113. //}}}
  114. //{{{ Entry class
  115. static class Entry
  116. {
  117. int layer;
  118. TextAreaExtension ext;
  119. Entry(int layer, TextAreaExtension ext)
  120. {
  121. this.layer = layer;
  122. this.ext = ext;
  123. }
  124. } //}}}
  125. }