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

📄 imbeeapplicationpanel.java

📁 图像检索的代码b
💻 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-2004 by Mathias Lux (mathias@juggle.at) and the Know-Center Graz
 * Inffeldgasse 21a, 8010 Graz, Austria
 * http://www.know-center.at
 */
package at.know.center.wv_wr.imb.objectcatalog.semanticscreator;

import at.know.center.wv_wr.imb.objectcatalog.OCToolkit;
import at.know.center.wv_wr.imb.objectcatalog.gui.AgentTableModel;
import at.know.center.wv_wr.imb.objectcatalog.gui.EventTableModel;
import at.know.center.wv_wr.imb.objectcatalog.gui.SemanticObjectTableModel;
import at.know.center.wv_wr.imb.objectcatalog.gui.DNDJTable;
import at.know.center.wv_wr.imb.objectcatalog.mpeg7tools.Mpeg7FileFilter;
import at.lux.fotoannotation.AnnotationFrame;
import at.lux.fotoannotation.dialogs.*;
import org.jdom.*;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
import org.jdom.output.Format;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Vector;

/**
 * <p>Teil des Projekts <b>IMB - Retrievaltools</b> vom Know-Center Graz in Kooperation mit dem Joanneum Research</p>
 * Applikation zum Zusammenstellen von semantischen Beschreibung auf Basis von MPEG-7 Deskriptoren
 *
 * @author Mathias Lux, mathias@juggle.at
 */
public class IMBeeApplicationPanel extends JPanel implements ActionListener, BeeDataExchange {
    public static String CONFIGURATION_FILE = "../data/imbee.conf.xml";
    public static String BASE_OBJECT_FILE = "base-objects.mp7.xml";
    private Document configFile;
    private SAXBuilder xmlBuilder;
    // private JToolBar drawingtoolbar;
    private BeePanel beePanel;
    // private JPanel buttonPane;
    private JTable agentTable, eventTable, venueTable;
    private JSplitPane rlSplitPane, tbSplitPane;
    // private JPopupMenu venueMenu;
    EventTableModel eventTableModel;
    AgentTableModel agentTableModel;
    SemanticObjectTableModel venueTableModel;
    JFrame parent;
    private String[] relationsArray;
    private JSplitPane agentEventSplit;


    public IMBeeApplicationPanel(JFrame parent) {
        super(new BorderLayout());
        this.parent = parent;
        xmlBuilder = new SAXBuilder();
        this.addComponentListener(new ComponentAdapter() {
            /**
             * Invoked when the component's size changes.
             */
            public void componentResized(ComponentEvent e) {
                super.componentResized(e);
                reArrange();
            }
        });

        // --------------------------------------
        // reading relations from file ...
        // --------------------------------------
        relationsArray = new String[1];
        relationsArray[0] = "no relation found";
        try {
            Document relDoc = xmlBuilder.build(OCToolkit.getRelationsFile());
            java.util.List relList = relDoc.getRootElement().getChildren();
            Vector tmpRelationsVector = new Vector();
            for (Iterator i = relList.iterator(); i.hasNext();) {
                Element elem = (Element) i.next();
                String tmpRelationName = elem.getChildText("name");
                String tmpInverseRelationName = elem.getChildText("inverse");
                if (tmpRelationName != null)
                    tmpRelationsVector.add(tmpRelationName);
                if (tmpInverseRelationName != null)
                    tmpRelationsVector.add(tmpInverseRelationName);
            }
            relationsArray = new String[tmpRelationsVector.size()];
            tmpRelationsVector.toArray(relationsArray);
        } catch (JDOMException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        Arrays.sort(relationsArray);

        // --------------------------------------
        // initialising tables ...
        // --------------------------------------
        agentTableModel = new AgentTableModel();
        eventTableModel = new EventTableModel();
        venueTableModel = new SemanticObjectTableModel();
        debug("[Startup IMBee] Reading base-objects");
        readBaseObjects();
        debug("[Startup IMBee] Finished reading base-objects");
        agentTableModel.detachAll();
        agentTableModel.sort();
        eventTableModel.detachAll();
        eventTableModel.sort();
        venueTableModel.detachAll();
        venueTableModel.sort();
        venueTable = new DNDJTable(venueTableModel);
//        venueTable.setDragEnabled(true);
        agentTable = new DNDJTable(agentTableModel);
//        agentTable.setDragEnabled(true);
//        agentTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        eventTable = new DNDJTable(eventTableModel);
//        eventTable.setDragEnabled(true);

        // --------------------------------------
        // creating buttons for the tables ...
        // --------------------------------------
        JButton remAgentButton = new JButton("-");
        remAgentButton.addActionListener(this);
        remAgentButton.setActionCommand("removeAgent");

        JButton importAgentsButton = new JButton("(i)");
        importAgentsButton.addActionListener(this);
        importAgentsButton.setActionCommand("importAgents");


        JButton newAgentButton = new JButton("new");
        newAgentButton.addActionListener(this);
        newAgentButton.setActionCommand("newAgent");

        JPanel agentPane = new JPanel(new BorderLayout());
        agentPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Agents"));
        agentPane.add(new JScrollPane(agentTable), BorderLayout.CENTER);
        JPanel abp = new JPanel();
        abp.add(remAgentButton);
        abp.add(newAgentButton);
        abp.add(importAgentsButton);
        agentPane.add(abp, BorderLayout.SOUTH);

        JButton newEventButton = new JButton("new");
        newEventButton.addActionListener(this);
        newEventButton.setActionCommand("newEvent");

        JButton remEventButton = new JButton("-");
        remEventButton.addActionListener(this);
        remEventButton.setActionCommand("removeEvent");

        JButton importEventsButton = new JButton("(i)");
        importEventsButton.addActionListener(this);
        importEventsButton.setActionCommand("importEvents");

        JPanel ebp = new JPanel();
        ebp.add(remEventButton);
        ebp.add(newEventButton);
        ebp.add(importEventsButton);

        // objects ...
        JButton newObjectButton = new JButton("new");
        newObjectButton.addActionListener(this);
        newObjectButton.setActionCommand("newObject");

        JButton remObjectButton = new JButton("-");
        remObjectButton.addActionListener(this);
        remObjectButton.setActionCommand("removeObject");

        JButton importObjectsButton = new JButton("(i)");
        importObjectsButton.addActionListener(this);
        importObjectsButton.setActionCommand("importObjects");

        JPanel obp = new JPanel();
        obp.add(remObjectButton);
        obp.add(newObjectButton);
        obp.add(importObjectsButton);

        JPanel eventPane = new JPanel(new BorderLayout());
        eventPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Events"));
        eventPane.add(new JScrollPane(eventTable), BorderLayout.CENTER);
        eventPane.add(ebp, BorderLayout.SOUTH);

        JPanel venuePane = new JPanel(new BorderLayout());
        venuePane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Places, Times and Objects"));
        venuePane.add(new JScrollPane(venueTable), BorderLayout.CENTER);
        venuePane.add(obp, BorderLayout.SOUTH);

        agentEventSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
//        agentEventSplit.setDividerLocation(180);
        agentEventSplit.setContinuousLayout(true);

        agentEventSplit.add(agentPane, JSplitPane.TOP);
        agentEventSplit.add(eventPane, JSplitPane.BOTTOM);


        // ---------------------------------------
        // Panels & SplitPanels ...
        // ---------------------------------------
        beePanel = new BeePanel(this);

        tbSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
//        tbSplitPane.setDividerLocation(400);
        tbSplitPane.add(venuePane, JSplitPane.BOTTOM);
        tbSplitPane.add(agentEventSplit, JSplitPane.TOP);
        rlSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);


        rlSplitPane.setContinuousLayout(true);
        rlSplitPane.add(beePanel, JSplitPane.LEFT);
        rlSplitPane.add(tbSplitPane, JSplitPane.RIGHT);
        this.add(rlSplitPane, BorderLayout.CENTER);
        reArrange();
    }

    /**
     * creation of the toolbar
     */
    private JToolBar getDrawingToolBar() {
        JToolBar tb = new JToolBar("Drawing tools");
        tb.add(createNewButton("Object", "createObject", "create new Object"));
        tb.add(createNewButton("Relation", "createRelation", "create new Relation"));
        return tb;
    }

    /**
     * shortens creation of buttons
     */
    private JButton createNewButton(String label, String actionCommand, String toolTipText) {
        JButton ret = new JButton(label);
        ret.addActionListener(this);
        ret.setActionCommand(actionCommand);
        ret.setToolTipText(toolTipText);
        return ret;
    }

    /**
     * Invoked when an action occurs.
     */
    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals("createObjectFromAgent")) {
            if (agentTable.getSelectedRow() > -1) {
                // String s = (String) agentTable.getValueAt(agentTable.getSelectedRow(), 0);
                Element elem = agentTableModel.getNodeAt(agentTable.getSelectedRow());
                beePanel.addObject(new Point(20 + (int) (Math.random() * 100), 20 + (int) (Math.random() * 100)), elem);
            }
        } else if (e.getActionCommand().equals("createObjectFromEvent")) {
            if (eventTable.getSelectedRow() > -1) {
                Element elem = eventTableModel.getNodeAt(eventTable.getSelectedRow());
                beePanel.addObject(new Point(20 + (int) (Math.random() * 100), 20 + (int) (Math.random() * 100)), elem);
            }
        } else if (e.getActionCommand().equals("export")) {
            exportXMLData(beePanel.createDocument());
        } else if (e.getActionCommand().equals("removeAgent")) {
            int[] indices = agentTable.getSelectedRows();
            Arrays.sort(indices);
            for (int i = 0; i < indices.length; i++) {
                int index = indices[indices.length - i - 1];   // von hinten loeschen, sonst stimmts nimmer
                agentTableModel.getAgents().remove(index);
            }
            agentTableModel.fireTableDataChanged();
        } else if (e.getActionCommand().equals("removeEvent")) {
            int[] indices = eventTable.getSelectedRows();
            Arrays.sort(indices);
            for (int i = 0; i < indices.length; i++) {
                int index = indices[indices.length - i - 1];   // von hinten loeschen, sonst stimmts nimmer
                eventTableModel.getEvents().remove(index);
            }
            eventTableModel.fireTableDataChanged();
        } else if (e.getActionCommand().equals("removeObject")) {
            int[] indices = venueTable.getSelectedRows();
            Arrays.sort(indices);
            for (int i = 0; i < indices.length; i++) {
                int index = indices[indices.length - i - 1];   // von hinten loeschen, sonst stimmts nimmer
                venueTableModel.getObjects().remove(index);
            }
            venueTableModel.fireTableDataChanged();
        } else if (e.getActionCommand().equals("newAgent")) {
            NewAgentDialog dialog = new NewAgentDialog(parent);
            dialog.setSize(460, 230);
            Dimension ss = Toolkit.getDefaultToolkit().getScreenSize();

            dialog.setLocation((ss.width - dialog.getWidth()) >> 1, (ss.height - dialog.getHeight()) >> 1);
            dialog.setVisible(true);

            if (dialog.createXML() != null) {
                agentTableModel.addAgent(dialog.createXML());
                agentTableModel.sort();
                agentTableModel.fireTableDataChanged();
            }
        } else if (e.getActionCommand().equals("newEvent")) {
            NewEventDialog dialog = new NewEventDialog(parent);
            dialog.setSize(460, 230);
            Dimension ss = Toolkit.getDefaultToolkit().getScreenSize();
            dialog.setLocation((ss.width - dialog.getWidth()) >> 1, (ss.height - dialog.getHeight()) >> 1);
            dialog.setVisible(true);

            if (dialog.createXML() != null) {
                eventTableModel.addEvent(dialog.createXML());
                eventTableModel.sort();
                eventTableModel.fireTableDataChanged();
            }
        } else if (e.getActionCommand().equals("importAgents")) {
            importAgents();
        } else if (e.getActionCommand().equals("importEvents")) {
            importEvents();
        } else if (e.getActionCommand().equals("importObjects")) {

⌨️ 快捷键说明

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