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

📄 annotationframe.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)
 * http://www.juggle.at
 */

package at.lux.fotoannotation;

/*
 * Created by Mathias Lux, mathias@juggle.at
 * User: Mathias Lux, mathias@juggle.at
 * Date: 05.09.2002
 * Time: 21:22:11
 */

import at.know.center.wv_wr.imb.objectcatalog.semanticscreator.IMBeeApplicationPanel;
import at.lux.components.ImageThumbPanel;
import at.lux.fotoannotation.dialogs.*;
import at.lux.fotoannotation.mpeg7.Mpeg7ImageDescription;
import at.lux.fotoannotation.mpeg7.Mpeg7ThumbnailMediaProfile;
import at.lux.fotoannotation.panels.*;
import at.lux.fotoannotation.utils.TextChangesListener;
import at.lux.splash.SplashScreen;
import at.lux.StatusBar;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
import org.jdom.output.Format;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.*;
import java.text.DecimalFormat;
import java.util.Properties;

/**
 * This Class is the main JFrame where the application is started.
 *
 * @author Mathias Lux, mathias@juggle.at
 * @version 0.9 alpha
 */

public class AnnotationFrame extends JFrame implements ActionListener, StatusBar {
    public static final boolean DEBUG = false;
    public static boolean DIRTY = false;
    public static String TITLE_BAR = AnnotationToolkit.PROGRAM_NAME;
    private AnnotationFrameProperties properties;
    private ImageThumbPanel imagePanel;
    private MetadataDescriptionPanel mdPanel;
    private QualityPanel qualityPanel;
    private TextDescriptionPanel textPanel;
    // private AgentComboBoxModel agentsModel;
    private File currentFile = null;
    private FilePanel fp;
    private JSplitPane lrSplit, tbSplit;
    private JTabbedPane tabs;
    private CreationPanel creationPanel;
    private DecimalFormat df;
    private JLabel status;
    private IMBeeApplicationPanel beePanel;
    private ColorLayoutPanel colorPanel;
    private JPanel gridPanel1;
    private JProgressBar garbageState;
    private GarbageTracker gtracker;

    public AnnotationFrame() {
        super(TITLE_BAR);
        try {
            this.setIconImage(ImageIO.read(AnnotationFrame.class.getResource("data/icon.gif")));
        } catch (Exception e) {
            debug("Couldn't set Icon: IOException " + e.getMessage());
        }
        df = (DecimalFormat) DecimalFormat.getInstance();
        df.setMaximumFractionDigits(2);

        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent event) {
                super.windowClosing(event);
                exitApplication();
            }
        });
        // -------------------------------------------------------------------------------
        // Ueberpruefung ob das agent file existiert, sonst muss es angelegt werden ...
        // Eine sicherheitskopie befindet sich im package ...
        // -------------------------------------------------------------------------------
        debug("Checking if agentfile is here ...");
        File agentsFile = new File(AnnotationToolkit.AGENTS_FILE);
        if (!agentsFile.exists()) {
            try {
                debug("Generating sample agents file");
                Document d = new SAXBuilder().build(AnnotationFrame.class.getResource("data/agents.mp7.xml"));
                FileOutputStream fos = new FileOutputStream(agentsFile);
                OutputStreamWriter osw = new OutputStreamWriter(fos, "utf-8");
                new XMLOutputter(Format.getPrettyFormat()).output(d, osw);
                osw.close();
                fos.close();
                debug("Finished generating sample agents file");
            } catch (Exception e) {
                debug("Error generating sample agents file " + e.toString() + ", " + e.getMessage());
            }
        } else {
            debug("agentfile found :)");
        }
        debug("reading configurationfile ... ");
        // -------------------------------------------------------------------------------
        // Ueberpruefung ob das base-object file existiert, sonst muss es angelegt werden.
        // Eine sicherheitskopie befindet sich im package ...
        // -------------------------------------------------------------------------------
        debug("Checking if agentfile is here ...");
        File baseobjectsFile = new File("base-objects.mp7.xml");
        if (!baseobjectsFile.exists()) {
            try {
                debug("Generating sample base-objects file");
                Document d = new SAXBuilder().build(AnnotationFrame.class.getResource("data/base-objects.mp7.xml"));
                FileOutputStream fos = new FileOutputStream(baseobjectsFile);
                OutputStreamWriter osw = new OutputStreamWriter(fos, "utf-8");
                new XMLOutputter(Format.getPrettyFormat()).output(d, osw);
                osw.close();
                fos.close();
                debug("Finished generating sample base-objects file");
            } catch (Exception e) {
                debug("Error generating sample base-objects file " + e.toString() + ", " + e.getMessage());
            }
        } else {
            debug("base-objects file found :)");
        }
        debug("reading configurationfile ... ");
        // -------------------------------------------------------------------------------
        // Ueberpruefung ob das property file existiert, sonst muss es angelegt werden ...
        // Eine sicherheitskopie befindet sich im package ...
        // -------------------------------------------------------------------------------
        File pFile = new File("properties.xml");
        if (!pFile.exists()) {
            try {
                debug("Generating sample property file");
                Document d = new SAXBuilder().build(AnnotationFrame.class.getResource("data/properties.xml"));
                FileOutputStream fos = new FileOutputStream(pFile);
                OutputStreamWriter osw = new OutputStreamWriter(fos, "utf-8");
                new XMLOutputter(Format.getPrettyFormat()).output(d, osw);
                osw.close();
                fos.close();
                debug("Finished generating sample property file");
            } catch (Exception e) {
                debug("Error generating sample property file " + e.toString() + ", " + e.getMessage());
            }
        }
        properties = new AnnotationFrameProperties(new File("properties.xml"), this);
        debug("finished reading configurationfile");
        this.setJMenuBar(properties.getMenuBar());
        debug("finished creating menu");

        // -------------------------------------
        // Initialising main Objects ...
        // -------------------------------------
        // TextChangeListener intialization for detecting changes of the document.
        TextChangesListener.createInstance(this);
        // -------------------------------------
        // Adding Components
        // -------------------------------------

        beePanel = new IMBeeApplicationPanel(this);
        colorPanel = new ColorLayoutPanel();

        lrSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
        tbSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT);

        mdPanel = new MetadataDescriptionPanel(new AgentComboBoxModel(this));
        imagePanel = new ImageThumbPanel();
        fp = new FilePanel(new File("."), this);
        qualityPanel = new QualityPanel(new AgentComboBoxModel(this));
        textPanel = new TextDescriptionPanel(this);
        creationPanel = new CreationPanel(new AgentComboBoxModel(this));

        JPanel qualTextPanel = new JPanel(new BorderLayout());
        qualTextPanel.add(qualityPanel, BorderLayout.SOUTH);
        qualTextPanel.add(textPanel, BorderLayout.CENTER);
        gridPanel1 = new JPanel(new GridLayout(0, 2));
        JPanel _leftPanel1 = new JPanel(new BorderLayout());
//        gridPanel2.add(textPanel);
        _leftPanel1.add(qualTextPanel, BorderLayout.CENTER);
        _leftPanel1.add(mdPanel, BorderLayout.SOUTH);
        gridPanel1.add(_leftPanel1);
        gridPanel1.add(creationPanel);
        JPanel gridPanel3 = new JPanel(new GridLayout(0, 1));
        gridPanel3.add(colorPanel);
//        gridPanel3.add(qualTextPanel);

        tabs = new JTabbedPane(JTabbedPane.TOP);
        tabs.add("Image Information", gridPanel1);
        tabs.add("Semantics", beePanel);
        tabs.add("Visuals", gridPanel3);

        tbSplit.add(fp, JSplitPane.TOP);
        tbSplit.add(imagePanel, JSplitPane.BOTTOM);

        lrSplit.add(tbSplit, JSplitPane.LEFT);
        lrSplit.add(tabs, JSplitPane.RIGHT);

        lrSplit.setDividerLocation(properties.getLrSplit());
        tbSplit.setDividerLocation(properties.getTbSplit());

        status = new JLabel("Status");
        garbageState = new JProgressBar(JProgressBar.HORIZONTAL, 0, 100);
        garbageState.setStringPainted(true);
        garbageState.setPreferredSize(new Dimension(100, 18));
        garbageState.setToolTipText("This bar shows the memory allocated by the VM and how much of it is already in use.");
        gtracker = new GarbageTracker(garbageState);

        JPanel sgcPanel = new JPanel(new BorderLayout());
        sgcPanel.add(garbageState, BorderLayout.EAST);
        sgcPanel.add(status, BorderLayout.CENTER);

        this.getContentPane().add(lrSplit, BorderLayout.CENTER);
        this.getContentPane().add(sgcPanel, BorderLayout.SOUTH);

        this.setSize(properties.getFrameWidth(), properties.getFrameHeigth());
        this.setLocation(properties.getFrameLocationX(), properties.getFrameLocationY());

        beePanel.reArrange();
        //beePanel.revalidate();
        gtracker.start();
    }

    /**
     * Main method used to start Caliph
     *
     * @param args
     */
    public static void main(String[] args) {
/*
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            System.err.println("Could not set Look & Feel: " + e.toString());
        }
*/
        AnnotationFrame frame = new AnnotationFrame();
        boolean showSplash = true;

        // get config file from splashscreen class
        File splashProps = new File(SplashScreen.LICENSE_ACCEPTED_FILENAME);
        // look if exists
        if (splashProps.exists()) {
            // load props
            try {
                Properties licenseAcceptedProps = new Properties();
                licenseAcceptedProps.load(new FileInputStream(splashProps));
                // if property is set we do not have to show the splashscreen:
                String tmp = licenseAcceptedProps.getProperty("license.accepted");
                if (tmp != null && tmp.equals("true")) {
                    showSplash = false;
                }
            } catch (IOException e) {
                System.err.println("Warn: Could not read license properties file.");
            }
        }

        if (showSplash) {
            // now show the splash screen if this has not been done before.
            SplashScreen splash = new SplashScreen(frame);
            splash.setVisible(true);
        }

        frame.setVisible(true);
    }

    /**
     * implemented from Interface ActionListener
     */
    public void actionPerformed(ActionEvent event) {
//        gtracker.run();

⌨️ 快捷键说明

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