Cosmetic
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / preferences / JavaSourcePreviewerUpdater.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11
12 package net.sourceforge.phpdt.internal.ui.preferences;
13
14 import net.sourceforge.phpdt.ui.PreferenceConstants;
15 import net.sourceforge.phpdt.ui.text.PHPSourceViewerConfiguration;
16
17 import org.eclipse.jface.preference.IPreferenceStore;
18 import org.eclipse.jface.resource.JFaceResources;
19 import org.eclipse.jface.text.source.SourceViewer;
20 import org.eclipse.jface.util.Assert;
21 import org.eclipse.jface.util.IPropertyChangeListener;
22 import org.eclipse.jface.util.PropertyChangeEvent;
23 import org.eclipse.swt.events.DisposeEvent;
24 import org.eclipse.swt.events.DisposeListener;
25 import org.eclipse.swt.graphics.Font;
26 //import net.sourceforge.phpdt.ui.text.JavaSourceViewerConfiguration;
27
28 /**
29  * Handles Java editor font changes for Java source preview viewers.
30  * 
31  * @since 3.0
32  */
33 class JavaSourcePreviewerUpdater {
34         
35         /**
36          * Creates a Java source preview updater for the given viewer, configuration and preference store.
37          *
38          * @param viewer the viewer
39          * @param configuration the configuration
40          * @param preferenceStore the preference store
41          */
42         JavaSourcePreviewerUpdater(final SourceViewer viewer, final PHPSourceViewerConfiguration configuration, final IPreferenceStore preferenceStore) {
43                 Assert.isNotNull(viewer);
44                 Assert.isNotNull(configuration);
45                 Assert.isNotNull(preferenceStore);
46                 final IPropertyChangeListener fontChangeListener= new IPropertyChangeListener() {
47                         /*
48                          * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
49                          */
50                         public void propertyChange(PropertyChangeEvent event) {
51                                 if (event.getProperty().equals(PreferenceConstants.EDITOR_TEXT_FONT)) {
52                                         Font font= JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT);
53                                         viewer.getTextWidget().setFont(font);
54                                 }
55                         }
56                 };
57                 final IPropertyChangeListener propertyChangeListener= new IPropertyChangeListener() {
58                         /*
59                          * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
60                          */
61                         public void propertyChange(PropertyChangeEvent event) {
62                                 if (configuration.affectsTextPresentation(event)) {
63                                         configuration.handlePropertyChangeEvent(event);
64                                         viewer.invalidateTextPresentation();
65                                 }
66                         }
67                 };
68                 viewer.getTextWidget().addDisposeListener(new DisposeListener() {
69                         /*
70                          * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
71                          */
72                         public void widgetDisposed(DisposeEvent e) {
73                                 preferenceStore.removePropertyChangeListener(propertyChangeListener);
74                                 JFaceResources.getFontRegistry().removeListener(fontChangeListener);
75                         }
76                 });
77                 JFaceResources.getFontRegistry().addListener(fontChangeListener);
78                 preferenceStore.addPropertyChangeListener(propertyChangeListener);
79         }
80 }