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

/jEdit/tags/jedit-4-2-pre14/org/gjt/sp/jedit/Marker.java

#
Java | 119 lines | 43 code | 12 blank | 64 comment | 3 complexity | 01861663ea19fbc972f9c0eab300bb56 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. * Marker.java - Named location in a buffer
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 1998, 1999, 2000, 2001 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;
  23. import javax.swing.text.Position;
  24. /**
  25. * Buffers may contain one or more <i>markers</i> which serve
  26. * as textual bookmarks.<p>
  27. *
  28. * A <code>Marker</code> has three key attributes: the
  29. * <code>Buffer</code> to which it relates, the line number to which
  30. * the marker refers, and an optional shortcut character. The shortcut
  31. * identifies the the key that can be pressed with the
  32. * <b>Markers</b>&gt;<b>Go To Marker</b> command.
  33. *
  34. * @author Slava Pestov
  35. * @author John Gellene (API documentation)
  36. * @version $Id: Marker.java 4469 2003-02-08 18:53:03Z spestov $
  37. */
  38. public class Marker
  39. {
  40. //{{{ getShortcut() method
  41. /**
  42. * Returns the marker's shortcut character.
  43. * @since jEdit 3.2pre1
  44. */
  45. public char getShortcut()
  46. {
  47. return shortcut;
  48. } //}}}
  49. //{{{ getPosition() method
  50. /**
  51. * Returns the position of this marker.
  52. * @since jEdit 3.2pre1
  53. */
  54. public int getPosition()
  55. {
  56. return (position == null ? pos : position.getOffset());
  57. } //}}}
  58. //{{{ Package-private members
  59. //{{{ Marker constructor
  60. Marker(Buffer buffer, char shortcut, int position)
  61. {
  62. this.buffer = buffer;
  63. this.shortcut = shortcut;
  64. this.pos = position;
  65. } //}}}
  66. //{{{ setShortcut() method
  67. /**
  68. * Sets the marker's shortcut.
  69. * @param shortcut The new shortcut
  70. * @since jEdit 3.2pre1
  71. */
  72. void setShortcut(char shortcut)
  73. {
  74. this.shortcut = shortcut;
  75. } //}}}
  76. //{{{ createPosition() method
  77. void createPosition()
  78. {
  79. position = buffer.createPosition(pos);
  80. } //}}}
  81. //{{{ removePosition() method
  82. void removePosition()
  83. {
  84. // forget the cached Position instance
  85. if(position != null)
  86. {
  87. pos = position.getOffset();
  88. position = null;
  89. }
  90. } //}}}
  91. //{{{ setPosition() method
  92. /**
  93. * Sets the position of this marker.
  94. * @since jEdit 4.0pre5
  95. */
  96. void setPosition(int pos)
  97. {
  98. this.pos = pos;
  99. } //}}}
  100. //}}}
  101. //{{{ Private members
  102. private Buffer buffer;
  103. private char shortcut;
  104. private int pos;
  105. private Position position;
  106. //}}}
  107. }