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

📄 interlinear.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * File:     Interlinear.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.interlinear;import mpi.eudico.client.annotator.Preferences;import mpi.eudico.server.corpora.clom.Annotation;import mpi.eudico.server.corpora.clom.Tier;import mpi.eudico.server.corpora.clomimpl.abstr.TierImpl;import mpi.eudico.server.corpora.clomimpl.abstr.TranscriptionImpl;import java.awt.Font;import java.awt.Graphics;import java.awt.image.BufferedImage;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.Vector;/** * Main object for options for interlinearisation.  Creates a BlockMetrics * object that performs calculations etc. for interlinear layout. * * @author MPI */public class Interlinear {    // constants    // units for page width and height    /** constant for centimeter layout unit */    public static final int CM = 0;    /** constant for inch layout unit */    public static final int INCH = 1;    /** constant for pixel layout unit */    public static final int PIXEL = 2;    /** constant for character layout unit */    public static final int NUM_CHARACTERS = 3;    // wrap styles for blocks and lines    /** block wrap style where each block start at a new 'block line' */    public static final int EACH_BLOCK = 0;    /**     * block wrap style where where wrapping to a new line occurs when the next     * block does not  fit completely on the current 'block line'     */    public static final int BLOCK_BOUNDARY = 1;    /**     * block wrap style where block wrapping only occurs when the next     * annotations do not fit  on the current 'block lline'!     */    public static final int WITHIN_BLOCKS = 2;    /**     * block and line wrap style where no wrapping is applied; all annotations     * are positions  on a single 'block line'     */    public static final int NO_WRAP = 3;    // wrap styles for lines    /**     * line wrap style where a line that does not fit on the current line is     * wrapped to the next     */    public static final int NEXT_LINE = 4;    // time code types    /** the hour/minutes/seconds/milliseconds format */    public static final int HHMMSSMS = 0;    /** the seconds/milliseconds format */    public static final int SSMS = 1;    /** the pure milliseconds format */    public static final int MS = 2;    // unit for text alignment    /** constant for pixel based text alignment */    public static final int PIXELS = 0;    /** constant for bytes based text alignment */    public static final int BYTES = 1;    /** constant for character based alignment */    public static final int CHARACTERS = 2;    // font    //	public static Font DEFAULTFONT = new Font("SansSerif", Font.PLAIN, 12);    /** constant for the default font size for annotations */    public static final int DEFAULT_FONT_SIZE = 12;    /** the default font for printing */    public static Font DEFAULTFONT = new Font("MS Arial Unicode", Font.PLAIN,            DEFAULT_FONT_SIZE);    /** the default preview font for character based alignment! */    public static Font MONOSPACED_FONT = new Font("Monospaced", Font.PLAIN,            DEFAULT_FONT_SIZE);    /** the default font size for time codes */    public static final int TIMECODE_FONT_SIZE = 10;    // empty line style    /** constant for template style empty line style */    public static final int TEMPLATE = 0;    /** constant for an empty line style where empty lines are hidden */    public static final int HIDE_EMPTY_LINES = 1;    // sorting style    /** sorting as read from file */    public static final int EXTERNALLY_SPECIFIED = 0;    /** sorting according t otier dependencies */    public static final int TIER_HIERARCHY = 1;    /** sorting by linguistic type */    public static final int BY_LINGUISTIC_TYPE = 2;    /** sorting by participant */    public static final int BY_PARTICIPANT = 3;    /** random user defined sorting */    public static final int USER_DEFINED = 4;    /** constant for the mode where all timecodes are on a single line */    public static final int SINGLE_TIMECODE = 0;    /** constant for a timecode per root tier */    public static final int MULTIPLE_TIMECODE = 1;    // character encoding    /** output text encoding in utf8 */    public static final int UTF8 = 0;    /** iso-latin encoding */    public static final int ISOLATIN = 1;    /** sil-ipa encoding */    public static final int SIL = 2;    // output modes    /** preview/output mode for printing */    public static final int PRINT = 100;    /** preview output mode for interlinear text */    public static final int INTERLINEAR_TEXT = 101;    /** output mode for shoebox */    public static final int SHOEBOX_TEXT = 102;    /** output mode for interlinear html */    public static final int HTML = 103;    // constants for text out    /** default line width */    public static final int DEFAULT_NUM_CHARS = 80;    /** space between label and contents */    public static final int LABEL_VALUE_MARGIN = 3;    /** default number of newlines between blocks */    public static final int DEFAULT_TEXT_BLOCK_SPACING = 2;    /** the transcription */    private final TranscriptionImpl transcription;    private int width;    private int height;    private ArrayList visibleTiers;    private boolean tierLabelsShown;    private long[] visibleTimeInterval;    private int blockWrapStyle;    private int lineWrapStyle;    private boolean timeCodeShown;    private int timeCodeType;    private HashMap fonts;    private HashMap fontSizes;    private boolean emptySlotsShown;    private int lineSpacing;    private int blockSpacing = -1;    private int emptySpace; // the space between words/annotations     private Annotation activeAnnotation;    private long[] selection;    private long mediaTime;    private int alignmentUnit;    private int emptyLineStyle; // show full 'template' for block, or hide empty lines    private int sortingStyle;    private HashMap charEncodings;    private int outputMode;    private int timeCodeMultiplicity;    private BlockMetrics metrics;    private int pageHeight;    private boolean selectionOnly = false;    //only applicable for text export, insert a space and a tab char between annotations     // for easier postprocessing in texteditors    private boolean insertTabs = false;    // preferences keys    /** pref key */    final String prefSelectionOnly = "Interlinear.SelectionOnly";    /** pref key */    final String prefLabelsShown = "Interlinear.LabelsShown";    /** pref key */    final String prefTimeCodeShown = "Interlinear.TimeCodeShown";    /** pref key */    final String prefTimeCodeType = "Interlinear.TimeCodeType";    /** pref key */    final String prefBlockWrapStyle = "Interlinear.BlockWrapStyle";    /** pref key */    final String prefLineWrapStyle = "Interlinear.LineWrapStyle";    /** pref key */    final String prefBlockSpacing = "Interlinear.BlockSpacing";    /** pref key */    final String prefBlockSpacingTextOut = "Interlinear.BlockSpacing.Text";    /** pref key */    final String prefLineSpacing = "Interlinear.LineSpacing";    /** pref key */    final String prefTierSortingStyle = "Interlinear.TierSortingStyle";    /** pref key */    final String prefVisibleTiers = "Interlinear.VisibleTiers";    /** pref key */    final String prefTierOrder = "Interlinear.TierOrder";    /** pref key */    final String prefFontSizes = "Interlinear.FontSizes";    /** pref key */    final String prefNumCharPerLine = "Interlinear.NumCharPerLine";    /** pref key */    final String prefHTMLPixWidth = "Interlinear.HTMLPixWidth";    /** pref key */    final String prefInsertTab = "Interlinear.InsertSpace";    /**     * Creates a new Interlinear instance. Default mode is Print mode     *     * @param tr the transcription holding tiers and annotations.     */    public Interlinear(TranscriptionImpl tr) {        this(tr, PRINT);    }    /**     * Creates a new Interlinear instance.     *     * @param tr the transcription holding tiers and annotations.     * @param mode one of <code>PRINT</code>, <code>INTERLINEAR_TEXT</code> or     *        <code>SHOEBOX_TEXT</code>     */    public Interlinear(TranscriptionImpl tr, int mode) {        transcription = tr;        if ((mode < PRINT) || (mode > HTML)) {            outputMode = PRINT;        } else {            outputMode = mode;        }        metrics = new BlockMetrics(this);        setDefaultValues();    }    /**     * Resets the Metrics object.     */    private void resetMetrics() {        metrics.reset();    }    /**     * Initialises default values.     */    private void setDefaultValues() {        if (outputMode == PRINT) {            width = 550;            pageHeight = 600;            height = pageHeight;            alignmentUnit = PIXELS;            blockSpacing = 0;            emptySpace = 10;            emptySlotsShown = false;        } else if (outputMode == INTERLINEAR_TEXT) {            width = DEFAULT_NUM_CHARS;            height = 800;            pageHeight = height;            alignmentUnit = CHARACTERS;            emptySpace = 1;            emptySlotsShown = false;        } else if (outputMode == SHOEBOX_TEXT) {            width = DEFAULT_NUM_CHARS;            height = 800;            pageHeight = height;            alignmentUnit = BYTES;            emptySpace = 1;            emptySlotsShown = false;        } else {            // html            width = 800;            pageHeight = 800;            height = 800;            alignmentUnit = PIXELS;            emptySpace = 10;            emptySlotsShown = true;        }        tierLabelsShown = true;        blockWrapStyle = BLOCK_BOUNDARY;        lineWrapStyle = NEXT_LINE;        timeCodeShown = false;        timeCodeType = HHMMSSMS;        emptyLineStyle = HIDE_EMPTY_LINES;        sortingStyle = EXTERNALLY_SPECIFIED;        timeCodeMultiplicity = MULTIPLE_TIMECODE;        visibleTiers = new ArrayList();        // defaults for font and fontsizes        fonts = new HashMap();        fontSizes = new HashMap();        charEncodings = new HashMap();        // set default visible tiers to all tier names        if (transcription != null) {            visibleTiers.addAll(transcription.getTiers());            Iterator tierIt = visibleTiers.iterator();            TierImpl t;            while (tierIt.hasNext()) {                t = (TierImpl) tierIt.next();                if ((outputMode == PRINT) || (outputMode == HTML)) {                    setFont(t.getName(), DEFAULTFONT);                } else {                    setFont(t.getName(), MONOSPACED_FONT);                }                setFontSize(t.getName(), DEFAULT_FONT_SIZE);            }        }        loadPreferences();    }    /**     * Since Interlinear can be used with or withou a ui, this method should be     * called  by other objects: the ui/dialog it is in (on closing/disposing     * of the ui) or by the CommandAction that created this Interlinear     * object.     */    public void savePreferences() {        Preferences.set(prefSelectionOnly, new Boolean(selectionOnly),            transcription);        Preferences.set(prefBlockWrapStyle, blockWrapStyle, null);        Preferences.set(prefLabelsShown, new Boolean(tierLabelsShown), null);        Preferences.set(prefLineSpacing, lineSpacing, null);        Preferences.set(prefLineWrapStyle, lineWrapStyle, null);        Preferences.set(prefTierSortingStyle, sortingStyle, null);        Preferences.set(prefTimeCodeType, timeCodeType, null);        //  ordered, visible tiers        String[] tierNames = new String[visibleTiers.size()];        for (int i = 0; i < visibleTiers.size(); i++) {            tierNames[i] = ((Tier) visibleTiers.get(i)).getName();        }        Preferences.set(prefVisibleTiers, tierNames, transcription);        if (outputMode == PRINT) {            Preferences.set(prefFontSizes, fontSizes, transcription);            Preferences.set(prefBlockSpacing, blockSpacing, null);        } else if (outputMode == HTML) {            Preferences.set(prefFontSizes, fontSizes, transcription);            Preferences.set(prefHTMLPixWidth, getWidth(), null);            Preferences.set(prefBlockSpacingTextOut, blockSpacing, null);        } else {            Preferences.set(prefNumCharPerLine, width, null);            Preferences.set(prefBlockSpacingTextOut, blockSpacing, null);

⌨️ 快捷键说明

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