PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 153 lines | 82 code | 13 blank | 58 comment | 12 complexity | 93ca2da347026cfa0aadd146d0e3ebb1 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. * JEditMode.java - jEdit editing mode
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2007 Matthieu Casanova
  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 org.gjt.sp.util.Log;
  24. /**
  25. * @author Matthieu Casanova
  26. * @version $Id: Buffer.java 8190 2006-12-07 07:58:34Z kpouer $
  27. * @since jEdit 4.3pre10
  28. */
  29. class JEditMode extends Mode
  30. {
  31. //{{{ JEditMode constructor
  32. JEditMode(String name)
  33. {
  34. super(name);
  35. } //}}}
  36. //{{{ setProperty() method
  37. /**
  38. * Sets a mode property.
  39. * @param key The property name
  40. * @param value The property value
  41. */
  42. @Override
  43. public void setProperty(String key, Object value)
  44. {
  45. if (initialized)
  46. {
  47. String prefix = "mode." + name + '.';
  48. jEdit.setProperty(prefix + key, value.toString());
  49. }
  50. props.put(key,value);
  51. } //}}}
  52. //{{{ unsetProperty() method
  53. /**
  54. * Unsets a mode property.
  55. * @param key The property name
  56. */
  57. @Override
  58. public void unsetProperty(String key)
  59. {
  60. if (initialized)
  61. {
  62. String prefix = "mode." + name + '.';
  63. jEdit.unsetProperty(prefix + key);
  64. }
  65. props.remove(key);
  66. } //}}}
  67. //{{{ getProperty() method
  68. /**
  69. * Returns a mode property.
  70. *
  71. * @param key The property name
  72. * @since jEdit 4.3pre10
  73. */
  74. @Override
  75. public Object getProperty(String key)
  76. {
  77. String prefix = "mode." + name + '.';
  78. //if(jEdit.getBooleanProperty(prefix + "customSettings"))
  79. //{
  80. String property = jEdit.getProperty(prefix + key);
  81. if(property != null)
  82. {
  83. Object value;
  84. try
  85. {
  86. value = new Integer(property);
  87. }
  88. catch(NumberFormatException nf)
  89. {
  90. value = property;
  91. }
  92. return value;
  93. }
  94. //}
  95. Object value = props.get(key);
  96. if(value != null)
  97. return value;
  98. String global = jEdit.getProperty("buffer." + key);
  99. if(global != null)
  100. {
  101. try
  102. {
  103. return new Integer(global);
  104. }
  105. catch(NumberFormatException nf)
  106. {
  107. return global;
  108. }
  109. }
  110. else
  111. return null;
  112. } //}}}
  113. //{{{ init() method
  114. /**
  115. * Keeps track of mode initialization, to avoid overwriting
  116. * custom mode properties in the user's settings.
  117. */
  118. @Override
  119. public void init()
  120. {
  121. initialized = true;
  122. super.init();
  123. } //}}}
  124. //{{{ loadIfNecessary() method
  125. /**
  126. * Loads the mode from disk if it hasn't been loaded already.
  127. * @since jEdit 4.3pre10
  128. */
  129. @Override
  130. public void loadIfNecessary()
  131. {
  132. if(marker == null)
  133. {
  134. jEdit.loadMode(this);
  135. if (marker == null)
  136. Log.log(Log.ERROR, this, "Mode not correctly loaded, token marker is still null");
  137. }
  138. } //}}}
  139. private boolean initialized = false;
  140. }