plantuml/src/net/sourceforge/plantuml/emoji/PSystemListEmoji.java

121 lines
3.9 KiB
Java
Raw Normal View History

2021-12-07 18:15:43 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2023-02-22 18:43:48 +00:00
* (C) Copyright 2009-2024, Arnaud Roques
2021-12-07 18:15:43 +00:00
*
2023-02-22 18:43:48 +00:00
* Project Info: https://plantuml.com
2021-12-07 18:15:43 +00:00
*
* If you like this project or if you find it useful, you can support us at:
*
2023-02-22 18:43:48 +00:00
* https://plantuml.com/patreon (only 1$ per month!)
* https://plantuml.com/paypal
2021-12-07 18:15:43 +00:00
*
* 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.emoji;
import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
import java.util.TreeMap;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.PlainDiagram;
import net.sourceforge.plantuml.core.DiagramDescription;
import net.sourceforge.plantuml.core.UmlSource;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.klimt.UTranslate;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.klimt.drawing.UGraphic;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.klimt.font.StringBounder;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.klimt.shape.GraphicStrings;
2023-02-26 18:51:17 +00:00
import net.sourceforge.plantuml.klimt.shape.TextBlock;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.klimt.shape.UDrawable;
2021-12-07 18:15:43 +00:00
public class PSystemListEmoji extends PlainDiagram {
2023-02-06 21:04:53 +00:00
// ::remove file when CORE
2021-12-07 18:15:43 +00:00
private final String text;
@Override
protected UDrawable getRootDrawable(FileFormatOption fileFormatOption) throws IOException {
return new UDrawable() {
public void drawU(UGraphic ug) {
2023-02-26 18:51:17 +00:00
final TextBlock header = GraphicStrings
2021-12-07 18:15:43 +00:00
.createBlackOnWhite(Arrays.asList("<b><size:16>Emoji available on Unicode Block " + text,
2021-12-14 18:03:11 +00:00
"(Blocks available: 26, 27, 1F3, 1F4, 1F5, 1F6, 1F9)"));
2021-12-07 18:15:43 +00:00
header.drawU(ug);
final StringBounder stringBounder = ug.getStringBounder();
ug = ug.apply(UTranslate.dy(header.calculateDimension(stringBounder).getHeight()));
final UGraphic top = ug;
final Map<String, Emoji> some = new TreeMap<>();
for (Map.Entry<String, Emoji> ent : Emoji.getAll().entrySet())
if (ent.getKey().startsWith(text))
some.put(ent.getKey(), ent.getValue());
final int third = (some.size() + 2) / 3;
int i = 0;
for (Map.Entry<String, Emoji> ent : some.entrySet()) {
final String code = ent.getKey();
final String shortcut = ent.getValue().getShortcut();
final StringBuilder sb = new StringBuilder();
sb.append("<size:13>");
sb.append("\"\"<U+003C>:" + code + ":<U+003E> \"\"");
sb.append("<:" + code + ":>");
sb.append(" ");
sb.append("<#0:" + code + ":>");
if (shortcut != null) {
sb.append(" ");
sb.append("\"\"<U+003C>:" + shortcut + ":<U+003E> \"\"");
}
2023-02-26 18:51:17 +00:00
final TextBlock tmp = GraphicStrings.createBlackOnWhite(Arrays.asList(sb.toString()));
2021-12-07 18:15:43 +00:00
tmp.drawU(ug);
ug = ug.apply(UTranslate.dy(tmp.calculateDimension(stringBounder).getHeight()));
i++;
if (i == third)
ug = top.apply(UTranslate.dx(500));
if (i == 2 * third)
ug = top.apply(UTranslate.dx(1000));
}
}
};
}
public PSystemListEmoji(UmlSource source, String text) {
super(source);
this.text = text;
}
public DiagramDescription getDescription() {
return new DiagramDescription("(List Emoji)");
}
}