Package de.FeatureModellingTool.InfoExplorer

Source Code of de.FeatureModellingTool.InfoExplorer.Manager

package de.FeatureModellingTool.InfoExplorer;

import component.FComponent;
import manager.ManagerInterface;
import manager.IllegalParameterException;

import javax.swing.*;
import java.util.Hashtable;
import java.awt.dnd.DragGestureListener;

import context.Context;

/**
* Created by IntelliJ IDEA.
* User: saturn
* Date: 2003-8-30
* Time: 15:30:20
* To change this template use Options | File Templates.
*/
public class Manager implements ManagerInterface {

    public static ManagerInterface getInstance() {
        return new Manager();
    }

    public static InfoExplorer createInfoExplorer() {
        return new InfoExplorerImplementation();
    }

    public static InfoExplorerUI getInfoExplorerUI(InfoExplorer infoExplorer) {
        if (infoExplorer instanceof InfoExplorerImplementation) {
            return (InfoExplorerUI) infoExplorer;
        }

        return null;
    }

    public static DragGestureListener getDragGestureListener(InfoExplorer infoExplorer) {
        if (infoExplorer instanceof InfoExplorerImplementation) {
            return ((InfoExplorerImplementation) infoExplorer).getDragGestureListener();
        }

        return null;
    }

    public final static String INFOEXPLORER_NAME = "InfoExplorer";

    public final static String INFOEXPLORER_INTERFACE = "InfoExplorer";
    public final static String JCOMPONENT_INTERFACE = "JComponent";
    public final static String DRAGGESTURELISTENER_INTERFACE = "DragGestureListener";

    protected Context cont = null;

    protected Manager() {
        if (cont == null) {
            try {
                cont = (Context) context.Manager.getInstance().getInstance(context.Manager.CONTEXT, Context.class);
            } catch (IllegalParameterException ipe) {
                //nerver arrive here
            }
        }
    }


    public Context getContext() {
        return cont;
    }

    public Object getInstance(String name, Class type) throws java.lang.IllegalArgumentException {

        if ((!INFOEXPLORER_NAME.equals(name)) || (!type.equals(FComponent.class)))
            throw new java.lang.IllegalArgumentException("IllegalArgument");

        InfoExplorer infoExplorer = createInfoExplorer();
        JComponent infoExplorerUI = getInfoExplorerUI(infoExplorer).getExplorerComponent();
        DragGestureListener dragGestureListener = getDragGestureListener(infoExplorer);

        Hashtable interfaces = new Hashtable();
        Hashtable classes = new Hashtable();

        interfaces.put(INFOEXPLORER_INTERFACE, infoExplorer);
        interfaces.put(JCOMPONENT_INTERFACE, infoExplorerUI);
        interfaces.put(DRAGGESTURELISTENER_INTERFACE, dragGestureListener);

        classes.put(INFOEXPLORER_INTERFACE, InfoExplorer.class);
        classes.put(JCOMPONENT_INTERFACE, JComponent.class);
        classes.put(DRAGGESTURELISTENER_INTERFACE, DragGestureListener.class);

        ManagerInterface mi = component.Manager.getInstance();

        mi.getContext().putValue(component.Manager.INTERFACES, interfaces);
        mi.getContext().putValue(component.Manager.CLASSES, classes);
        mi.getContext().putValue(component.Manager.NAME, INFOEXPLORER_NAME);

        try {
            return (FComponent) mi.getInstance(component.Manager.NGOBJECT, FComponent.class);
        }
        catch(IllegalParameterException ipe){
            return null;
        }
    }
}
TOP

Related Classes of de.FeatureModellingTool.InfoExplorer.Manager

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.