use of net.sf.sdedit.text.TextHandler in project abstools by abstools.
the class MultipageExporter method init.
public void init() throws SyntaxError, SemanticError {
paintDevice = new MultipagePaintDevice(properties, size);
TextHandler th = new TextHandler(source);
new Diagram(configuration, th, paintDevice).generate();
int n = paintDevice.getPanels().size();
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
int i = 0;
for (MultipagePaintDevice.MultipagePanel panel : paintDevice.getPanels()) {
i++;
JPanel wrap = new JPanel();
wrap.setLayout(new BoxLayout(wrap, BoxLayout.Y_AXIS));
wrap.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
wrap.setAlignmentY(0.5F);
ZoomPane zoomPane = new ZoomPane(false);
zoomPane.setViewportView(panel);
zoomPane.setScale(scale);
zoomPane.setMinimumSize(previewSize);
zoomPane.setMaximumSize(previewSize);
zoomPane.setPreferredSize(previewSize);
zoomPane.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
wrap.add(zoomPane);
JLabel label = new JLabel(i + "/" + n);
label.setAlignmentX(0.5F);
wrap.add(label);
add(wrap);
}
}
use of net.sf.sdedit.text.TextHandler 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