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