From fc29036cf30bc6c11def1d4c61bca480a432cd88 Mon Sep 17 00:00:00 2001 From: lonnen Date: Wed, 7 Jul 2010 16:56:52 +0000 Subject: [PATCH] Added a preferences page for the editor --- editor/org.processing.editor/plugin.xml | 14 +++++ .../preferences/PreferenceConstants.java | 27 +++++++++ .../preferences/PreferenceInitializer.java | 38 +++++++++++++ .../ProcessingPreferencesPage.java | 55 +++++++++++++++++++ 4 files changed, 134 insertions(+) create mode 100644 editor/org.processing.editor/src/org/processing/preferences/PreferenceConstants.java create mode 100644 editor/org.processing.editor/src/org/processing/preferences/PreferenceInitializer.java create mode 100644 editor/org.processing.editor/src/org/processing/preferences/ProcessingPreferencesPage.java diff --git a/editor/org.processing.editor/plugin.xml b/editor/org.processing.editor/plugin.xml index d6a4d8c43..7e1d1eb9f 100644 --- a/editor/org.processing.editor/plugin.xml +++ b/editor/org.processing.editor/plugin.xml @@ -45,4 +45,18 @@ + + + + + + + + diff --git a/editor/org.processing.editor/src/org/processing/preferences/PreferenceConstants.java b/editor/org.processing.editor/src/org/processing/preferences/PreferenceConstants.java new file mode 100644 index 000000000..61bf7668b --- /dev/null +++ b/editor/org.processing.editor/src/org/processing/preferences/PreferenceConstants.java @@ -0,0 +1,27 @@ +package org.processing.preferences; + +/** + * Constant definitions for plug-in preferences + */ +public class PreferenceConstants { + + // Editor Preferences + public static final String PROCESSING_SKETCH = "sketch_path"; // path preference + public static final String PROCESSING_AUTO_INDENT = "eclipse.editor.auto.indent"; + +// // PROCESSING_PREFERENCES prefix indicates membership in the processing.app preferences class +// public static final String PROCESSING_APP_PREFERENCES_EDITOR_TABS_SIZE = "editor.tabs.size"; +// public static final String PROCESSING_APP_PREFERENCES_PREPROC_SUBSTITUTE_FLOATS= "preproc.substitute_floats"; +// public static final String PROCESSING_APP_PREFERENCES_PREPROC_WEB_COLORS = "preproc.web_colors"; +// public static final String PROCESSING_APP_PREFERENCES_PREPROC_COLOR_DATATYPE = "preproc.color_datatype"; +// public static final String PROCESSING_APP_PREFERENCES_PREPROC_ENHANCED_CASTING = "preproc.enhanced_casted"; +// public static final String PROCESSING_APP_PREFERENCES_PREPROC_SUBSTITUTE_UNICODE = "preproc.substitute.unicode"; +// public static final String PROCESSING_APP_PREFERENCES_PREPROC_OUTPUT_PARSE_TREE = "preproc.output_parse.tree"; +// public static final String PROCESSING_APP_PREFERENCES_PREPROC_EXPORT_APPLICATION_FULLSCREEN = "export.application.fullscreen"; +// public static final String PROCESSING_APP_PREFERENCES_PREPROC_RUN_PRESENT_BGCOLOR = "run.present.bgcolor"; +// public static final String PROCESSING_APP_PREFERENCES_PREPROC_EXPORT_APPLICATION_STOP = "export.application.stop"; +// public static final String PROCESSING_APP_PREFERENCES_PREPROC_RUN_PRESENT_STOP_COLOR = "run.present.stop.color"; +// public static final String PROCESSING_APP_PREFERENCES_PREPROC_RUN_WINDOW_BGCOLOR = "run.window.bgcolor"; +// public static final String PROCESSING_APP_PREFERENCES_PREPROC_PREPROC_IMPORTS_LIST = "preproc.imports.list"; + +} diff --git a/editor/org.processing.editor/src/org/processing/preferences/PreferenceInitializer.java b/editor/org.processing.editor/src/org/processing/preferences/PreferenceInitializer.java new file mode 100644 index 000000000..2533609f5 --- /dev/null +++ b/editor/org.processing.editor/src/org/processing/preferences/PreferenceInitializer.java @@ -0,0 +1,38 @@ +package org.processing.preferences; + +import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; +import org.eclipse.jface.preference.IPreferenceStore; + +import org.processing.editor.ProcessingEditorPlugin; + +/** + * Class used to initialize default preference values. + */ +public class PreferenceInitializer extends AbstractPreferenceInitializer { + + /** + * Sets the default preference values + */ + public void initializeDefaultPreferences() { + IPreferenceStore store = ProcessingEditorPlugin.getDefault().getPreferenceStore(); + + //store.setDefault(PreferenceContants.PROCESSING_SKETCH, value); + store.setDefault(PreferenceConstants.PROCESSING_AUTO_INDENT, true); + + // PROCESSING_PREFERENCES are processing.app preferences +// store.setDefault(PreferenceConstants.PROCESSING_APP_PREFERENCES_EDITOR_TABS_SIZE, "4"); +// store.setDefault(PreferenceConstants.PROCESSING_APP_PREFERENCES_PREPROC_SUBSTITUTE_FLOATS, "true"); +// store.setDefault(PreferenceConstants.PROCESSING_APP_PREFERENCES_PREPROC_WEB_COLORS, "true"); +// store.setDefault(PreferenceConstants.PROCESSING_APP_PREFERENCES_PREPROC_COLOR_DATATYPE, "true"); +// store.setDefault(PreferenceConstants.PROCESSING_APP_PREFERENCES_PREPROC_ENHANCED_CASTING, "true"); +// store.setDefault(PreferenceConstants.PROCESSING_APP_PREFERENCES_PREPROC_SUBSTITUTE_UNICODE, "true"); +// store.setDefault(PreferenceConstants.PROCESSING_APP_PREFERENCES_PREPROC_OUTPUT_PARSE_TREE, "false"); +// store.setDefault(PreferenceConstants.PROCESSING_APP_PREFERENCES_PREPROC_EXPORT_APPLICATION_FULLSCREEN, "false"); +// store.setDefault(PreferenceConstants.PROCESSING_APP_PREFERENCES_PREPROC_RUN_PRESENT_BGCOLOR, "#666666"); +// store.setDefault(PreferenceConstants.PROCESSING_APP_PREFERENCES_PREPROC_EXPORT_APPLICATION_STOP, "true"); +// store.setDefault(PreferenceConstants.PROCESSING_APP_PREFERENCES_PREPROC_RUN_PRESENT_STOP_COLOR, "#cccccc"); +// store.setDefault(PreferenceConstants.PROCESSING_APP_PREFERENCES_PREPROC_RUN_WINDOW_BGCOLOR, "#ECE9D8"); +// store.setDefault(PreferenceConstants.PROCESSING_APP_PREFERENCES_PREPROC_PREPROC_IMPORTS_LIST, "java.applet.*,java.awt.Dimension,java.awt.Frame,java.awt.event.MouseEvent,java.awt.event.KeyEvent,java.awt.event.FocusEvent,java.awt.Image,java.io.*,java.net.*,java.text.*,java.util.*,java.util.zip.*,java.util.regex.*"); + } + +} diff --git a/editor/org.processing.editor/src/org/processing/preferences/ProcessingPreferencesPage.java b/editor/org.processing.editor/src/org/processing/preferences/ProcessingPreferencesPage.java new file mode 100644 index 000000000..3c9231438 --- /dev/null +++ b/editor/org.processing.editor/src/org/processing/preferences/ProcessingPreferencesPage.java @@ -0,0 +1,55 @@ +package org.processing.preferences; + +import org.eclipse.jface.preference.*; +import org.eclipse.ui.IWorkbenchPreferencePage; +import org.eclipse.ui.IWorkbench; +import org.processing.editor.ProcessingEditorPlugin; + +/** + * This page is used to modify preferences only. They + * are stored in the preference store that belongs to + * the main plug-in class. That way, preferences can + * be accessed directly via the preference store. + *

+ * Two editor preferences are included as examples, but + * currently do not do anything. + *

+ * //TODO transfer Processing.app preferences here + * this may involve subclassing PreferencePage, + * but things could be setup such that these are read + * from a file, and we could use a customized version of + * a standard Processing preferences file to store this. + */ + +public class ProcessingPreferencesPage + extends FieldEditorPreferencePage + implements IWorkbenchPreferencePage { + + public ProcessingPreferencesPage() { + super(GRID); + setPreferenceStore(ProcessingEditorPlugin.getDefault().getPreferenceStore()); + setDescription("Processing Plugin Preferences (nothing here is used, see JavaDoc)"); + } + + /** + * Creates the field editors. Field editors are abstractions of + * the common GUI blocks needed to manipulate various types + * of preferences. Each field editor knows how to save and + * restore itself. + */ + public void createFieldEditors() { + addField(new DirectoryFieldEditor(PreferenceConstants.PROCESSING_SKETCH, + "Sketchbook Directory:", getFieldEditorParent())); + addField( + new BooleanFieldEditor( + PreferenceConstants.PROCESSING_AUTO_INDENT, + "Auto indent", + getFieldEditorParent())); + } + + /** + * Initializes the preference page. Nothing to do here, but it has to be subclassed. + */ + public void init(IWorkbench workbench) {} + +} \ No newline at end of file