4c2ea9db7f461d27326ef0c6fc3fd996850d95d4
[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.phpdoc.PHPDocCodeScanner;
16 import net.sourceforge.phpeclipse.phpeditor.php.HTMLCodeScanner;
17 import net.sourceforge.phpeclipse.phpeditor.php.PHPCodeScanner;
18 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
19
20 /** The PHPEditorEnvironment maintains singletons used by the php editor
21  */
22 public class PHPEditorEnvironment {
23
24   private static PHPColorProvider fgColorProvider;
25   private static PHPCodeScanner fgPHPCodeScanner;
26   private static HTMLCodeScanner fgHTMLCodeScanner;
27   private static PHPDocCodeScanner fgDocScanner;
28
29   private static int fgRefCount = 0;
30
31   /**
32    * A connection has occured - initialize the receiver if it is the first activation.
33    */
34   public static void connect(Object client) {
35     if (++fgRefCount == 1) {
36       fgColorProvider = new PHPColorProvider();
37       fgPHPCodeScanner = new PHPCodeScanner(fgColorProvider);
38       fgHTMLCodeScanner = new HTMLCodeScanner(fgColorProvider);
39       fgDocScanner = new PHPDocCodeScanner(fgColorProvider);
40     }
41   }
42
43   /**
44    * A disconnection has occured - clear the receiver if it is the last deactivation.
45    */
46   public static void disconnect(Object client) {
47     if (--fgRefCount == 0) {
48       fgPHPCodeScanner = null;
49       fgHTMLCodeScanner = null;
50       fgDocScanner = null;
51       fgColorProvider.dispose();
52       fgColorProvider = null;
53     }
54   }
55
56   /**
57    * Returns the singleton scanner.
58    */
59   public static PHPCodeScanner getPHPCodeScanner() {
60     return fgPHPCodeScanner;
61   }
62
63   /**
64    * Returns the singleton scanner.
65    */
66   public static HTMLCodeScanner getHTMLCodeScanner() {
67     return fgHTMLCodeScanner;
68   }
69
70   /**
71    * Returns the singleton PHPDoc scanner.
72    */
73   public static PHPDocCodeScanner getPHPDocCodeScanner() {
74     return fgDocScanner;
75   }
76
77   /**
78    * Returns the singleton color provider.
79    */
80   public static PHPColorProvider getPHPColorProvider() {
81     return fgColorProvider;
82   }
83
84 }