Search in sources :

Example 61 with HeadlessException

use of java.awt.HeadlessException in project opt4j by felixreimann.

the class Opt4J method main.

/**
 * Starts the {@link Opt4J} configuration GUI.
 *
 * @param args
 *            accepts a configuration file
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    System.out.println("Starting Opt4J " + getVersion() + " (Build " + getDateISO() + ")");
    if (args.length > 0 && args[0].equalsIgnoreCase("-s")) {
        SplashScreen splash = null;
        try {
            splash = SplashScreen.getSplashScreen();
        } catch (HeadlessException e) {
        // ignore
        }
        if (splash != null) {
            splash.close();
        }
        String[] a = new String[args.length - 1];
        System.arraycopy(args, 1, a, 0, a.length);
        Opt4JStarter.main(a);
    } else {
        SplashScreen splash = SplashScreen.getSplashScreen();
        SplashDecorator decorator = null;
        if (splash != null) {
            decorateVersionDate(splash);
            decorator = new SplashDecorator(splash);
        }
        searchModules(decorator);
        Configurator configurator = new Opt4J();
        configurator.start(args);
    }
}
Also used : HeadlessException(java.awt.HeadlessException) Configurator(org.opt4j.core.config.visualization.Configurator) SplashScreen(java.awt.SplashScreen)

Example 62 with HeadlessException

use of java.awt.HeadlessException in project pdfbox by apache.

the class PDFToImage method call.

public Integer call() {
    if (outputPrefix == null) {
        outputPrefix = FilenameUtils.removeExtension(infile.getAbsolutePath());
    }
    if (getImageFormats().indexOf(imageFormat) == -1) {
        SYSERR.println("Error: Invalid image format " + imageFormat + " - supported are: " + getImageFormats());
        return 2;
    }
    if (quality < 0) {
        quality = "png".equals(imageFormat) ? 0f : 1f;
    }
    if (dpi == 0) {
        try {
            dpi = Toolkit.getDefaultToolkit().getScreenResolution();
        } catch (HeadlessException e) {
            dpi = 96;
        }
    }
    try (PDDocument document = Loader.loadPDF(infile, password)) {
        PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm();
        if (acroForm != null && acroForm.getNeedAppearances()) {
            acroForm.refreshAppearances();
        }
        if (cropbox != null) {
            changeCropBox(document, cropbox[0], cropbox[1], cropbox[2], cropbox[3]);
        }
        long startTime = System.nanoTime();
        // render the pages
        boolean success = true;
        endPage = Math.min(endPage, document.getNumberOfPages());
        PDFRenderer renderer = new PDFRenderer(document);
        renderer.setSubsamplingAllowed(subsampling);
        for (int i = startPage - 1; i < endPage; i++) {
            BufferedImage image = renderer.renderImageWithDPI(i, dpi, imageType);
            String fileName = outputPrefix + "-" + (i + 1) + "." + imageFormat;
            success &= ImageIOUtil.writeImage(image, fileName, dpi, quality);
        }
        // performance stats
        long endTime = System.nanoTime();
        long duration = endTime - startTime;
        int count = 1 + endPage - startPage;
        if (showTime) {
            SYSERR.printf("Rendered %d page%s in %dms%n", count, count == 1 ? "" : "s", duration / 1000000);
        }
        if (!success) {
            SYSERR.println("Error: no writer found for image format '" + imageFormat + "'");
            return 1;
        }
    } catch (IOException ioe) {
        SYSERR.println("Error converting document [" + ioe.getClass().getSimpleName() + "]: " + ioe.getMessage());
        return 4;
    }
    return 0;
}
Also used : HeadlessException(java.awt.HeadlessException) PDDocument(org.apache.pdfbox.pdmodel.PDDocument) PDAcroForm(org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm) IOException(java.io.IOException) PDFRenderer(org.apache.pdfbox.rendering.PDFRenderer) BufferedImage(java.awt.image.BufferedImage)

Example 63 with HeadlessException

use of java.awt.HeadlessException in project Spark by igniterealtime.

the class CertificateDialog method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == okButton) {
        // controller should be passed to this class only if there is need to modification content of Keystore.
        if (certControll != null) {
            addCert = true;
            if (certControll instanceof CertificateController && !certControll.isOnExceptionList(certModel) && exceptionBox.isSelected()) {
                CertificateController crtCtrl = (CertificateController) certControll;
                try {
                    crtCtrl.addCertificateAsExempted(certModel);
                } catch (HeadlessException | InvalidNameException | KeyStoreException e1) {
                    Log.error(e1);
                }
            }
        }
        this.dispose();
    } else if (e.getSource() == cancelButton) {
        if (certControll != null) {
            certControll.setAddToKeystore(false);
        }
        this.dispose();
    } else if (e.getSource() == deleteButton) {
        try {
            certControll.deleteEntry(certModel.getAlias());
            this.dispose();
        } catch (KeyStoreException ex) {
            Log.error("Couldn't delete the certificate", ex);
        }
    } else if (e.getSource() == exceptionBox) {
        certControll.addOrRemoveFromExceptionList(exceptionBox.isSelected());
    } else if (e.getSource() == checkValidity) {
        checkValidity();
    }
}
Also used : HeadlessException(java.awt.HeadlessException) InvalidNameException(javax.naming.InvalidNameException) CertificateController(org.jivesoftware.sparkimpl.certificates.CertificateController) KeyStoreException(java.security.KeyStoreException)

Aggregations

HeadlessException (java.awt.HeadlessException)63 IOException (java.io.IOException)19 File (java.io.File)16 Point (java.awt.Point)8 GraphicsConfiguration (java.awt.GraphicsConfiguration)7 BufferedImage (java.awt.image.BufferedImage)7 Dimension (java.awt.Dimension)6 Rectangle (java.awt.Rectangle)6 ActionEvent (java.awt.event.ActionEvent)5 PrintService (javax.print.PrintService)5 StreamPrintService (javax.print.StreamPrintService)5 JFrame (javax.swing.JFrame)5 GraphicsDevice (java.awt.GraphicsDevice)4 GraphicsEnvironment (java.awt.GraphicsEnvironment)4 PrinterException (java.awt.print.PrinterException)4 DialogTypeSelection (javax.print.attribute.standard.DialogTypeSelection)4 ImageIcon (javax.swing.ImageIcon)4 JFileChooser (javax.swing.JFileChooser)4 Frame (java.awt.Frame)3 Graphics (java.awt.Graphics)3