1 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 46 public class TextEditorPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { 47 48 53 private static boolean fgInitialized= false; 54 55 58 public TextEditorPreferencePage() { 59 super(GRID); 60 61 setDescription(TextEditorMessages.PreferencePage_description); 62 Plugin plugin= Platform.getPlugin("org.eclipse.ui.workbench"); if (plugin instanceof AbstractUIPlugin) { 64 AbstractUIPlugin uiPlugin= (AbstractUIPlugin) plugin; 65 setPreferenceStore(uiPlugin.getPreferenceStore()); 66 } 67 } 68 69 72 public void createControl(Composite parent) { 73 super.createControl(parent); 74 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), ITextEditorHelpContextIds.TEXT_EDITOR_PREFERENCE_PAGE); 75 } 76 77 80 public void createFieldEditors() { 81 addField(new FontFieldEditor(JFaceResources.TEXT_FONT, TextEditorMessages.PreferencePage_fontEditor, getFieldEditorParent())); 82 } 83 84 87 public void init(IWorkbench workbench) { 88 } 89 90 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 |