1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-06 10:20:54 +00:00
plantuml/src/net/sourceforge/plantuml/graph/MethodsOrFieldsArea2.java

160 lines
5.4 KiB
Java
Raw Normal View History

2010-11-25 21:12:39 +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
*
* Revision $Revision: 5608 $
*
*/
package net.sourceforge.plantuml.graph;
import java.awt.Graphics2D;
import java.awt.geom.Dimension2D;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.sourceforge.plantuml.Dimension2DDouble;
import net.sourceforge.plantuml.FontParam;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.cucadiagram.Member;
2011-01-23 19:36:52 +00:00
import net.sourceforge.plantuml.graphic.FontConfiguration;
2010-11-25 21:12:39 +00:00
import net.sourceforge.plantuml.graphic.HorizontalAlignement;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.graphic.HtmlColor;
2010-11-25 21:12:39 +00:00
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.graphic.TextBlockUtils;
import net.sourceforge.plantuml.skin.VisibilityModifier;
import net.sourceforge.plantuml.skin.rose.Rose;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.ugraphic.ColorMapper;
2010-11-25 21:12:39 +00:00
import net.sourceforge.plantuml.ugraphic.PlacementStrategyVisibility;
import net.sourceforge.plantuml.ugraphic.PlacementStrategyY1Y2Left;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.ugraphic.UFont;
2010-11-25 21:12:39 +00:00
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UGroup;
2011-09-07 20:41:58 +00:00
public class MethodsOrFieldsArea2 implements TextBlock {
2010-11-25 21:12:39 +00:00
2011-08-08 17:48:29 +00:00
private final UFont font;
2010-11-25 21:12:39 +00:00
private final List<Member> members = new ArrayList<Member>();
private final ISkinParam skinParam;
2011-08-08 17:48:29 +00:00
private final HtmlColor color;
2010-11-25 21:12:39 +00:00
private final Rose rose = new Rose();
public MethodsOrFieldsArea2(List<Member> attributes, FontParam fontParam, ISkinParam skinParam) {
this.members.addAll(attributes);
this.skinParam = skinParam;
2011-01-05 18:23:06 +00:00
this.font = skinParam.getFont(fontParam, null);
2010-11-25 21:12:39 +00:00
this.color = rose.getFontColor(skinParam, FontParam.CLASS_ATTRIBUTE);
}
private boolean hasSmallIcon() {
for (Member m : members) {
if (m.getVisibilityModifier() != null) {
return true;
}
}
return false;
}
public Dimension2D calculateDimension(StringBounder stringBounder) {
double x = 0;
double y = 0;
for (Member m : members) {
final String s = m.getDisplayWithoutVisibilityChar();
final TextBlock bloc = createTextBlock(s);
final Dimension2D dim = bloc.calculateDimension(stringBounder);
y += dim.getHeight();
x = Math.max(dim.getWidth(), x);
}
if (hasSmallIcon()) {
2011-09-07 20:41:58 +00:00
x += skinParam.getCircledCharacterRadius() + 3;
2010-11-25 21:12:39 +00:00
}
return new Dimension2DDouble(x, y);
}
private TextBlock createTextBlock(String s) {
2011-01-23 19:36:52 +00:00
return TextBlockUtils.create(Arrays.asList(s), new FontConfiguration(font, color), HorizontalAlignement.LEFT);
2010-11-25 21:12:39 +00:00
}
2011-09-07 20:41:58 +00:00
public void drawTOBEREMOVED(ColorMapper colorMapper, Graphics2D g2d, double x, double y) {
2010-11-25 21:12:39 +00:00
throw new UnsupportedOperationException();
}
2011-09-07 20:41:58 +00:00
public void drawU(UGraphic ug, double x, double y) {
2010-11-25 21:12:39 +00:00
final Dimension2D dim = calculateDimension(ug.getStringBounder());
final UGroup group;
if (hasSmallIcon()) {
2011-09-07 20:41:58 +00:00
group = new UGroup(new PlacementStrategyVisibility(ug.getStringBounder(), skinParam
.getCircledCharacterRadius() + 3));
2010-11-25 21:12:39 +00:00
for (Member att : members) {
final String s = att.getDisplayWithoutVisibilityChar();
final TextBlock bloc = createTextBlock(s);
final VisibilityModifier modifier = att.getVisibilityModifier();
group.add(getUBlock(modifier));
group.add(bloc);
}
} else {
group = new UGroup(new PlacementStrategyY1Y2Left(ug.getStringBounder()));
for (Member att : members) {
final String s = att.getDisplayWithoutVisibilityChar();
final TextBlock bloc = createTextBlock(s);
group.add(bloc);
}
}
group.drawU(ug, x, y, dim.getWidth(), dim.getHeight());
}
private TextBlock getUBlock(final VisibilityModifier modifier) {
if (modifier == null) {
return new TextBlock() {
public void drawU(UGraphic ug, double x, double y) {
}
2011-08-08 17:48:29 +00:00
public void drawTOBEREMOVED(ColorMapper colorMapper, Graphics2D g2d, double x, double y) {
2010-11-25 21:12:39 +00:00
throw new UnsupportedOperationException();
}
public Dimension2D calculateDimension(StringBounder stringBounder) {
return new Dimension2DDouble(1, 1);
}
};
}
2011-09-07 20:41:58 +00:00
final HtmlColor back = modifier.getBackground() == null ? null : rose.getHtmlColor(skinParam, modifier
.getBackground());
2011-08-08 17:48:29 +00:00
final HtmlColor fore = rose.getHtmlColor(skinParam, modifier.getForeground());
2010-11-25 21:12:39 +00:00
final TextBlock uBlock = modifier.getUBlock(skinParam.getCircledCharacterRadius(), fore, back);
return uBlock;
}
}