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

📄 externallauncher.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * File:     ExternalLauncher.java * Project:  MPI Linguistic Application * Date:     02 May 2007 * * Copyright (C) 2001-2007  Max Planck Institute for Psycholinguistics * * This program 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. * * This program 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */package mpi.eudico.client.annotator.integration;import mpi.eudico.client.annotator.Constants;import mpi.eudico.client.annotator.ElanFrame2;import mpi.eudico.client.annotator.FrameManager;import mpi.util.LogUtil;import org.xml.sax.SAXException;import java.io.File;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import java.net.URI;import java.net.URISyntaxException;import java.util.HashMap;import java.util.Vector;import java.util.logging.Logger;import javax.swing.JOptionPane;/** * This class acts as a listener to a file in the elan home dir and opens a new * ElanFrame once a new open request has been written to it. Follows the * Singleton pattern. * * @author Han Sloetjes */public class ExternalLauncher {    /** a Logger */    private static final Logger LOG = Logger.getLogger(ExternalLauncher.class.getName());    private static String exchangeFile = "externallaunch";    /** the open command */    //private static final String OPEN = "open";    /** the executed command */    //private static final String EXECUTED = "executed";    /** the IMDI session command */    private static final String IMDI_SESSION = "IMDI_Session: ";    private static File launchFile;    private static FileReader reader;    private static ExternalLauncher externalLauncher;    private static LaunchThread launchThread;    private static long lastModified = 0L;    private static boolean running = false;    /**     * Creates a new ExternalLauncher instance     */    private ExternalLauncher() {        init();    }    /**     * Starts the listener/polling thread.     */    public static void start() {        if (externalLauncher == null) {            externalLauncher = new ExternalLauncher();            LOG.info("External launch thread started...");        }    }    /**     * Stops the listener/polling thread and deletes the external launch file.     * Note: maybe change the return type to boolean, to confirm the deletion     * of the file succeeded.     */    public static void stop() {        running = false;        if ((launchThread != null) && launchThread.isAlive()) {            try {                launchThread.interrupt();            } catch (SecurityException se) {                LOG.warning("Could not stop the launch thread.\n" +                    LogUtil.formatStackTrace(se));            }        }        if (reader != null) {            try {                reader.close();            } catch (IOException ioe) {                LOG.warning("Could not close the file: " +                    launchFile.getAbsolutePath() + "\n" +                    LogUtil.formatStackTrace(ioe));            }        }        if (launchFile != null) {            try {                launchFile.delete();            } catch (SecurityException se) {                LOG.warning("Could not delete the file: " +                    launchFile.getAbsolutePath() + "\n" +                    LogUtil.formatStackTrace(se));            }        }        LOG.info("External launch thread stopped...");    }    /**     * Starts the listener thread.     *     * @param exchangeFileName the file to read from     */    public static void start(String exchangeFileName) {        if (externalLauncher == null) {            if ((exchangeFileName != null) && (exchangeFileName.length() > 0)) {                exchangeFile = exchangeFileName;            }            externalLauncher = new ExternalLauncher();        }    }    private static void init() {        launchFile = new File(Constants.ELAN_DATA_DIR, exchangeFile);        if (launchFile.exists()) {            launchFile.deleteOnExit(); //??        }        launchThread = new LaunchThread(1000);        launchThread.setPriority(Thread.MIN_PRIORITY);        running = true;        launchThread.start();        // for testing        // new TestLauncher().start();		    }    private static void checkChange() {        if (!running) {            return;        }        if ((launchFile == null) || !launchFile.exists()) {            return;        }        if ((lastModified == 0) || (lastModified < launchFile.lastModified())) {            try {                reader = new FileReader(launchFile);                char[] ch = new char[(int) launchFile.length()];                reader.read(ch);                String line = new String(ch);                if (line != null) {                    //System.out.println("Read: " + line);                    openElanFrame(line);                    lastModified = launchFile.lastModified();                }                reader.close();            } catch (FileNotFoundException fnfe) {                LOG.severe("Could not read file: \n" +                    launchFile.getAbsolutePath() +                    LogUtil.formatStackTrace(fnfe));            } catch (IOException ioe) {                LOG.severe("Error reading file: \n" +                    launchFile.getAbsolutePath() +                    LogUtil.formatStackTrace(ioe));            }        }    }    private static void openElanFrame(String line) {        if ((line == null)) {            return;        }        //String directive = line.substring(OPEN.length() + 1);        if (line.startsWith(IMDI_SESSION)) {            // parse imdi file            String IMDIString = line.substring(IMDI_SESSION.length());            if (IMDIString.length() > 0) {                IMDIString = pathToURLString(IMDIString);                IMDISessionParser parser = new IMDISessionParser();                HashMap filesMap = null;                try {                    parser.parse(IMDIString);                    filesMap = parser.getFilesMap();                } catch (IOException ioe) {                    LOG.warning("Could not access the .imdi file\n" +                        LogUtil.formatStackTrace(ioe));                    showWarningDialog(                        "Elan launcher:\nCould not access the imdi file.");                    return;                } catch (SAXException sax) {                    LOG.warning("Could not parse the .imdi file\n" +                        LogUtil.formatStackTrace(sax));                    showWarningDialog(                        "Elan launcher:\nCould not parse the imdi file.");                    return;                }                if (filesMap != null) {                    String eafString = (String) filesMap.get(IMDISessionParser.EAF);                    if ((eafString == null) ||                            !eafString.toLowerCase().endsWith(".eaf")) {                        LOG.warning("No .eaf file found");                        showWarningDialog(                            "Elan launcher:\nNo eaf file found in the imdi file.");                        return;                    } else {                        // create an absolute path...                        eafString = absolutePath(IMDIString, eafString);                        LOG.info("Launching: " + eafString);                    }                    String videoString = (String) filesMap.get("video");                    String audioString = (String) filesMap.get("audio");                    Vector mediaFiles = new Vector();

⌨️ 快捷键说明

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