The_Cute_Hedgehog
The_Cute_Hedgehog

Reputation: 1340

How can I design User Preferences module in my Swing application?

I have dialog for storing user preferences of the application which is developed using Java Swing. There are 20+ preferences and I would like to notify other modules when the particular preference changes. I know that I can hold a list of listeners and notify them whenever the preferences change. However, I would like to know about two issues:

Dependending your experience, how would you resolve that architecture? What are the best practices to follow?

Thanks

Upvotes: 0

Views: 258

Answers (1)

bracco23
bracco23

Reputation: 2221

I developed a Swing application where the user could modify some parameters to change functionality or the graphic of the application.

I approached it this way:

  • A general Setting abstract class represent a single value that the user can change.
  • A subclass is created for different types of value, in my case: boolean, integer, floating points, colors, etc.
  • I use a Map to keep track of the created Setting and a Preferences object to store the values.

For the actual settings, I create a static attribute somewhere (in my case, dedicated classes for different logical groups of settings) and use that attribute to read and change the values fo the settings.

PRO: The Settings keeps track of all the settings instantiated, so I don't need to code the frame for changing them twice, I just did it once in an indipendent way from the number of the settings

CONS: It clearly requires changing the code to add a new setting. While in my case it was not an issue because a new setting was needed only because of other changes in the code, in your case it might be.

Upvotes: 1

Related Questions