📄 blockmetrics.java
字号:
*/ private void splitAnnotation(InterlinearAnnotation prAnn, int available) { String val = prAnn.getValue(); if ((val.indexOf(SPACE_CHAR) < 0) || (val.length() < available)) { return; } ArrayList vals = new ArrayList(); String sub = null; while (val.length() > available) { sub = val.substring(0, available); int breakSpace = sub.lastIndexOf(SPACE_CHAR); if (breakSpace < 0) { breakSpace = val.indexOf(SPACE_CHAR); if (breakSpace < 0) { vals.add(val); break; } else { vals.add(val.substring(0, breakSpace + 1)); val = val.substring(breakSpace + 1); } } else { vals.add(sub.substring(0, breakSpace + 1)); val = val.substring(breakSpace + 1); } if (val.length() <= available) { vals.add(val); break; } } // if there are more than one line if (vals.size() > 1) { prAnn.setLines((String[]) vals.toArray(new String[] { })); // ?? is this right, or calc the max length of the strings? prAnn.calcWidth = available; prAnn.realWidth = available; } } /** * Creates a unique label for a timecode 'tier', based on the name of the * root tier or toplevel tier and only used internally. * * @param tierName the name of the top level tier * * @return a String in the form 'tiername'+ '-' + 'TC' */ private String createTCLabel(String tierName) { if (tierName == null) { return null; } String label = tierName + "-" + TC_TIER_NAME; if (transcription.getTierWithId(label) == null) { return label; } else { for (int i = 0; i < 10; i++) { String nl = label + i; if (transcription.getTierWithId(nl) == null) { return nl; } } } return null; } /** * Create a template print block; this is a block with a InterlinearTier * for every tie in the specified List. Print annotation can then be added * to this print block. Depending on the 'empty line style' parameter, * empty tiers/lines can be deleted to finish the block. * * @param names a List of visible tier (+time code tier) names * * @return a template <code>InterlinearBlock</code> */ private InterlinearBlock createPrintBlock(ArrayList names) { if (names == null) { return null; } ArrayList printTiers = new ArrayList(names.size()); int height; InterlinearTier pt = null; for (int i = 0; i < names.size(); i++) { String tierName = (String) names.get(i); pt = new InterlinearTier(tierName); pt.setMarginWidth(getLeftMargin()); //height = interlinearizer.getFontSize(tierName); height = getTierHeight(tierName); if (height != 0) { pt.setPrintHeight(height); } if (timecodeLabels.containsValue(tierName)) { pt.setTimeCode(true); } printTiers.add(pt); } if (printTiers.size() > 0) { return new InterlinearBlock(printTiers); } return null; } /** * Add all annotations to one block, without applying any wrapping. */ private void calcPrintBlocksNoWrap() { printBlocks.clear(); InterlinearBlock currentBlock = createPrintBlock(tierTemplate); DefaultMutableTreeNode curNode = null; InterlinearAnnotation curAnn = null; // loop over annotation blocks for (int i = 0; i < annotationBlocks.size(); i++) { curNode = (DefaultMutableTreeNode) annotationBlocks.get(i); curAnn = (InterlinearAnnotation) curNode.getUserObject(); int w = curAnn.calcWidth; Enumeration en = curNode.breadthFirstEnumeration(); while (en.hasMoreElements()) { curNode = (DefaultMutableTreeNode) en.nextElement(); curAnn = (InterlinearAnnotation) curNode.getUserObject(); InterlinearTier pt = currentBlock.getPrintTier(curAnn.getTierName()); int cur = pt.getPrintAdvance(); if (cur != 0) { curAnn.x = cur + interlinearizer.getEmptySpace(); } addToPrintTier(pt, curAnn); } if (i == 0) { currentBlock.setOccupiedBlockWidth(w); } else { currentBlock.setOccupiedBlockWidth(currentBlock.getOccupiedBlockWidth() + interlinearizer.getEmptySpace() + w); } } //remove empty lines if (interlinearizer.getEmptyLineStyle() == Interlinear.HIDE_EMPTY_LINES) { currentBlock.removeEmptyTiers(); if (interlinearizer.isEmptySlotsShown()) { currentBlock.removeEmptySlotOnlyTiers(); } } // print out block //printoutPrintBlock(currentBlock); printBlocks.add(currentBlock); } /** * Wrap to a new 'block line' for every new annotation block. This means * that every next toplevel annotation starts on a new 'block line'. */ private void calcPrintBlocksWrapEach() { printBlocks.clear(); InterlinearBlock currentBlock = null; InterlinearTier pt = null; ArrayList leftovers = new ArrayList(); DefaultMutableTreeNode curNode = null; InterlinearAnnotation curAnn = null; int availableWidth = interlinearizer.getWidth() - getLeftMargin(); // loop over annotation blocks for (int i = 0; i < annotationBlocks.size(); i++) { // start a new print block for every annotation block currentBlock = createPrintBlock(tierTemplate); printBlocks.add(currentBlock); leftovers.clear(); curNode = (DefaultMutableTreeNode) annotationBlocks.get(i); Enumeration en = curNode.breadthFirstEnumeration(); while (en.hasMoreElements()) { curNode = (DefaultMutableTreeNode) en.nextElement(); curAnn = (InterlinearAnnotation) curNode.getUserObject(); pt = currentBlock.getPrintTier(curAnn.getTierName()); if (curNode.isRoot()) { addToPrintTier(pt, curAnn); } else { if (leftovers.contains(curNode.getParent())) { leftovers.add(curNode); } else if (curAnn.calcWidth > availableWidth) { // symbolic association of root? if ((curAnn.x + curAnn.realWidth) <= availableWidth) { addToPrintTier(pt, curAnn); } else { leftovers.add(curNode); } } else if ((curAnn.x + curAnn.calcWidth) <= availableWidth) { // add if it fits addToPrintTier(pt, curAnn); } else { // add to leftovers for next blocks leftovers.add(curNode); } } } //remove empty lines if (interlinearizer.getEmptyLineStyle() == Interlinear.HIDE_EMPTY_LINES) { currentBlock.removeEmptyTiers(); if (interlinearizer.isEmptySlotsShown()) { currentBlock.removeEmptySlotOnlyTiers(); } //printoutPrintBlock(currentBlock); } // the annotations that have not been placed, wrap to next blocks // reuse a map of per tier shift values HashMap shifts = new HashMap(); while (leftovers.size() > 0) { // first find the lowest x-pos of the annotations not yet added int xShift; getXShiftPerTopNode(leftovers, shifts); // start with a new block and add as much as possible currentBlock = createPrintBlock(tierTemplate); ArrayList temp = new ArrayList(); // next leftovers for (int k = 0; k < leftovers.size(); k++) { curNode = (DefaultMutableTreeNode) leftovers.get(k); if (temp.contains(curNode.getParent())) { temp.add(curNode); continue; } curAnn = (InterlinearAnnotation) curNode.getUserObject(); pt = currentBlock.getPrintTier(curAnn.getTierName()); xShift = ((Integer) shifts.get(curAnn.getTierName())).intValue(); //int curAdv = pt.getPrintAdvance(); if (((curAnn.x + curAnn.calcWidth) - xShift) <= availableWidth) { // adjust x-pos and add curAnn.x -= xShift; addToPrintTier(pt, curAnn); } else if (curAnn.calcWidth > availableWidth) { // is an error: to prevent endless loop add it just the same curAnn.x -= xShift; addToPrintTier(pt, curAnn); } else { // add for next block temp.add(curNode); } } //remove empty lines if (interlinearizer.getEmptyLineStyle() == Interlinear.HIDE_EMPTY_LINES) { currentBlock.removeEmptyTiers(); if (interlinearizer.isEmptySlotsShown()) { currentBlock.removeEmptySlotOnlyTiers(); } } printBlocks.add(currentBlock); //printoutPrintBlock(currentBlock); leftovers = temp; } } } /** * Wrap to a new 'block line' if the whole block does not fit completely in * the current block. This means that a block of annotations is kept * together on one 'block line' as much as possible. */ private void calcPrintBlocksWrapBoundary() { printBlocks.clear(); InterlinearBlock currentBlock = createPrintBlock(tierTemplate); InterlinearTier pt = null; ArrayList leftovers = new ArrayList(); DefaultMutableTreeNode curNode = null; InterlinearAnnotation curAnn = null; int availableWidth = interlinearizer.getWidth() - getLeftMargin(); int xShift = 0; // loop over annotation blocks for (int i = 0; i < annotationBlocks.size(); i++) { leftovers.clear(); curNode = (DefaultMutableTreeNode) annotationBlocks.get(i); int blockwidth = 0; int curOccup = 0; Enumeration en = curNode.breadthFirstEnumeration(); while (en.hasMoreElements()) { curNode = (DefaultMutableTreeNode) en.nextElement(); curAnn = (InterlinearAnnotation) curNode.getUserObject(); pt = currentBlock.getPrintTier(curAnn.getTierName()); if (curNode.isRoot()) { // check if the root (== block) fits in the space left in the current block blockwidth = curAnn.calcWidth; if (blockwidth > availableWidth) { blockwidth = availableWidth; } curOccup = currentBlock.getOccupiedBlockWidth(); if (curOccup > 0) { xShift = curOccup + interlinearizer.getEmptySpace(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -