KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > util > Policy


1 /*******************************************************************************
2  * Copyright (c) 2004, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  * Chris Gross (schtoo@schtoo.com) - support for ILogger added
11  * (bug 49497 [RCP] JFace dependency on org.eclipse.core.runtime enlarges standalone JFace applications)
12  *******************************************************************************/

13 package org.eclipse.jface.util;
14
15 import java.util.Comparator JavaDoc;
16
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.jface.dialogs.AnimatorFactory;
19 import org.eclipse.jface.dialogs.ErrorSupportProvider;
20
21 /**
22  * The Policy class handles settings for behaviour, debug flags and logging
23  * within JFace.
24  *
25  * @since 3.0
26  */

27 public class Policy {
28
29     /**
30      * Constant for the the default setting for debug options.
31      */

32     public static final boolean DEFAULT = false;
33
34     /**
35      * The unique identifier of the JFace plug-in.
36      */

37     public static final String JavaDoc JFACE = "org.eclipse.jface";//$NON-NLS-1$
38

39     private static ILogger log;
40
41     private static Comparator JavaDoc viewerComparator;
42
43     private static AnimatorFactory animatorFactory;
44
45     /**
46      * A flag to indicate whether unparented dialogs should be checked.
47      */

48     public static boolean DEBUG_DIALOG_NO_PARENT = DEFAULT;
49
50     /**
51      * A flag to indicate whether actions are being traced.
52      */

53     public static boolean TRACE_ACTIONS = DEFAULT;
54
55     /**
56      * A flag to indicate whether toolbars are being traced.
57      */

58
59     public static boolean TRACE_TOOLBAR = DEFAULT;
60
61     private static ErrorSupportProvider errorSupportProvider;
62
63     /**
64      * Returns the dummy log to use if none has been set
65      */

66     private static ILogger getDummyLog() {
67         return new ILogger() {
68             public void log(IStatus status) {
69                 System.err.println(status.getMessage());
70                 if (status.getException() != null) {
71                     status.getException().printStackTrace(System.err);
72                 }
73             }
74         };
75     }
76
77     /**
78      * Sets the logger used by JFace to log errors.
79      *
80      * @param logger
81      * the logger to use, or <code>null</code> to use the default
82      * logger
83      * @since 3.1
84      */

85     public static void setLog(ILogger logger) {
86         log = logger;
87     }
88
89     /**
90      * Returns the logger used by JFace to log errors.
91      * <p>
92      * The default logger prints the status to <code>System.err</code>.
93      * </p>
94      *
95      * @return the logger
96      * @since 3.1
97      */

98     public static ILogger getLog() {
99         if (log == null) {
100             log = getDummyLog();
101         }
102         return log;
103     }
104
105     /**
106      * Return the default comparator used by JFace to sort strings.
107      *
108      * @return a default comparator used by JFace to sort strings
109      */

110     private static Comparator JavaDoc getDefaultComparator() {
111         return new Comparator JavaDoc() {
112             /**
113              * Compares string s1 to string s2.
114              *
115              * @param s1
116              * string 1
117              * @param s2
118              * string 2
119              * @return Returns an integer value. Value is less than zero if
120              * source is less than target, value is zero if source and
121              * target are equal, value is greater than zero if source is
122              * greater than target.
123              * @exception ClassCastException
124              * the arguments cannot be cast to Strings.
125              */

126             public int compare(Object JavaDoc s1, Object JavaDoc s2) {
127                 return ((String JavaDoc) s1).compareTo((String JavaDoc) s2);
128             }
129         };
130     }
131
132     /**
133      * Return the comparator used by JFace to sort strings.
134      *
135      * @return the comparator used by JFace to sort strings
136      * @since 3.2
137      */

138     public static Comparator JavaDoc getComparator() {
139         if (viewerComparator == null) {
140             viewerComparator = getDefaultComparator();
141         }
142         return viewerComparator;
143     }
144
145     /**
146      * Sets the comparator used by JFace to sort strings.
147      *
148      * @param comparator
149      * comparator used by JFace to sort strings
150      * @since 3.2
151      */

152     public static void setComparator(Comparator JavaDoc comparator) {
153         org.eclipse.core.runtime.Assert.isTrue(viewerComparator == null);
154         viewerComparator = comparator;
155     }
156
157     /**
158      * Sets the animator factory used by JFace to create control animator
159      * instances.
160      *
161      * @param factory
162      * the AnimatorFactory to use.
163      * @since 3.2
164      * @deprecated this is no longer in use as of 3.3
165      */

166     public static void setAnimatorFactory(AnimatorFactory factory) {
167         animatorFactory = factory;
168     }
169
170     /**
171      * Returns the animator factory used by JFace to create control animator
172      * instances.
173      *
174      * @return the animator factory used to create control animator instances.
175      * @since 3.2
176      * @deprecated this is no longer in use as of 3.3
177      */

178     public static AnimatorFactory getAnimatorFactory() {
179         if (animatorFactory == null)
180             animatorFactory = new AnimatorFactory();
181         return animatorFactory;
182     }
183
184     /**
185      * Set the error support provider for error dialogs.
186      *
187      * @param provider
188      * @since 3.3
189      */

190     public static void setErrorSupportProvider(ErrorSupportProvider provider) {
191         errorSupportProvider = provider;
192     }
193
194     /**
195      * Return the ErrorSupportProvider for the receiver.
196      *
197      * @return ErrorSupportProvider or <code>null</code> if this has not been set
198      * @since 3.3
199      */

200     public static ErrorSupportProvider getErrorSupportProvider() {
201         return errorSupportProvider;
202     }
203
204 }
205
Popular Tags