PageRenderTime 20ms CodeModel.GetById 11ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/bundles/plugins-trunk/Console/console/ErrorListModel.java

#
Java | 111 lines | 73 code | 12 blank | 26 comment | 5 complexity | 901fbc10dafae11eb389887b808654ed MD5 | raw file
  1package console;
  2// {{{ imports
  3import java.util.ArrayList;
  4import javax.swing.DefaultListModel;
  5import org.gjt.sp.jedit.jEdit;
  6import org.gjt.sp.util.StringList;
  7// }}}
  8
  9// {{{ ErrorListModel
 10/**
 11 * A model for storing a collection of ErrorMatchers.
 12 *
 13 * @version $Id$
 14 * @author ezust
 15 * @since Console 4.2.5
 16 *
 17 */
 18public class ErrorListModel extends DefaultListModel
 19{
 20    // {{{ Data Members
 21	ArrayList<ErrorMatcher> m_matchers;
 22	StringList m_default;
 23    // }}}
 24    // {{{ constructor
 25	public ErrorListModel()
 26	{
 27    } // }}}
 28    // {{{ Member Functions
 29	// {{{ get
 30	public ErrorMatcher get(int i)
 31	{
 32		return (ErrorMatcher) super.get(i);
 33    } // }}}
 34
 35    // {{{ load
 36	static public ErrorListModel load()
 37	{
 38		ErrorListModel retval = new ErrorListModel();
 39		retval.restore();
 40		return retval;
 41    } // }}}
 42
 43    // {{{ reset
 44	/* writes the default list back to console.errors.list */
 45	public void reset() {
 46		jEdit.setProperty("console.errors.list", m_default.join(" ") );
 47		restore();
 48    } // }}}
 49	// {{{
 50	public void save()
 51	{
 52		StringList visible = new StringList();
 53		for (ErrorMatcher matcher: m_matchers)
 54		{
 55			String key = matcher.internalName();
 56			if (matcher.isValid())
 57				matcher.save();
 58			visible.add(key);
 59		}
 60		jEdit.setProperty("console.errors.list", visible.join(" "));
 61    } // }}}
 62
 63    // {{{ restore
 64	/* Restores from properties, the default list */
 65	public void restore()
 66	{
 67		super.clear();
 68		m_matchers = new ArrayList<ErrorMatcher>();
 69		m_default = StringList.split(jEdit.getProperty("console.errors.default", ""), "\\s+");
 70		StringList visible = StringList.split(jEdit.getProperty("console.errors.list", ""), "\\s+");
 71		if (visible.size() == 0) {
 72			jEdit.setProperty("console.errors.list", m_default.join(" "));
 73			visible = m_default;
 74		}
 75
 76		for (String key: visible)
 77		{
 78			ErrorMatcher m = new ErrorMatcher(key);
 79			m_matchers.add(m);
 80			super.addElement(m);
 81		}
 82
 83    } // }}}
 84
 85
 86
 87
 88	// {{{ removeElementAt
 89	public void removeElementAt(int index)
 90	{
 91		m_matchers.remove(index);
 92		super.removeElementAt(index);
 93    } // }}}
 94
 95	// {{{ insertElementAt
 96	public void insertElementAt(Object obj, int index)
 97	{
 98		ErrorMatcher matcher = (ErrorMatcher) obj;
 99		m_matchers.add(index, matcher);
100		super.insertElementAt(obj, index);
101    } // }}}
102
103	// {{{ addElement
104	public void addElement(Object m)
105	{
106		ErrorMatcher matcher = (ErrorMatcher) m;
107		m_matchers.add(matcher);
108		super.addElement(m);
109	}   // }}}
110    // }}}
111} // }}}