Can someone help me get my brain around this.  I'm working to
get Swing events into the scene graph, and I'm generating some
pretty awful code.  There must be a sensible pattern to this
that I'm missing.

I take my basic pattern from the AWT_Interaction demo program.

This pattern calls for an AWT or Swing component to
add...Listener(MyListener) to itself.  MyListener is a subclass
of Behavior (it has an initialize() and a processStimulus()
method, it can PostId()), and it implements ...Listener (it has
event handlers).

I'm willing to accept that the next part is necessary for
synching to the Java 3D threads:  The event handler (triggered
by the AWT or Swing event) calls its PostId() method (which it
inherits from Behavior) to itself.  Then, maybe on the next
frame, its alarm goes off on the Behavior post, and, depending
on how it feels, it wakes up and executes its processStimulus()
method, which analyzes the PostId and deals with the event.

This seems to work ok for the simple controls like buttons, but
when there's data brought over by the event, it gets stripped
off by routing it through the PostId business.  I'll try to
explain by some examples in ascending order of kluginess.

1.  JButton adds an ActionListener.  ActionListener's
actionPerformed(ActionEvent e) method posts an Id.
processStimulus wakes up and deals with the button press.
Pretty straightforward.

2.  JScrollBar adds a ChangeListener to its model.
ChangeListener's stateChanged() method posts an Id.
processStimulus wakes up on Behavior post, gets the current
value -->from the JScrollBar<--- and deals with it.  This seems
to work ok, but I had to fool around some to make certain that
the JScrollBar was exposed to the Behavior so I could do the
get.

3.  JEditorPane adds a HyperlinkListener.  HyperlinkListener's
hyperlinkUpdate(HyperlinkEventEvent e) posts an Id.
processStimulus(Enumeration e) wakes up on its Behavior post and
tries to deal with the hyperlink event.  Trouble is that the
data that it needs, the URL, is a property of the HyperlinkEvent
that originally triggered the Listener, and it's long gone.
Maybe frames ago. This is a fundamentally different case from
the JScrollBar (and the JSlider) case in which the data is a
property of the component itself.

The options that are obvious to me are all ugly.  Do I do an
event.getURL() in the hyperlinkUpdate methods and try to attach
the URL to the PostId?  Do I try to staple a copy of the
HyperlinkEvent to the PostId so I can do the getURL() in the
processStimulus()?  Do I subclass Behavior to do this and
override PostId, giving it an object that includes the URL and
hope to be able to disassemble it later?  I'm really worried
about keeping all of this lined up, especially considering that
processStimulus can be getting a whole queue of events, only
some of which will be from the JEditorPane.

How am I really supposed to be approaching this?  I hope I'm
missing something.

TIA,

Fred Klingener
Brock Engineering

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to