KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > editors > text > TextEditorPreferencePage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.editors.text;
12
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.graphics.Color;
15 import org.eclipse.swt.graphics.Font;
16 import org.eclipse.swt.graphics.FontData;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.Display;
19
20 import org.eclipse.core.runtime.Platform;
21 import org.eclipse.core.runtime.Plugin;
22
23 import org.eclipse.jface.preference.FieldEditorPreferencePage;
24 import org.eclipse.jface.preference.FontFieldEditor;
25 import org.eclipse.jface.preference.IPreferenceStore;
26 import org.eclipse.jface.preference.PreferenceConverter;
27 import org.eclipse.jface.resource.JFaceResources;
28
29 import org.eclipse.ui.IWorkbench;
30 import org.eclipse.ui.IWorkbenchPreferencePage;
31 import org.eclipse.ui.PlatformUI;
32 import org.eclipse.ui.plugin.AbstractUIPlugin;
33 import org.eclipse.ui.texteditor.AbstractTextEditor;
34
35
36 /**
37  * A preference page to set the font used in the default text editor.
38  * <p>
39  * This preference page uses the text editor's preference bundle and
40  * uses the key <code>"PreferencePage.description"</code> to look up
41  * the page description. In addition, it uses <code>"PreferencePage.fontEditor"</code>
42  * for the editor description.
43  * </p>
44  * @deprecated As of 2.1, fonts are managed by the workbench, no longer supported
45  */

46 public class TextEditorPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
47
48     /**
49      * Indicates whether the preferences that this page manipulates have been initialized.
50      *
51      * @since 2.0
52      */

53     private static boolean fgInitialized= false;
54
55     /**
56      * Creates and returns the text editor preference page.
57      */

58     public TextEditorPreferencePage() {
59         super(GRID);
60
61         setDescription(TextEditorMessages.PreferencePage_description);
62         Plugin plugin= Platform.getPlugin("org.eclipse.ui.workbench"); //$NON-NLS-1$
63
if (plugin instanceof AbstractUIPlugin) {
64             AbstractUIPlugin uiPlugin= (AbstractUIPlugin) plugin;
65             setPreferenceStore(uiPlugin.getPreferenceStore());
66         }
67     }
68
69     /*
70      * @see IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
71      */

72     public void createControl(Composite parent) {
73         super.createControl(parent);
74         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), ITextEditorHelpContextIds.TEXT_EDITOR_PREFERENCE_PAGE);
75     }
76
77     /*
78      * @see FieldEditorPreferencePage#createFieldEditors()
79      */

80     public void createFieldEditors() {
81         addField(new FontFieldEditor(JFaceResources.TEXT_FONT, TextEditorMessages.PreferencePage_fontEditor, getFieldEditorParent()));
82     }
83
84     /*
85      * @see IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
86      */

87     public void init(IWorkbench workbench) {
88     }
89
90     /**
91      * Initializes the defaults for the given store.
92      *
93      * @param store the preference store
94      * @since 2.0
95      */

96     public static void initDefaults(IPreferenceStore store) {
97
98         if (fgInitialized)
99             return;
100
101         fgInitialized= true;
102
103         Font font= JFaceResources.getTextFont();
104         if (font != null) {
105             FontData[] data= font.getFontData();
106             if (data != null && data.length > 0)
107                 PreferenceConverter.setDefault(store, JFaceResources.TEXT_FONT, data[0]);
108         }
109
110         Display display= Display.getDefault();
111         Color color= display.getSystemColor(SWT.COLOR_LIST_FOREGROUND);
112         PreferenceConverter.setDefault(store, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND, color.getRGB());
113         store.setDefault(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT, true);
114
115         color= display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
116         PreferenceConverter.setDefault(store, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, color.getRGB());
117         store.setDefault(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, true);
118     }
119 }
120
Popular Tags