views:

58

answers:

1

Hello,

I'm trying to build a small application using Java and SWT for the GUI. I'm looking for a way to store in some file the preferences set by the user, I mean, if the window was resized then that new size should be saved for next time the application starts. The same thing with some controls like textbox and so on.

I came up with two ideas to solve this:

  • Use the classic hand-made .ini files to store those preferences. But it appears to be ugly and hard to maintain.
  • Serialization/Deserialization of the whole class that contains the GUI. Dunno if this is even possible.

Any ideas? What should I do?

Thanks in advance.

Added:

I'm not doing an Eclipse RCP project, it's just a normal SWT application.

More: I've already tried with serialization, but SWT widgets doesn't support it, so the only other option that I've found is create another class, say Configuration, mark it as serializable and hold there the values of my widgets. Almost like using java.util.prefs.Preferences, but not as simple.

I'm still waiting to see if there is another way to do this, maybe with some binding involved.

+3  A: 

Have a look at Memento design pattern.

Eclipse RCP already reuses this principle, you can refer to the following interface for more information:

org.eclipse.ui.IMemento
spektom
Thanks but I've just found the java.util.prefs.Preferences class, I think is better than what you suggest, I'll have to do the binding manually anyway.
Matías