1 11 12 package org.eclipse.jdt.internal.ui.preferences; 13 14 import org.eclipse.core.runtime.Assert; 15 16 import org.eclipse.swt.events.DisposeEvent; 17 import org.eclipse.swt.events.DisposeListener; 18 import org.eclipse.swt.graphics.Font; 19 20 import org.eclipse.jface.preference.IPreferenceStore; 21 import org.eclipse.jface.resource.JFaceResources; 22 import org.eclipse.jface.util.IPropertyChangeListener; 23 import org.eclipse.jface.util.PropertyChangeEvent; 24 25 import org.eclipse.jface.text.source.SourceViewer; 26 27 import org.eclipse.jdt.ui.PreferenceConstants; 28 import org.eclipse.jdt.ui.text.JavaSourceViewerConfiguration; 29 30 35 class JavaSourcePreviewerUpdater { 36 37 44 JavaSourcePreviewerUpdater(final SourceViewer viewer, final JavaSourceViewerConfiguration configuration, final IPreferenceStore preferenceStore) { 45 Assert.isNotNull(viewer); 46 Assert.isNotNull(configuration); 47 Assert.isNotNull(preferenceStore); 48 final IPropertyChangeListener fontChangeListener= new IPropertyChangeListener() { 49 52 public void propertyChange(PropertyChangeEvent event) { 53 if (event.getProperty().equals(PreferenceConstants.EDITOR_TEXT_FONT)) { 54 Font font= JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT); 55 viewer.getTextWidget().setFont(font); 56 } 57 } 58 }; 59 final IPropertyChangeListener propertyChangeListener= new IPropertyChangeListener() { 60 63 public void propertyChange(PropertyChangeEvent event) { 64 if (configuration.affectsTextPresentation(event)) { 65 configuration.handlePropertyChangeEvent(event); 66 viewer.invalidateTextPresentation(); 67 } 68 } 69 }; 70 viewer.getTextWidget().addDisposeListener(new DisposeListener() { 71 74 public void widgetDisposed(DisposeEvent e) { 75 preferenceStore.removePropertyChangeListener(propertyChangeListener); 76 JFaceResources.getFontRegistry().removeListener(fontChangeListener); 77 } 78 }); 79 JFaceResources.getFontRegistry().addListener(fontChangeListener); 80 preferenceStore.addPropertyChangeListener(propertyChangeListener); 81 } 82 } 83 | Popular Tags |