⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shapepanel.java

📁 基于MPEG 7 标准,符合未来语义网架构,很值得参考
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

                    returnValue.add(data);
                    cat.debug("-> DATA: " + data.toString());
                    cat.debug("-> DS: " + mds.toString());
                }*/ else {
                    log.error("Unknown MPEG7 Descriptor: \"" + ds.getClass().getName() + "\"");
                }
            } // end for

            List<IComponentData> componentList = new ArrayList<IComponentData>();
            for (int i = 0; i < guiData.size(); i++) {
                DataInterface dataInterface = guiData.get(i);
                if (dataInterface instanceof IComponentData) {
                    componentList.add((IComponentData) dataInterface);
                }
            }

            frame.setIComponents(componentList);
        }


        frame.revalidate();
        frame.repaint();
        repaint();
    }

    /**
     * Creates the MPEG-7 descriptor from the annotation
     * and returns it as JDOM Element
     *
     * @return the descriptor as JDOM Element or NULL on error
     */
    public Element createXML() {
        Element returnValue = null;

        List<IComponentData> components = frame.getDataList();
        Mpeg7 mpeg7 = generateMpeg7FromData(components);
        returnValue = mpeg7.getDocument((Element) null);
        // TODO: This save to file thing should vanish here ...
        String mpegString = mpeg7.getDocument("");
        FileTools.saveToFile("c:/test.xml", mpegString);
        /*System.out.println("==================================================");
        System.out.println(mpegString);
        System.out.println("==================================================");*/

        return returnValue;
    }

    /**
     * generate a mpeg7 document filled with data from the input-data list  (DataInterface)
     */
    private Mpeg7 generateMpeg7FromData(List<IComponentData> dataList1) {
        Mpeg7 returnValue = new Mpeg7();
        returnValue.createTemplateDocument();

        if (dataList1 == null) {
            return returnValue;
        }

        /*cat.debug("List contains: " + dataList1.size() + ", MPEG null: "
                + (returnValue.getDocument((Document) null) == null));*/

        Iterator it = dataList1.iterator();
        SpatialDecomposition spatialDecompWrapper = null;
        while (it.hasNext()) {
            //cat.debug("XX: " + it.next().getClass().getName());
            DataInterface dataObject = (DataInterface) it.next();
            if (dataObject == null) {
                continue;
            }

            if (dataObject.getId() == DataInterface.DESCRIPTION_DATA) {
                DescriptionData dsData = (DescriptionData) dataObject;
                //cat.debug("load a DescriptionDS, " + dsData.toString());
                DescriptionMetadataDs ds = new DescriptionMetadataDs();
                ds.createTemplateDocument();

                //cat.debug("MPEG null: " + (returnValue.getDocument((Document) null) == null));

                ds.setData(dsData.getDescription(),
                        dsData.getCreatorFirstName(), dsData.getCreatorLastName(),
                        dsData.getCreationTime(), dsData.getCreationPlace(), dsData.getCreationTool());
                returnValue.addDescriptor(ds);
                //--------------------------------------------------------------------------
                /*} else if (dataObject.getId() == DataInterface.CAMERA_MOTION_DATA) {
                    CameraMotionData dsData = (CameraMotionData) dataObject;
                    //cat.debug("process a Camera Motion DS, " + dsData.toString());
                    CameraMotionDs ds = new CameraMotionDs();
                    ds.createTemplateDocument();

                    //cat.debug("MPEG null: " + (returnValue.getDocument((Document) null) == null));

                    ds.setData(Mpeg7DateFormat.date2Timepoint(dsData.getTimePoint()), dsData.getDuration(),
                            dsData.getMotionName(), dsData.getAmountOfmotion());
                    returnValue.addDescriptor(ds);*/
                //--------------------------------------------------------------------------
            } else if (dataObject.getId() == DataInterface.ICOMPONENT_DATA) {
                IComponentData dsData = (IComponentData) dataObject;
                if (dsData.getComponentName().equalsIgnoreCase(IColorRectangle.class.getName())) {
                    //IColorRectangle colorRectangle = dsData.

                    //log.debug("process a ColorRectangle, " + dsData.toString());

                    // save the position
                    SpatialLocatorDs spatialLocator = new SpatialLocatorDs(SpatialLocatorDs.TYPE_BOX);
                    spatialLocator.createTemplateDocument();
                    spatialLocator.setData(dsData.getBoundary());
                    //log.debug(spatialLocator.toString());


                    // save the color
                    DominantColorDs dominantColor = new DominantColorDs();
                    dominantColor.createTemplateDocument();
                    dominantColor.setData(dsData.getForeGround());

                    // The stillregion holts region and color
                    StillRegionDs regionDs = new StillRegionDs();
                    regionDs.createTemplateDocument();

                    regionDs.setData(spatialLocator, dominantColor);

                    // the spatial wrapper that gets all the data regionData
                    if (spatialDecompWrapper == null) {
                        spatialDecompWrapper = new SpatialDecomposition();
                        spatialDecompWrapper.createTemplateDocument();
                    }

                    spatialDecompWrapper.addData(regionDs);
                } else if (dsData.getComponentName().equalsIgnoreCase(IShape.class.getName())) {

                    //log.debug("process a Shape, " + dsData.toString());

                    // save the Shape position
                    SpatialLocatorDs spatialLocator = new SpatialLocatorDs(SpatialLocatorDs.TYPE_SHAPE);
                    spatialLocator.createTemplateDocument();
                    spatialLocator.setData(dsData.getDotList());
                    //log.debug(spatialLocator.toString());

                    // save the color
                    DominantColorDs dominantColor = new DominantColorDs();
                    dominantColor.createTemplateDocument();
                    dominantColor.setData(dsData.getFillColor());


                    // The stillregion holts region and color
                    StillRegionDs regionDs = new StillRegionDs();
                    regionDs.createTemplateDocument();

                    regionDs.setData(spatialLocator, dominantColor);

                    // the spatial wrapper that gets all the data regionData
                    if (spatialDecompWrapper == null) {
                        spatialDecompWrapper = new SpatialDecomposition();
                        spatialDecompWrapper.createTemplateDocument();
                    }

                    spatialDecompWrapper.addData(regionDs);
                } else
                    log.error("Not implemented: can not create MPEG 7 for <" + dsData.getComponentName() + ">");
            } else
                log.error("Not implemented: can not save Data with id <" + dataObject.getId() + ">");
        } // end while

        // add the wrapper with all StillRegionDs desrcipions
        if (spatialDecompWrapper != null) {
            returnValue.addDescriptor(spatialDecompWrapper);
        }

        log.debug("MPEG7: " + returnValue.toString());
        //System.out.println("XXXMPEG7: " + returnValue.toString());

        returnValue.writeToFile("C:/mpeg7/" + Settings.DEFAULT_MPEG7_NAME);
        log.debug("MPEG 7 Creation done");
        return returnValue;
    } // end method

    /**
     * extract data from a mpeg7 document and filles data list with all extracted Descriptors.
     * This dat can be used in the userinterface to display the content
     */
    private List extractMpeg7Data(Mpeg7 mpeg7Document1) {
        List returnValue = new ArrayList<IComponentData>();

        if (mpeg7Document1 == null) {
            return returnValue;
        }

        // pass the file to all Mpeg 7 descriptor classes and let them extract their data
        // extract description Metadata
        List<IComponentData> descriptionList = new DescriptionMetadataDs().extractFromMpeg7(mpeg7Document1.getDocument((Document) null));
        log.debug("Extraction Info: " + descriptionList.size() + " DescriptionMetadata extracted");
        returnValue.addAll(descriptionList);

        //extract CameraMotion
        descriptionList = new CameraMotionDs().extractFromMpeg7(mpeg7Document1.getDocument((Document) null));
        log.debug("Extraction Info: " + descriptionList.size() + " Camera Motion data extracted");
        returnValue.addAll(descriptionList);

        /*System.out.println("---------------------------------------------------");
        System.out.println("MPEG: " + mpeg7Document1.toString());
        System.out.println("---------------------------------------------------");*/
        //extract Dominant color and positon
        descriptionList = new StillRegionDs().extractFromMpeg7(mpeg7Document1.getDocument((Document) null));
        log.debug("Extraction Info: " + descriptionList.size() + " Color+Position data extracted");
        returnValue.addAll(descriptionList);

        //extract Semantic descriptor
        /*descriptionList = new SemanticDs().extractFromMpeg7(mpeg7Document1.getDocument((Document) null));
        log.debug("Extraction Info: " + descriptionList.size() + " Semantic data extracted");
        returnValue.addAll(descriptionList);*/


        log.debug("Data extraction from MPEG 7 file done: " + returnValue.toString());
        return returnValue;
    } // end method


    public void setImage(BufferedImage image) {
        BufferedImage img = image;
        frame.setImage(img);
    }
}

⌨️ 快捷键说明

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