use of net.sf.sdedit.diagram.Diagram in project abstools by abstools.
the class UserInterfaceImpl method fullScreen.
public void fullScreen() {
if (fullScreen == null) {
errorMessage("Full-screen mode is not supported\nby your graphics environment.");
return;
}
Diagram diag = getDiagram();
if (diag != null) {
PanelPaintDevice ppd = (PanelPaintDevice) diag.getPaintDevice();
setVisible(false);
fullScreen.display(ppd.getPanel());
fullScreen.getZoomPane().fitSize();
}
}
use of net.sf.sdedit.diagram.Diagram 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.diagram.Diagram 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());
}
}
}
use of net.sf.sdedit.diagram.Diagram in project abstools by abstools.
the class ExportAction method actionPerformed.
public void actionPerformed(ActionEvent e) {
Diagram diagram = editor.getUI().getDiagram();
if (diagram == null) {
return;
}
exportDevice = (PanelPaintDevice) diagram.getPaintDevice();
if (exportDevice.isEmpty()) {
return;
}
try {
File file = editor.getUI().getCurrentFile();
if (exportDialog == null) {
exportDialog = new ExportDialog("Quick Sequence Diagram Editor");
LookAndFeelManager.instance().registerOrphan(exportDialog);
exportDialog.setUserProperties(properties);
exportDialog.addExportDialogListener(this);
if (file != null) {
properties.setProperty(SAVE_AS_FILE_PROPERTY, file.getAbsolutePath());
}
} else {
String fileName = properties.getProperty(SAVE_AS_FILE_PROPERTY);
File current = fileName != null ? new File(fileName) : null;
if (current != null && current.exists()) {
File dir = current.getParentFile();
if (file == null) {
current = new File(dir, "untitled");
} else {
current = new File(dir, file.getName());
}
properties.setProperty(SAVE_AS_FILE_PROPERTY, current.getAbsolutePath());
}
}
exportDialog.showExportDialog((Component) editor.getUI(), "Export via FreeHEP library (see http://www.freehep.org/vectorgraphics)", exportDevice.getPanel().asJComponent(), "untitled");
} catch (Exception ex) {
ex.printStackTrace();
editor.getUI().errorMessage("Cannot export due to an exception\n" + "of type " + ex.getClass().getSimpleName() + "\n" + "with the message: " + ex.getMessage());
} finally {
exportDevice.setAntialiasing(true);
}
}
Aggregations