Example usage for javax.swing ProgressMonitor.ProgressCallback ProgressMonitor.ProgressCallback

List of usage examples for javax.swing ProgressMonitor.ProgressCallback ProgressMonitor.ProgressCallback

Introduction

In this page you can find the example usage for javax.swing ProgressMonitor.ProgressCallback ProgressMonitor.ProgressCallback.

Prototype

ProgressMonitor.ProgressCallback

Source Link

Usage

From source file:com.yifanlu.PSXperiaTool.Interface.GUI.java

private void convertButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_convertButtonActionPerformed
    Runnable run = new Runnable() {
        public void run() {
            try {
                mThis.setEnabled(false);
                convertButton.setEnabled(false);
                CommandLine.verifyTitleID(titleIdInput.getText());
                setPropertiesFromFields(mSettings);
                File inputFile = new File(isoInput.getText());
                File dataDir = new File(dataInput.getText());
                File outputDir = new File(convertOutputInput.getText());
                PSXperiaTool tool = new PSXperiaTool(mSettings, inputFile, dataDir, outputDir);
                ProgressMonitor.ProgressCallback callback = new ProgressMonitor.ProgressCallback() {

                    public void nextStep(String string) {
                        convertStatus.setText(string);
                    }/*from w w w .ja  v  a2s . com*/

                    public void stepsTook(int current, int max) {
                        convertProgress.setMaximum(max);
                        convertProgress.setValue(current);
                    }
                };
                tool.setCallback(callback);
                tool.startBuild();
                convertProgress.setValue(0);
                convertButton.setEnabled(true);
                mThis.setEnabled(true);
            } catch (InputMismatchException ex) {
                Logger.error("Input error: %s", ex.getMessage());
                ex.printStackTrace();
            } catch (InterruptedException ex) {
                Logger.error(
                        "Cannot run build commands, are \"aapk\" and \"jarsigner\" in your system's PATH variable? Java says: %s",
                        ex.getMessage());
                ex.printStackTrace();
            } catch (IOException ex) {
                Logger.error("Cannot build APK! Java says: %s", ex.getMessage());
                ex.printStackTrace();
            } catch (GeneralSecurityException ex) {
                Logger.error("Error signing JAR, Java says: %s", ex.getMessage());
                ex.printStackTrace();
            } catch (SignedJarBuilder.IZipEntryFilter.ZipAbortException ex) {
                Logger.error("Error signing JAR, Java says: %s", ex.getMessage());
                ex.printStackTrace();
            } finally {
                convertProgress.setValue(0);
                convertButton.setEnabled(true);
                mThis.setEnabled(true);
            }
        }
    };
    (new Thread(run)).start();
}

From source file:com.yifanlu.PSXperiaTool.Interface.GUI.java

private void extractButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_extractButtonActionPerformed
    Runnable run = new Runnable() {
        public void run() {
            try {
                mThis.setEnabled(false);
                extractButton.setEnabled(false);
                File inputApk = new File(apkFileInput.getText());
                File inputZpak = new File(zpakFileInput.getText());
                File outputDataDir = new File(extractOutputInput.getText());
                if (!inputApk.exists()) {
                    Logger.error("Cannot find APK file!");
                    return;
                }//from  ww  w .j av a 2s  . c o  m
                if (!inputZpak.exists()) {
                    Logger.error("Cannot find ZPAK file!");
                    return;
                }
                CrashBandicootExtractor extract = new CrashBandicootExtractor(inputApk, inputZpak,
                        outputDataDir);
                ProgressMonitor.ProgressCallback callback = new ProgressMonitor.ProgressCallback() {

                    public void nextStep(String string) {
                        extractStatus.setText(string);
                    }

                    public void stepsTook(int current, int max) {
                        extractProgress.setMaximum(max);
                        extractProgress.setValue(current);
                    }
                };
                extract.setCallback(callback);
                extract.extractApk();
                extractProgress.setValue(0);
                extractButton.setEnabled(true);
                mThis.setEnabled(true);
            } catch (IOException ex) {
                Logger.error("Cannot extract APK! Java says %s", ex.getMessage());
                ex.printStackTrace();
            } catch (UnsupportedOperationException ex) {
                Logger.error("Unsupported exception: %s", ex.getMessage());
                ex.printStackTrace();
            } catch (Exception ex) {
                Logger.error("Exception: %s", ex.getMessage());
                ex.printStackTrace();
            } finally {
                extractProgress.setValue(0);
                extractButton.setEnabled(true);
                mThis.setEnabled(true);
            }
        }
    };
    (new Thread(run)).start();
}