All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.xhtmlrenderer.demo.browser.actions.GenerateDiffAction Maven / Gradle / Ivy

There is a newer version: 9.11.1
Show newest version
package org.xhtmlrenderer.demo.browser.actions;

import org.xhtmlrenderer.demo.browser.BrowserStartup;
import org.xhtmlrenderer.test.DocumentDiffTest;
import org.xhtmlrenderer.util.Uu;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.net.URL;

/**
 * Action to generate a unit test diff file of the current document
 * in the browser
 *
 * @author jmarinacci
 * @since November 17, 2004
 */
public class GenerateDiffAction extends AbstractAction {

    private final BrowserStartup root;

    public GenerateDiffAction(BrowserStartup root) {
        super("Generate Diff");
        this.root = root;
    }

    @Override
    public void actionPerformed(ActionEvent evt) {
        try {

            URL url = root.panel.view.getURL();
            if (url.toString().startsWith("file:")) {
                String str = url.toString();
                str = str.substring(6, str.length() - 6);
                if (new File(str + ".diff").exists()) {
                    int n = JOptionPane.showConfirmDialog(root.panel.view,
                            "Diff already exists. Overwrite?",
                            "Warning",
                            JOptionPane.OK_CANCEL_OPTION);
                    if (n != JOptionPane.OK_OPTION) {
                        return;
                    }
                }
                DocumentDiffTest.generateTestFile(str + ".xhtml",
                        str + ".diff",
                        500, 500);
                Uu.p("wrote out: " + str + ".diff");
            }
        } catch (Exception ex) {
            Uu.p(ex);
        }
    }
}






© 2015 - 2024 Weber Informatics LLC | Privacy Policy