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

📄 shapepanel.java

📁 基于MPEG 7 标准,符合未来语义网架构,很值得参考
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * This file is part of Caliph & Emir.
 *
 * Caliph & Emir is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Caliph & Emir is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Caliph & Emir; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Copyright statement:
 * --------------------
 * (c) 2002-2005 by Mathias Lux (mathias@juggle.at)
 * http://www.juggle.at, http://caliph-emir.sourceforge.net
 */
package at.lux.fotoannotation.panels;

import at.lux.fotoannotation.AnnotationFrame;
import at.wklieber.Settings;
import at.wklieber.gui.*;
import at.wklieber.gui.data.DataInterface;
import at.wklieber.gui.data.DescriptionData;
import at.wklieber.gui.data.IComponentData;
import at.wklieber.mpeg7.*;
import at.wklieber.tools.FileTools;
import at.wklieber.tools.Mpeg7DateFormat;
import org.apache.log4j.Logger;
import org.jdom.Document;
import org.jdom.Element;

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Date: 16.03.2005
 * Time: 22:09:05
 *
 * @author Werner Klieber, werner@klieber.info
 */
public class ShapePanel extends JPanel implements AnnotationPanel {
    static Logger log = Logger.getLogger(ShapePanel.class);

    private AnnotationFrame parent;

    private ObjectPalette palette;
    private IDrawPanel drawPanel;
    private JPanel buttonPanel;
    private Container toolbar;
    private DrawSketchFrame frame;

    /**
     * Creates a new <code>ShapePanel</code> with a double buffer
     * and a flow layout.
     */
    public ShapePanel(AnnotationFrame parent) {
        init(parent);
    }

    private void init(AnnotationFrame parent) {
        this.parent = parent;

        JPanel palettePanel = new JPanel();
        palettePanel.setLayout(new BorderLayout());
        palettePanel.setSize(300, 300);
        palettePanel.setMinimumSize(new Dimension(300, 300));

        palettePanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Color palette"));

        ///JLabel test = new JLabel("palleten panel");
        //palettePanel.add(test, BorderLayout.NORTH);

        //System.out.println("PAl: " + palettePanel.getSize());
        palette = new ObjectPalette(palettePanel);
        palettePanel.validate();
        palettePanel.repaint();

        // initialize all member-menu Panels
        //drawPanel = new IDrawPanel(this);
        drawPanel = new IDrawPanel();
        drawPanel.setMathMode(true);
        buttonPanel = new JPanel();

        //------------------------ define the Drawpanel ---------------------------
        toolbar = new Container();
        LayoutManager mgr = new FlowLayout(FlowLayout.LEFT);
        toolbar.setLayout(mgr);
        //JToolBar tool = new JToolBar("test");
        //toolbar.add(tool);
        //tool.add(new JLabel("test"));
        //tool.add(new JButton("ui"));


        //get the image
        AnnotationFrame parentFrame = parent;
        List iComponentList = new ArrayList();
        frame = new DrawSketchFrame(parentFrame, toolbar, iComponentList);


        //link all panels together
        this.setLayout(new BorderLayout());
        Container pane = new Container();
        pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
        //JButton spacer = new JButton("this is a placeholder");
        //spacer.setMinimumSize(new Dimension(100, 2));
        JPanel spacer = new JPanel(null, true);
        spacer.setMinimumSize(new Dimension(100,3));
        spacer.setMaximumSize(new Dimension(100,3));
        spacer.setPreferredSize(new Dimension(100,3));

        pane.add(palettePanel);
        pane.add(spacer);
        //pane.add(toolbar);


        this.add(toolbar, BorderLayout.NORTH);
        this.add(frame, BorderLayout.CENTER);
        this.add(pane,BorderLayout.WEST);
        //this.add(palettePanel, BorderLayout.WEST);

        this.revalidate();
        this.validate();
        //spacer.setVisible(false);
    }


    /**
     * Is called if the user selects another image to annotate.
     *
     * @param shapeDescriptor can be null if no descriptor exists.
     */
    public void setDescriptor(Element shapeDescriptor) {
        BufferedImage img = parent.getImage();
        frame.setImage(img);

        if (shapeDescriptor!=null) {
            // in this specific case the whole document is returned to the panel:
            // a template is created and the shapes are read.
            Mpeg7 mpeg7 = new Mpeg7();
            mpeg7.createTemplateDocument();
            Document doc1 = new Document(((Element) ((Element) shapeDescriptor.clone()).detach()));
            mpeg7.setDocument(doc1);
            // all necessary shape descriptors are extracted from a
            // fully featured MPEG-7 file ...
            List xmlData = extractMpeg7Data(mpeg7);
            List<DataInterface> guiData = new ArrayList<DataInterface>();
            for (int i = 0; i < xmlData.size(); i++) {
                Object ds = xmlData.get(i);
                if (DescriptionMetadataDs.class.isInstance(ds)) {
                    DescriptionMetadataDs mds = (DescriptionMetadataDs) ds;

                    DescriptionData data = new DescriptionData();
                    data.setDescription(mds.getCreationDescription());
                    data.setCreatorFirstName(mds.getCreatorGivenName());
                    data.setCreatorLastName(mds.getCreatorFamilyName());
                    data.setCreationPlace(mds.getCreationPlace());
                    data.setCreationTime(Mpeg7DateFormat.format(mds.getCreationTime(), null));
                    data.setCreationTool(mds.getCreationTool());

                    log.debug("-> DATA: " + data.toString());
                    log.debug("-> DS: " + mds.toString());

                    guiData.add(data);
                } else /*if (CameraMotionDs.class.isInstance(ds)) {
                    CameraMotionDs mds = (CameraMotionDs) ds;
                    CameraMotionData data = new CameraMotionData();

                    data.setMotionName(mds.getMotionName());
                    data.setAmountOfmotion(mds.getMotionAmount());
                    data.setDuration(mds.getDuration());
                    data.setMotionsegmentType("MIXED");
                    data.setTimePoint(Mpeg7DateFormat.format(mds.getTimePoint(), new Date(0)));

                    returnValue.add(data);
                    cat.debug("-> DATA: " + data.toString());
                    cat.debug("-> DS: " + mds.toString());
                } else*/ if (StillRegionDs.class.isInstance(ds)) {
                    StillRegionDs mds = (StillRegionDs) ds;

                    // if data contains box and dominant color, then extract color and position
                    Rectangle box = mds.getBox();
                    if ((box != null) && (box.getWidth() != 0) && (box.getHeight() != 0)) {
                        IComponentData data = new IComponentData(new IColorRectangle());
                        data.setBoundary(box);
                        Color[] cArray = mds.getColors();
                        if (cArray != null && cArray.length > 0) {
                            data.setForeGround(cArray[0]);
                        }

                        guiData.add(data);
                        log.debug("-> DATA: " + data.toString());
                        log.debug("-> DS: " + mds.toString());
                    } else { // now check if it has a shape. Then extract the shape data
                        IComponentData data = new IComponentData(new IShape());
                        List pointList = mds.getShape();

                        data.setDotList(pointList);
                        Color[] cArray = mds.getColors();
                        if (cArray != null && cArray.length > 0) {
                            data.setFillColor(cArray[0]);
                        }

                        guiData.add(data);
                        log.debug("-> DATA: " + data.toString());
                        log.debug("-> DS: " + mds.toString());


                    }
                } /*else if (SemanticDs.class.isInstance(ds)) {
                    SemanticDs mds = (SemanticDs) ds;
                    SemanticMpeg7Data data = new SemanticMpeg7Data();

                    data.setSemanticDs(mds.getDocument(new Document(new Element(Mpeg7Template.getRootTag()))));

⌨️ 快捷键说明

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