magicplanetimagecomponent.java

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

JAVA
1,090
字号
    /**     * @return the object currently known as the MapBean by this object.     */    protected MapBean getMapBean() {        return mapBean;    }    /**     * Set the MapBean, become a PropertyChangeListener object to it to know     * when the background color on the MapBean changes. If there is already a     * MapBean known to this component, this component will remove itself as a     * listener to the previous MapBean.     *      * @param mb MapBean.     */    protected void setMapBean(MapBean mb) {        if (mapBean != null) {            mapBean.removePropertyChangeListener(this);        }        mapBean = mb;        if (mapBean != null) {            mapBean.addPropertyChangeListener(this);        }    }    public void setProperties(String prefix, Properties props) {        super.setProperties(prefix, props);        prefix = PropUtils.getScopedPropertyPrefix(prefix);        setOutputDirectoryString(props.getProperty(prefix                + OutputDirectoryProperty));        setAutoUpdate(PropUtils.booleanFromProperties(props, prefix                + AutoUpdateProperty, isAutoUpdate()));        setHeight(PropUtils.intFromProperties(props,                prefix + HeightProperty,                getHeight()));        setWidth(PropUtils.intFromProperties(props,                prefix + WidthProperty,                getWidth()));        setScale(PropUtils.floatFromProperties(props,                prefix + ScaleProperty,                scale));        setUpdateInterval(PropUtils.intFromProperties(props, prefix                + UpdateIntervalProperty, getUpdateInterval()));        setInitialDelay(PropUtils.intFromProperties(props, prefix                + InitialDelayProperty, getInitialDelay()));        setCleanup(PropUtils.booleanFromProperties(props, prefix                + CleanupProperty, isCleanup()));        setCleanupInterval(PropUtils.intFromProperties(props, prefix                + CleanupIntervalProperty, getCleanupInterval()));        setLastImageFile(props.getProperty(prefix + LastImageFileProperty,                getLastImageFile()));        setPostProcessingScript(props.getProperty(prefix                + PostProcessingScriptProperty, getPostProcessingScript()));    }    public Properties getProperties(Properties props) {        props = super.getProperties(props);        String prefix = PropUtils.getScopedPropertyPrefix(this);        props.put(prefix + OutputDirectoryProperty,                PropUtils.unnull(getOutputDirectoryString()));        props.put(prefix + AutoUpdateProperty, Boolean.toString(isAutoUpdate()));        props.put(prefix + HeightProperty, Integer.toString(getHeight()));        props.put(prefix + WidthProperty, Integer.toString(getWidth()));        props.put(prefix + ScaleProperty, Float.toString(getScale()));        props.put(prefix + UpdateIntervalProperty,                Integer.toString(getUpdateInterval()));        props.put(prefix + InitialDelayProperty,                Integer.toString(getInitialDelay()));        props.put(prefix + CleanupProperty, Boolean.toString(isCleanup()));        props.put(prefix + CleanupIntervalProperty,                Integer.toString(getCleanupInterval()));        props.put(prefix + LastImageFileProperty,                PropUtils.unnull(getLastImageFile()));        props.put(prefix + PostProcessingScriptProperty,                PropUtils.unnull(getPostProcessingScript()));        return props;    }    public Properties getPropertyInfo(Properties props) {        props = super.getPropertyInfo(props);        String interString;        // -------        interString = i18n.get(MagicPlanetImageComponent.class,                OutputDirectoryProperty,                I18n.TOOLTIP,                "Path to directory that holds created images.");        props.put(OutputDirectoryProperty, interString);        props.put(OutputDirectoryProperty + ScopedEditorProperty,                "com.bbn.openmap.util.propertyEditor.DirectoryPropertyEditor");        interString = i18n.get(MagicPlanetImageComponent.class,                OutputDirectoryProperty,                "Directory Path");        props.put(OutputDirectoryProperty + LabelEditorProperty, interString);        // -------        interString = i18n.get(MagicPlanetImageComponent.class,                AutoUpdateProperty,                I18n.TOOLTIP,                "Immediately create new images when the layers/background color changes.");        props.put(AutoUpdateProperty, interString);        props.put(AutoUpdateProperty + ScopedEditorProperty,                "com.bbn.openmap.util.propertyEditor.YesNoPropertyEditor");        interString = i18n.get(MagicPlanetImageComponent.class,                AutoUpdateProperty,                "Auto-Update");        props.put(AutoUpdateProperty + LabelEditorProperty, interString);        // -------        interString = i18n.get(MagicPlanetImageComponent.class,                HeightProperty,                I18n.TOOLTIP,                "Image pixel height (-1 defers to scale setting).");        props.put(HeightProperty, interString);        interString = i18n.get(MagicPlanetImageComponent.class,                HeightProperty,                "Image Height");        props.put(HeightProperty + LabelEditorProperty, interString);        // -------        interString = i18n.get(MagicPlanetImageComponent.class,                WidthProperty,                I18n.TOOLTIP,                "Image pixel width (-1 defers to scale setting).");        props.put(WidthProperty, interString);        interString = i18n.get(MagicPlanetImageComponent.class,                WidthProperty,                "Image Width");        props.put(WidthProperty + LabelEditorProperty, interString);        // -------        interString = i18n.get(MagicPlanetImageComponent.class,                ScaleProperty,                I18n.TOOLTIP,                "Scale to use for image projection (larger numbers make smaller maps).");        props.put(ScaleProperty, interString);        interString = i18n.get(MagicPlanetImageComponent.class,                ScaleProperty,                "Projection Scale");        props.put(ScaleProperty + LabelEditorProperty, interString);        // -------        interString = i18n.get(MagicPlanetImageComponent.class,                UpdateIntervalProperty,                I18n.TOOLTIP,                "Number of milliseconds until next image.");        props.put(UpdateIntervalProperty, interString);        interString = i18n.get(MagicPlanetImageComponent.class,                UpdateIntervalProperty,                "Update Interval");        props.put(UpdateIntervalProperty + LabelEditorProperty, interString);        // -------        interString = i18n.get(MagicPlanetImageComponent.class,                InitialDelayProperty,                I18n.TOOLTIP,                "Number of milliseconds until the first image is created.");        props.put(InitialDelayProperty, interString);        interString = i18n.get(MagicPlanetImageComponent.class,                InitialDelayProperty,                "Initial Delay");        props.put(InitialDelayProperty + LabelEditorProperty, interString);        // -------        interString = i18n.get(MagicPlanetImageComponent.class,                CleanupProperty,                I18n.TOOLTIP,                "Delete old images automatically.");        props.put(CleanupProperty, interString);        props.put(CleanupProperty + ScopedEditorProperty,                "com.bbn.openmap.util.propertyEditor.YesNoPropertyEditor");        interString = i18n.get(MagicPlanetImageComponent.class,                CleanupProperty,                "Delete Old Images");        props.put(CleanupProperty + LabelEditorProperty, interString);        // -------        interString = i18n.get(MagicPlanetImageComponent.class,                CleanupIntervalProperty,                I18n.TOOLTIP,                "Number of milliseconds to keep old images (86400000 is one day).");        props.put(CleanupIntervalProperty, interString);        interString = i18n.get(MagicPlanetImageComponent.class,                CleanupIntervalProperty,                "Cleanup Interval");        props.put(CleanupIntervalProperty + LabelEditorProperty, interString);        // -------        interString = i18n.get(MagicPlanetImageComponent.class,                LastImageFileProperty,                I18n.TOOLTIP,                "Path to file containing name of last image file created.");        props.put(LastImageFileProperty, interString);        interString = i18n.get(MagicPlanetImageComponent.class,                LastImageFileProperty,                "Last Image Name");        props.put(LastImageFileProperty + LabelEditorProperty, interString);        // -------        interString = i18n.get(MagicPlanetImageComponent.class,                PostProcessingScriptProperty,                I18n.TOOLTIP,                "Script to run on the image file after it's been created.");        props.put(PostProcessingScriptProperty, interString);        interString = i18n.get(MagicPlanetImageComponent.class,                PostProcessingScriptProperty,                "Post Processing Script");        props.put(PostProcessingScriptProperty + LabelEditorProperty,                interString);        props.put(initPropertiesProperty, OutputDirectoryProperty + " "                + ScaleProperty + " " + InitialDelayProperty + " "                + UpdateIntervalProperty + " " + AutoUpdateProperty + " "                + CleanupProperty + " " + CleanupIntervalProperty + " "                + HeightProperty + " " + WidthProperty + " "                + LastImageFileProperty + " " + PostProcessingScriptProperty);        return props;    }    /*     * (non-Javadoc)     *      * @see com.bbn.openmap.event.LayerListener#setLayers(com.bbn.openmap.event.LayerEvent)     */    public void setLayers(LayerEvent evt) {        if (evt.getType() == LayerEvent.REPLACE) {            setLayers(evt.getLayers());        }    }    /**     * Checks to see if there is a timer, and if the component wants to     * automatically update the current image. If the timer isn't running, it's     * started.     */    public void handleUpdate() {        Timer timer = getTimer();        if (timer != null && (isAutoUpdate() || !timer.isRunning())) {            timer.restart();        }        // Else do nothing, the timer is running and will pick up the        // changes.    }    /**     * Create a new image.     */    public void createImage() {        if (isCleanup()) {            cleanup(false);        }        String fileName = getFileNameForTime(System.currentTimeMillis());        String filePath = getOutputDirectoryString() + "/" + fileName;        if (DEBUG) {            Debug.output("MagicPlanetImageComponent: creating image: "                    + filePath);        }        Layer[] layers = getLayers();        if (layers == null) {            return;        }        ImageServer is = new ImageServer(layers, new SunJPEGFormatter());        try {            is.setBackground(getBackground());        } catch (NoSuchMethodError nsme) {            // Older version of OpenMap, going to just use what the            // MapBean has        }        byte[] imageBytes = is.createImage(getProj(), getWidth(), getHeight());        FileOutputStream fos;        try {            fos = new FileOutputStream(filePath);            fos.write(imageBytes);            fos.flush();            fos.close();            if (DEBUG) {                Debug.output("  MP: done writing image");            }        } catch (FileNotFoundException e) {            e.printStackTrace();        } catch (IOException e) {            e.printStackTrace();        }        mapBean.setProjection(mapBean.getProjection());        String launchCmd = generatePostProcessingCmd(postProcessingScript,                filePath);        if (launchCmd != null) {            try {                if (DEBUG)                    Debug.output("MP post processing: " + launchCmd);                Runtime.getRuntime().exec(launchCmd);            } catch (IOException e) {                System.err.println("MP post processing:  " + e);            }        }        if (lastImageFile != null) {            try {                File lastImageFileFile = new File(lastImageFile);                fos = new FileOutputStream(lastImageFileFile);                fos.write(new String(LAST_IMAGE_FILE_KEY + "=" + fileName).getBytes());                fos.flush();                fos.close();                if (DEBUG) {                    Debug.output("  MP: done writing file noting last image file name: "                            + lastImageFile);                }            } catch (IOException ioe) {                Debug.error("MP: error writing file to note last image file name:\n"                        + ioe.getMessage());                ioe.printStackTrace();                lastImageFile = null;            }        }    }    protected String generatePostProcessingCmd(String script, String filePath) {        String ret = null;        if (script != null && filePath != null) {            // nvdxt.exe -file Image.jpg -all -swap -dxt1c -output            // Image.dds            // nvdxt.exe -file %FILENAME% -all -swap -dxt1c -output            // %FILENAME_WITHOUT_EXTENSION%.dds            if (DEBUG) {                Debug.output(" Replacing script: |" + script + "|" + filePath);            }            ret = script.replaceAll(REPLACE_FILEPATH_MARKER, filePath);            ret = ret.replaceAll(REPLACE_FILENAME_MARKER,                    filePath.substring(filePath.lastIndexOf('/') + 1));            ret = ret.replaceAll(REPLACE_FILENAME_WOEXT_MARKER,                    filePath.substring(filePath.lastIndexOf('/') + 1,                            filePath.lastIndexOf('.')));            try {                if (Environment.get("os.name").startsWith("Windows")) {                    ret = ret.replace('/', '\\');                }            } catch (NullPointerException npe) {                // Applet, or Environment not set up.            }            if (DEBUG) {                Debug.output(" returning script: " + ret);            }        }        return ret;

⌨️ 快捷键说明

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