On Saturday 01 May 2004 14:11, [EMAIL PROTECTED] wrote:
> Hi Niclas,
>
> > I'm slightly in the dark of what you are trying to do.
>
> thanks for the fast reply. What we are trying to do is quite simple:
> - we have Display component that would like to know if there are any
> providers of softkey events (like the softkeys on an ATM or a mapped
> PINPad) in the system, in order to register itself as a listener for these
> events and - as a slave - provide feedback to the customer by setting the
> appropriate button in a "pressed" state in the current display.
> - the display component works fine if there is no softkey event provider in
> the system, but hte same scenario is valid for other "just interested"
> clients.
So I understand this as;
+----------+ +---------+ +----------+
| SoftKey |--->| SoftKey |--->| SoftKey |
| Provider | | | | Listener |
+----------+ +---------+ +----------+
"SoftKey" is the 'function' itself, for instance, Refresh, Options, Exit and
so on.
public class HardwareButton implements SoftKeyProvider
{
private SoftKey m_SoftKey;
/** @avalon.dependency key="softkey"
type="org.hedhman.softkeys.SoftKey"
*/
public void service( ServiceManager man )
{
m_SoftKey = (SoftKey) man.lookup( "softkey" );
}
}
public class ExitHandler implement SoftKeyListener
{
private SoftKey m_SoftKey;
/** @avalon.dependency key="softkey-exit"
type="org.hedhman.softkeys.SoftKey"
*/
public void service( ServiceManager man )
{
m_SoftKey = (SoftKey) man.lookup( "softkey-exit" );
m_SoftKey.addSoftKeyListener( this );
}
public void dispose()
{
m_SoftKey.removeSoftKeyListener( this );
}
public void softKeyPressed( SoftKeyEvent )
{
// handle event
}
}
Then you always include the Softkeys and the listeners to the softkeys, and
the HardwareButtons/SoftKeyProviders are all dependent on the SoftKey and not
the other way around.
Get it?
Alternatively, you could go for a rather complex class, instead of many
SoftKeys, that handles everything for everyone. That would be more of an
EventBus pattern. That is more suitable if the HardwareButton is rewired on
the fly to different SoftKeys.
In fact, there are some variations on this, but the important part is;
Instead of
A dependsOn B, where A and/or B may or may not exist,
use
A dependsOn C
B dependsOn C
where C must be present, the rest is optional.
I hope you get some more ideas from this.
Niclas
--
+---------//-------------------+
| http://www.bali.ac |
| http://niclas.hedhman.org |
+------//----------------------+
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]