📄 blockmetrics.java
字号:
if ((i == 0) || (curOccup == 0)) { addToPrintTier(pt, curAnn); continue; } if ((xShift + blockwidth) <= availableWidth) { // ...if so, add to the block if (curOccup > 0) { curAnn.x += xShift; } addToPrintTier(pt, curAnn); } else { // ...else jump to the next block // remove empty lines of current block if (interlinearizer.getEmptyLineStyle() == Interlinear.HIDE_EMPTY_LINES) { currentBlock.removeEmptyTiers(); if (interlinearizer.isEmptySlotsShown()) { currentBlock.removeEmptySlotOnlyTiers(); } } printBlocks.add(currentBlock); //printoutPrintBlock(currentBlock); currentBlock = createPrintBlock(tierTemplate); pt = currentBlock.getPrintTier(curAnn.getTierName()); addToPrintTier(pt, curAnn); xShift = 0; } } else { if (leftovers.contains(curNode.getParent())) { leftovers.add(curNode); } else { // check if this annotation fits on this block // if the calcWidth > available width it is a sym-association annotation int relWidth = (curAnn.calcWidth > availableWidth) ? curAnn.realWidth : curAnn.calcWidth; if ((curAnn.x + relWidth + xShift) <= availableWidth) { curAnn.x += xShift; addToPrintTier(pt, curAnn); } else { leftovers.add(curNode); } } } } if (leftovers.size() == 0) { currentBlock.setOccupiedBlockWidth(currentBlock.getOccupiedBlockWidth() + interlinearizer.getEmptySpace() + blockwidth); // go to next annotation block continue; } else { //remove empty lines if (interlinearizer.getEmptyLineStyle() == Interlinear.HIDE_EMPTY_LINES) { currentBlock.removeEmptyTiers(); if (interlinearizer.isEmptySlotsShown()) { currentBlock.removeEmptySlotOnlyTiers(); } } printBlocks.add(currentBlock); //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) { // find the minimal x-pos of the annotations not yet added getXShiftPerTopNode(leftovers, shifts); //System.out.println("xShift: " + xShift); currentBlock = createPrintBlock(tierTemplate); ArrayList temp = new ArrayList(); 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); } } leftovers = temp; if (leftovers.size() > 0) { //remove empty lines and create a new block if (interlinearizer.getEmptyLineStyle() == Interlinear.HIDE_EMPTY_LINES) { currentBlock.removeEmptyTiers(); if (interlinearizer.isEmptySlotsShown()) { currentBlock.removeEmptySlotOnlyTiers(); } } printBlocks.add(currentBlock); //printoutPrintBlock(currentBlock); //currentBlock = createPrintBlock(tierTemplate); } else { // finish the block by calculating the current occupied horizontal block space currentBlock.setOccupiedBlockWidth(currentBlock.calculateOccupiedBlockWidth()); } } } // end annotations loop // fimally finish and add the last block, if needed if (!printBlocks.contains(currentBlock)) { if (interlinearizer.getEmptyLineStyle() == Interlinear.HIDE_EMPTY_LINES) { currentBlock.removeEmptyTiers(); if (interlinearizer.isEmptySlotsShown()) { currentBlock.removeEmptySlotOnlyTiers(); } } printBlocks.add(currentBlock); //printoutPrintBlock(currentBlock); } } /** * Wrap to a new 'block line' if the "root" annotation and it's first * children on each depending tier don't fit completely in the current * block. Else start adding to the current block. */ private void calcPrintBlocksWrapWithin() { printBlocks.clear(); InterlinearBlock currentBlock = createPrintBlock(tierTemplate); InterlinearTier pt = null; ArrayList leftovers = new ArrayList(); ArrayList firstChildren; DefaultMutableTreeNode curNode = null; InterlinearAnnotation curAnn = null; int availableWidth = interlinearizer.getWidth() - getLeftMargin(); int xShift = 0; // loop over the annotation blocks for (int i = 0; i < annotationBlocks.size(); i++) { leftovers.clear(); curNode = (DefaultMutableTreeNode) annotationBlocks.get(i); // calculate the max. realwidth of the root and first children int relMaxWidth = getMaximumWidthOfFirstChildren(curNode); firstChildren = getFirstChildrenOfRoot(curNode); 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) and relevant child annotations // fit 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(); } if ((i == 0) || (curOccup == 0)) { addToPrintTier(pt, curAnn); continue; } if ((xShift + relMaxWidth) <= availableWidth) { // ...if so, add to the block if (curOccup > 0) { curAnn.x += xShift; } addToPrintTier(pt, curAnn); } else { // ...else jump to the next block // remove empty lines of current block if (interlinearizer.getEmptyLineStyle() == Interlinear.HIDE_EMPTY_LINES) { currentBlock.removeEmptyTiers(); if (interlinearizer.isEmptySlotsShown()) { currentBlock.removeEmptySlotOnlyTiers(); } } printBlocks.add(currentBlock); //printoutPrintBlock(currentBlock); currentBlock = createPrintBlock(tierTemplate); pt = currentBlock.getPrintTier(curAnn.getTierName()); addToPrintTier(pt, curAnn); xShift = 0; } } else { if (leftovers.contains(curNode.getParent())) { leftovers.add(curNode); } else { // check if this annotation fits on this block // if the calcWidth > available width it is a sym-association annotation int relWidth = (curAnn.calcWidth > availableWidth) ? curAnn.realWidth : curAnn.calcWidth; if ((curAnn.x + relWidth + xShift) <= availableWidth) { curAnn.x += xShift; addToPrintTier(pt, curAnn); } else if (firstChildren.contains(curAnn)) { curAnn.x += xShift; addToPrintTier(pt, curAnn); } else { leftovers.add(curNode); } } } } if (leftovers.size() == 0) { currentBlock.setOccupiedBlockWidth(currentBlock.getOccupiedBlockWidth() + interlinearizer.getEmptySpace() + blockwidth); // go to next annotation block continue; } else { //remove empty lines if (interlinearizer.getEmptyLineStyle() == Interlinear.HIDE_EMPTY_LINES) { currentBlock.removeEmptyTiers(); if (interlinearizer.isEmptySlotsShown()) { currentBlock.removeEmptySlotOnlyTiers(); } } printBlocks.add(currentBlock); //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) { // find the minimal x-pos of the annotations not yet added getXShiftPerTopNode(leftovers, shifts); //System.out.println("xShift: " + xShift); currentBlock = createPrintBlock(tierTemplate); ArrayList temp = new ArrayList(); 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); } } leftovers = temp; if (leftovers.size() > 0) { //remove empty lines and create a new block if (interlinearizer.getEmptyLineStyle() == Interlinear.HIDE_EMPTY_LINES) { currentBlock.removeEmptyTiers(); if (interlinearizer.isEmptySlotsShown()) { currentBlock.removeEmptySlotOnlyTiers(); } } printBlocks.add(currentBlock); //printoutPrintBlock(currentBlock); //currentBlock = createPrintBlock(tierTemplate); } else { // finish the block by calculating the current occupied horizontal block space currentBlock.setOccupiedBlockWidth(currentBlock.calculateOccupiedBlockWidth()); } } } // end annotati
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -