001: /* uDig - User Friendly Desktop Internet GIS client
002: * http://udig.refractions.net
003: * (C) 2004, Refractions Research Inc.
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation;
008: * version 2.1 of the License.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: */
015: package net.refractions.udig.printing.ui.internal;
016:
017: import net.refractions.udig.printing.model.BoxPrinter;
018:
019: import org.eclipse.core.runtime.CoreException;
020: import org.eclipse.core.runtime.IConfigurationElement;
021: import org.eclipse.jface.resource.ImageDescriptor;
022: import org.eclipse.ui.plugin.AbstractUIPlugin;
023:
024: /**
025: * A utility class for processing Box extensions. Provides a convenient way of accessing
026: * the data in a particular box configuration element.
027: *
028: * @author Jesse
029: * @since 1.1.0
030: */
031: public class BoxFactory {
032:
033: private IConfigurationElement configurationElement;
034: private boolean visible;
035: private String description;
036: private ImageDescriptor smallImage;
037: private ImageDescriptor largeImage;
038: private String name;
039: private Class<? extends BoxPrinter> type;
040: private boolean attempted = false;
041:
042: public BoxFactory(IConfigurationElement element) {
043: this .configurationElement = element;
044: this .visible = "true".equals(element.getAttribute("visible")); //$NON-NLS-1$//$NON-NLS-2$
045: this .description = element.getAttribute("description"); //$NON-NLS-1$
046: this .smallImage = (createDescriptor(element, element
047: .getAttribute("smallImage"))); //$NON-NLS-1$
048: this .largeImage = (createDescriptor(element, element
049: .getAttribute("largeImage"))); //$NON-NLS-1$
050: this .name = element.getAttribute("name"); //$NON-NLS-1$
051: }
052:
053: private ImageDescriptor createDescriptor(
054: IConfigurationElement element, String imagePath) {
055: if (imagePath == null)
056: return null;
057:
058: String pluginID = element.getNamespace();
059:
060: ImageDescriptor imageDescriptor = AbstractUIPlugin
061: .imageDescriptorFromPlugin(pluginID, imagePath);
062: return imageDescriptor;
063: }
064:
065: public boolean isVisible() {
066: return visible;
067: }
068:
069: public synchronized BoxPrinter createBox() throws CoreException {
070: BoxPrinter box = (BoxPrinter) configurationElement
071: .createExecutableExtension("class");//$NON-NLS-1$
072: this .type = box.getClass();
073: return box;
074: }
075:
076: public synchronized Class<? extends BoxPrinter> getType() {
077: // return null;
078: if (type == null && !attempted) {
079: attempted = true;
080: try {
081: createBox();
082: } catch (CoreException e) {
083: PrintingPlugin.log("", e); //$NON-NLS-1$
084: }
085: }
086: return type;
087: }
088:
089: public String getName() {
090: return name;
091: }
092:
093: public String getDescription() {
094: return description;
095: }
096:
097: public ImageDescriptor getSmallImage() {
098: return smallImage;
099: }
100:
101: public ImageDescriptor getLargeImage() {
102: return largeImage;
103: }
104:
105: }
|