List of usage examples for javax.swing JProgressBar setMaximum
@BeanProperty(bound = false, preferred = true, description = "The progress bar's maximum value.") public void setMaximum(int n)
n
. From source file:Main.java
public static void main(String[] argv) throws Exception { int minimum = 0; int maximum = 100; JProgressBar progress = new JProgressBar(minimum, maximum); // Get the current value int value = progress.getValue(); // Get the minimum value int min = progress.getMinimum(); // Get the maximum value int max = progress.getMaximum(); // Change the minimum value int newMin = 0; progress.setMinimum(newMin);//from w ww .j ava2 s .com // Change the maximum value int newMax = 256; progress.setMaximum(newMax); // Set the value; the new value will be forced into the bar's range int newValue = 33; progress.setValue(newValue); }
From source file:Main.java
/** * @return//w w w.j av a2 s . com */ private static JProgressBar createProgressBar() { JProgressBar progressBar = new JProgressBar(); progressBar.setIndeterminate(true); progressBar.setIndeterminate(false); progressBar.setMaximum(100); progressBar.setValue(100); return progressBar; }
From source file:net.redstonelamp.gui.RedstoneLampGUI.java
private static void installCallback(JFrame frame, File selected) { JDialog dialog = new JDialog(frame); JLabel status = new JLabel("Downloading build..."); JProgressBar progress = new JProgressBar(); dialog.pack();/* w w w . j a v a 2 s.c om*/ dialog.setVisible(true); try { URL url = new URL("http://download.redstonelamp.net/?file=LatestBuild"); InputStream is = url.openStream(); int size = is.available(); progress.setMinimum(0); progress.setMaximum(size); int size2 = size; OutputStream os = new FileOutputStream(new File(selected, "RedstoneLamp.jar")); while (size2 > 0) { int length = Math.min(4096, size2); byte[] buffer = new byte[length]; size2 -= length; is.read(buffer); progress.setValue(size2); os.write(buffer); } is.close(); os.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.heliosdecompiler.bootstrapper.Bootstrapper.java
private static HeliosData loadHelios() throws IOException { System.out.println("Finding Helios implementation"); HeliosData data = new HeliosData(); boolean needsToDownload = !IMPL_FILE.exists(); if (!needsToDownload) { try (JarFile jarFile = new JarFile(IMPL_FILE)) { ZipEntry entry = jarFile.getEntry("META-INF/MANIFEST.MF"); if (entry == null) { needsToDownload = true;/*from w w w .ja va 2 s.c om*/ } else { Manifest manifest = new Manifest(jarFile.getInputStream(entry)); String ver = manifest.getMainAttributes().getValue("Implementation-Version"); try { data.buildNumber = Integer.parseInt(ver); data.version = manifest.getMainAttributes().getValue("Version"); data.mainClass = manifest.getMainAttributes().getValue("Main-Class"); } catch (NumberFormatException e) { needsToDownload = true; } } } catch (IOException e) { needsToDownload = true; } } if (needsToDownload) { URL latestJar = new URL(LATEST_JAR); System.out.println("Downloading latest Helios implementation"); FileOutputStream out = new FileOutputStream(IMPL_FILE); HttpURLConnection connection = (HttpURLConnection) latestJar.openConnection(); if (connection.getResponseCode() == 200) { int contentLength = connection.getContentLength(); if (contentLength > 0) { InputStream stream = connection.getInputStream(); byte[] buffer = new byte[1024]; int amnt; AtomicInteger total = new AtomicInteger(); AtomicBoolean stop = new AtomicBoolean(false); Thread progressBar = new Thread() { public void run() { JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); JLabel label = new JLabel(); label.setText("Downloading latest Helios build"); panel.add(label); GridLayout layout = new GridLayout(); layout.setColumns(1); layout.setRows(3); panel.setLayout(layout); JProgressBar pbar = new JProgressBar(); pbar.setMinimum(0); pbar.setMaximum(100); panel.add(pbar); JTextArea textArea = new JTextArea(1, 3); textArea.setOpaque(false); textArea.setEditable(false); textArea.setText("Downloaded 00.00MB/00.00MB"); panel.add(textArea); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setContentPane(panel); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); while (!stop.get()) { SwingUtilities.invokeLater( () -> pbar.setValue((int) (100.0 * total.get() / contentLength))); textArea.setText("Downloaded " + bytesToMeg(total.get()) + "MB/" + bytesToMeg(contentLength) + "MB"); try { Thread.sleep(100); } catch (InterruptedException ignored) { } } frame.dispose(); } }; progressBar.start(); while ((amnt = stream.read(buffer)) != -1) { out.write(buffer, 0, amnt); total.addAndGet(amnt); } stop.set(true); return loadHelios(); } else { throw new IOException("Content-Length set to " + connection.getContentLength()); } } else if (connection.getResponseCode() == 404) { // Most likely bootstrapper is out of date throw new RuntimeException("Bootstrapper out of date!"); } else { throw new IOException(connection.getResponseCode() + ": " + connection.getResponseMessage()); } } return data; }
From source file:Main.java
private JProgressBar makeProgressBar(int min, int max) { JProgressBar progressBar1 = new JProgressBar(); progressBar1.setMinimum(min);//from ww w. j a v a2 s . c o m progressBar1.setMaximum(max); progressBar1.setStringPainted(true); progressBar1.setBorderPainted(true); getContentPane().add(progressBar1); return progressBar1; }
From source file:com.roche.iceboar.progressview.ProgressUpdater.java
public ProgressUpdater(JProgressBar progressBar, JLabel messageLabel, ProgressEventFactory progressEventFactory) { this.progressBar = progressBar; this.messageLabel = messageLabel; this.events = new HashSet<ProgressEvent>(progressEventFactory.getAllProgressEvents()); amountOfEvents = events.size();/* w ww. ja va2 s . co m*/ progressBar.setMinimum(0); progressBar.setMaximum(amountOfEvents); progressBar.setValue(0); progressBar.setString("0 %"); }
From source file:com.moss.appprocs.swing.ProgressMonitorBean.java
private void update() { if (log.isDebugEnabled()) log.debug("Updating " + process.name()); ProgressReport report = process.progressReport(); super.getLabelTaskname().setText(process.name()); super.getLabelDescription().setText(process.description()); final JProgressBar pBar = getProgressBar(); String string = report.accept(new ProgressReportVisitor<String>() { public String visit(BasicProgressReport r) { getCommandButton().setEnabled(false); pBar.setIndeterminate(true); return r.describe() + "..."; }//from w w w . j a v a 2 s. c o m public String visit(TrackableProgressReport t) { pBar.setIndeterminate(false); pBar.setMinimum(0); pBar.setMaximum((int) t.length()); pBar.setValue((int) t.progress()); return t.describe(); } }); if (process.state() == State.STOPPABLE) { stopButton().setEnabled(true); } else { stopButton().setEnabled(false); } pBar.setString(string); }
From source file:com.enderville.enderinstaller.util.InstallScript.java
/** * Installs the specified list of mods, updating the gui as it goes. * * @param mods The list of mods to install. * @param text The text area to update with logging statements. * @param progressBar The progress bar to update. *///www. ja va 2s . c o m public static void guiInstall(List<String> mods, JTextArea text, JProgressBar progressBar) { //Create backups to restore if the install fails. try { createBackup(); } catch (IOException e) { text.append("Failed to create backup copies of minecraft.jar and mods folder"); LOGGER.error("Failed to create backup copies of minecraft.jar and mods folder", e); return; } //Create a temp directory where we can unpack the jar and install mods. File tmp; try { tmp = getTempDir(); } catch (IOException e) { text.append("Error creating temp directory!"); LOGGER.error("Install Error", e); return; } if (!tmp.mkdirs()) { text.append("Error creating temp directory!"); return; } File mcDir = new File(InstallerConfig.getMinecraftFolder()); File mcJar = new File(InstallerConfig.getMinecraftJar()); File reqDir = new File(InstallerConfig.getRequiredModsFolder()); //Calculate the number of "tasks" for the progress bar. int reqMods = 0; for (File f : reqDir.listFiles()) { if (f.isDirectory()) { reqMods++; } } //3 "other" steps: unpack, repack, delete temp int baseTasks = 3; int taskSize = reqMods + mods.size() + baseTasks; progressBar.setMinimum(0); progressBar.setMaximum(taskSize); int task = 1; try { text.append("Unpacking minecraft.jar\n"); unpackMCJar(tmp, mcJar); progressBar.setValue(task++); text.append("Installing Core mods\n"); //TODO specific ordering required! for (File mod : reqDir.listFiles()) { if (!mod.isDirectory()) { continue; } String name = mod.getName(); text.append("...Installing " + name + "\n"); installMod(mod, tmp, mcDir); progressBar.setValue(task++); } if (!mods.isEmpty()) { text.append("Installing Extra mods\n"); //TODO specific ordering required! for (String name : mods) { File mod = new File(FilenameUtils .normalize(FilenameUtils.concat(InstallerConfig.getExtraModsFolder(), name))); text.append("...Installing " + name + "\n"); installMod(mod, tmp, mcDir); progressBar.setValue(task++); } } text.append("Repacking minecraft.jar\n"); repackMCJar(tmp, mcJar); progressBar.setValue(task++); } catch (Exception e) { text.append("!!!Error installing mods!!!"); LOGGER.error("Installation error", e); try { restoreBackup(); } catch (IOException ioe) { text.append("Error while restoring backup files minecraft.jar.backup and mods_backup folder\n!"); LOGGER.error("Error while restoring backup files minecraft.jar.backup and mods_backup folder!", ioe); } } text.append("Deleting temporary files\n"); try { FileUtils.deleteDirectory(tmp); progressBar.setValue(task++); } catch (IOException e) { text.append("Error deleting temporary files!\n"); LOGGER.error("Install Error", e); return; } text.append("Finished!"); }
From source file:bemap.TrackOrganiser.java
/** * Data treatment that has to be done after the import can be added here: * For instance:/*from w ww. j av a 2 s . c o m*/ * Splits the imported tracks into several tracks after the import. */ public void postImportTreatment(JProgressBar progressBar) throws JSONException { BeMapEditor.mainWindow.append("\nTreatment..."); int indexOfImportedTrack = currentTrack.getID(); if (TRACK_DEBUG) BeMapEditor.mainWindow.append("\nImport track:" + indexOfImportedTrack); Data importTrack = currentTrack; int firstTrackID = currentTrack.getFirstTrackID(); int lastTrackID = currentTrack.getLastTrackID(); if (TRACK_DEBUG) BeMapEditor.mainWindow.append("\nFirst track: " + firstTrackID + " Last track: " + lastTrackID); progressBar.setMinimum(firstTrackID); progressBar.setMaximum(lastTrackID); for (int i = firstTrackID; i <= lastTrackID; i++) { progressBar.setValue(i); int nb = importTrack.getNumberOfPoints(i); if (nb >= MIN_NB_POINTS_IMPORT) { createNewTrack("Track " + i + "-" + BeMapEditor.mainWindow.getUsrIDofConnectedDevice()); if (TRACK_DEBUG) BeMapEditor.mainWindow.append("\nTrack " + i + " has " + nb + " points."); currentTrack.importJSONList(importTrack.exportJSONLayer(i)); } else if (TRACK_DEBUG) BeMapEditor.mainWindow.append("\nTrack " + i + " has " + nb + " points: No track created!"); } //delete import track deleteTrack(indexOfImportedTrack); BeMapEditor.mainWindow.append("\nTreatment ok!"); }
From source file:jcan2.SimpleSerial.java
public int importDataFromDevice(JProgressBar progressBar, JTextArea status) throws InterruptedException, JSONException { if ("Error - no Port found".equals(serialPortName)) return -1; else {// ww w. j a va2 s .c om 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: Getting user ID from server not yet supported!"); BeMapEditor.mainWindow.setUsr(-1); } else { status.append("\nError: No User ID found! Import aborted."); return -1; } 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 } } }