omgraphichandlerlayer.java

来自「OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你」· Java 代码 · 共 1,519 行 · 第 1/4 页

JAVA
1,519
字号
        super.setProperties(prefix, props);

        String realPrefix = PropUtils.getScopedPropertyPrefix(prefix);

        // Check to see if the layer wants to set its own projection
        // change policy.
        String pcpString = props.getProperty(realPrefix
                + ProjectionChangePolicyProperty);
        String policyPrefix;
        if (pcpString != null) {
            policyPrefix = realPrefix + pcpString;

            // If the projection change policy is null, try to create
            // it.
            if (projectionChangePolicy == null) {
                String pcpClass = props.getProperty(policyPrefix + ".class");
                if (pcpClass == null) {
                    Debug.error("Layer "
                            + getName()
                            + " has "
                            + policyPrefix
                            + " property defined in properties for PropertyChangePolicy, but "
                            + policyPrefix + ".class property is undefined.");
                } else {
                    Object obj = ComponentFactory.create(pcpClass,
                            policyPrefix,
                            props);
                    if (obj != null) {

                        if (Debug.debugging("layer")) {
                            Debug.output("Layer " + getName()
                                    + " setting ProjectionChangePolicy ["
                                    + obj.getClass().getName() + "]");
                        }

                        try {
                            setProjectionChangePolicy((ProjectionChangePolicy) obj);
                        } catch (ClassCastException cce) {
                            Debug.error("Layer "
                                    + getName()
                                    + " has "
                                    + policyPrefix
                                    + " property defined in properties for ProjectionChangePolicy, but "
                                    + policyPrefix
                                    + ".class property ("
                                    + pcpClass
                                    + ") does not define a valid ProjectionChangePolicy. A "
                                    + obj.getClass().getName()
                                    + " was created instead.");
                        }

                    } else {
                        Debug.error("Layer "
                                + getName()
                                + " has "
                                + policyPrefix
                                + " property defined in properties for PropertyChangePolicy, but "
                                + policyPrefix
                                + ".class property does not define a valid PropertyChangePolicy.");
                    }
                }

            } else { // ProjectionChangePolicy is not null...
                // If the projection change policy is not null and the
                // policy is a PropertyConsumer, pass the properties
                // to the policy. Note that the property prefix for
                // the policy is prefix +
                // ProjectionChangePolicyProperty

                if (projectionChangePolicy instanceof PropertyConsumer) {
                    ((PropertyConsumer) projectionChangePolicy).setProperties(policyPrefix,
                            props);
                }
            }

        } else if (Debug.debugging("layer")) {
            Debug.output("Layer " + getName()
                    + " using default ProjectionChangePolicy ["
                    + getProjectionChangePolicy().getClass().getName() + "]");
        }

        // Check to see if the layer want to set its own rendering
        // policy.
        String rpString = props.getProperty(realPrefix + RenderPolicyProperty);
        if (rpString != null) {
            policyPrefix = realPrefix + rpString;
            if (renderPolicy == null) {
                String rpClass = props.getProperty(policyPrefix + ".class");
                if (rpClass == null) {
                    Debug.error("Layer "
                            + getName()
                            + " has "
                            + policyPrefix
                            + " property defined in properties for RenderPolicy, but "
                            + policyPrefix + ".class property is undefined.");
                } else {

                    Object rpObj = ComponentFactory.create(rpClass,
                            policyPrefix,
                            props);

                    if (rpObj != null) {
                        if (Debug.debugging("layer")) {
                            Debug.output("Layer " + getName()
                                    + " setting RenderPolicy ["
                                    + rpObj.getClass().getName() + "]");
                        }

                        try {
                            setRenderPolicy((RenderPolicy) rpObj);
                        } catch (ClassCastException cce) {
                            Debug.error("Layer "
                                    + getName()
                                    + " has "
                                    + policyPrefix
                                    + " property defined in properties for RenderPolicy, but "
                                    + policyPrefix
                                    + ".class property ("
                                    + rpClass
                                    + ") does not define a valid RenderPolicy. A "
                                    + rpObj.getClass().getName()
                                    + " was created instead.");
                        }
                    } else {
                        Debug.error("Layer "
                                + getName()
                                + " has "
                                + policyPrefix
                                + " property defined in properties for RenderPolicy, but "
                                + policyPrefix + ".class property (" + rpClass
                                + ") isn't being created.");
                    }
                }
            } else { // RenderPolicy is not null...
                // Same thing with renderPolicy as with projection
                // change policy.
                if (renderPolicy instanceof PropertyConsumer) {
                    ((PropertyConsumer) renderPolicy).setProperties(policyPrefix,
                            props);
                }
            }

        } else if (Debug.debugging("layer")) {
            Debug.output("Layer " + getName() + " using default RenderPolicy ["
                    + getRenderPolicy().getClass().getName() + "]");
        }

        String mmString = props.getProperty(realPrefix + MouseModesProperty);
        if (mmString != null) {
            Vector mmv = PropUtils.parseSpacedMarkers(mmString);
            if (mmv.size() > 0) {
                String[] mm = new String[mmv.size()];
                Iterator it = mmv.iterator();
                int i = 0;
                while (it.hasNext()) {
                    mm[i++] = (String) it.next();
                }
                setMouseModeIDsForEvents(mm);
            }
        }

        consumeEvents = PropUtils.booleanFromProperties(props, realPrefix
                + ConsumeEventsProperty, consumeEvents);

        setTransparency(PropUtils.floatFromProperties(props, realPrefix
                + TransparencyProperty, getTransparency()));

        setInterruptable(PropUtils.booleanFromProperties(props, realPrefix
                + InterruptableProperty, isInterruptable()));
    }

    /**
     * Overrides Layer getProperties method., also calls that method on Layer.
     * Sets the properties from the policy objects used by this OMGraphicHandler
     * layer.
     */
    public Properties getProperties(Properties props) {
        props = super.getProperties(props);

        String prefix = PropUtils.getScopedPropertyPrefix(this);
        String policyPrefix = null;

        // //// ProjectionChangePolicy

        ProjectionChangePolicy pcp = getProjectionChangePolicy();
        if (pcp instanceof PropertyConsumer) {
            policyPrefix = ((PropertyConsumer) pcp).getPropertyPrefix();
            ((PropertyConsumer) pcp).getProperties(props);
        }

        if (policyPrefix == null) {
            policyPrefix = prefix + "pcp";
        }

        // Whoops, need to make sure pcp is valid but removing the
        // OMGHL prefix from the front of the policy prefix (if
        // applicable). Same for RenderPolicy

        props.put(prefix + ProjectionChangePolicyProperty,
                policyPrefix.substring(prefix.length()));
        // This has to come after the above line, or the above
        // property will have a trailing period.
        policyPrefix = PropUtils.getScopedPropertyPrefix(policyPrefix);
        props.put(policyPrefix + "class", pcp.getClass().getName());

        RenderPolicy rp = getRenderPolicy();
        if (rp instanceof PropertyConsumer) {
            policyPrefix = ((PropertyConsumer) rp).getPropertyPrefix();
            ((PropertyConsumer) rp).getProperties(props);
        }

        // /// RenderPolicy

        if (policyPrefix == null) {
            policyPrefix = prefix + "rp";
        }

        props.put(prefix + RenderPolicyProperty,
                policyPrefix.substring(prefix.length()));
        // This has to come after the above line, or the above
        // property will have a trailing period.
        policyPrefix = PropUtils.getScopedPropertyPrefix(policyPrefix);
        props.put(policyPrefix + "class", rp.getClass().getName());

        props.put(prefix + ConsumeEventsProperty,
                new Boolean(consumeEvents).toString());

        String[] mm = getMouseModeIDsForEvents();
        if (mm != null && mm.length > 0) {
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < mm.length; i++) {
                // Don't need any MouseModes that have been scoped to
                // the pretty name, those are automatically generated.
                if (mm[i].equals(getName())) {
                    continue;
                }
                sb.append(mm[i] + " ");
            }
            props.put(prefix + MouseModesProperty, sb.toString());
        }

        props.put(prefix + TransparencyProperty,
                Float.toString(getTransparency()));

        props.put(prefix + InterruptableProperty,
                Boolean.toString(isInterruptable()));

        return props;
    }

    /**
     * Overrides Layer getProperties method., also calls that method on Layer.
     * Sets the properties from the policy objects used by this OMGraphicHandler
     * layer.
     */
    public Properties getPropertyInfo(Properties list) {
        list = super.getPropertyInfo(list);

        String policyPrefix = null;

        ProjectionChangePolicy pcp = getProjectionChangePolicy();
        if (pcp instanceof PropertyConsumer) {
            policyPrefix = ((PropertyConsumer) pcp).getPropertyPrefix();
            if (policyPrefix != null) {
                int index = policyPrefix.indexOf(".");
                if (index != -1) {
                    policyPrefix = policyPrefix.substring(index + 1);
                }

                ((PropertyConsumer) pcp).getPropertyInfo(list);
            }
        }

        if (policyPrefix == null) {
            policyPrefix = "pcp";
        }

        PropUtils.setI18NPropertyInfo(i18n,
                list,
                OMGraphicHandlerLayer.class,
                policyPrefix + ".class",
                "Projection Change Policy",
                "Class name of ProjectionChangePolicy (optional)",
                null);

        RenderPolicy rp = getRenderPolicy();
        if (rp instanceof PropertyConsumer) {
            policyPrefix = ((PropertyConsumer) rp).getPropertyPrefix();

            if (policyPrefix != null) {
                int index = policyPrefix.indexOf(".");
                if (index != -1) {
                    policyPrefix = policyPrefix.substring(index + 1);
                }
            }

            ((PropertyConsumer) rp).getPropertyInfo(list);
        } else {
        }

        if (policyPrefix == null) {
            policyPrefix = "rp";
        }

        PropUtils.setI18NPropertyInfo(i18n,
                list,
                OMGraphicHandlerLayer.class,
                policyPrefix + ".class",
                "Rendering Policy",
                "Class name of RenderPolicy (optional)",
                null);

        PropUtils.setI18NPropertyInfo(i18n,
                list,
                OMGraphicHandlerLayer.class,
                ConsumeEventsProperty,
                "Consume mouse events",
                "Flag that tells the layer to consume mouse events, or let other layers use them as well.",
                "com.bbn.openmap.util.propertyEditor.OnOffPropertyEditor");

        PropUtils.setI18NPropertyInfo(i18n,
                list,
                OMGraphicHandlerLayer.class,
                MouseModesProperty,
                "Mouse modes",
                "Space-separated list of MouseMode IDs to receive events from.",
                null);

        PropUtils.setI18NPropertyInfo(i18n,
                list,
                OMGraphicHandlerLayer.class,
                TransparencyProperty,
                "Transparency",
                "Transparency setting for layer, between 0 (clear) and 1",
                null);

        PropUtils.setI18NPropertyInfo(i18n,
                list,
                OMGraphicHandlerLayer.class,
                InterruptableProperty,
                "Interruptable",
                "Flat to set whether the layer should immediately stop performing current work when the projection changes.",
                "com.bbn.openmap.util.propertyEditor.YesNoPropertyEditor");

        return list;
    }

    /**
     * The MapMouseInterpreter used to catch the MapMouseEvents and direct them
     * to layer as referencing certain OMGraphics. Mananges how the layer
     * responds to mouse events.
     */
    protected MapMouseInterpreter mouseEventInterpreter = null;

    /**
     * Set the interpreter used to field and interpret MouseEvents, thereby
     * calling GestureResponsePolicy methods on this layer.
     */
    public synchronized void setMouseEventInterpreter(MapMouseInterpreter mmi) {

        if (mmi instanceof StandardMapMouseInterpreter) {
            String[] modeList = getMouseModeIDsForEvents();
            ((StandardMapMouseInterpreter) mmi).setMouseModeServiceList(modeList);
            ((StandardMapMouseInterpreter) mmi).setConsumeEvents(getConsumeEvents());
        }

        if (mouseEventInterpreter != null) {
            // Remove handle
            mouseEventInterpreter.setGRP(null);
        }

        mmi.setGRP(this);
        mouseEventInterpreter = mmi;
    }

    /**
     * Get the interpreter used to field and interpret MouseEvents, thereby
     * calling GestureResponsePolicy methods on this layer. This method checks
     * to see if any mouse modes ids have been set via the
     * getMouseModeIDsForEvents() method, and if there were and the interpreter

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?