Professional Development

Pro-D
  • Front Page
  • Contact
  • Log in
  • « More work on reflection and prefs
  • help Martin with using Reflection for Preferences »

Wrote the basics of a preferences reflection class

Posted by mholmes on 05 Jun 2007 in Activity log

As part of the teiJournal project, I needed to write a simple text-transformer that would turn CSS rulesets into XSLT attribute-sets (documented on that blog). I decided to do this in Java to get more practice with basic apps, and take advantage of the opportunity to abstract more of the code I learned writing the Apparatus app into general-purpose utility classes.

I created a class called MdhPrefs in ca.uvic.hcmc.utils. The purpose of this class is to save and reload a range of key info for a JFrame descendant, so that the JFrame can initialize an instance of the object when it starts up (after initComponents() is called) and get preferences for a wide range of settings loaded automatically.

How to use it:

  1. Create a private variable in the JFrame descendant class:
    private MdhPrefs mdhPrefs;
  2. Initialize it after initComponents() is called in the class's constructor:
    mdhPrefs = new MdhPrefs(this);
  3. In the JFrame descendant's formWindowClosing event, make a call to save the data:
    mdhPrefs.saveData();

At the moment, this class saves only window size and position, and the position of any splitter bars, but it will be extended to include a lot more information. The load/save code is recursive, so it should catch all components which are descendants of the JFrame.

This kind of reflection looks to be very powerful; it's similar to the code I've written in the past for Delphi, but (so far) a bit cleaner, because the component hierarchies seem more straightforward. A set of classes for translating the interface could be created in the same way.

This entry was posted by Martin and filed under Activity log.

Professional Development

This blog is used to record research and learning we do which is not part of a specific project, such as learning a new programming language in anticipation of using it for future projects, or installing and testing development tools that may be useful.
  • Home
  • Recently
  • Archives
  • Categories
  • Latest comments

Search

Categories

  • All
  • Activity log
  • Announcements
  • Tasks

XML Feeds

  • RSS 2.0: Posts
  • Atom: Posts
More on RSS

Recent Posts

  • Expenses claim
  • Another hour on QT
  • A little QT learning
  • Repro training
  • POS tagging tool
  • QT: learning about directory views and models
  • QT: Preparing icon collection for use as a resource
  • QT: learning about namespaces, enums, and writing classes
  • QT: Successful portable app with SVG icons
  • QT work

Sidebar 2

This is the "Sidebar 2" container. You can place any widget you like in here. In the evo toolbar at the top of this page, select "Customize", then "Blog Widgets".

This collection ©2026 by admin • Help • open source blog • reseller hosting