PageRenderTime 18ms CodeModel.GetById 11ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/options/PluginOptions.java

#
Java | 145 lines | 93 code | 16 blank | 36 comment | 10 complexity | bc29e93351d511b93dafee5d87e2780e MD5 | raw file
  1/*
  2 * PluginOptions.java - Plugin options dialog
  3 * :tabSize=8:indentSize=8:noTabs=false:
  4 * :folding=explicit:collapseFolds=1:
  5 *
  6 * Copyright (C) 2003 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
 23package org.gjt.sp.jedit.options;
 24
 25//{{{ Imports
 26import java.awt.Dialog;
 27import java.awt.Frame;
 28import org.gjt.sp.jedit.gui.OptionsDialog;
 29import org.gjt.sp.jedit.options.*;
 30import org.gjt.sp.jedit.*;
 31import org.gjt.sp.util.Log;
 32//}}}
 33
 34public class PluginOptions extends OptionsDialog
 35{
 36	//{{{ PluginOptions constructor
 37	public PluginOptions(Frame frame)
 38	{
 39		super(frame,"plugin-options",jEdit.getProperty("plugin-options.last"));
 40	} //}}}
 41
 42	//{{{ PluginOptions constructor
 43	public PluginOptions(Frame frame, String pane)
 44	{
 45		super(frame,"plugin-options",pane);
 46	} //}}}
 47
 48	//{{{ PluginOptions constructor
 49	public PluginOptions(Dialog dialog)
 50	{
 51		super(dialog,"plugin-options",jEdit.getProperty("plugin-options.last"));
 52	} //}}}
 53
 54	//{{{ PluginOptions constructor
 55	public PluginOptions(Dialog dialog, String pane)
 56	{
 57		super(dialog,"plugin-options",pane);
 58	} //}}}
 59
 60	//{{{ createOptionTreeModel() method
 61	protected OptionTreeModel createOptionTreeModel()
 62	{
 63		OptionTreeModel paneTreeModel = new OptionTreeModel();
 64		OptionGroup rootGroup = (OptionGroup) paneTreeModel.getRoot();
 65
 66		// initialize the Plugins branch of the options tree
 67		pluginsGroup = new OptionGroup("plugins");
 68		pluginsGroup.setSort(true);
 69
 70		// Query plugins for option panes
 71		EditPlugin[] plugins = jEdit.getPlugins();
 72		for(int i = 0; i < plugins.length; i++)
 73		{
 74			EditPlugin ep = plugins[i];
 75			if(ep instanceof EditPlugin.Broken)
 76				continue;
 77
 78			String className = ep.getClassName();
 79			if(jEdit.getProperty("plugin." + className + ".activate") == null)
 80			{
 81				// Old API
 82				try
 83				{
 84					ep.createOptionPanes(this);
 85				}
 86				catch(Throwable t)
 87				{
 88					Log.log(Log.ERROR, ep,
 89						"Error creating option pane");
 90					Log.log(Log.ERROR, ep, t);
 91				}
 92			}
 93			else
 94			{
 95				String optionPane = jEdit.getProperty(
 96					"plugin." + className + ".option-pane");
 97				if(optionPane != null)
 98					pluginsGroup.addOptionPane(optionPane);
 99				else
100				{
101					String options = jEdit.getProperty(
102						"plugin." + className
103						+ ".option-group");
104					if(options != null)
105					{
106						pluginsGroup.addOptionGroup(
107							new OptionGroup(
108							"plugin." + className,
109							jEdit.getProperty("plugin."
110							+ className + ".name"),
111							options)
112						);
113					}
114				}
115			}
116		}
117
118		// only add the Plugins branch if there are OptionPanes
119		if (pluginsGroup.getMemberCount() == 0)
120			pluginsGroup.addOptionPane(new NoPluginsPane());
121
122		rootGroup.addOptionGroup(pluginsGroup);
123
124		return paneTreeModel;
125	} //}}}
126
127	//{{{ getDefaultGroup() method
128	protected OptionGroup getDefaultGroup()
129	{
130		return pluginsGroup;
131	} //}}}
132
133	//{{{ Private members
134	private OptionGroup pluginsGroup;
135	//}}}
136
137	//{{{ NoPluginsPane class
138	static class NoPluginsPane extends AbstractOptionPane
139	{
140		public NoPluginsPane()
141		{
142			super("no-plugins");
143		}
144	} //}}}
145}