Re: DocumentListener is too slow
- From: "William Z." <Wizumwalt@xxxxxxxxx>
- Date: 4 Nov 2005 09:21:35 -0800
> I take it the performance problem is with each key press, not set up time.
Correct, each char that get's modified does a lookup on the correct
Hashtable, to get another Hashtabel for that type, makes the change,
and put's it back in.
> >
> > public void changedUpdate( DocumentEvent de ) {
>
> This event is called when a attribute (for instance colour) is changed.
> I think it's insertUpdate and removeUpdate you really want.
What I really have is a method that insertUpdate(), removeUpdate(), and
changedUpdate() all call a single method that does the same, so no
matter what the user does to the textfield, it updates my stored data.
>
> > Document doc = de.getDocument();
> >
> > // Since this listener is registered to a material form,
> > // I get the current material definition from FormDefinitions
> > // which is a static Hashtable of form types
> >
> > int matId = FormDefinitions.getInstance().getCurrentMaterial();
> > Material material = (Material)
> > FormDefinitions.getInstance().get(MATERIAL_FORM, matId);
>
> Ick. Singleton abuse.
I know, I hated doing this too, but I didn't know how else to do it. I
didn't want to have a "god" class init everything or pass this stored
data around in every method that needed it (which was a lot), cause the
code was really looking ugly. So I figured as long as I didn't have to
many of these around, it'd be ok. Certainly works better, but if I only
had a better way ... cause I use this data all over my application.
>
> > // get user typed input
> > String txt = doc.getText(0, doc.getLength());
> >
> > // set info to my material object
> > if (label.getText().equals("weight")) {
>
> That is really nasty.
Agreed, but how else do I know which field was updated and map it to my
storage classes?
>
> > material.setWeight(new Integer(txt));
> Glad to see someone is going for a half decent UI.
>
> If you are trying to store it back to a database I would suggest you:
> o Execute the updates in another thread.
> o Group all remaining outstanding updates each transaction.
> o Have some sort of minimum period between transactions.
> o If multiuser, cache in a middle tier.
Actually, no database, just POJO's stored in memory.
.
- References:
- DocumentListener is too slow
- From: William Z.
- Re: DocumentListener is too slow
- From: Thomas Hawtin
- DocumentListener is too slow
- Prev by Date: Re: Help with GridBagLayout
- Next by Date: Re: DocumentListener is too slow
- Previous by thread: Re: DocumentListener is too slow
- Next by thread: Re: DocumentListener is too slow
- Index(es):
Relevant Pages
|