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

📄 beepanel.java

📁 图像检索的代码b
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            remRelation.setEnabled(false);
        menu.show(this, x, y);
    }

    private void remObject(Point p) {
        Object toremove = null;
        for (Iterator iterator = objects.iterator(); iterator.hasNext();) {
            SemanticObjectRepresentation sem = (SemanticObjectRepresentation) iterator.next();
            if (sem.checkIfInside(p)) {
                toremove = sem;
            }
        }
        if (toremove != null) {
            Vector rem = new Vector();
            for (Iterator iterator = relations.iterator(); iterator.hasNext();) {
                SemanticRelationRepresentation rel = (SemanticRelationRepresentation) iterator.next();
                if (rel.getSource().equals(toremove) || rel.getTarget().equals(toremove)) {
                    rem.add(rel);
                }
            }
            objects.remove(toremove);
            for (Iterator iterator = rem.iterator(); iterator.hasNext();) {
                relations.remove(iterator.next());
            }
            TextChangesListener.getInstance().fireDataChanged();
        }
    }

    private void remRelation(Point p) {

        if (highlightedRelation != null) {
            relations.remove(highlightedRelation);
            TextChangesListener.getInstance().fireDataChanged();
        }
    }

    private void addRelation(SemanticObjectRepresentation src, SemanticObjectRepresentation target) {
        Object label = JOptionPane.showInputDialog(this, "Please specify relation:", "Add semantic relation",
                JOptionPane.PLAIN_MESSAGE, null, parent.getRelations(), parent.getRelations()[0]);
        if (label != null) {
            relations.add(new SemanticRelationRepresentation(src, target, label.toString()));
            TextChangesListener.getInstance().fireDataChanged();
            embedElements();
        }
    }

    private void addRelation(SemanticObjectRepresentation src, SemanticObjectRepresentation target, String label) {
        relations.add(new SemanticRelationRepresentation(src, target, label));
        TextChangesListener.getInstance().fireDataChanged();
        embedElements();
    }

    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals("addObject")) {
            addObject(clickedAt);
        } else if (e.getActionCommand().equals("remObject")) {
            remObject(clickedAt);
        } else if (e.getActionCommand().equals("remMarked")) {
            removeMarkedElements();
        } else if (e.getActionCommand().equals("remRelation")) {
            remRelation(clickedAt);
        } else if (e.getActionCommand().equals("cascade")) {
            cascadeElements();
        } else if (e.getActionCommand().equals("about")) {
            showAbout();
        } else if (e.getActionCommand().equals("distribute")) {
            distributeElements();
        } else if (e.getActionCommand().equals("embed")) {
            embedElements();
        } else if (e.getActionCommand().equals("import")) {
            importFile();
        } else if (e.getActionCommand().startsWith("addVenue-")) {
//            System.out.println(e.getActionCommand());
            String label = e.getActionCommand().substring(9);
            Vector a = parent.getPossibleObjects();
            for (Iterator i = a.iterator(); i.hasNext();) {
                Element elem = (Element) i.next();
                if (elem.getChild("Label", elem.getNamespace()).getChildText("Name", elem.getNamespace()).equals(label))
                    addObject(new Point(10, 10), elem);
            }
        }
    }

    private void checkIfNewRelation() {
        SemanticObjectRepresentation src = null;
        SemanticObjectRepresentation tgt = null;
        for (Iterator iterator = objects.iterator(); iterator.hasNext();) {
            SemanticObjectRepresentation sem = (SemanticObjectRepresentation) iterator.next();
            if (sem.checkIfInside(startRel))
                src = sem;
            if (sem.checkIfInside(endRel))
                tgt = sem;
        }
        if (src != null && tgt != null) addRelation(src, tgt);
    }

    private void cascadeElements() {
        int x = 30, y = 30;
        for (Iterator iterator = objects.iterator(); iterator.hasNext();) {
            SemanticObjectRepresentation sem = (SemanticObjectRepresentation) iterator.next();
            Point p = sem.getP();
            p.setLocation(x, y);
            sem.setP(p);
            x += 40;
            y += 40;
        }
    }

    private BufferedImage generateBackground() {
        BufferedImage tmp = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = (Graphics2D) tmp.getGraphics();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setColor(Color.black);
        g2.fillRect(0, 0, this.getWidth(), this.getHeight());
        g2.setColor(new Color(152, 181, 255));
        g2.fillRect(2, 2, this.getWidth() - 4, this.getHeight() - 4);

        // draw Help:
        g2.setColor(Color.black);
        g2.setFont(g2.getFont().deriveFont(Font.ITALIC, 10f));
        g2.drawString("Help:", 10, this.getHeight() - 38);
        g2.drawString("Drag and drop objects from the tables on the right hand side.", 10, this.getHeight() - 24);
        g2.drawString("<alt>+<left mouse button> or <middle mouse button> to draw relations.", 10, this.getHeight() - 10);

        g2.drawImage(logo, this.getWidth() - logo.getWidth() - 11, this.getHeight() - logo.getHeight() - 11, this);
        return tmp;
    }

    /**
     * creates a MPEG-7 representation of the created or edited semantic description and returns it
     *
     * @return the MPEG-7 Document of the created semantic description
     */
    public Document createDocument() {
        Namespace mpeg7 = Namespace.getNamespace("", "urn:mpeg:mpeg7:schema:2001");
        Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
        Namespace fsw = OCToolkit.getFSWNamespace();
        Element root = new Element("Mpeg7", mpeg7);
        root.setAttribute("schemaLocation", "urn:mpeg:mpeg7:schema:2001 Mpeg7-2001.xsd http://www.at.know-center.at/fsw Know-soccer.xsd", xsi);
        root.addNamespaceDeclaration(mpeg7);
        root.addNamespaceDeclaration(xsi);
        root.addNamespaceDeclaration(fsw);
        Document d = new Document(root);
        // Description
        Element description = new Element("Description", mpeg7);
        description.setAttribute("type", "SemanticDescriptionType", xsi);
        root.addContent(description);
        // Semantics
        Element semantics = new Element("Semantics", mpeg7);
        semantics.addContent(new Element("Label", mpeg7).addContent(new Element("Name", mpeg7).addContent("")));
        description.addContent(semantics);
        Hashtable h = new Hashtable();
        int count = 0;
        for (Iterator iterator = objects.iterator(); iterator.hasNext();) {
            SemanticObjectRepresentation r = (SemanticObjectRepresentation) iterator.next();
            count++;
            String id = "id_" + count;
            h.put(r, id);
            Element node = (Element) r.getNode().clone();
            node.setAttribute("id", id);
            semantics.addContent(node);
        }
        Element graph = new Element("Graph", mpeg7);
        for (Iterator it = relations.iterator(); it.hasNext();) {
            SemanticRelationRepresentation r = (SemanticRelationRepresentation) it.next();
            Element tmpElement = new Element("Relation", mpeg7);
            tmpElement.setAttribute("type", "urn:mpeg:mpeg7:cs:SemanticRelationCS:2001:" + r.getLabel());
            tmpElement.setAttribute("source", "#" + (String) h.get(r.getSource()));
            tmpElement.setAttribute("target", "#" + (String) h.get(r.getTarget()));
            graph.addContent(tmpElement);
        }
        semantics.addContent(graph);
        return d;
    }

    /**
     * Creates list of all names of semantic agents currently attached to the
     * semantic description.
     *
     * @return list of names
     */
    public String[] getSemanticAgentsNames() {
        return getObjectNamesOfType("AgentObjectType");
    }

    /**
     * Creates list of all names of semantic events currently attached to the
     * semantic description.
     *
     * @return list of names
     */
    public String[] getSemanticEventsNames() {
        return getObjectNamesOfType("EventType");
    }

    /**
     * Creates list of all names of semantic times currently attached to the
     * semantic description.
     *
     * @return list of names
     */
    public String[] getSemanticTimesNames() {
        return getObjectNamesOfType("SemanticTimeType");
    }

    /**
     * Creates list of all names of semantic places currently attached to the
     * semantic description.
     *
     * @return list of names
     */
    public String[] getSemanticPlacesNames() {
        return getObjectNamesOfType("SemanticPlaceType");
    }


    private String[] getObjectNamesOfType(String type) {
        Namespace xsi;
        xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");

        String[] result;
        LinkedList<String> l = new LinkedList<String>();
        for (Iterator iterator = objects.iterator(); iterator.hasNext();) {
            SemanticObjectRepresentation r = (SemanticObjectRepresentation) iterator.next();
            Element elem = r.getNode();
            if (elem.getAttribute("type", xsi).getValue().startsWith(type)) {
                l.add(r.getLabel());
            }
        }
        result = new String[l.size()];
        int i = 0;
        for (Iterator<String> iterator = l.iterator(); iterator.hasNext();) {
            String s = iterator.next();
            result[i] = s;
            i++;
        }
        return result;
    }

    public void importNode(Element node) {
        Namespace mpeg7 = Namespace.getNamespace("", "urn:mpeg:mpeg7:schema:2001");
        if (node.getChild("SemanticBase", mpeg7) != null) { // are there any useable elements?
            // simply add all Elements ...
            objects.removeAllElements();
            relations.removeAllElements();
            java.util.List oList = node.getChildren("SemanticBase", mpeg7);
            for (Iterator i = oList.iterator(); i.hasNext();) {
                Element e = (Element) i.next();
                SemanticObjectRepresentation sor = new SemanticObjectRepresentation(new Point(10, 10), e);
                objects.add(sor);
            }

            // now create the graph ...
            if (node.getChild("Graph", node.getNamespace()) != null) {
                if (node.getChild("Graph", node.getNamespace()).getChild("Relation", node.getNamespace()) != null) {
                    oList = node.getChild("Graph", node.getNamespace()).getChildren("Relation", node.getNamespace());
                    for (Iterator i = oList.iterator(); i.hasNext();) {
                        Element e = (Element) i.next();
                        String src = e.getAttributeValue("source");
                        String tgt = e.getAttributeValue("target");
                        String rel = e.getAttributeValue("type");
                        // logger.debug("Searching for relation source=" + src + ", target=" + tgt + ", relation=" + rel);
                        SemanticObjectRepresentation sort = null, sors = null;
                        if (rel != null && rel.lastIndexOf(":") > -1) {
                            rel = rel.substring(rel.lastIndexOf(":") + 1);
                        } else {
                            // logger.error("Import: no relation found");
                        }
                        if (src != null && tgt != null) {
                            src = src.substring(1);

⌨️ 快捷键说明

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