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.internal.feature.shapefile;
018:
019: import java.util.logging.Level;
020: import java.util.logging.Logger;
021:
022: import org.eclipse.core.runtime.IStatus;
023: import org.eclipse.core.runtime.Platform;
024: import org.eclipse.core.runtime.Plugin;
025: import org.eclipse.core.runtime.Status;
026: import org.geotools.renderer.shape.ShapefileRenderer;
027: import org.osgi.framework.BundleContext;
028:
029: /**
030: * Plugin class for BasicGridCoverage
031: * @author jones
032: * @since 0.6.0
033: */
034: public class RendererPlugin extends Plugin {
035:
036: private static RendererPlugin plugin;
037:
038: public static final String ID = "net.refractions.udig.render.feature.shapefile"; //$NON-NLS-1$
039:
040: /**
041: * Construct <code>RendererPlugin</code>.
042: *
043: */
044: public RendererPlugin() {
045: super ();
046: plugin = this ;
047:
048: }
049:
050: @Override
051: public void start(BundleContext context) throws Exception {
052: super .start(context);
053:
054: ClassLoader current = getClass().getClassLoader();
055: try {
056: Thread.currentThread().setContextClassLoader(
057: ShapefileRenderer.class.getClassLoader());
058: Logger logger = Logger
059: .getLogger("org.geotools.renderer.shape");//$NON-NLS-1$
060: if (!isDebugging("net.refractions.udig.render.feature.shapefile/finest")) { //$NON-NLS-1$
061: logger.setLevel(Level.SEVERE);
062: } else {
063: logger.setLevel(Level.FINEST);
064: }
065: } finally {
066: Thread.currentThread().setContextClassLoader(current);
067: }
068: }
069:
070: public static Plugin getDefault() {
071: return plugin;
072: }
073:
074: /**
075: * Writes an info log in the plugin's log.
076: * <p>
077: * This should be used for user level messages.
078: * </p>
079: * @param message Message to tell the user
080: * @param e Throwable assocaited with this message
081: */
082: public static void log(String message, Throwable e) {
083: getDefault().getLog().log(
084: new Status(IStatus.INFO, ID, 0, message, e));
085: }
086:
087: /**
088: * Messages that only engage if getDefault().isDebugging()
089: * <p>
090: * It is much prefered to do this:<pre><code>
091: * private static final String RENDERING = "net.refractions.udig.project/render/trace";
092: * if( ProjectUIPlugin.getDefault().isDebugging() && "true".equalsIgnoreCase( RENDERING ) ){
093: * System.out.println( "your message here" );
094: * }
095: * @param message Message to send to standard out
096: * @param e Throwable associated with this trace
097: */
098: public static void trace(String message, Throwable e) {
099: if (getDefault().isDebugging()) {
100: if (message != null)
101: System.out.println(message);
102: if (e != null)
103: e.printStackTrace();
104: }
105: }
106:
107: /**
108: * Performs the Platform.getDebugOption true check on the provided trace
109: * <p>
110: * Note: ProjectUIPlugin.getDefault().isDebugging() must also be on.
111: * <ul>
112: * <li>Trace.RENDER - trace rendering progress
113: * </ul>
114: * </p>
115: * @param trace currently only RENDER is defined
116: * @return true if -debug is used with a .options file to enable tracing
117: */
118: public static boolean isDebugging(final String trace) {
119: return getDefault().isDebugging()
120: && "true".equalsIgnoreCase(Platform.getDebugOption(trace)); //$NON-NLS-1$
121: }
122: }
|