use of net.sf.sdedit.config.Configuration 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.config.Configuration in project abstools by abstools.
the class PrintDialog method reinitialize.
private void reinitialize() {
String source = ui.getCode();
Configuration configuration = ui.getConfiguration().getDataObject();
exporter = new MultipageExporter(printerProperties.getDataObject(), source, configuration);
try {
exporter.init();
} catch (RuntimeException re) {
throw re;
} catch (SemanticError se) {
/* ignored */
} catch (SyntaxError se) {
/* ignored */
}
int scale = (int) (100 * exporter.getScale());
scaleLabel.setText("Zoom factor: " + scale + " %");
preview.setViewportView(exporter);
}
use of net.sf.sdedit.config.Configuration in project abstools by abstools.
the class Editor method saveImage.
/**
* Saves the current diagram as a PNG image file whose name is chosen by the
* user. Asks for confirmation, if a file would be overwritten.
*
* @throws IOException
* if the image file cannot be written due to an i/o error
*/
void saveImage() throws IOException {
String code = getUI().getCode().trim();
if (code.equals("")) {
return;
}
ImagePaintDevice ipd = new ImagePaintDevice();
TextHandler handler = new TextHandler(code);
Configuration conf = getUI().getConfiguration().getDataObject();
try {
new Diagram(conf, handler, ipd).generate();
} catch (Exception ex) {
ui.errorMessage("The diagram source text has errors.");
return;
}
Image image = ipd.getImage();
if (image != null) {
File current = null;
if (!firstImageSaved) {
current = ui.getCurrentFile();
if (current != null) {
current = current.getParentFile();
}
firstImageSaved = true;
}
String currentFile = null;
if (ui.getCurrentFile() != null) {
currentFile = ui.getCurrentFile().getName();
int dot = currentFile.lastIndexOf('.');
if (dot >= 0) {
currentFile = currentFile.substring(0, dot + 1) + "png";
}
}
File[] files = ui.getFiles(false, false, "save as PNG", currentFile, current, "PNG image", "png");
File imageFile = files != null ? files[0] : null;
if (imageFile != null && (!imageFile.exists() || 1 == ui.confirmOrCancel("Overwrite existing file " + imageFile.getName() + "?"))) {
ipd.saveImage(imageFile);
ui.message("Exported image as\n" + imageFile.getAbsolutePath());
}
}
}
Aggregations