|
Subject: Example of how AOP can help Newsgroups: gmane.comp.java.luxor-xul.user Date: 2004-01-03 21:59:06 GMT (4 years, 26 weeks, 2 days, 1 hour and 51 minutes ago)
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;
}
}
-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
Free Linux Tutorials. Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
|
|
|