Example usage for javax.swing JProgressBar setMaximum

List of usage examples for javax.swing JProgressBar setMaximum

Introduction

In this page you can find the example usage for javax.swing JProgressBar setMaximum.

Prototype

@BeanProperty(bound = false, preferred = true, description = "The progress bar's maximum value.")
public void setMaximum(int n) 

Source Link

Document

Sets the progress bar's maximum value (stored in the progress bar's data model) to n.

Usage

From source file:bemap.SimpleSerial.java

public int importDataFromDevice(JProgressBar progressBar, JTextArea status)
        throws InterruptedException, JSONException {
    if ("Error - no Port found".equals(serialPortName))
        return -1;
    else {//from www  .  j a  v  a 2s .  c o  m
        SerialPort serialPort = new SerialPort(serialPortName);

        try {
            serialPort.openPort();//Open serial port
            serialPort.setParams(SerialPort.BAUDRATE_115200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
                    SerialPort.PARITY_NONE);//Set params. Also you can set params by this string: serialPort.setParams(9600, 8, 1, 0);

            serialPort.writeBytes("$ORUSR*11\n".getBytes());//Write data to port
            Thread.sleep(WAIT_MS);
            String userString = serialPort.readString();
            int usr = decodeUserID(userString);
            if (usr > 0) {
                BeMapEditor.mainWindow.setUsr(usr);
                status.append("\nUser ID: " + usr);
            } else if (usr == -1) {
                //code for getting usr id from server
                //$ORUSR,25*11\n
                status.append("\nError: No user ID set!");
                BeMapEditor.mainWindow.setUsr(-1);
            } else {
                status.append("\nError: No User ID found! Import aborted.");
                return -1;
            }

            //import settings
            serialPort.writeBytes("$ORCFG*11\n".getBytes());//Write data to port
            Thread.sleep(WAIT_MS);
            String configString = serialPort.readString();
            if (decodeSettings(configString) == 1 && SERIAL_DEBUG) {
                BeMapEditor.mainWindow.append("\nSettings decoded");
            } else
                BeMapEditor.mainWindow.append("\nError decoding settings");

            //Start importing points
            serialPort.writeBytes("$ORNUM*11\n".getBytes());
            Thread.sleep(WAIT_MS);
            String numberString = serialPort.readString();
            int totalNumber = decodeNbPoints(numberString);
            if (totalNumber > 0)
                status.append("\nNumber of points to import: " + totalNumber);
            else if (totalNumber == 0) {
                status.append("\nNo points stored to import! ");
                return 0;
            } else {
                status.append("\nError: Number of Points");
                return -1;
            }

            //prepare track to import
            BeMapEditor.trackOrganiser.createNewTrack("Import");

            int nbRequests = (totalNumber / (MAX_DATA_PER_IMPORT)) + 1;
            int rest = totalNumber - (nbRequests - 1) * MAX_DATA_PER_IMPORT; //nb of points for the last request
            if (SERIAL_DEBUG)
                BeMapEditor.mainWindow.append("\nNumber of requests necessary: " + nbRequests);
            if (SERIAL_DEBUG)
                BeMapEditor.mainWindow.append("\nPoints resting for last request: " + rest);

            //init progress bar
            progressBar.setMaximum(nbRequests);

            for (int i = 0; i < (nbRequests - 1); i++) {
                //import serie of points
                int offset = i * MAX_DATA_PER_IMPORT;
                if (importSerieOfPoints(serialPort, MAX_DATA_PER_IMPORT, offset) < 0)
                    return 0;
                //actualize progress bar
                progressBar.setValue(i + 1);
            }
            int final_offset = (nbRequests - 1) * MAX_DATA_PER_IMPORT;
            if (importSerieOfPoints(serialPort, rest, final_offset) < 0)
                return 0; //import the rest of the points
            progressBar.setValue(nbRequests);

            status.append("\n" + totalNumber + " Points successfully imported");

            serialPort.writeString("$ORMEM*11\n");
            Thread.sleep(WAIT_MS);
            decodeMemoryState(serialPort.readString());

            serialPort.closePort();//Close serial port

            BeMapEditor.trackOrganiser.postImportTreatment(progressBar);
            return 1;
        } catch (SerialPortException ex) {
            return 0;//do not print error
        }
    }

}

From source file:edu.ku.brc.specify.tasks.subpane.wb.wbuploader.Uploader.java

/**
 * @param min// ww  w . ja  va2s .  co m
 * @param max
 * @param paintString - true if the progress bar should display string description of progress
 * @param itemName - string description will be: "itemName x of max" (using English resource).
 * 
 * Initializes progress bar for upload actions. If min and max = 0, sets progress bar is
 * indeterminate.
 */
protected void initProgressBar(final int min, final int max, final boolean paintString, final String itemName,
        final boolean useAppProgress) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            if (!useAppStatBar && mainPanel == null) {
                log.error("UI does not exist.");
                return;
            }
            minProgVal = min;
            maxProgVal = max;
            indeterminateProgress = minProgVal == 0 && maxProgVal == 0;
            useAppStatBar = useAppProgress;
            if (useAppStatBar) {
                if (indeterminateProgress) {
                    UIRegistry.getStatusBar().setIndeterminate("UPLOADER", indeterminateProgress);
                } else {
                    UIRegistry.getStatusBar().setProgressRange("UPLOADER", minProgVal, maxProgVal);
                }
            } else {
                JProgressBar pb = mainPanel.getCurrOpProgress();
                pb.setVisible(true);
                if (indeterminateProgress) {
                    pb.setIndeterminate(true);
                    pb.setString("");
                } else {
                    if (pb.isIndeterminate()) {
                        pb.setIndeterminate(false);
                    }
                    pb.setStringPainted(paintString);
                    if (paintString) {
                        pb.setName(itemName);
                    }
                    pb.setMinimum(minProgVal);
                    pb.setMaximum(maxProgVal);
                    pb.setValue(minProgVal);
                }
            }
        }
    });
}

From source file:org.jets3t.gui.skins.SkinsFactory.java

/**
 * @param itemName/*from www.j a va  2 s  .c o m*/
 * the name of this specific item in the GUI, which may be used to determine how the skinned
 * item should look or behave.
 *
 * @return
 * a <code>SkinnedJProgressBar</code> class implementation for the current skin, or a default
 * JProgressBar if no skin-specific implementation is available.
 */
public JProgressBar createSkinnedJProgressBar(String itemName, int min, int max) {
    JProgressBar jProgressBar = (JProgressBar) instantiateClass(buildSkinnedClassName("SkinnedJProgressBar"),
            itemName);
    if (jProgressBar != null) {
        jProgressBar.setMinimum(min);
        jProgressBar.setMaximum(max);
        return jProgressBar;
    } else {
        jProgressBar = new JProgressBar(min, max);
        return jProgressBar;
    }
}