bluej.extensions
Interface PreferenceGenerator


public interface PreferenceGenerator

Extensions which wish to add preference items to BlueJ's Tools/Preferences/Extensions panel should register an instance of PreferenceGenerator with the BlueJ proxy object. The PreferenceGenerator allows the creation of a Panel to contain preference data, and the loading and saving of that data. Below is a simple example to create a preference panel with a single text item to record a user's favourite colour. To activate the preference panel you instantiate an object of the Preferences class and then register it with the BlueJ proxy object, e.g.:

        Preferences myPreferences = new Preferences(bluej);
        bluej.setPreferenceGenerator(myPreferences);
 
The code for the Preferences class is:
 public class Preferences implements PreferenceGenerator
 {
 private JPanel myPanel;
 private JTextField color;
 private BlueJ bluej;
 public static final String PROFILE_LABEL="Favourite-Colour";

 public Preferences(BlueJ bluej) {
   this.bluej = bluej;
   myPanel = new JPanel();
   myPanel.add (new JLabel ("Favourite Colour"));
   color = new JTextField (40);
   myPanel.add (color);
   // Load the default value
   loadValues();
   }

 public JPanel getPanel ()  { return myPanel; }

 public void saveValues () {
   // Save the preference value in the BlueJ properties file
   bluej.setExtensionPropertyString(PROFILE_LABEL, color.getText());
   }

 public void loadValues () {
   // Load the property value from the BlueJ proerties file, default to an empty string
   color.setText(bluej.getExtensionPropertyString(PROFILE_LABEL,""));
   }
 }
 

Version:
$Id: PreferenceGenerator.java 6215 2009-03-30 13:28:25Z polle $

Method Summary
 javax.swing.JPanel getPanel()
          Bluej will call this method to get the panel where preferences for this extension are.
 void loadValues()
          When this method is called the Extension should load its current values into its preference panel.
 void saveValues()
          When this method is called the Extension should save values from the preference panel into its internal state.
 

Method Detail

getPanel

javax.swing.JPanel getPanel()
Bluej will call this method to get the panel where preferences for this extension are. Preferences can be laid out as desired.

Returns:
The JPanel to contain preference data.

loadValues

void loadValues()
When this method is called the Extension should load its current values into its preference panel. This is called from a swing thread, so be quick.


saveValues

void saveValues()
When this method is called the Extension should save values from the preference panel into its internal state. Value checking can be performed at this point. This is called from a swing thread, so be quick.



BlueJ homepage