Example usage for java.beans PropertyChangeListener PropertyChangeListener

List of usage examples for java.beans PropertyChangeListener PropertyChangeListener

Introduction

In this page you can find the example usage for java.beans PropertyChangeListener PropertyChangeListener.

Prototype

PropertyChangeListener

Source Link

Usage

From source file:canreg.client.gui.management.CanReg4MigrationInternalFrame.java

@Action
public void MigrationAction() {
    okButton.setEnabled(false);/*  www .ja v a2 s.  c  o m*/
    doneButton.setEnabled(false);
    cancelButton.setEnabled(true);
    jList1.setEnabled(false);
    EditDatabaseVariableTableAssociationInternalFrame edvif = new EditDatabaseVariableTableAssociationInternalFrame();
    int addServer = JOptionPane.showInternalConfirmDialog(
            CanRegClientApp.getApplication().getMainFrame().getContentPane(),
            java.util.ResourceBundle
                    .getBundle("canreg/client/gui/management/resources/CanReg4SystemConverterInternalFrame")
                    .getString("SUCCESSFULLY_CREATED_XML: ") + "\'" + Globals.CANREG_SERVER_SYSTEM_CONFIG_FOLDER
                    + Globals.FILE_SEPARATOR + regcode + "\'.\n"
                    + java.util.ResourceBundle.getBundle(
                            "canreg/client/gui/management/resources/CanReg4SystemConverterInternalFrame")
                            .getString("ADD_IT_TO_FAV_SERVERS?"),
            "Success", JOptionPane.YES_NO_OPTION);
    if (addServer == JOptionPane.YES_OPTION) {
        localSettings = CanRegClientApp.getApplication().getLocalSettings();
        localSettings.addServerToServerList(dlm.get(list.getSelectedIndex()), "localhost", Globals.DEFAULT_PORT,
                regcode);
        localSettings.writeSettings();
    }
    try {
        edvif.setTitle("Variables and Tables for "
                + WordUtils.capitalize(dlm.get(list.getSelectedIndex()).toLowerCase()));
        edvif.loadSystemDefinition(
                Globals.CANREG_SERVER_SYSTEM_CONFIG_FOLDER + Globals.FILE_SEPARATOR + regcode + ".xml");
        edvif.setDesktopPane(desktopPane);
        CanRegClientView.showAndPositionInternalFrame(desktopPane, edvif);
    } catch (IOException ex) {
        Logger.getLogger(CanReg4SystemConverterInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ParserConfigurationException ex) {
        Logger.getLogger(CanReg4SystemConverterInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SAXException ex) {
        Logger.getLogger(CanReg4SystemConverterInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
    }

    edvif.saveButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            //logout from canreg system before conversion
            if (CanRegClientApp.getApplication().loggedIn) {
                try {
                    CanRegClientApp.getApplication().logOut();
                } catch (RemoteException ex) {
                    Logger.getLogger(CanReg4MigrationInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            //check to see if there is a database already - rename it
            File databaseFolder = new File(
                    Globals.CANREG_SERVER_DATABASE_FOLDER + Globals.FILE_SEPARATOR + regcode);
            if (databaseFolder.exists()) {
                int i = 0;
                File folder2 = databaseFolder;
                while (folder2.exists()) {
                    i++;
                    folder2 = new File(
                            Globals.CANREG_SERVER_DATABASE_FOLDER + Globals.FILE_SEPARATOR + regcode + i);
                }
                databaseFolder.renameTo(folder2);
                debugOut("database: " + databaseFolder);
                try {
                    canreg.common.Tools.fileCopy(
                            Globals.CANREG_SERVER_SYSTEM_CONFIG_FOLDER + Globals.FILE_SEPARATOR + regcode
                                    + ".xml",
                            Globals.CANREG_SERVER_SYSTEM_CONFIG_FOLDER + Globals.FILE_SEPARATOR + regcode + i
                                    + ".xml");
                } catch (IOException ex) {
                    Logger.getLogger(CanReg4MigrationInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            ProgressBar.setStringPainted(true);
            cTask = new ProgressTask(
                    org.jdesktop.application.Application.getInstance(canreg.client.CanRegClientApp.class));
            cTask.execute();
            cTask.addPropertyChangeListener(new PropertyChangeListener() {
                @Override
                public void propertyChange(PropertyChangeEvent evt) {
                    if ("progress".equals(evt.getPropertyName())) {
                        ProgressBar.setValue((Integer) evt.getNewValue());
                        ProgressBar.setString(evt.getNewValue().toString() + "%");
                    }
                }
            });
        }
    });
}

From source file:org.squidy.designer.model.NodeShape.java

/**
 * //from  w w w  .  ja va2  s.c  o  m
 */
private void buildPropertiesForPropertiesTable() {
    propertiesTable.clearEntries();

    Field[] fields = ReflectionUtil.getFieldsInObjectHierarchy(getProcessable().getClass());
    for (Field field : fields) {

        if (field.isAnnotationPresent(Property.class)) {

            final String fieldName = field.getName();
            Object value = MVEL.getProperty(field.getName(), getProcessable());
            final AbstractBasicControl<Object, ?> control;
            if (field.isAnnotationPresent(TextField.class)) {
                control = (AbstractBasicControl<Object, ?>) ControlUtils
                        .createControl(field.getAnnotation(TextField.class), value);
            } else if (field.isAnnotationPresent(CheckBox.class)) {
                control = (AbstractBasicControl<Object, ?>) ControlUtils
                        .createControl(field.getAnnotation(CheckBox.class), value);
            } else if (field.isAnnotationPresent(ComboBox.class)) {
                control = (AbstractBasicControl<Object, ?>) ControlUtils
                        .createControl(field.getAnnotation(ComboBox.class), value);
            } else if (field.isAnnotationPresent(Slider.class)) {
                control = (AbstractBasicControl<Object, ?>) ControlUtils
                        .createControl(field.getAnnotation(Slider.class), value);
            } else if (field.isAnnotationPresent(Spinner.class)) {
                control = (AbstractBasicControl<Object, ?>) ControlUtils
                        .createControl(field.getAnnotation(Spinner.class), value);
            } else if (field.isAnnotationPresent(ImagePanel.class)) {
                control = (AbstractBasicControl<Object, ?>) ControlUtils
                        .createControl(field.getAnnotation(ImagePanel.class), value);
            } else if (field.isAnnotationPresent(Gauge.class)) {
                control = (AbstractBasicControl<Object, ?>) ControlUtils
                        .createControl(field.getAnnotation(Gauge.class), value);
            } else if (field.isAnnotationPresent(FileChooser.class)) {
                control = (AbstractBasicControl<Object, ?>) ControlUtils
                        .createControl(field.getAnnotation(FileChooser.class), value);
            } else {
                throw new SquidyException("Couldn't add property " + fieldName
                        + " to properties table because of a not existing control annotation.");
            }

            Property property = field.getAnnotation(Property.class);

            String name = property.name();
            String description = property.description();
            String prefix = property.prefix();
            String suffix = property.suffix();

            // Add property change listener to receive processing updates.
            getProcessable().addStatusChangeListener(fieldName, new PropertyChangeListener() {

                /*
                 * (non-Javadoc)
                 * 
                 * @see
                 * java.beans.PropertyChangeListener#propertyChange(java
                 * .beans.PropertyChangeEvent)
                 */
                public void propertyChange(PropertyChangeEvent evt) {
                    try {
                        control.setValueWithoutPropertyUpdate(evt.getNewValue());
                    } catch (Exception e) {
                        control.setValueWithoutPropertyUpdate(
                                control.valueFromString(evt.getNewValue().toString()));
                    }
                    control.getComponent().repaint();

                    propertiesTable.firePropertyChange(CropScroll.CROP_SCROLLER_UPDATE, null, null);
                }
            });

            // Add property update change listener to inform the processable
            // about UI update events.
            control.addPropertyUpdateListener(new PropertyUpdateListener<Object>() {

                /*
                 * (non-Javadoc)
                 * 
                 * @see org.squidy.designer.components.
                 * PropertyUpdateListener #propertyUpdate(java.lang.Object)
                 */
                public void propertyUpdate(Object value) {
                    try {
                        // Notify manager about property changes.
                        Manager.get().propertyChanged(getProcessable(), fieldName, value);

                        control.firePropertyChange(PROPERTY_BINDING_OK, null, null);
                    } catch (Exception e) {
                        control.firePropertyChange(PROPERTY_BINDING_EXCEPTION, null, null);
                        publishFailure(new SquidyException("Could not set property " + fieldName
                                + ". Please check setter of this property for any Exceptions such as NullPointerException.",
                                e));
                    }

                    propertiesTable.firePropertyChange(CropScroll.CROP_SCROLLER_UPDATE, null, null);
                }
            });

            TableEntry entry = new TableEntry<IBasicControl<?, ?>>(name, description, control, prefix, suffix);
            if (field.isAnnotationPresent(ImagePanel.class)) {
                entry.addInputEventListener(new PBasicInputEventHandler() {
                    @Override
                    public void mouseClicked(PInputEvent event) {
                        control.customPInputEvent(event);
                    }
                });
            }
            propertiesTable.addEntryToGroup(entry, property.group());
        }
    }
}

From source file:org.isatools.isacreatorconfigurator.configui.FieldInterface.java

/**
 * Create an DropDownComponent field.//from   w  w w . j ava  2 s  .  c  om
 *
 * @param field                     - JTextField to be associated with the OntologySelectionTool.
 * @param allowsMultiple            - Should the OntologySelectionTool allow multiple terms to be selected.
 * @param recommendedOntologySource - A recommended ontology source.
 * @return DropDownComponent object.
 */
protected DropDownComponent createOntologyDropDown(final JTextField field, boolean allowsMultiple,
        Map<String, RecommendedOntology> recommendedOntologySource) {
    final OntologySelectionTool ost = new OntologySelectionTool(allowsMultiple, false,
            recommendedOntologySource);
    ost.createGUI();

    final DropDownComponent dropdown = new DropDownComponent(field, ost, DropDownComponent.ONTOLOGY);
    ost.addPropertyChangeListener("selectedOntology", new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            dropdown.hidePopup(ost);
            String value = evt.getNewValue().toString();
            // for this section, we are only storing the term at the minute, not the entire unique id
            // returned from the ontology lookup tool!
            value = value.contains(":") ? value.substring(value.indexOf(":") + 1) : value;
            field.setText(value);
        }
    });

    ost.addPropertyChangeListener("noSelectedOntology", new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            dropdown.hidePopup(ost);
        }
    });

    return dropdown;
}

From source file:edu.ku.brc.af.core.db.MySQLBackupService.java

/**
 * @param databaseName// w  ww. j av a 2 s  .c om
 * @param restoreFilePath
 * @param glassPane
 * @param completionMsgKey
 */
protected boolean doRestoreInBackground(final String databaseName, final String restoreFilePath,
        final SimpleGlassPane glassPane, final String completionMsgKey, final PropertyChangeListener pcl,
        final boolean doSynchronously) {
    AppPreferences remotePrefs = AppPreferences.getLocalPrefs();
    final String mysqlLoc = remotePrefs.get(MYSQL_LOC, getDefaultMySQLLoc());

    getNumberofTables();

    SynchronousWorker backupWorker = new SynchronousWorker() {
        long dspMegs = 0;
        long fileSize = 0;

        /* (non-Javadoc)
         * @see javax.swing.SwingWorker#doInBackground()
         */
        @Override
        protected Integer doInBackground() throws Exception {
            FileInputStream input = null;
            try {
                String userName = itUsername != null ? itUsername : DBConnection.getInstance().getUserName();
                String password = itPassword != null ? itPassword : DBConnection.getInstance().getPassword();
                String port = DatabaseDriverInfo.getDriver(DBConnection.getInstance().getDriverName())
                        .getPort();
                String server = DBConnection.getInstance().getServerName();

                String cmdLine = String.format("%s -u %s --password=%s --host=%s %s %s", mysqlLoc, userName,
                        password, server, (port != null ? ("--port=" + port) : ""), databaseName);
                Vector<String> args = new Vector<String>();
                args.add(mysqlLoc);
                args.add("--user=" + userName);
                args.add("--password=" + password);
                args.add("--host=" + server);
                if (port != null) {
                    args.add("--port=" + port);
                }
                args.add(databaseName);

                Process process = Runtime.getRuntime().exec(args.toArray(new String[0]));

                Thread.sleep(100);

                OutputStream out = process.getOutputStream();

                // wait as long it takes till the other process has prompted.
                try {
                    File inFile = new File(restoreFilePath);
                    fileSize = inFile.length();
                    //System.out.println(fileSize);

                    double oneMB = (1024.0 * 1024.0);
                    double threshold = fileSize < (oneMB * 4) ? 8192 * 8 : oneMB;
                    long totalBytes = 0;

                    dspMegs = 0;

                    input = new FileInputStream(inFile);
                    try {
                        byte[] bytes = new byte[8192 * 4];
                        do {
                            int numBytes = input.read(bytes, 0, bytes.length);

                            totalBytes += numBytes;
                            if (numBytes > 0) {
                                out.write(bytes, 0, numBytes);

                                long megs = (long) (totalBytes / threshold);
                                if (megs != dspMegs) {
                                    dspMegs = megs;
                                    firePropertyChange(MEGS, dspMegs, (int) ((100.0 * totalBytes) / fileSize));
                                }

                            } else {
                                break;
                            }
                        } while (true);
                    } finally {
                        input.close();
                    }
                } catch (IOException ex) {
                    edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                    //edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(MySQLBackupService.class, ex);
                    ex.printStackTrace();
                    errorMsg = ex.toString();
                    UIRegistry.showLocalizedError("MySQLBackupService.EXCP_RS");

                } catch (Exception ex) {
                    ex.printStackTrace();
                    if (pcl != null) {
                        pcl.propertyChange(new PropertyChangeEvent(MySQLBackupService.this, ERROR, 0, 1));
                    }
                }

                setProgress(100);

                out.flush();
                out.close();

                BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
                String line = null;
                while ((line = in.readLine()) != null) {
                    //System.err.println(line);
                }

                in = new BufferedReader(new InputStreamReader(process.getErrorStream()));
                StringBuilder sb = new StringBuilder();
                while ((line = in.readLine()) != null) {
                    if (line.startsWith("ERR")) {
                        sb.append(line);
                        sb.append("\n");
                    }
                }
                errorMsg = sb.toString();

            } catch (Exception ex) {
                ex.printStackTrace();
                errorMsg = ex.toString();
                if (pcl != null) {
                    pcl.propertyChange(new PropertyChangeEvent(MySQLBackupService.this, ERROR, 0, 1));
                }
            }

            return null;
        }

        @Override
        protected void done() {
            super.done();

            JStatusBar statusBar = UIRegistry.getStatusBar();
            if (statusBar != null) {
                statusBar.setProgressDone(STATUSBAR_NAME);
            }

            if (glassPane != null) {
                UIRegistry.clearSimpleGlassPaneMsg();
            }

            if (StringUtils.isNotEmpty(errorMsg)) {
                UIRegistry.showError(errorMsg);
            }

            if (statusBar != null) {
                statusBar.setText(UIRegistry.getLocalizedMessage(completionMsgKey, dspMegs));
            }

            if (pcl != null) {
                pcl.propertyChange(new PropertyChangeEvent(MySQLBackupService.this, DONE, 0, 1));
            }
        }
    };

    if (glassPane != null) {
        glassPane.setProgress(0);
    }

    backupWorker.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(final PropertyChangeEvent evt) {
            if (MEGS.equals(evt.getPropertyName()) && glassPane != null) {
                int value = (Integer) evt.getNewValue();

                if (value < 100) {
                    glassPane.setProgress((Integer) evt.getNewValue());
                } else {
                    glassPane.setProgress(100);
                }
            }
        }
    });

    if (doSynchronously) {
        return backupWorker.doWork();
    }

    backupWorker.execute();
    return true;
}

From source file:org.apache.log4j.chainsaw.LogUI.java

private void setupReceiverPanel() {
    receiversPanel = new ReceiversPanel();
    receiversPanel.addPropertyChangeListener("visible", new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            getApplicationPreferenceModel().setReceivers(((Boolean) evt.getNewValue()).booleanValue());
        }//from w w  w  .  j a  va2  s .c o  m
    });
}

From source file:org.mwc.cmap.xyplot.views.XYPlotView.java

private void setupFiringChangesToChart() {

    // see if we've alreay been configured
    if (_timeListener != null)
        return;//from  w  w w  .  j  a  va  2  s.c o m

    // get the document being edited
    final IWorkbench wb = PlatformUI.getWorkbench();
    final IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
    final IWorkbenchPage page = win.getActivePage();
    editor = null;

    // the page might not yet be open...
    if (page != null) {
        editor = page.getActiveEditor();
        // do we have an active editor?
        if (editor == null) {
            // see if there are any editors at all open
            final IEditorReference[] theEditors = page.getEditorReferences();
            for (int i = 0; i < theEditors.length; i++) {
                final IEditorReference thisE = theEditors[i];
                editor = thisE.getEditor(false);

                // right, see if it has a time manager
                final TimeProvider tp = (TimeProvider) editor.getAdapter(TimeProvider.class);
                if (tp != null) {
                    final String hisId = tp.getId();
                    if (hisId == _myId)
                        break;
                }
            }

            // nope, drop out.
            return;
        }
    }

    TimeProvider prov = null;
    if (editor != null) {
        // get it's time-provider interface
        prov = (TimeProvider) editor.getAdapter(TimeProvider.class);
    } else
        CorePlugin.logError(Status.WARNING, "Failed to identify time provider", null);

    if (prov != null) {
        // create our listener
        _timeListener = new PropertyChangeListener() {
            public void propertyChange(final PropertyChangeEvent evt) {
                // ok - fire the time change to the chart
                final HiResDate newDTG = (HiResDate) evt.getNewValue();

                // right tell the plot it's new time
                _thePlot.newTime(null, newDTG, null);

                // and tell the plot holder to redraw everything
                _chartInPanel.newTime(null, newDTG, null);
                refreshPlot();
            }
        };

        // add our listener to the time object
        prov.addListener(_timeListener, TimeProvider.TIME_CHANGED_PROPERTY_NAME);

        // fire the current time to our chart (just to start us off)
        _chartInPanel.newTime(null, prov.getTime(), null);
        refreshPlot();
    }
}

From source file:edu.ku.brc.specify.tasks.subpane.VisualQueryPanel.java

/**
 * @throws IOException /*from www.j  av a 2s  .c  o  m*/
 * 
 */
private void doSearch() throws IOException {
    final String CNT = "CNT";

    UIFieldFormatterIFace fieldFmt = null;
    if (typeCBX.getSelectedIndex() == 0) {
        fieldFmt = DBTableIdMgr.getFieldFormatterFor(CollectionObject.class, "catalogNumber");
    }

    final StringBuilder pmStr = new StringBuilder();
    final String placeMark = " <Placemark><name>%s - %d / %d</name><Point><coordinates>%8.5f, %8.5f, 5</coordinates></Point></Placemark>\n";

    polySB.setLength(0);
    boxSB.setLength(0);

    final JStatusBar statusBar = UIRegistry.getStatusBar();
    final UIFieldFormatterIFace fldFmt = fieldFmt;
    SwingWorker<Integer, Integer> worker = new SwingWorker<Integer, Integer>() {
        @Override
        protected Integer doInBackground() throws Exception {
            // fills pntList from polyline
            // polyline was filled via clicks on WorldWind
            totalNumRecords = BasicSQLUtils.getCountAsInt(buildSQL(true));

            availPoints.clear();
            model = (DefaultListModel) dbObjList.getModel();
            model.removeAllElements();
            topIdHash.clear();

            markers.clear();

            polygon = new Polyline(polyline.getPositions());
            polygon.setClosed(true);

            for (Position p : polyline.getPositions()) {
                polySB.append(String.format("    %8.5f, %8.5f, 20\n", p.longitude.degrees, p.latitude.degrees));
            }

            int maxThreshold = 1000;
            int index = 0;
            Connection conn = null;
            Statement stmt = null;
            try {
                conn = DBConnection.getInstance().createConnection();
                stmt = conn.createStatement();

                int currCnt = 0;
                ResultSet rs = stmt.executeQuery(buildSQL(false));
                while (rs.next()) {
                    if (currCnt < maxThreshold) {
                        double lat = rs.getBigDecimal(2).doubleValue();
                        double lon = rs.getBigDecimal(3).doubleValue();

                        Position pos = Position.fromDegrees(lat, lon, 0.0);
                        // ZZZ                            
                        //                            if (GeometryMath.isLocationInside(pos, polygon.getPositions()))
                        //                            {
                        //                                LatLonPoint llp = new LatLonPoint(rs.getInt(1), lat, lon);
                        //                                String title = rs.getString(4);
                        //                                if (title != null)
                        //                                {
                        //                                    title = (fldFmt != null ? fldFmt.formatToUI(title) :title).toString();
                        //                                } else
                        //                                {
                        //                                    title = "N/A";
                        //                                }
                        //                                llp.setTitle(title);
                        //                                llp.setIndex(index++);
                        //                                availPoints.add(llp);
                        //                                markers.add(llp);
                        //                                topIdHash.add(llp.getLocId());
                        //                                System.out.println(index+" / "+currCnt+" In:      "+lat+",  "+lon);
                        //                                pmStr.append(String.format(placeMark, "In: ",index, currCnt, lon, lat));
                        //                                
                        //                            } else
                        //                            {
                        //                                System.out.println(index+" / "+currCnt+" Tossing: "+lat+",  "+lon);
                        //                                pmStr.append(String.format(placeMark, "Tossing: ", index, currCnt, lon, lat));
                        //                            }
                    }
                    currCnt++;
                    if (currCnt % 100 == 0) {
                        firePropertyChange(CNT, 0, currCnt);
                    }
                }
                rs.close();
            } catch (SQLException ex) {
                ex.printStackTrace();
                /*UsageTracker.incrSQLUsageCount();
                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(BaseTreeTask.class, ex);
                log.error("SQLException: " + ex.toString()); //$NON-NLS-1$
                lo .error(ex.getMessage());*/

            } finally {
                try {
                    if (stmt != null)
                        stmt.close();
                    if (conn != null)
                        conn.close();
                } catch (Exception ex) {
                    edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                    edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(BaseTreeTask.class, ex);
                    ex.printStackTrace();
                }
            }

            return null;
        }

        /* (non-Javadoc)
         * @see javax.swing.SwingWorker#done()
         */
        @Override
        protected void done() {
            super.done();

            if (doDebug) {
                try {
                    final String template = FileUtils.readFileToString(new File("template.kml"));
                    final PrintWriter pw = new PrintWriter(new File("debug.kml"));

                    String str = StringUtils.replace(template, "<!-- BOX -->", boxSB.toString());
                    str = StringUtils.replace(str, "<!-- POLYGON -->", polySB.toString());
                    str = StringUtils.replace(str, "<!-- PLACEMARKS -->", pmStr.toString());
                    pw.println(str);
                    pw.flush();
                    pw.close();
                } catch (IOException ex) {
                }
            }

            UIRegistry.clearSimpleGlassPaneMsg();
            statusBar.setProgressDone(STATUSBAR_NAME);

            for (LatLonPlacemarkIFace llp : markers) {
                model.addElement(llp);
            }

            if (markers.size() > 0) {
                wwPanel.placeMarkers(markers, null);
                searchBtn.setEnabled(false);

            } else {
                doClearAll(true);
                startBtn.setEnabled(false);
            }
            clearAllBtn.setEnabled(true);
            clearSearchBtn.setEnabled(true);
        }
    };

    statusBar.setIndeterminate(STATUSBAR_NAME, false);
    statusBar.setProgressRange(STATUSBAR_NAME, 0, 100);

    final SimpleGlassPane glassPane = UIRegistry
            .writeSimpleGlassPaneMsg(getLocalizedMessage("MySQLBackupService.BACKINGUP", "XXX"), 24);

    worker.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(final PropertyChangeEvent evt) {
            if (CNT.equals(evt.getPropertyName())) {
                int value = (Integer) evt.getNewValue();
                int progress = (int) (((double) value / (double) totalNumRecords) * 100.0);
                glassPane.setProgress(progress);
                statusBar.setValue(STATUSBAR_NAME, progress);
            }
        }
    });
    worker.execute();
}

From source file:tauargus.model.batch.java

static boolean readMicrodataBatch() throws ArgusException {
    Date startDate = new Date();
    long timeDiff;
    TableService.readMicrodata(new PropertyChangeListener() {
        @Override/*  w ww .  ja va2  s .c  o m*/
        public void propertyChange(PropertyChangeEvent evt) {
        }
    });
    Date endDate = new Date();
    timeDiff = (endDate.getTime() - startDate.getTime()) / 1000;
    SystemUtils.writeLogbook("Micro data file read; processing time " + timeDiff + " seconds");
    return true;
}

From source file:org.openmicroscopy.shoola.agents.metadata.view.MetadataViewerComponent.java

/**
 * Implemented as specified by the {@link MetadataViewer} interface.
 * @see MetadataViewer#makeMovie(int, Color)
 *//*from  w w  w .  j ava  2 s  .co m*/
public void makeMovie(int scaleBar, Color overlayColor) {
    Object refObject = model.getRefObject();
    if (refObject instanceof WellSampleData) {
        WellSampleData wsd = (WellSampleData) refObject;
        refObject = wsd.getImage();
    }
    if (!(refObject instanceof ImageData))
        return;
    PixelsData data = null;
    ImageData img = (ImageData) refObject;
    try {
        data = ((ImageData) refObject).getDefaultPixels();
    } catch (Exception e) {
    }
    if (data == null)
        return;
    int maxT = data.getSizeT();
    int maxZ = data.getSizeZ();
    int defaultZ = maxZ;
    int defaultT = maxT;

    Object value = data.getSizeC();
    if (model.getEditor().getChannelData() != null)
        value = model.getEditor().getChannelData();
    String name = EditorUtil.getPartialName(img.getName());
    JFrame f = MetadataViewerAgent.getRegistry().getTaskBar().getFrame();
    MovieExportDialog dialog = new MovieExportDialog(f, name, maxT, maxZ, defaultZ, defaultT, value);
    dialog.setBinaryAvailable(MetadataViewerAgent.isBinaryAvailable());
    dialog.setScaleBarDefault(scaleBar, overlayColor);
    dialog.addPropertyChangeListener(new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent evt) {
            String name = evt.getPropertyName();
            if (MovieExportDialog.CREATE_MOVIE_PROPERTY.equals(name)) {
                Object src = evt.getSource();
                if (src instanceof MovieExportDialog) {
                    MovieExportDialog d = (MovieExportDialog) src;
                    createMovie(d.getParameters());
                }
            }
        }
    });
    dialog.centerDialog();
}

From source file:org.jdesktop.swingworker.AccumulativeRunnable.java

public static void main(String[] args) throws Exception {
    JFrame frame = new JFrame("Prime Numbers Demo");
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    JTextArea textArea = new JTextArea();
    textArea.setEditable(false);/*w  ww .  j  a v  a 2s .  com*/
    frame.add(new JScrollPane(textArea), BorderLayout.CENTER);
    PrimeNumbersTask task = new PrimeNumbersTask(textArea, 10000);
    final JProgressBar progressBar = new JProgressBar(0, 100);
    progressBar.setIndeterminate(true);
    frame.add(progressBar, BorderLayout.NORTH);

    frame.setSize(500, 500);
    frame.setVisible(true);

    task.addPropertyChangeListener(
        new PropertyChangeListener() {
            public  void propertyChange(PropertyChangeEvent evt) {
                if ("progress".equals(evt.getPropertyName())) {
                    progressBar.setIndeterminate(false);
                    progressBar.setValue((Integer)evt.getNewValue());
                }
            }
        });
    task.execute();

    return;
}