2013-12-10 19:36:50 +00:00
|
|
|
/* ========================================================================
|
|
|
|
* PlantUML : a free UML diagram generator
|
|
|
|
* ========================================================================
|
|
|
|
*
|
2016-01-09 12:15:40 +00:00
|
|
|
* (C) Copyright 2009-2017, Arnaud Roques
|
2013-12-10 19:36:50 +00:00
|
|
|
*
|
2016-03-06 16:47:34 +00:00
|
|
|
* Project Info: http://plantuml.com
|
2013-12-10 19:36:50 +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.turing;
|
|
|
|
|
|
|
|
import java.awt.Font;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.sourceforge.plantuml.AbstractPSystem;
|
|
|
|
import net.sourceforge.plantuml.FileFormatOption;
|
|
|
|
import net.sourceforge.plantuml.core.DiagramDescription;
|
|
|
|
import net.sourceforge.plantuml.core.DiagramDescriptionImpl;
|
|
|
|
import net.sourceforge.plantuml.core.ImageData;
|
|
|
|
import net.sourceforge.plantuml.graphic.GraphicPosition;
|
|
|
|
import net.sourceforge.plantuml.graphic.GraphicStrings;
|
|
|
|
import net.sourceforge.plantuml.graphic.HtmlColorUtils;
|
2015-04-07 18:18:37 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.UAntiAliasing;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UFont;
|
|
|
|
|
|
|
|
public class PSystemTuring extends AbstractPSystem {
|
|
|
|
|
|
|
|
private final String program;
|
|
|
|
private final String input;
|
|
|
|
|
|
|
|
PSystemTuring(String program, String input) {
|
|
|
|
this.program = program;
|
|
|
|
this.input = input;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException {
|
2015-04-07 18:18:37 +00:00
|
|
|
final GraphicStrings result = getGraphicStrings();
|
|
|
|
final ImageBuilder imageBuilder = new ImageBuilder(new ColorMapperIdentity(), 1.0, result.getBackcolor(),
|
|
|
|
getMetadata(), null, 0, 0, null, false);
|
2016-03-06 16:47:34 +00:00
|
|
|
imageBuilder.setUDrawable(result);
|
2015-05-31 18:56:03 +00:00
|
|
|
return imageBuilder.writeImageTOBEMOVED(fileFormat, os);
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private GraphicStrings getGraphicStrings() throws IOException {
|
|
|
|
final List<String> strings = new ArrayList<String>();
|
|
|
|
final BFMachine machine = new BFMachine(program, input);
|
|
|
|
/* final boolean ok = */machine.run();
|
|
|
|
final String output = machine.getOutput();
|
|
|
|
for (String s : output.split("\n")) {
|
|
|
|
strings.add(s);
|
|
|
|
}
|
|
|
|
final UFont font = new UFont("Monospaced", Font.PLAIN, 14);
|
2015-04-07 18:18:37 +00:00
|
|
|
return new GraphicStrings(strings, font, HtmlColorUtils.BLACK, HtmlColorUtils.WHITE, UAntiAliasing.ANTI_ALIASING_ON,
|
|
|
|
null, GraphicPosition.BACKGROUND_CORNER_BOTTOM_RIGHT);
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public DiagramDescription getDescription() {
|
|
|
|
return new DiagramDescriptionImpl("(Turing)", getClass());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|