JFace preferences and field editors : Preferences « SWT JFace Eclipse « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JDK 6
25.JNDI LDAP
26.JPA
27.JSP
28.JSTL
29.Language Basics
30.Network Protocol
31.PDF RTF
32.Reflection
33.Regular Expressions
34.Scripting
35.Security
36.Servlets
37.Spring
38.Swing Components
39.Swing JFC
40.SWT JFace Eclipse
41.Threads
42.Tiny Application
43.Velocity
44.Web Services SOA
45.XML
Java » SWT JFace Eclipse » PreferencesScreenshots 
JFace preferences and field editors


import java.io.IOException;

import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.ColorFieldEditor;
import org.eclipse.jface.preference.DirectoryFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.FileFieldEditor;
import org.eclipse.jface.preference.FontFieldEditor;
import org.eclipse.jface.preference.IntegerFieldEditor;
import org.eclipse.jface.preference.PathEditor;
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.jface.preference.PreferenceManager;
import org.eclipse.jface.preference.PreferenceNode;
import org.eclipse.jface.preference.PreferenceStore;
import org.eclipse.jface.preference.RadioGroupFieldEditor;
import org.eclipse.jface.preference.ScaleFieldEditor;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.swt.widgets.Display;

/**
 * This class demonstrates JFace preferences and field editors
 */
public class ShowFieldPrefs {
  /**
   * Runs the application
   */
  public void run() {
    Display display = new Display();

    // Create the preference manager
    PreferenceManager mgr = new PreferenceManager();

    // Create the nodes
    PreferenceNode one = new PreferenceNode("one""One", null,
        FieldEditorPageOne.class.getName());
    PreferenceNode two = new PreferenceNode("two""Two", null,
        FieldEditorPageTwo.class.getName());

    // Add the nodes
    mgr.addToRoot(one);
    mgr.addToRoot(two);

    // Create the preferences dialog
    PreferenceDialog dlg = new PreferenceDialog(null, mgr);

    // Set the preference store
    PreferenceStore ps = new PreferenceStore("showfieldprefs.properties");
    try {
      ps.load();
    catch (IOException e) {
      // Ignore
    }
    dlg.setPreferenceStore(ps);

    // Open the dialog
    dlg.open();

    try {
      // Save the preferences
      ps.save();
    catch (IOException e) {
      e.printStackTrace();
    }
    display.dispose();
  }

  /**
   * The application entry point
   
   @param args
   *            the command line arguments
   */
  public static void main(String[] args) {
    new ShowFieldPrefs().run();
  }
}

/**
 * This class demonstrates field editors
 */

class FieldEditorPageOne extends FieldEditorPreferencePage {
  public FieldEditorPageOne() {
    // Use the "flat" layout
    super(FLAT);
  }

  /**
   * Creates the field editors
   */
  protected void createFieldEditors() {
    // Add a boolean field
    BooleanFieldEditor bfe = new BooleanFieldEditor("myBoolean""Boolean",
        getFieldEditorParent());
    addField(bfe);

    // Add a color field
    ColorFieldEditor cfe = new ColorFieldEditor("myColor""Color:",
        getFieldEditorParent());
    addField(cfe);

    // Add a directory field
    DirectoryFieldEditor dfe = new DirectoryFieldEditor("myDirectory",
        "Directory:", getFieldEditorParent());
    addField(dfe);

    // Add a file field
    FileFieldEditor ffe = new FileFieldEditor("myFile""File:",
        getFieldEditorParent());
    addField(ffe);

    // Add a font field
    FontFieldEditor fontFe = new FontFieldEditor("myFont""Font:",
        getFieldEditorParent());
    addField(fontFe);

    // Add a radio group field
    RadioGroupFieldEditor rfe = new RadioGroupFieldEditor("myRadioGroup",
        "Radio Group"2new String[][] { { "First Value""first" },
            "Second Value""second" },
            "Third Value""third" },
            "Fourth Value""fourth" } }, getFieldEditorParent(),
        true);
    addField(rfe);

    // Add a path field
    PathEditor pe = new PathEditor("myPath""Path:""Choose a Path",
        getFieldEditorParent());
    addField(pe);
  }
}
/**
 * This class demonstrates field editors
 */

class FieldEditorPageTwo extends FieldEditorPreferencePage {
  public FieldEditorPageTwo() {
    // Use the "grid" layout
    super(GRID);
  }

  /**
   * Creates the field editors
   */
  protected void createFieldEditors() {
    // Add an integer field
    IntegerFieldEditor ife = new IntegerFieldEditor("myInt""Int:",
        getFieldEditorParent());
    addField(ife);

    // Add a scale field
    ScaleFieldEditor sfe = new ScaleFieldEditor("myScale""Scale:",
        getFieldEditorParent()0100110);
    addField(sfe);

    // Add a string field
    StringFieldEditor stringFe = new StringFieldEditor("myString",
        "String:", getFieldEditorParent());
    addField(stringFe);
  }
}


//showfieldprefs.properties

/*
#Sat Feb 28 16:06:57 GMT-05:00 2004
myPath=C\:\\Documents and Settings\\Owner\\My Documents;C\:\\;
myRadioGroup=
myScale=0
myColor=0,128,0
myFont=1|Terminal|8|0|WINDOWS|1|-13|0|0|0|400|0|0|0|-1|1|2|1|49|Terminal;
myFile=.\\0249f1701.bmp
myString=
myBoolean=true
myDirectory=C\:\\Documents and Settings\\Owner\\My Documents


*/



           
       
Related examples in the same category
1.JFace preferences
2.Demonstrates PreferenceStore
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.