Search in sources :

Example 6 with TextHandler

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);
    }
}
Also used : JPanel(javax.swing.JPanel) ZoomPane(net.sf.sdedit.ui.components.ZoomPane) BoxLayout(javax.swing.BoxLayout) TextHandler(net.sf.sdedit.text.TextHandler) JLabel(javax.swing.JLabel) Diagram(net.sf.sdedit.diagram.Diagram)

Example 7 with TextHandler

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());
        }
    }
}
Also used : ImagePaintDevice(net.sf.sdedit.ui.ImagePaintDevice) GlobalConfiguration(net.sf.sdedit.config.GlobalConfiguration) Configuration(net.sf.sdedit.config.Configuration) TextHandler(net.sf.sdedit.text.TextHandler) Image(java.awt.Image) File(java.io.File) IOException(java.io.IOException) XMLException(net.sf.sdedit.util.DocUtil.XMLException) Diagram(net.sf.sdedit.diagram.Diagram)

Aggregations

Diagram (net.sf.sdedit.diagram.Diagram)7 TextHandler (net.sf.sdedit.text.TextHandler)7 File (java.io.File)4 IOException (java.io.IOException)3 Configuration (net.sf.sdedit.config.Configuration)3 ImagePaintDevice (net.sf.sdedit.ui.ImagePaintDevice)3 DiagramError (net.sf.sdedit.error.DiagramError)2 FatalError (net.sf.sdedit.error.FatalError)2 Image (java.awt.Image)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 BoxLayout (javax.swing.BoxLayout)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 GlobalConfiguration (net.sf.sdedit.config.GlobalConfiguration)1 SemanticError (net.sf.sdedit.error.SemanticError)1 Exporter (net.sf.sdedit.server.Exporter)1 PanelPaintDevice (net.sf.sdedit.ui.PanelPaintDevice)1