5243cfaa9c1a00dea970de490cd1287ac20487e9
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / PHPEditorEnvironment.java
1 package net.sourceforge.phpeclipse.phpeditor;
2
3 /**********************************************************************
4 Copyright (c) 2000, 2002 IBM Corp. and others.
5 All rights reserved. This program and the accompanying materials
6 are made available under the terms of the Common Public License v1.0
7 which accompanies this distribution, and is available at
8 http://www.eclipse.org/legal/cpl-v10.html
9
10 Contributors:
11     IBM Corporation - Initial implementation
12     Klaus Hartlage - www.eclipseproject.de
13 **********************************************************************/
14
15 import net.sourceforge.phpdt.internal.ui.text.JavaColorManager;
16 import net.sourceforge.phpdt.internal.ui.text.phpdoc.PHPDocCodeScanner;
17 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
18 import net.sourceforge.phpeclipse.phpeditor.php.HTMLCodeScanner;
19 import net.sourceforge.phpeclipse.phpeditor.php.PHPCodeScanner;
20 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
21
22 /** The PHPEditorEnvironment maintains singletons used by the php editor
23  */
24 public class PHPEditorEnvironment {
25  // PHPColorProvider
26   private static JavaColorManager fgColorProvider;
27   private static PHPCodeScanner fgPHPCodeScanner;
28   private static HTMLCodeScanner fgHTMLCodeScanner;
29   private static PHPDocCodeScanner fgDocScanner;
30
31   private static int fgRefCount = 0;
32
33   /**
34    * A connection has occured - initialize the receiver if it is the first activation.
35    */
36   public static void connect(Object client) {
37     if (++fgRefCount == 1) {
38       fgColorProvider = new JavaColorManager(); // new PHPColorProvider();
39       fgPHPCodeScanner = new PHPCodeScanner(fgColorProvider, PHPeclipsePlugin.getDefault().getPreferenceStore() );
40       fgHTMLCodeScanner = new HTMLCodeScanner(fgColorProvider, PHPeclipsePlugin.getDefault().getPreferenceStore());
41       fgDocScanner = new PHPDocCodeScanner(fgColorProvider, PHPeclipsePlugin.getDefault().getPreferenceStore() );
42     }
43   }
44
45   /**
46    * A disconnection has occured - clear the receiver if it is the last deactivation.
47    */
48   public static void disconnect(Object client) {
49     if (--fgRefCount == 0) {
50       fgPHPCodeScanner = null;
51       fgHTMLCodeScanner = null;
52       fgDocScanner = null;
53       fgColorProvider.dispose();
54       fgColorProvider = null;
55     }
56   }
57
58   /**
59    * Returns the singleton scanner.
60    */
61   public static PHPCodeScanner getPHPCodeScanner() {
62     return fgPHPCodeScanner;
63   }
64
65   /**
66    * Returns the singleton scanner.
67    */
68   public static HTMLCodeScanner getHTMLCodeScanner() {
69     return fgHTMLCodeScanner;
70   }
71
72   /**
73    * Returns the singleton PHPDoc scanner.
74    */
75   public static PHPDocCodeScanner getPHPDocCodeScanner() {
76     return fgDocScanner;
77   }
78
79   /**
80    * Returns the singleton color provider.
81    */
82   public static JavaColorManager getPHPColorProvider() {
83     return fgColorProvider;
84   }
85
86 }