1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-01 08:00:48 +00:00
plantuml/src/net/sourceforge/plantuml/skin/rose/ComponentRoseNote.java

109 lines
3.4 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
2011-08-08 17:48:29 +00:00
* Revision $Revision: 6590 $
2010-11-15 20:35:36 +00:00
*
*/
package net.sourceforge.plantuml.skin.rose;
import java.awt.geom.Dimension2D;
import java.util.List;
import net.sourceforge.plantuml.graphic.HorizontalAlignement;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.graphic.HtmlColor;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.skin.AbstractTextualComponent;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.ugraphic.UFont;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.ULine;
import net.sourceforge.plantuml.ugraphic.UPolygon;
final public class ComponentRoseNote extends AbstractTextualComponent {
private final int cornersize = 10;
2011-08-08 17:48:29 +00:00
private final HtmlColor back;
private final HtmlColor foregroundColor;
2010-11-15 20:35:36 +00:00
2011-08-08 17:48:29 +00:00
public ComponentRoseNote(HtmlColor back, HtmlColor foregroundColor, HtmlColor fontColor, UFont font,
2010-11-15 20:35:36 +00:00
List<? extends CharSequence> strings) {
super(strings, fontColor, font, HorizontalAlignement.LEFT, 6, 15, 5);
this.back = back;
this.foregroundColor = foregroundColor;
}
@Override
final public double getPreferredWidth(StringBounder stringBounder) {
final double result = getTextWidth(stringBounder) + 2 * getPaddingX();
return result;
}
@Override
final public double getPreferredHeight(StringBounder stringBounder) {
return getTextHeight(stringBounder) + 2 * getPaddingY();
}
@Override
public double getPaddingX() {
return 5;
}
@Override
public double getPaddingY() {
return 5;
}
@Override
protected void drawInternalU(UGraphic ug, Dimension2D dimensionToUse) {
final StringBounder stringBounder = ug.getStringBounder();
final int textHeight = (int) getTextHeight(stringBounder);
final int x2 = (int) getTextWidth(stringBounder);
final UPolygon polygon = new UPolygon();
polygon.addPoint(0, 0);
polygon.addPoint(0, textHeight);
polygon.addPoint(x2, textHeight);
polygon.addPoint(x2, cornersize);
polygon.addPoint(x2 - cornersize, 0);
polygon.addPoint(0, 0);
ug.getParam().setColor(foregroundColor);
ug.getParam().setBackcolor(back);
ug.draw(0, 0, polygon);
ug.draw(x2 - cornersize, 0, new ULine(0, cornersize));
ug.draw(x2, cornersize, new ULine(-cornersize, 0));
getTextBlock().drawU(ug, getMarginX1(), getMarginY());
}
}