Example usage for javax.swing SwingWorker execute

List of usage examples for javax.swing SwingWorker execute

Introduction

In this page you can find the example usage for javax.swing SwingWorker execute.

Prototype

public final void execute() 

Source Link

Document

Schedules this SwingWorker for execution on a worker thread.

Usage

From source file:com.dfki.av.sudplan.ui.MainFrame.java

private void bGoWMSHeightActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bGoWMSHeightActionPerformed
    String urlString;//ww w  .  j a v  a  2 s.  co  m
    if (rbCbServerUrl.isSelected()) {
        urlString = cbServerURL.getSelectedItem().toString();
    } else {
        urlString = txtServerURL.getText();
    }
    bGoWMSHeight.setEnabled(false);
    pbWMS.setIndeterminate(true);
    pbWMS.setVisible(true);
    SwingWorker worker = new LayerInfoRetreiver(urlString, false);
    worker.addPropertyChangeListener(this);
    worker.execute();
}

From source file:com.orthancserver.DicomDecoder.java

public DicomDecoder(final OrthancConnection c, boolean isInstance, String uuid)
        throws IOException, InterruptedException, ExecutionException {
    ImageStack stack = null;/*  w  w  w  . j a va2 s . c o  m*/
    JSONObject tags = null;
    String tagsUri, name;

    if (isInstance) {
        name = "Instance " + uuid;
        tags = (JSONObject) c.ReadJson("/instances/" + uuid + "/tags");
        stack = AddSlice(stack, c, uuid);
    } else {
        name = "Series " + uuid;

        JSONObject series = (JSONObject) c.ReadJson("/series/" + uuid);
        JSONArray instances = (JSONArray) series.get("Instances");

        try {
            tags = (JSONObject) c.ReadJson("/series/" + uuid + "/shared-tags");
        } catch (Exception e) {
            // Fallback for old versions of Orthanc, without "shared-tags"
            tags = (JSONObject) c.ReadJson("/instances/" + (String) instances.get(0) + "/tags");
        }

        final String[] slices = GetSlices(c, instances);
        final ProgressDialog progress = new ProgressDialog(slices.length);

        try {
            progress.setVisible(true);
            SwingWorker<ImageStack, Float> worker = new SwingWorker<ImageStack, Float>() {
                @Override
                protected ImageStack doInBackground() {
                    try {
                        ImageStack stack = null;

                        for (int i = 0; i < slices.length; i++) {
                            if (progress.IsCanceled()) {
                                return null;
                            }

                            progress.SetProgress(i);
                            stack = AddSlice(stack, c, slices[i]);
                        }

                        return stack;
                    } catch (IOException e) {
                        return null;
                    }
                }
            };

            worker.execute();
            stack = worker.get();
        } finally {
            progress.setVisible(false);
        }
    }

    image_ = new ImagePlus(name, stack);

    ExtractCalibration(image_, tags);
    ExtractPixelSpacing(image_, tags);
    ExtractDicomInfo(image_, tags);
}

From source file:com.mirth.connect.plugins.datapruner.DataPrunerPanel.java

@Override
public boolean doSave() {
    if (!validateFields()) {
        return false;
    }/*from ww  w  . ja  v  a2 s . co  m*/

    final String workingId = getFrame().startWorking("Saving " + getTabName() + " properties...");

    SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {

        public Void doInBackground() {
            try {
                plugin.setPropertiesToServer(getProperties());
            } catch (Exception e) {
                getFrame().alertThrowable(getFrame(), e);
            }
            return null;
        }

        @Override
        public void done() {
            setSaveEnabled(false);
            getFrame().stopWorking(workingId);
            updateStatus();
        }
    };

    worker.execute();

    return true;
}

From source file:co.edu.unal.pos.gui.PosHadoopJFrame.java

private void saveConfigurationJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_configurationJButtonActionPerformed
    SwingWorker<Void, Void> swingWorker = new SwingWorker<Void, Void>() {

        @Override/* ww w . j  a va 2  s.  c om*/
        protected Void doInBackground() throws Exception {
            disableGUI();
            properties.clear();
            for (int i = 0; i < configurationTableDataModel.getRowCount(); i++) {
                properties.put(configurationTableDataModel.getValueAt(i, 0).toString(),
                        configurationTableDataModel.getValueAt(i, 1).toString());
            }
            PropertiesProvider.getInstance().saveProperties(properties);
            enableGUI();
            return null;
        }

    };
    swingWorker.execute();
}

From source file:it.unibas.spicygui.controllo.spicy.ActionRankTransformations.java

@Override
public void performAction() {
    executeInjection();//  w  w w .  j  a v  a  2  s. c  om
    Scenario scenario = (Scenario) modello.getBean(Costanti.CURRENT_SCENARIO);
    MappingTask mappingTask = scenario.getMappingTask();
    if (mappingTask.getTargetProxy().getInstances().isEmpty()) {
        DialogDisplayer.getDefault()
                .notify(new NotifyDescriptor.Message(
                        NbBundle.getMessage(Costanti.class, Costanti.WARNING_NOT_TARGET_INSTANCES),
                        DialogDescriptor.INFORMATION_MESSAGE));
        return;
    }
    //        MappingTaskInfo mappingTaskInfo = (MappingTaskInfo) modello.getBean(Costanti.MAPPINGTASK_INFO);
    if (mappingTask.getMappingData() == null) {
        DialogDisplayer.getDefault()
                .notify(new NotifyDescriptor.Message(NbBundle.getMessage(Costanti.class, Costanti.NOT_MAPPED),
                        DialogDescriptor.INFORMATION_MESSAGE));
        return;
    }
    // TODO: check
    //        if (mappingTaskInfo.getTransformations().size() == 1) {
    //            DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(NbBundle.getMessage(Costanti.class, Costanti.SINGLE_TRANSFORMATION), DialogDescriptor.INFORMATION_MESSAGE));
    //            return;
    //        }
    SwingWorker swingWorker = new SwingWorker() {

        private Scenario scenario;

        @Override
        protected Object doInBackground() throws Exception {
            scenario = (Scenario) modello.getBean(Costanti.CURRENT_SCENARIO);
            MappingTask mappingTask = scenario.getMappingTask();
            List<Transformation> rankedTransformations = tranformationRanker.rankTransformations(mappingTask);
            modello.putBean(Costanti.RANKED_TRANSFORMATIONS, rankedTransformations);
            return true;
        }

        @Override
        protected void done() {
            try {
                if ((Boolean) get() && !isCancelled()) {
                    actionViewRankedTranformations.performActionWithScenario(scenario);
                }
            } catch (InterruptedException ex) {
                logger.error(ex);
            } catch (ExecutionException ex) {
                logger.error(ex);
            }
        }
    };
    swingWorker.execute();

}

From source file:es.emergya.ui.plugins.admin.AdminLayers.java

protected Action subeCapaAction(final CapaInformacion capa) {
    Action a = new AbstractAction("", LogicConstants.getIcon("button_up")) {

        private static final long serialVersionUID = 912391796510206341L;

        @Override//from   www. ja v a 2  s.  c o m
        public void actionPerformed(ActionEvent e) {
            log.debug("subeCapaAction(" + capa + ")");
            SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() {

                @Override
                protected Object doInBackground() throws Exception {
                    CapaInformacionAdmin.sube(capa);
                    return null;
                }

                @Override
                protected void done() {
                    super.done();
                    AdminLayers.this.refresh(null);
                }
            };
            sw.execute();
        }
    };

    return a;
}

From source file:es.emergya.ui.plugins.admin.AdminLayers.java

protected Action bajaCapaAction(final CapaInformacion capa) {
    Action a = new AbstractAction("", LogicConstants.getIcon("button_down")) {

        private static final long serialVersionUID = -4001983030571380494L;

        @Override//from  w w w  . j  a v  a2  s .c  o m
        public void actionPerformed(ActionEvent e) {
            log.debug("bajaCapaAction(" + capa + ")");
            SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() {

                @Override
                protected Object doInBackground() throws Exception {
                    CapaInformacionAdmin.baja(capa);
                    return null;
                }

                @Override
                protected void done() {
                    super.done();
                    AdminLayers.this.refresh(null);
                }
            };
            sw.execute();
        }
    };

    return a;
}

From source file:edu.ku.brc.specify.plugins.imgproc.ImageProcessorPanel.java

/**
 * /* www . j  a va 2 s . c o m*/
 */
protected void doNextStep() {
    if (step > -1) {
        procObjs.get(step).setOn(false);
    }

    step++;
    if (step >= procObjs.size()) {
        step = 0;
    }

    System.out.println("Step: " + step);

    procObjs.get(step).setOn(true);

    SwingWorker<Integer, Integer> worker = new SwingWorker<Integer, Integer>() {
        /* (non-Javadoc)
         * @see javax.swing.SwingWorker#doInBackground()
         */
        @Override
        protected Integer doInBackground() throws Exception {
            switch (step) {
            case 0:
                acquireImages();
                break;

            case 1:
                processBarCode();
                break;

            case 2:
                processMetaData();
                break;

            case 3:
                processSaveToDisk();
                break;

            }
            return null;
        }
    };
    worker.execute();
}

From source file:com.mirth.connect.manager.ManagerController.java

public void stopMirthWorker() {
    PlatformUI.MANAGER_DIALOG.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    setEnabledOptions(false, false, false, false);

    SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
        private String errorMessage = null;

        public Void doInBackground() {
            errorMessage = stopMirth();//from  ww  w  .j  a v a2s .c om
            return null;
        }

        public void done() {
            if (errorMessage == null) {
                PlatformUI.MANAGER_TRAY.alertInfo("The Mirth Connect Service was stopped successfully.");
            } else {
                PlatformUI.MANAGER_TRAY.alertError(errorMessage);
            }

            updateMirthServiceStatus();
            PlatformUI.MANAGER_DIALOG.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        }
    };

    worker.execute();
}

From source file:com.mirth.connect.manager.ManagerController.java

public void startMirthWorker() {
    PlatformUI.MANAGER_DIALOG.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    ManagerController.getInstance().setEnabledOptions(false, false, false, false);

    SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
        private String errorMessage = null;

        public Void doInBackground() {
            errorMessage = startMirth();
            return null;
        }/*  ww  w  .  j a  va 2s.c  om*/

        public void done() {
            if (errorMessage == null) {
                PlatformUI.MANAGER_TRAY.alertInfo("The Mirth Connect Service was started successfully.");
            } else {
                PlatformUI.MANAGER_TRAY.alertError(errorMessage);
            }

            updateMirthServiceStatus();
            PlatformUI.MANAGER_DIALOG.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        }
    };

    worker.execute();
}