001: /*
002: * uDig - User Friendly Desktop Internet GIS client
003: * http://udig.refractions.net
004: * (C) 2004, Refractions Research Inc.
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package net.refractions.udig.render.wms.basic;
018:
019: import org.eclipse.core.runtime.IStatus;
020: import org.eclipse.core.runtime.Platform;
021: import org.eclipse.core.runtime.Status;
022: import org.eclipse.ui.plugin.AbstractUIPlugin;
023: import org.osgi.framework.BundleContext;
024:
025: /**
026: * WMS renderer plugin
027: * @author jones
028: * @since 0.6.0
029: */
030: public class WMSPlugin extends AbstractUIPlugin {
031:
032: public static final String ID = "net.refractions.udig.render.wms.basic"; //$NON-NLS-1$
033: private static WMSPlugin plugin;
034:
035: /**
036: * Construct <code>WMSPlugin</code>.
037: *
038: */
039: public WMSPlugin() {
040: super ();
041: plugin = this ;
042: }
043:
044: public static WMSPlugin getDefault() {
045: return plugin;
046: }
047:
048: /**
049: * This method is called upon plug-in activation
050: */
051: public void start(BundleContext context) throws Exception {
052: super .start(context);
053: }
054:
055: /**
056: * This method is called when the plug-in is stopped
057: */
058: public void stop(BundleContext context) throws Exception {
059: super .stop(context);
060: plugin = null;
061: }
062:
063: public static void log(String message) {
064: log(message, null);
065: }
066:
067: public static void log(String message, Throwable exception) {
068: WMSPlugin.getDefault().getLog().log(
069: new Status(IStatus.INFO, WMSPlugin.ID, IStatus.OK,
070: message, exception));
071: }
072:
073: /**
074: * Messages that only engage if getDefault().isDebugging()
075: * <p>
076: * It is much prefered to do this:<pre><code>
077: * private static final String RENDERING = "net.refractions.udig.project/render/trace";
078: * if( ProjectUIPlugin.getDefault().isDebugging() && "true".equalsIgnoreCase( RENDERING ) ){
079: * System.out.println( "your message here" );
080: * }
081: */
082: public final static void trace(String message, Throwable e) {
083: if (getDefault().isDebugging()) {
084: if (message != null)
085: System.out.println(message);
086: if (e != null)
087: e.printStackTrace();
088: }
089: }
090:
091: public static final void trace(String message) {
092: trace(message, null);
093: }
094:
095: /**
096: * Performs the Platform.getDebugOption true check on the provided trace
097: * <p>
098: * Note: ProjectUIPlugin.getDefault().isDebugging() must also be on.
099: * <ul>
100: * <li>Trace.RENDER - trace rendering progress
101: * </ul>
102: * </p>
103: * @param trace currently only RENDER is defined
104: */
105: public static boolean isDebugging(final String trace) {
106: return getDefault().isDebugging()
107: && "true".equalsIgnoreCase(Platform.getDebugOption(trace)); //$NON-NLS-1$
108:
109: }
110: }
|