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

📄 newplacedialog.java

📁 基于MPEG 7 标准,符合未来语义网架构,很值得参考
💻 JAVA
字号:
/*
 * 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.dialogs;

import org.jdom.Element;
import org.jdom.Namespace;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.Vector;

public class NewPlaceDialog extends JDialog implements ActionListener, NewDescriptorDialogInterface {
    JTextField name;
    JTextArea freeText, addressLines;
    JButton ok, cancel;
    Element placeDescriptor = null;

    public NewPlaceDialog(Frame owner) {
        super(owner, true);
        init();
    }

    private void init() {
        setTitle("Create new SemanticPlace object");
        JPanel labelPane = new JPanel(new GridLayout(0, 1));
        JPanel inputPane = new JPanel(new GridLayout(0, 1));
        JPanel buttonPane = new JPanel(new FlowLayout());
        JPanel textPane = new JPanel(new BorderLayout());
        JPanel addressPane = new JPanel(new BorderLayout());

        ok = new JButton("OK");
        ok.setActionCommand("ok");
        ok.addActionListener(this);
        cancel = new JButton("Cancel");
        cancel.setActionCommand("cancel");
        cancel.addActionListener(this);

        buttonPane.add(ok);
        buttonPane.add(cancel);

        freeText = new JTextArea(3, 20);
        textPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Description"));
        textPane.add(new JScrollPane(freeText), BorderLayout.CENTER);

        addressLines = new JTextArea(3, 20);
        addressPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Address"));
        addressPane.add(new JScrollPane(addressLines), BorderLayout.CENTER);

        name = new JTextField();
        inputPane.add(name);
        labelPane.add(new JLabel("Name: "));

        JPanel tmp = new JPanel(new BorderLayout());
        tmp.add(labelPane, BorderLayout.WEST);
        tmp.add(inputPane, BorderLayout.CENTER);
        tmp.add(addressPane, BorderLayout.SOUTH);

        this.getContentPane().add(tmp, BorderLayout.NORTH);
        this.getContentPane().add(textPane, BorderLayout.CENTER);
        this.getContentPane().add(buttonPane, BorderLayout.SOUTH);

    }

    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals("ok")) {
            if (createDocument())
                this.setVisible(false);
        } else if (e.getActionCommand().equals("cancel")) {
            this.setVisible(false);
        }

    }


    private boolean createDocument() {
        boolean desc_created = false;
        if (name.getText().length() > 0) {
            Vector lines = null;
            if (addressLines.getText().length() > 0) {
                lines = new Vector();
                StringTokenizer t = new StringTokenizer(addressLines.getText(), "\n", false);
                while (t.hasMoreElements()) {
                    String s = t.nextToken();
                    lines.add(s.trim());
                }
            }

            Namespace mpeg7, xsi;
            mpeg7 = Namespace.getNamespace("", "urn:mpeg:mpeg7:schema:2001");
            xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
            placeDescriptor = new Element("SemanticBase", mpeg7).setAttribute("type", "SemanticPlaceType", xsi);
            Element label = new Element("Label", mpeg7).addContent(new Element("Name", mpeg7).addContent(name.getText()));
            placeDescriptor.addContent(label);
            if (freeText.getText().length() > 0) {
                placeDescriptor.addContent(new Element("Definition", mpeg7).addContent(new Element("FreeTextAnnotation", mpeg7).addContent(freeText.getText())));
            }

            if (lines != null) {
                Element elem_address = new Element("PostalAddress", mpeg7);
                for (Iterator it1 = lines.iterator(); it1.hasNext();) {
                    String s = (String) it1.next();
                    elem_address.addContent(new Element("AddressLine", mpeg7).addContent(s));
                }
                placeDescriptor.addContent(new Element("Place", mpeg7).addContent(elem_address));
            }
            desc_created = true;
        } else {
            JOptionPane.showMessageDialog(this, "At least a name is required!");
        }

        return desc_created;
    }

    public Element createXML() {
        return placeDescriptor;
    }
}

⌨️ 快捷键说明

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