plantuml/src/net/sourceforge/plantuml/cucadiagram/BodierMap.java

125 lines
3.4 KiB
Java
Raw Normal View History

2020-04-05 15:13:04 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2022-03-07 19:33:46 +00:00
* (C) Copyright 2009-2023, Arnaud Roques
2020-04-05 15:13:04 +00:00
*
* Project Info: http://plantuml.com
*
* If you like this project or if you find it useful, you can support us at:
*
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
*
* 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 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.
*
*
* Original Author: Arnaud Roques
*
*
*/
package net.sourceforge.plantuml.cucadiagram;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
2021-05-09 21:14:40 +00:00
import java.util.Objects;
2020-04-05 15:13:04 +00:00
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sourceforge.plantuml.ISkinParam;
2022-10-05 20:32:57 +00:00
import net.sourceforge.plantuml.LineBreakStrategy;
2021-10-20 16:33:09 +00:00
import net.sourceforge.plantuml.graphic.FontConfiguration;
2020-04-05 15:13:04 +00:00
import net.sourceforge.plantuml.graphic.TextBlock;
2020-12-01 21:39:27 +00:00
import net.sourceforge.plantuml.style.Style;
2020-04-05 15:13:04 +00:00
public class BodierMap implements Bodier {
2021-05-14 08:42:57 +00:00
private final List<CharSequence> rawBody = new ArrayList<>();
2020-04-05 15:13:04 +00:00
private final Map<String, String> map = new LinkedHashMap<String, String>();
private ILeaf leaf;
2021-10-20 16:33:09 +00:00
@Override
2020-04-05 15:13:04 +00:00
public void muteClassToObject() {
throw new UnsupportedOperationException();
}
public BodierMap() {
}
2021-10-20 16:33:09 +00:00
@Override
2020-04-05 15:13:04 +00:00
public void setLeaf(ILeaf leaf) {
2021-05-09 21:14:40 +00:00
this.leaf = Objects.requireNonNull(leaf);
2020-04-05 15:13:04 +00:00
}
public static String getLinkedEntry(String s) {
final Pattern p = Pattern.compile("(\\*-+\\>)");
final Matcher m = p.matcher(s);
if (m.find()) {
return m.group(1);
}
return null;
}
2021-10-20 16:33:09 +00:00
@Override
2022-04-10 19:24:55 +00:00
public boolean addFieldOrMethod(String s) {
2020-04-05 15:13:04 +00:00
if (s.contains("=>")) {
final int x = s.indexOf("=>");
map.put(s.substring(0, x).trim(), s.substring(x + 2).trim());
2022-04-10 19:24:55 +00:00
return true;
2020-04-05 15:13:04 +00:00
} else if (getLinkedEntry(s) != null) {
final String link = getLinkedEntry(s);
final int x = s.indexOf(link);
map.put(s.substring(0, x).trim(), "\0");
2022-04-10 19:24:55 +00:00
return true;
2020-04-05 15:13:04 +00:00
}
2022-04-10 19:24:55 +00:00
return false;
2020-04-05 15:13:04 +00:00
}
2021-10-20 16:33:09 +00:00
@Override
2020-12-14 18:31:06 +00:00
public Display getMethodsToDisplay() {
2020-04-05 15:13:04 +00:00
throw new UnsupportedOperationException();
}
2021-10-20 16:33:09 +00:00
@Override
2020-12-14 18:31:06 +00:00
public Display getFieldsToDisplay() {
2020-04-05 15:13:04 +00:00
throw new UnsupportedOperationException();
}
2021-10-20 16:33:09 +00:00
@Override
2020-04-05 15:13:04 +00:00
public boolean hasUrl() {
return false;
}
2021-10-20 16:33:09 +00:00
@Override
2022-10-05 20:32:57 +00:00
public TextBlock getBody(ISkinParam skinParam, final boolean showMethods, final boolean showFields,
Stereotype stereotype, Style style, FontConfiguration fontConfiguration) {
final LineBreakStrategy wordWrap = style.wrapWidth();
return new TextBlockMap(fontConfiguration, skinParam, map, wordWrap);
2020-04-05 15:13:04 +00:00
}
2021-10-20 16:33:09 +00:00
@Override
2020-12-14 18:31:06 +00:00
public List<CharSequence> getRawBody() {
2020-04-05 15:13:04 +00:00
return Collections.unmodifiableList(rawBody);
}
}