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

📄 metrics.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * File:     Metrics.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 *//* * Created on Sep 24, 2004 * */package mpi.eudico.server.corpora.clomimpl.shoebox.interlinear;import mpi.eudico.server.corpora.clom.Annotation;import java.util.Arrays;import java.util.Collection;import java.util.Collections;import java.util.Comparator;import java.util.Enumeration;import java.util.HashSet;import java.util.Hashtable;import java.util.Iterator;import java.util.List;import java.util.Set;import java.util.Vector;/** * Metrics is a data container for storage and transfer of size and position * information. It is used by Interlinearizer during the generation of * interlinear views of Transcription objects. * * @author hennie */public class Metrics {    private TimeCodedTranscription transcription;    private Interlinearizer interlinearizer;    private Hashtable sizeTable;    private Hashtable usedWidthTable;    private Hashtable horizontalPositions;    private Hashtable verticalPositions;    private Hashtable tierHeights;    private Vector blockWiseOrdered; // annotations sorted on hor. pos and tier hierarchy    private Vector verticallyOrdered; // annotations sorted on vertical position    private int leftMargin;    private boolean leftMarginOn = false;    /**     * Creates a new Metrics instance     *     * @param tr DOCUMENT ME!     * @param interlinearizer DOCUMENT ME!     */    public Metrics(TimeCodedTranscription tr, Interlinearizer interlinearizer) {        transcription = tr;        this.interlinearizer = interlinearizer;        sizeTable = new Hashtable();        usedWidthTable = new Hashtable();        horizontalPositions = new Hashtable();        verticalPositions = new Hashtable();        tierHeights = new Hashtable();    }    /**     * DOCUMENT ME!     */    public void reset() {        sizeTable.clear();        usedWidthTable.clear();        horizontalPositions.clear();        verticalPositions.clear();        tierHeights.clear();        blockWiseOrdered = null;        verticallyOrdered = null;    }    /**     * DOCUMENT ME!     *     * @param annot DOCUMENT ME!     * @param size DOCUMENT ME!     */    public void setSize(Annotation annot, int size) {        sizeTable.put(annot, new Integer(size));    }    /**     * DOCUMENT ME!     *     * @param annot DOCUMENT ME!     *     * @return DOCUMENT ME!     */    public int getSize(Annotation annot) {        int size = 0;        Integer intSize = (Integer) sizeTable.get(annot);        if (intSize != null) {            size = intSize.intValue();        }        return size;    }    /**     * DOCUMENT ME!     *     * @param annot DOCUMENT ME!     * @param width DOCUMENT ME!     */    public void setUsedWidth(Annotation annot, int width) {        usedWidthTable.put(annot, new Integer(width));    }    /**     * DOCUMENT ME!     *     * @param annot DOCUMENT ME!     *     * @return DOCUMENT ME!     */    public int getUsedWidth(Annotation annot) {        int usedWidth = 0;        Integer intWidth = (Integer) usedWidthTable.get(annot);        if (intWidth != null) {            usedWidth = intWidth.intValue();        }        return usedWidth;    }    /**     * DOCUMENT ME!     *     * @param annot DOCUMENT ME!     * @param hPos DOCUMENT ME!     */    public void setHorizontalPosition(Annotation annot, int hPos) {        horizontalPositions.put(annot, new Integer(hPos));    }    /**     * DOCUMENT ME!     *     * @param annot DOCUMENT ME!     *     * @return DOCUMENT ME!     */    public int getHorizontalPosition(Annotation annot) {        int hPos = 0;        Integer intHPos = (Integer) horizontalPositions.get(annot);        if (intHPos != null) {            hPos = intHPos.intValue();        }        return hPos;    }    /**     * DOCUMENT ME!     *     * @param annot DOCUMENT ME!     * @param vPos DOCUMENT ME!     */    public void setVerticalPosition(Annotation annot, int vPos) {        verticalPositions.put(annot, new Integer(vPos));    }    /**     * Sets initial (before any wrapping takes place) position of  annotation     * on basis of tier heights.     *     * @param annot     */    public void setVerticalPosition(Annotation annot) {        int vPos = 0;        String tierName = annot.getTier().getName();        String[] visibleTiers = getInterlinearizer().getVisibleTiers();        for (int i = 0; i < visibleTiers.length; i++) {            if (tierName.equals(visibleTiers[i])) {                vPos += getTierHeight(visibleTiers[i]);                break;            } else {                vPos += (getTierHeight(visibleTiers[i]) +                getInterlinearizer().getLineSpacing());            }        }        verticalPositions.put(annot, new Integer(vPos));    }    /**     * DOCUMENT ME!     *     * @param annot DOCUMENT ME!     *     * @return DOCUMENT ME!     */    public int getVerticalPosition(Annotation annot) {        int vPos = 0;        Integer intVPos = (Integer) verticalPositions.get(annot);        if (intVPos != null) {            vPos = intVPos.intValue();        }        return vPos;    }    /**     * DOCUMENT ME!     *     * @return DOCUMENT ME!     */    public int getMaxVerticalPosition() {        int maxPosition = 0;        Collection c = verticalPositions.values();        Iterator cIter = c.iterator();        while (cIter.hasNext()) {            int vPos = ((Integer) cIter.next()).intValue();            if (vPos > maxPosition) {                maxPosition = vPos;            }        }        return maxPosition;    }    /**     * DOCUMENT ME!     *     * @return DOCUMENT ME!     */    public int getMaxHorizontallyUsedWidth() {        int maxHUsed = 0;        int hpos = 0;        int usedWidth = 0;        Annotation a = null;        Enumeration en = horizontalPositions.keys();        while (en.hasMoreElements()) {            a = (Annotation) en.nextElement();            hpos = ((Integer) horizontalPositions.get(a)).intValue();            usedWidth = ((Integer) usedWidthTable.get(a)).intValue();            if ((hpos + usedWidth) > maxHUsed) {                maxHUsed = hpos + usedWidth;            }        }        return maxHUsed + getLeftMargin();    }    /**     * DOCUMENT ME!     *     * @param tierName DOCUMENT ME!     * @param tierHeight DOCUMENT ME!     */    public void setTierHeight(String tierName, int tierHeight) {        tierHeights.put(tierName, new Integer(tierHeight));    }    /**     * DOCUMENT ME!     *     * @param forTier DOCUMENT ME!     *     * @return DOCUMENT ME!     */    public int getTierHeight(String forTier) {        Integer i = (Integer) tierHeights.get(forTier);        if (i != null) {            return i.intValue();        } else {            return 0;        }    }    /**     * Calculates total height of all visible tiers, plus potential additional     * line spacing (total height of 'tier bundle').     *     * @return total height     */    public int getCumulativeTierHeights() {        int totalHeight = 0;        Collection heights = tierHeights.values();        Iterator hIter = heights.iterator();        while (hIter.hasNext()) {            totalHeight += ((Integer) hIter.next()).intValue();        }        int numOfVisibleTiers = getInterlinearizer().getVisibleTiers().length;        totalHeight += (numOfVisibleTiers * getInterlinearizer().getLineSpacing());        return totalHeight;    }    /**     * Derives list of vertical (Integer) positions on basis of the vertical     * positions of all annotations (after position and wrapping).     *     * @return Vector with Integers for unique vertical positions of tiers     */    public Vector getPositionsOfNonEmptyTiers() {        Collection c = verticalPositions.values();        return new Vector(new HashSet(c));    }    /**     * DOCUMENT ME!     *     * @param position DOCUMENT ME!     *     * @return DOCUMENT ME!

⌨️ 快捷键说明

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