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

📄 blockmetrics.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        case Interlinear.EACH_BLOCK:            calcPrintBlocksWrapEach();            break;        case Interlinear.BLOCK_BOUNDARY:            calcPrintBlocksWrapBoundary();            break;        case Interlinear.WITHIN_BLOCKS:            calcPrintBlocksWrapWithin();            break;        case Interlinear.NO_WRAP:            calcPrintBlocksNoWrap();            break;        default:}        //test        /*        if (printBlocks.size() > 0) {            printHTML((InterlinearBlock)printBlocks.get(0));            for (int i = 0; i < printBlocks.size(); i++) {                printoutPrintBlock((InterlinearBlock)printBlocks.get(i));            }        }        */        if (interlinearizer.getOutputMode() == Interlinear.HTML) {            addHiddenCellsAndColSpan();        }    }    /**     * Page breaks are stored as an array of four integers: the first index is     * the first InterlinearBlock index, the second index is the index of the     * first line  within that block. The third index is the index of the last     * InterlinearBlock on the page  and the fourth index is the index of the     * last line in that block that fits on the  page. All indices are zero     * based.  For text based output there is only one page break object. In     * that case  the total height is calculated just for preview painting.     */    public void calculatePageBreaks() {        pageBreaks.clear();        if (printBlocks.size() == 0) {            return;        }        InterlinearBlock curBlock = null;        ArrayList printTiers = null;        int curPageHeight = 0;        if ((interlinearizer.getOutputMode() == Interlinear.INTERLINEAR_TEXT) ||                (interlinearizer.getOutputMode() == Interlinear.SHOEBOX_TEXT)) {            for (int block = 0; block < printBlocks.size(); block++) {                curBlock = (InterlinearBlock) printBlocks.get(block);                curPageHeight += (curBlock.getNumberOfLines() * Interlinear.DEFAULT_FONT_SIZE);                curPageHeight += (interlinearizer.getBlockSpacing() * Interlinear.DEFAULT_FONT_SIZE);            }            interlinearizer.setHeight(curPageHeight);            // it is just one page            curBlock = (InterlinearBlock) printBlocks.get(printBlocks.size() -                    1);            pageBreaks.add(new int[] {                    0, 0, printBlocks.size() - 1,                    curBlock.getNumberOfLines() - 1                });            return;        }        int pageHeight = interlinearizer.getPageHeight();        //System.out.println("Page height: " + pageHeight);               int beginBlock = 0;        int beginLine = 0;        int line = 0;        InterlinearTier curTier = null;        for (int block = 0; block < printBlocks.size(); block++) {            curBlock = (InterlinearBlock) printBlocks.get(block);            printTiers = curBlock.getPrintTiers();            line = 0;            for (int j = 0; j < printTiers.size(); j++) {                curTier = (InterlinearTier) printTiers.get(j);                for (int k = 0; k < curTier.getNumLines(); k++) {                    curPageHeight += curTier.getPrintHeight();                    //System.out.println("Height after: " + curTier.getTierName() + " line: " + k + " = " + curPageHeight);                    if (curPageHeight > pageHeight) {                        // add a new pagebreak                        if ((line == 0) && (block > 0)) {                            // if the first line of a block does not fit                             // the last line of the previous block is the last on the page                            InterlinearBlock prev = (InterlinearBlock) printBlocks.get(block -                                    1);                            pageBreaks.add(new int[] {                                    beginBlock, beginLine, block - 1,                                    prev.getNumberOfLines() - 1                                });                            //System.out.println("Add break after block: " + beginBlock + " - " + beginLine + " - " +                            //	(block - 1) + " - " + (prev.getNumberOfLines() - 1) + "(" + curPageHeight + ")" + " tier: " + curTier.getTierName());                        } else {                            pageBreaks.add(new int[] {                                    beginBlock, beginLine, block, line - 1                                });                            //System.out.println("Add break in block: " + beginBlock + " - " + beginLine + " - " +                            //	(block) + " - " + (line - 1) + "(" + curPageHeight + ")" + " tier: " + curTier.getTierName());                        }                        beginBlock = block;                        beginLine = line;                        curPageHeight = curTier.getPrintHeight();                    }                    // don't add line spacing after the last line in a tier                    if (k != (curTier.getNumLines() - 1)) {                        curPageHeight += interlinearizer.getLineSpacing();                    }                    line++;                }                // don't add line spacing after the last tier in a block                 if (j != (printTiers.size() - 1)) {                    curPageHeight += interlinearizer.getLineSpacing();                }            }            if (block != (printBlocks.size() - 1)) {                // add block spacing                curPageHeight += interlinearizer.getBlockSpacing();            } else {                // add a break after the last block                pageBreaks.add(new int[] { beginBlock, beginLine, block, line -                        1 });                //System.out.println("Add final break: " + beginBlock + " - " + beginLine + " - " +                //(block) + " - " + (line - 1) + " tier: " + curTier.getTierName());            }        }    }    /**     * Returns a List of <code>InterlinearBlock</code> (a.k.a PrintBlock)     * objects.     *     * @return a List of <code>InterlinearBlock</code> objects     */    public ArrayList getPrintBlocks() {        return printBlocks;    }    /**     * Returns a List of page break objects. A page break object is an aaray of     * four integers: the first block (index), the first line (index) in that     * block, the last block (index) and the last line (index) in that block     *     * @return a List of page break objects     */    public ArrayList getPageBreaks() {        return pageBreaks;    }    /**     * Sends the contents of InterlinearAnnotation objects in a node or tree to     * standard out. For testing.     *     * @param node the (root) node holding a <code>InterlinearAnnotation</code>     *        object     */    private void printoutNode(DefaultMutableTreeNode node) {        if (node == null) {            return;        }        Enumeration nodeEnum = node.breadthFirstEnumeration();        DefaultMutableTreeNode curNode;        InterlinearAnnotation prann;        while (nodeEnum.hasMoreElements()) {            curNode = (DefaultMutableTreeNode) nodeEnum.nextElement();            prann = (InterlinearAnnotation) curNode.getUserObject();            System.out.println("T: " + prann.getTierName() + " A: " +                prann.getValue() + " X: " + prann.x + " C: " + prann.calcWidth +                " R: " + prann.realWidth);            if (prann.nrOfLines > 1) {                System.out.println("Num lines: " + prann.nrOfLines);                for (int i = 0; i < prann.nrOfLines; i++) {                    System.out.println("" + i + " " + prann.getLines()[i]);                }            }        }    }    /**     * Sends the contents of a InterlinearBlock object to standard out. For     * testing     *     * @param block a <code>InterlinearBlock</code> object     */    private void printoutPrintBlock(InterlinearBlock block) {        if (block == null) {            return;        }        System.out.println("New block:");        ArrayList pts = block.getPrintTiers();        for (int i = 0; i < pts.size(); i++) {            InterlinearTier pt = (InterlinearTier) pts.get(i);            System.out.println("Tier: " + pt.getTierName());            ArrayList anns = pt.getAnnotations();            for (int j = 0; j < anns.size(); j++) {                InterlinearAnnotation pa = (InterlinearAnnotation) anns.get(j);                if (pa.nrOfLines > 1) {                    System.out.println("A: " + pa.getLines()[0]);                    for (int k = 1; k < pa.nrOfLines; k++) {                        System.out.println("..." + pa.getLines()[k]);                    }                } else {                    System.out.println("A: " + pa.getValue());                }                System.out.println("\tX: " + pa.x + " W: " + pa.calcWidth);            }        }    }    /*       private void calculateTierHeightsAndMargin(Graphics g) {           int maxTierLabelWidth = 0;           Tier t;           String name = null;           Font font = null;           FontMetrics fontMetrics = null;           // iterate over visible tiers           for (int i = 0; i < visibleTiers.size(); i++) {               t = (Tier) visibleTiers.get(i);               name = "";               try {                   name = t.getName();               } catch (RemoteException re) {               }               font = interlinearizer.getFont(name);               fontMetrics = g.getFontMetrics(font);                  int tierHeight = fontMetrics.getHeight();                  setTierHeight(name, tierHeight);                  if (fontMetrics.stringWidth(name) > maxTierLabelWidth) {                      maxTierLabelWidth = fontMetrics.stringWidth(name);                  }              }              setLeftMargin(maxTierLabelWidth + interlinearizer.getEmptySpace());          }     */    /**     * Calculates sizes and positions of annotations in one block, using the     * specified  Graphics object for measurements.     *     * @param rootNode the root node holding the root annotation     * @param g the <code>Graphics</code> object     */    private void calculateBlock(DefaultMutableTreeNode rootNode, Graphics g) {        if ((rootNode == null) ||                ((g == null) &&                (interlinearizer.getAlignmentUnit() == Interlinear.PIXELS))) {            return;        }        //Enumeration enum = rootNode.depthFirstEnumeration();        Enumeration en = rootNode.breadthFirstEnumeration();        ArrayList allNodes = new ArrayList();        Font font = null;        FontMetrics fontMetrics = null;        DefaultMutableTreeNode curNode = null;        DefaultMutableTreeNode otherNode = null;        InterlinearAnnotation curAnn = null;        InterlinearAnnotation otherAnn = null;        boolean includeRootInCalculations = true;        int availableWidth = interlinearizer.getWidth() - getLeftMargin();        // System.out.println("PR width: " + availableWidth);        // first calculate real widths        while (en.hasMoreElements()) {            curNode = (DefaultMutableTreeNode) en.nextElement();            curAnn = (InterlinearAnnotation) curNode.getUserObject();            if (curNode == rootNode) {                if (!visibleTiers.contains(transcription.getTierWithId(                                curAnn.getTierName()))) {                    includeRootInCalculations = false;                }            }            int size = 0;            if (interlinearizer.getAlignmentUnit() == Interlinear.PIXELS) {                if (curAnn.type == InterlinearAnnotation.TIMECODE) {                    //font = Interlinear.DEFAULTFONT.deriveFont((float) Interlinear.TIMECODE_FONT_SIZE);                    font = interlinearizer.getFont(curAnn.getTierName());                } else {                    font = interlinearizer.getFont(curAnn.getTierName());                }                fontMetrics = g.getFontMetrics(font);                // ensure a mininmal width of "empty space"?                size = Math.max(fontMetrics.stringWidth(curAnn.getValue()),                        interlinearizer.getEmptySpace());            } else {                size = curAnn.getValue().length();            }            if (curNode.isRoot() && !includeRootInCalculations) {                curAnn.realWidth = 0;                curAnn.calcWidth = 0;            } else {                curAnn.realWidth = size;                curAnn.calcWidth = size;            }            // check wrapping params and wrap if needed            if ((interlinearizer.getBlockWrapStyle() != Interlinear.NO_WRAP) &&                    (interlinearizer.getLineWrapStyle() == Interlinear.NEXT_LINE)) {

⌨️ 快捷键说明

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