[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jedit-cvs
Subject:    [ jEdit-CVS ] plugins/Optional/optional OptionGroupPane.java,NONE,1.1 PluginOptionGroup.java,1.1,1.2
From:       Alan Ezust <ezust () users ! sourceforge ! net>
Date:       2005-10-27 7:49:31
Message-ID: E1EV2W0-0004Xv-Pg () mail ! sourceforge ! net
[Download RAW message or body]

Update of /cvsroot/jedit/plugins/Optional/optional
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20027/optional

Modified Files:
	PluginOptionGroup.java TabbedOptionDialog.java 
Added Files:
	OptionGroupPane.java 
Log Message:


Index: PluginOptionGroup.java
===================================================================
RCS file: /cvsroot/jedit/plugins/Optional/optional/PluginOptionGroup.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- PluginOptionGroup.java	27 Oct 2005 03:58:43 -0000	1.1
+++ PluginOptionGroup.java	27 Oct 2005 07:49:29 -0000	1.2
@@ -1,5 +1,5 @@
 /*
- * PluginOptionGroup.java - Plugin options dialog
+ * PluginOptionGroup.java - Plugin options model
  * :tabSize=8:indentSize=8:noTabs=false:
  * :folding=explicit:collapseFolds=1:
  *
@@ -30,21 +30,22 @@
 import org.gjt.sp.util.Log;
 
 /**
-  * NOTE: This version no longer shows options from plugins that
+  * NOTE: This version does not show options from plugins that
   * use the deprecated APIs.  
   * @since jedit4.3pre3
   * 
 */
-// {{{
 
 /**
-*  Refactored from PluginOptions.java - this class contains only the OptionGroup
+*  Refactored from PluginOptions.java - this class
+*  contains only the OptionGroup
 *  and none of the GUI code.
 */
 
 public class PluginOptionGroup extends OptionGroup 
 {
-	public PluginOptionGroup() {
+	public PluginOptionGroup() 
+	{
 		super("plugins");
 		createOptionTreeModel();
 	}
@@ -95,7 +96,9 @@
 		rootGroup.addOptionGroup(this);
 
 		return paneTreeModel;
-	} //}}}		
+	}		
 		
 }
 
+
+

--- NEW FILE: OptionGroupPane.java ---
/*
 * OptionGroupPane.java - A Pane (view) for displaying/selecting OptionGroups.
 * :tabSize=8:indentSize=8:noTabs=false:
 * :folding=explicit:collapseFolds=1:
 *
 * Copyright (C) 2005 Slava Pestov, Alan Ezust
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package optional;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTree;
import javax.swing.border.EmptyBorder;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.TreePath;

import org.gjt.sp.jedit.AbstractOptionPane;
import org.gjt.sp.jedit.BeanShell;
import org.gjt.sp.jedit.GUIUtilities;
import org.gjt.sp.jedit.OperatingSystem;
import org.gjt.sp.jedit.OptionGroup;
import org.gjt.sp.jedit.OptionPane;
import org.gjt.sp.jedit.jEdit;
import org.gjt.sp.jedit.gui.OptionsDialog;
import org.gjt.sp.jedit.gui.OptionsDialog.OptionTreeModel;
import org.gjt.sp.jedit.gui.OptionsDialog.PaneNameRenderer;
import org.gjt.sp.util.Log;

/**
 * An option pane for displaying groups of options.
 * There is a lot of code here which was taken from OptionsDialog,
 * but this class is a component which can be embedded in other Dialogs.
 * @see OptionDialog
 * 
 * 
 * @author ezust
 * 
 */

public class OptionGroupPane extends AbstractOptionPane implements TreeSelectionListener
{
	
	public OptionGroupPane(OptionGroup group)
	{
		super(group.getName());
		optionGroup = group;
		init();
	}

	// {{{ valueChanged() method
	public void valueChanged(TreeSelectionEvent evt)
	{
		TreePath path = evt.getPath();

		if (path == null)
			return;

		Object lastPathComponent = path.getLastPathComponent();
		if (!(lastPathComponent instanceof String || lastPathComponent instanceof OptionPane))
		{
			return;
		}

		Object[] nodes = path.getPath();

		StringBuffer buf = new StringBuffer();

		OptionPane optionPane = null;

		int lastIdx = nodes.length - 1;

		for (int i = paneTree.isRootVisible() ? 0 : 1; i <= lastIdx; i++)
		{
			String label;
			Object node = nodes[i];
			if (node instanceof OptionPane)
			{
				optionPane = (OptionPane) node;
				label = jEdit.getProperty("options." + optionPane.getName()
					+ ".label");
			}
			else if (node instanceof OptionGroup)
			{
				label = ((OptionGroup) node).getLabel();
			}
			else if (node instanceof String)
			{
				label = jEdit.getProperty("options." + node + ".label");
				optionPane = (OptionPane) deferredOptionPanes.get((String) node);
				if (optionPane == null)
				{
					String propName = "options." + node + ".code";
					String code = jEdit.getProperty(propName);
					if (code != null)
					{
						optionPane = (OptionPane) BeanShell.eval(jEdit
							.getActiveView(), BeanShell.getNameSpace(),
							code);

						if (optionPane != null)
						{
							deferredOptionPanes.put(node, optionPane);
						}
						else
							continue;
					}
					else
					{
						Log.log(Log.ERROR, this, propName + " not defined");
						continue;
					}
				}
			}
			else
			{
				continue;
			}

			buf.append(label);

			if (i != lastIdx)
				buf.append(": ");
		}

		if (optionPane == null)
			return;

		String title = jEdit.getProperty("options.title-template", new Object[] {
			jEdit.getProperty(this.getName() + ".title"), buf.toString() });

		try
		{
			optionPane.init();
		}
		catch (Throwable t)
		{
			Log.log(Log.ERROR, this, "Error initializing options:");
			Log.log(Log.ERROR, this, t);
		}

		if (currentPane != null)
			stage.remove(currentPane.getComponent());
		currentPane = optionPane;
		stage.add(BorderLayout.CENTER, currentPane.getComponent());
		stage.revalidate();
		stage.repaint();

		if (!isShowing())
			addNotify();

		currentPane = optionPane;
	} // }}}

	private boolean selectPane(OptionGroup node, String name)
	{
		return selectPane(node, name, new ArrayList());
	} // }}}

	// {{{ selectPane() method
	private boolean selectPane(OptionGroup node, String name, ArrayList path)
	{
		path.add(node);

		Enumeration e = node.getMembers();
		while (e.hasMoreElements())
		{
			Object obj = e.nextElement();
			if (obj instanceof OptionGroup)
			{
				OptionGroup grp = (OptionGroup) obj;
				if (grp.getName().equals(name))
				{
					path.add(grp);
					path.add(grp.getMember(0));
					TreePath treePath = new TreePath(path.toArray());
					if (treePath != null) {
						paneTree.scrollPathToVisible(treePath);
						paneTree.setSelectionPath(treePath);
						return true;
					}
				}
				else if (selectPane((OptionGroup) obj, name, path))
					return true;
			}
			else if (obj instanceof OptionPane)
			{
				OptionPane pane = (OptionPane) obj;
				if (pane.getName().equals(name) || name == null)
				{
					path.add(pane);
					TreePath treePath = new TreePath(path.toArray());
					paneTree.scrollPathToVisible(treePath);
					paneTree.setSelectionPath(treePath);
					return true;
				}
			}
			else if (obj instanceof String)
			{
				String pane = (String) obj;
				if (pane.equals(name) || name == null)
				{
					path.add(pane);
					TreePath treePath = new TreePath(path.toArray());
					paneTree.scrollPathToVisible(treePath);
					paneTree.setSelectionPath(treePath);
					return true;
				}
			}
		}

		path.remove(node);

		return false;
	} // }}}

	protected void _init()
	{

		setLayout(new BorderLayout());
		deferredOptionPanes = new HashMap();
		optionTreeModel = new OptionTreeModel();
		OptionGroup rootGroup = (OptionGroup) optionTreeModel.getRoot();
		rootGroup.addOptionGroup(optionGroup);
		paneTree = new JTree(optionTreeModel);
		paneTree.setMinimumSize(new Dimension(100, 0));
		paneTree.setVisibleRowCount(1);
		paneTree.setCellRenderer(new PaneNameRenderer());

		JPanel content = new JPanel(new BorderLayout(12, 12));
		content.setBorder(new EmptyBorder(12, 12, 12, 12));
		add(content, BorderLayout.CENTER);

		stage = new JPanel(new BorderLayout());

		// looks bad with the OS X L&F, apparently...
		if (!OperatingSystem.isMacOSLF())
			paneTree.putClientProperty("JTree.lineStyle", "Angled");

		paneTree.setShowsRootHandles(true);
		paneTree.setRootVisible(false);

		JScrollPane scroller = new JScrollPane(paneTree,
			JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
			JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
		splitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scroller, stage);
		content.add(splitter, BorderLayout.CENTER);

		// register the Options dialog as a TreeSelectionListener.
		// this is done before the initial selection to ensure that the
		// first selected OptionPane is displayed on startup.
		paneTree.getSelectionModel().addTreeSelectionListener(this);

		OptionGroup rootNode = (OptionGroup) paneTree.getModel().getRoot();
		for (int i = 0; i < rootNode.getMemberCount(); i++)
		{
			paneTree.expandPath(new TreePath(new Object[] { rootNode,
				rootNode.getMember(i) }));
		}

		// returns false if no such pane exists; calling with null
		// param selects first option pane found
		String name = optionGroup.getName();
		selectPane(rootNode, null);
/*		if ((defaultPaneName != null) && (!selectPane(rootNode, defaultPaneName)))
			selectPane(rootNode, null); */

		splitter.setDividerLocation(paneTree.getPreferredSize().width
			+ scroller.getVerticalScrollBar().getPreferredSize().width);

		String pane = jEdit.getProperty(name + ".last");
		selectPane(rootNode,pane);
		

		
		int dividerLocation = jEdit.getIntegerProperty(name + ".splitter", -1);
		if (dividerLocation != -1)
			splitter.setDividerLocation(dividerLocation);

	}

	protected void _save()
	{
		if(currentPane != null)
			jEdit.setProperty(getName() + ".last",currentPane.getName());

		save(optionGroup);
	}

	private void save(Object obj)
	{
		
		if (obj instanceof OptionGroup)
		{
			OptionGroup grp = (OptionGroup) obj;
			Enumeration members = grp.getMembers();
			while (members.hasMoreElements())
			{
				save(members.nextElement());
			}
		}
		else if (obj instanceof OptionPane)
		{
			try
			{
				((OptionPane) obj).save();
			}
			catch (Throwable t)
			{
				Log.log(Log.ERROR, this, "Error saving options:");
				Log.log(Log.ERROR, this, t);
			}
		}
		else if (obj instanceof String)
		{
			save(deferredOptionPanes.get(obj));
		}
	}
	// {{{ Members
	OptionGroup optionGroup;

	JSplitPane splitter;

	JTree paneTree;

	OptionPane currentPane;

	OptionTreeModel optionTreeModel;

	HashMap deferredOptionPanes;

	JPanel stage;
	// }}}

}

Index: TabbedOptionDialog.java
===================================================================
RCS file: /cvsroot/jedit/plugins/Optional/optional/TabbedOptionDialog.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- TabbedOptionDialog.java	27 Oct 2005 07:02:42 -0000	1.2
+++ TabbedOptionDialog.java	27 Oct 2005 07:49:29 -0000	1.3
@@ -1,3 +1,25 @@
+/*
+ * TabbedOptionDialog.java - Plugin options model
+ * :tabSize=8:indentSize=8:noTabs=false:
+ * :folding=explicit:collapseFolds=1:
+ *
+ * Copyright (C) 2005 Slava Pestov, Alan Ezust
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
 package optional;
 
 import java.awt.BorderLayout;
@@ -29,13 +51,12 @@
 import org.gjt.sp.jedit.OptionPane;
 import org.gjt.sp.jedit.jEdit;
 import org.gjt.sp.jedit.gui.EnhancedDialog;
-import org.gjt.sp.jedit.gui.OptionGroupPane;
 import org.gjt.sp.jedit.gui.OptionsDialog.OptionTreeModel;
 
 
 /**
- * Much simpler than the OptionsDialog, because it uses the OptionGroupPane 
- * instead of managing its own optons.
+ * Replacement for OptionsDialog.
+ * It uses the OptionGroupPane instead of managing its own optons.
  * 
  * This class should eventually replace @ref OptionsDialog
  * 



-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
jEdit-CVS mailing list
jEdit-CVS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jedit-cvs
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic