Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-07-2008, 06:48 PM
Moderator
 
Join Date: Nov 2007
Posts: 1,657
Java Tip will become famous soon enoughJava Tip will become famous soon enough
How to use JFace Preferences and Field Editors
Code:
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", 2, new 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(), 0, 100, 1, 10); 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 */
__________________
Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums! (closes on July 27, 2008)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
JFace Preferences Demonstration Java Tip SWT 0 07-07-2008 06:48 PM
First JFace application Java Tip SWT 0 07-02-2008 10:13 PM
JFace Window Java Tip SWT 0 07-02-2008 10:12 PM
editors hareclipse Eclipse 1 06-14-2008 04:09 AM
Jface + Gef Eric Advanced Java 1 07-05-2007 10:07 PM


All times are GMT +3. The time now is 08:27 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org