Luxor Network: Luxor - Luxilla - Petra - Installer DeLux - Luxor Contrib - Luxor Forum - The Memphis Sun
The Memphis Sun Logo
The Luxor News Blog
« Installer DeLux Project Kicked Off (Create Installers Using XUL and Ant) | Main | Luxor XUL Example Suite for Groovy Now Checked In »
AspectJ In Action: Weave In Your Own Luxor XUL Widget Attributes
posted by Gerald Bauer on January 03, 2004

R. Dale Asberry (of Judy Jini.org project fame) writes in the mail titled "Example of how AOP can help":

While working with Installer DeLux, I ran into some difficulty when I wanted to add a new "feature" to XButton.

Currently, Xul.Attribute.DISABLED is only used for MenuItemDef and ToolBarButtonDef. So that I could disable the "Next" button on the accept license page, I originally subclassed XButton and ButtonDef. However, I was able to determine a simple AOP solution that not only worked for button, but all XUL components. The same technique can be used for setting color, background, border, font, name, and actions. This would eliminate programming errors by eliminating the need to repeat this code.

The pointcut details important OO events (method calls). The around() "advice" tells what should happen when the getJComponent() pointcut is matched. The last two java blocks "introduce" the initialized field and the initialize() method on the luxor.swing.AbstractComponent class.

package luxor.swing;

import javax.swing.JComponent;

import luxor.core.Xul;

public privileged aspect ComponentFunctionalAspect
{
	private pointcut getJComponent(AbstractComponent pComp):
		execution(JComponent AbstractComponent+.getJComponent()) &&
		target(pComp) &&
		!within(ComponentFunctionalAspect)
		;

	JComponent around(AbstractComponent pComp): getJComponent(pComp)
	{
		JComponent lGuiComp = proceed(pComp);
		if(!pComp.initialized)
		{
			pComp.initialize(lGuiComp);
		}
		return lGuiComp;
	}

	private boolean AbstractComponent.initialized = false;

	public void AbstractComponent.initialize(JComponent pGuiComp)
	{
		if("true".equals(_def.getAttribute(Xul.Attribute.DISABLED)))
		{
			pGuiComp.setEnabled(false);
		}
		if("false".equals(_def.getAttribute(Xul.Attribute.VISIBLE)))
		{
			pGuiComp.setVisible(false);
		}
		initialized = true;
	}
}
Comments
Hosted by SourceForge SourceForge Logo For questions related to the use of Luxor, please consult our web pages. If that fails, the luxor-xul-user mailinglist might help.
Please send comments on our web pages and the development of Luxor to our public luxor-xul-develop mailinglist.
Maintained by Luxor Team
Copyright © 2001, 2002, 2003, 2004, 2005 Luxor Foundation