/* ======================================================================== * PlantUML : a free UML diagram generator * ======================================================================== * * (C) Copyright 2009-2014, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * * This file is part of PlantUML. * * Licensed under The MIT License (Massachusetts Institute of Technology License) * * See http://opensource.org/licenses/MIT * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * * Original Author: Arnaud Roques */ package net.sourceforge.plantuml.project2; import java.awt.geom.Dimension2D; import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UTranslate; class RowMerge implements Row { private final Row r1; private final Row r2; public RowMerge(Row r1, Row r2) { this.r1 = r1; this.r2 = r2; } public TextBlock asTextBloc(final TimeConverter timeConverter) { return new TextBlock() { public void drawU(UGraphic ug) { r1.asTextBloc(timeConverter).drawU(ug); r2.asTextBloc(timeConverter).drawU(ug.apply(new UTranslate(0, r1.getHeight()))); } public Dimension2D calculateDimension(StringBounder stringBounder) { final double width = getMaxXwithoutHeader(timeConverter) - getMinXwithoutHeader(timeConverter); final double height = getHeight(); return new Dimension2DDouble(width, height); } }; } public double getMinXwithoutHeader(TimeConverter timeConverter) { return Math.min(r1.getMinXwithoutHeader(timeConverter), r2.getMinXwithoutHeader(timeConverter)); } public double getMaxXwithoutHeader(TimeConverter timeConverter) { return Math.max(r1.getMaxXwithoutHeader(timeConverter), r2.getMaxXwithoutHeader(timeConverter)); } public double getHeight() { return r1.getHeight() + r2.getHeight(); } public TextBlock header() { return new TextBlock() { public void drawU(UGraphic ug) { r1.header().drawU(ug); r2.header().drawU(ug.apply(new UTranslate(0, r1.getHeight()))); } public Dimension2D calculateDimension(StringBounder stringBounder) { final double width = Math.max(r1.header().calculateDimension(stringBounder).getWidth(), r2.header() .calculateDimension(stringBounder).getWidth()); final double height = getHeight(); return new Dimension2DDouble(width, height); } }; } }