use of net.sf.sdedit.text.TextHandler in project abstools by abstools.
the class Engine method _render.
private synchronized void _render(final boolean syntaxCheckOnly) {
editor.getUI().leaveFilterMode();
Diagram diagram = editor.getUI().renderDiagram();
// method is not synchronized. Why?
if (diagram == null) {
return;
}
DiagramError error = editor.getUI().getDiagramError();
if (error == null) {
editor.getUI().setErrorStatus(false, "", -1, -1);
if (diagram.getFragmentManager().openFragmentsExist()) {
editor.getUI().setErrorStatus(true, "Warning: There are open comments. Use [c:<type> <text>]...[/c]", -1, -1);
}
int noteNumber = diagram.getNextFreeNoteNumber();
if (noteNumber == 0) {
editor.getUI().setStatus("");
} else {
editor.getUI().setStatus("Next note number: " + diagram.getNextFreeNoteNumber());
}
} else {
editor.getUI().setStatus("");
if (error instanceof FatalError) {
FatalError fatal = (FatalError) error;
System.err.println("********************************************************");
System.err.println("* *");
System.err.println("* A FATAL ERROR HAS OCCURED. *");
System.err.println("* *");
System.err.println("********************************************************");
error.getCause().printStackTrace();
// cautiously embedding this call into a try/catch-block
try {
handle(diagram, fatal.getCause());
} catch (Throwable t) {
t.printStackTrace();
}
} else {
TextHandler handler = (TextHandler) error.getProvider();
String prefix = "";
if (error instanceof SemanticError) {
prefix = diagram.isThreaded() && diagram.getCallerThread() != -1 ? "Thread " + diagram.getCallerThread() + ": " : "";
}
editor.getUI().setErrorStatus(false, prefix + error.getMessage(), handler.getLineBegin() - 1, handler.getLineEnd());
}
}
if (!syntaxCheckOnly) {
editor.getUI().redraw();
}
}
use of net.sf.sdedit.text.TextHandler in project abstools by abstools.
the class ExportMapAction method actionPerformed.
/**
* See {@linkplain ExportMapAction}.
*
* @param e
*/
public void actionPerformed(ActionEvent e) {
Diagram diagram = editor.getUI().getDiagram();
if (diagram == null || diagram.getLifelines().isEmpty()) {
return;
}
TextHandler textHandler = (TextHandler) diagram.getDataProvider();
File currentFile = editor.getUI().getCurrentFile();
if (currentFile == null) {
editor.getUI().message("Please save the diagram as a file first.");
return;
}
String name = currentFile.getName();
int dot = Math.min(name.length(), name.lastIndexOf('.'));
name = currentFile.getName().substring(0, dot);
if (directory == null) {
directory = currentFile.getParentFile();
}
File[] target = editor.getUI().getFiles(false, false, "Export HTML map file", name + ".html", directory, "HTML files", "html");
if (target != null && target.length > 0) {
directory = target[0].getParentFile();
if (!target[0].exists() || 1 == editor.getUI().confirmOrCancel("Overwrite existing file:\n" + target[0].getAbsolutePath() + "?")) {
try {
generateMapFile(diagram, textHandler, name, target[0]);
} catch (IOException ex) {
editor.getUI().errorMessage("The map file could not be saved due to an exception of type\n" + ex.getClass().getSimpleName() + " with the message: " + ex.getMessage());
}
}
}
}
use of net.sf.sdedit.text.TextHandler in project abstools by abstools.
the class Main method createImage.
private static void createImage(CommandLine cmd) throws IOException, XMLException, SyntaxError, SemanticError {
File inFile = new File(getInputFiles(cmd)[0]);
File outFile = new File(cmd.getOptionValue('o'));
String type = "png";
if (cmd.getOptionValue('t') != null) {
type = cmd.getOptionValue('t').toLowerCase();
}
String format = "A4";
if (cmd.getOptionValue('f') != null) {
format = cmd.getOptionValue('f').toUpperCase();
}
String orientation = "Portrait";
if (cmd.getOptionValue('r') != null) {
orientation = cmd.getOptionValue('r').toLowerCase();
if (orientation.length() > 0) {
orientation = orientation.substring(0, 1).toUpperCase() + orientation.substring(1);
}
}
InputStream in = null;
OutputStream out = null;
in = new FileInputStream(inFile);
try {
out = new FileOutputStream(outFile);
try {
Pair<String, Bean<Configuration>> pair = DiagramLoader.load(in, ConfigurationManager.getGlobalConfiguration().getFileEncoding());
TextHandler th = new TextHandler(pair.getFirst());
Bean<Configuration> conf = pair.getSecond();
configure(conf, cmd);
if (type.equals("png")) {
ImagePaintDevice paintDevice = new ImagePaintDevice();
new Diagram(conf.getDataObject(), th, paintDevice).generate();
paintDevice.writeToStream(out);
} else {
Exporter paintDevice = Exporter.getExporter(type, orientation, format, out);
new Diagram(conf.getDataObject(), th, paintDevice).generate();
paintDevice.export();
}
out.flush();
} finally {
out.close();
}
} finally {
in.close();
}
}
use of net.sf.sdedit.text.TextHandler in project abstools by abstools.
the class SequenceTaglet method generateOutput.
/**
* Creates a sequence diagram image from a part of the contents of a
* sequence.diagram tag, saves it in the image directory and returns HTML
* code that references the image.
*
* @param path
* the path to the directory where the diagram image is to be
* stored (usually a path going upwards, i. e. containing ../'s)
* @param imageBaseName
* the base name of the image to be stored
* @param source
* string array containing the lines of the diagram specification
* @return the output that is to appear on the javadoc page (i. e. the
* <img> tag referencing the image
* @throws SequenceTagletException
* if the creation of the diagram fails
*/
private String generateOutput(String path, String imageBaseName, String[] source) throws SequenceTagletException {
if (source == null || source.length == 0) {
return "";
}
// Set custom diagram title if first line is quoted
String diagramTitle = null;
if (source[0].trim().matches("^[\"'].*[\"']$")) {
// Set the title and remove the title quote
diagramTitle = source[0].replaceAll("[\"']", "");
// Remove the custom title from the sd spec
source[0] = "";
}
StringBuffer buffer = new StringBuffer();
for (String string : source) {
string = string.trim();
if (string.startsWith("<") && string.endsWith(">")) {
continue;
}
buffer.append(string + "\n");
}
String specification = buffer.toString().trim();
if (specification.length() == 0) {
return "";
}
Configuration conf = ConfigurationManager.createNewDefaultConfiguration().getDataObject();
conf.setHeadWidth(25);
conf.setMainLifelineWidth(5);
conf.setSubLifelineWidth(5);
conf.setThreaded(true);
conf.setGlue(3);
ImagePaintDevice device = new ImagePaintDevice();
TextHandler handler = new TextHandler(specification);
try {
new Diagram(conf, handler, device).generate();
} catch (Exception e) {
int error = handler.getLineNumber();
StringBuffer code = new StringBuffer("<br><tt>");
for (int i = 0; i < source.length; i++) {
String html = source[i].replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """);
if (i == error) {
html = "<FONT COLOR=\"red\"><U><B>" + html + "</B></U></FONT>";
}
code.append(html + "<br>");
}
throw new SequenceTagletException("Malformed diagram specification: " + e.getMessage(), "<DT><HR><B>Sequence Diagram:</B></DT>" + "<DD><B>Could not create sequence diagram: " + "<font color=\"red\">" + e.getMessage() + "</font></B>" + code.toString() + "</DD>");
}
String fileName = imageBaseName + ".png";
File imageFile = new File(diagramDirectory, fileName);
try {
device.saveImage(imageFile.getAbsolutePath());
} catch (IOException ioe) {
throw new SequenceTagletException("Could not save diagram image: " + ioe.getMessage(), "");
}
if (diagramTitle == null) {
diagramTitle = "Sequence Diagram " + imageBaseName;
}
String imageUrl = path + imageSubDirectory + "/" + fileName;
String anchor = "<A name=\"" + imageBaseName + "\"/>";
return "<DT><HR><B>" + anchor + diagramTitle + ":</B><P></DT>" + "<DD><img src='" + imageUrl + "'></DD>";
}
use of net.sf.sdedit.text.TextHandler in project abstools by abstools.
the class Tab method renderDiagram.
void renderDiagram() {
PanelPaintDevice paintDevice = new PanelPaintDevice(true);
for (PanelPaintDeviceListener listener : ppdListeners) {
paintDevice.addListener(listener);
}
TextHandler textHandler = new TextHandler(getCode());
Diagram diagram = new Diagram(configuration.getDataObject(), textHandler, paintDevice);
DiagramError newError = null;
try {
diagram.generate();
} catch (RuntimeException e) {
newError = new FatalError(textHandler, e);
} catch (DiagramError e) {
newError = e;
}
synchronized (diagramStack) {
diagramStack.addLast(diagram);
synchronized (this) {
error = newError;
}
}
}
Aggregations