Re: Events
"Brian Duff" <[email protected]> Sun, 11 Nov 2001 01:12:30 -0000
| Newsgroups | gmane.games.freeciv.java |
|---|---|
| Message-ID | <[email protected]> |
Hi Alex, You're absolutely right, there is a distinct lack of eventing in some areas of the code. At the moment, the handlers tend to call methods to update things after they've been updated. I would really like to sort this out, because it's bad programming practice and means that many methods on the Client have visibility that really shouldn't. It was written this way, because that's pretty much how the C client works. But it's less than ideal. Hopefully, we can eventually add event code to the "data" classes in org.freeciv.common for notification when objects get changed, or when items get added or removed from lists (e.g. a city's name changes, a new unit is added to the supported list of a city). This will go a great way towards making the code neater and more object oriented. At the moment, there are a large number of Action implementations in the org.freeciv.client.action package. These make up the core of the user-invokable events: anything that can be done through the UI. These classes all implement ActionListener (Action is derived from it), so can be easily plugged in to buttons and other controls. For each class of action, a single instance is maintained by the Client: you can obtain the instance for any given action using clientInstance.getAction( Class actionClass ) where actionClass is the class for the action you want to retrieve. For the console window, the best thing might be to define an action along the lines of ACTSendConsoleMessage, then add it as an actionlistener to the Console. There might be some issues with the order in which listeners get added; I seem to remember that Console already adds a listener internally, to clear the field after the user presses Enter. We'd want this to happen after the console message action was fired. For this reason, probably the best way to implement it is to add addActionListener() removeActionListener() methods to Console, then have the client or main window actually register the ACTSendConsoleMessage action with the Console. Then Console can use its own internal action listener to ensure its field clearing happens after firing the action event out to listeners added to Console. Anyway, let me know if this helps, or if I've gone off on the wrong track entirely.. Thanks, Brian -----Original Message----- From: freeciv-java-bounce-0/[email protected] [mailto:freeciv-java-bounce-0/[email protected]]On Behalf Of Alexander Braun Sent: 09 November 2001 19:34 To: jFreeCiv Subject: [FreeCiv-Java] Events Dear all, I just started looking at the code in earnest, and after about close to three hours of looking (read: staring) at it I start to see a pattern emerging :-) _But_ as far as I see it there's no dedicated class handling the action events?! Or I didn't see it yet :-) Actually I'd like to stick to the facts: I was thinking of implementing the chat line, because that seemed like an easy start. And for _that_ (i.e. the client.panel.Console) I didn't see an action handler sign up. And then the question arises: _where_ do we handle events? Normally I would have said in the main GUI class (ie. client.MainWindow) but as the client.Client class manages the lot on second thought it should be going there. And, then again, inner classes wouldn't be to bad either, especially with the many components floating around, some of them (like the MapOverview) quite complex. If this seems like a trivial question then sorry for that. At least for the Console it seems straightforward to simply use inner classes. But I guess there's a lot more going on which I don't see yet, and I can well imagine lot's of events hopping around without proper handling. Again, if this is trivia, I'd be glad if someone pointed out the obvious to me. If not it seems we should have a short discussion to agree on the matter of what gets handled where. Thanks, Alex ____________________________________________________________________________ __ Keine verlorenen Lotto-Quittungen, keine vergessenen Gewinne mehr! Beim WEB.DE Lottoservice: http://tippen2.web.de/?x=7