private void printAndUpdateIndex( DrawHandler drawer, RelationPointHandler relationPoints, PointDouble pointText, int index, String text, Set<Integer> usedIndexes) { drawer.print(text, pointText, AlignHorizontal.LEFT); // to make sure text is printed (and therefore withing relation-element-borders, resize relation // according to text relationPoints.setTextBox( index, new Rectangle( pointText.getX(), pointText.getY() - drawer.textHeightMax(), drawer.textWidth(text), drawer.textHeightMax())); usedIndexes.add(index); }
@Override public void parsingFinished(PropertiesParserState state, List<String> handledLines) { Map<String, Point> displacements = state.getOrInitFacetResponse( LineDescriptionPositionFacet.class, new HashMap<String, Point>()); RelationPointHandler relationPoints = getRelationPoints(state); DrawHandler drawer = state.getDrawer(); Set<Integer> usedIndexes = new HashSet<Integer>(); List<String> middleLines = new ArrayList<String>(); List<String> otherLines = new ArrayList<String>(); for (String line : handledLines) { if (LineDescriptionEnum.forString(line) == LineDescriptionEnum.MESSAGE_MIDDLE) { middleLines.add(line); } else { otherLines.add(line); } } double halfMiddleBlockHeight = middleLines.size() * drawer.textHeightMaxWithSpace() / 2; // because vertical text blocks should be centered, the half of the total text // block must be subtracted for (int i = 0; i < middleLines.size(); i++) { String line = LineDescriptionUtils.replaceArrowsWithUtf8Characters(middleLines.get(i)); PointDouble pointText = LineDescriptionUtils.calcPosOfMiddleText( drawer, line, relationPoints.getMiddleLine(), i, halfMiddleBlockHeight); int index = LineDescriptionEnum.MESSAGE_MIDDLE.getIndex() + i; // middle index is increased by the amount of middle text lines printAndUpdateIndex(drawer, relationPoints, pointText, index, line, usedIndexes); } for (String line : otherLines) { LineDescriptionEnum enumVal = LineDescriptionEnum.forString(line); String[] split = line.split(KeyValueFacet.SEP, -1); String text = split[1]; if (!text.isEmpty()) { PointDouble pointText = LineDescriptionUtils.calcPosOfEndText(drawer, text, relationPoints, enumVal); printAndUpdateIndex( drawer, relationPoints, pointText, enumVal.getIndex(), text, displacements.get(enumVal.getKey()), usedIndexes); } } // all unused textboxes must be reset to default size (to make sure the relation size is correct // even if LineDescriptionFacet is never called) relationPoints.resetTextBoxIndexesExcept(usedIndexes); relationPoints .resizeRectAndReposPoints(); // apply the (possible) changes now to make sure the following // facets use correct coordinates }