List of usage examples for javax.swing JProgressBar setValue
@BeanProperty(bound = false, preferred = true, description = "The progress bar's current value.") public void setValue(int n)
From source file:org.kchine.rpf.PoolUtils.java
public static void unzip(InputStream is, String destination, NameFilter nameFilter, int bufferSize, boolean showProgress, String taskName, int estimatedFilesNumber) { destination.replace('\\', '/'); if (!destination.endsWith("/")) destination = destination + "/"; final JTextArea area = showProgress ? new JTextArea() : null; final JProgressBar jpb = showProgress ? new JProgressBar(0, 100) : null; final JFrame f = showProgress ? new JFrame(taskName) : null; if (showProgress) { Runnable runnable = new Runnable() { public void run() { area.setFocusable(false); jpb.setIndeterminate(true); JPanel p = new JPanel(new BorderLayout()); p.add(jpb, BorderLayout.SOUTH); p.add(new JScrollPane(area), BorderLayout.CENTER); f.add(p);/*from w w w . ja v a 2 s. c o m*/ f.pack(); f.setSize(300, 90); f.setVisible(true); locateInScreenCenter(f); } }; if (SwingUtilities.isEventDispatchThread()) runnable.run(); else { SwingUtilities.invokeLater(runnable); } } try { ZipInputStream zis = new ZipInputStream(new BufferedInputStream(is)); int entriesNumber = 0; int currentPercentage = 0; int count; byte data[] = new byte[bufferSize]; ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { if (!entry.isDirectory() && (nameFilter == null || nameFilter.accept(entry.getName()))) { String entryName = entry.getName(); prepareFileDirectories(destination, entryName); String destFN = destination + File.separator + entry.getName(); FileOutputStream fos = new FileOutputStream(destFN); BufferedOutputStream dest = new BufferedOutputStream(fos, bufferSize); while ((count = zis.read(data, 0, bufferSize)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); if (showProgress) { ++entriesNumber; final int p = (int) (100 * entriesNumber / estimatedFilesNumber); if (p > currentPercentage) { currentPercentage = p; final JTextArea fa = area; final JProgressBar fjpb = jpb; SwingUtilities.invokeLater(new Runnable() { public void run() { fjpb.setIndeterminate(false); fjpb.setValue(p); fa.setText("\n" + p + "%" + " Done "); } }); SwingUtilities.invokeLater(new Runnable() { public void run() { fa.setCaretPosition(fa.getText().length()); fa.repaint(); fjpb.repaint(); } }); } } } } zis.close(); if (showProgress) { f.dispose(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.kchine.rpf.PoolUtils.java
public static String cacheJar(URL url, String location, int logInfo, boolean forced) throws Exception { final String jarName = url.toString().substring(url.toString().lastIndexOf("/") + 1); if (!location.endsWith("/") && !location.endsWith("\\")) location += "/"; String fileName = location + jarName; new File(location).mkdirs(); final JTextArea area = ((logInfo & LOG_PRGRESS_TO_DIALOG) != 0) ? new JTextArea() : null; final JProgressBar jpb = ((logInfo & LOG_PRGRESS_TO_DIALOG) != 0) ? new JProgressBar(0, 100) : null; final JFrame f = ((logInfo & LOG_PRGRESS_TO_DIALOG) != 0) ? new JFrame("copying " + jarName + " ...") : null;/*from www . j a va 2 s .com*/ try { ResponseCache.setDefault(null); URLConnection urlC = null; Exception connectionException = null; for (int i = 0; i < RECONNECTION_RETRIAL_NBR; ++i) { try { urlC = url.openConnection(); connectionException = null; break; } catch (Exception e) { connectionException = e; } } if (connectionException != null) throw connectionException; InputStream is = url.openStream(); File file = new File(fileName); long urlLastModified = urlC.getLastModified(); if (!forced) { boolean somethingToDo = !file.exists() || file.lastModified() < urlLastModified || (file.length() != urlC.getContentLength() && !isValidJar(fileName)); if (!somethingToDo) return fileName; } if ((logInfo & LOG_PRGRESS_TO_DIALOG) != 0) { Runnable runnable = new Runnable() { public void run() { try { f.setUndecorated(true); f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); area.setEditable(false); area.setForeground(Color.white); area.setBackground(new Color(0x00, 0x80, 0x80)); jpb.setIndeterminate(true); jpb.setForeground(Color.white); jpb.setBackground(new Color(0x00, 0x80, 0x80)); JPanel p = new JPanel(new BorderLayout()); p.setBorder(BorderFactory.createLineBorder(Color.black, 3)); p.setBackground(new Color(0x00, 0x80, 0x80)); p.add(jpb, BorderLayout.SOUTH); p.add(area, BorderLayout.CENTER); f.add(p); f.pack(); f.setSize(300, 80); locateInScreenCenter(f); f.setVisible(true); System.out.println("here"); } catch (Exception e) { e.printStackTrace(); } } }; if (SwingUtilities.isEventDispatchThread()) runnable.run(); else { SwingUtilities.invokeLater(runnable); } } if ((logInfo & LOG_PRGRESS_TO_SYSTEM_OUT) != 0) { System.out.println("Downloading " + jarName + ":"); System.out.print("expected:==================================================\ndone :"); } if ((logInfo & LOG_PRGRESS_TO_LOGGER) != 0) { log.info("Downloading " + jarName + ":"); } int jarSize = urlC.getContentLength(); int currentPercentage = 0; FileOutputStream fos = null; fos = new FileOutputStream(fileName); int count = 0; int printcounter = 0; byte data[] = new byte[BUFFER_SIZE]; int co = 0; while ((co = is.read(data, 0, BUFFER_SIZE)) != -1) { fos.write(data, 0, co); count = count + co; int expected = (50 * count / jarSize); while (printcounter < expected) { if ((logInfo & LOG_PRGRESS_TO_SYSTEM_OUT) != 0) { System.out.print("="); } if ((logInfo & LOG_PRGRESS_TO_LOGGER) != 0) { log.info((int) (100 * count / jarSize) + "% done."); } ++printcounter; } if ((logInfo & LOG_PRGRESS_TO_DIALOG) != 0) { final int p = (int) (100 * count / jarSize); if (p > currentPercentage) { currentPercentage = p; final JTextArea fa = area; final JProgressBar fjpb = jpb; SwingUtilities.invokeLater(new Runnable() { public void run() { fjpb.setIndeterminate(false); fjpb.setValue(p); fa.setText("Copying " + jarName + " ..." + "\n" + p + "%" + " Done. "); } }); SwingUtilities.invokeLater(new Runnable() { public void run() { fa.setCaretPosition(fa.getText().length()); fa.repaint(); fjpb.repaint(); } }); } } } /* * while ((oneChar = is.read()) != -1) { fos.write(oneChar); * count++; * * final int p = (int) (100 * count / jarSize); if (p > * currentPercentage) { System.out.print(p+" % "); currentPercentage = * p; if (showProgress) { final JTextArea fa = area; final * JProgressBar fjpb = jpb; SwingUtilities.invokeLater(new * Runnable() { public void run() { fjpb.setIndeterminate(false); * fjpb.setValue(p); fa.setText("\n" + p + "%" + " Done "); } }); * * SwingUtilities.invokeLater(new Runnable() { public void run() { * fa.setCaretPosition(fa.getText().length()); fa.repaint(); * fjpb.repaint(); } }); } else { if (p%2==0) System.out.print("="); } } * } * */ is.close(); fos.close(); } catch (MalformedURLException e) { System.err.println(e.toString()); throw e; } catch (IOException e) { System.err.println(e.toString()); } finally { if ((logInfo & LOG_PRGRESS_TO_DIALOG) != 0) { f.dispose(); } if ((logInfo & LOG_PRGRESS_TO_SYSTEM_OUT) != 0) { System.out.println("\n 100% of " + jarName + " has been downloaded \n"); } if ((logInfo & LOG_PRGRESS_TO_LOGGER) != 0) { log.info(" 100% of " + jarName + " has been downloaded"); } } return fileName; }
From source file:org.owasp.jbrofuzz.ui.viewers.WindowViewerFrame.java
/** * <p>/* ww w.ja v a 2 s .co m*/ * The window viewer that gets launched for each request within the * corresponding panel. * </p> * * @param parent The parent panel that the frame will belong to * @param name The full file name of the file location to be opened * * @author subere@uncon.org * @version 2.0 * @since 2.0 */ public WindowViewerFrame(final AbstractPanel parent, final String name) { super("JBroFuzz - File Viewer - " + name); setIconImage(ImageCreator.IMG_FRAME.getImage()); // The container pane final Container pane = getContentPane(); pane.setLayout(new BorderLayout()); // Define the Panel final JPanel listPanel = new JPanel(); listPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(name), BorderFactory.createEmptyBorder(1, 1, 1, 1))); listPanel.setLayout(new BorderLayout()); // Get the preferences for wrapping lines of text final boolean wrapText = JBroFuzz.PREFS.getBoolean(JBroFuzzPrefs.FUZZING[3].getId(), false); if (wrapText) { listTextArea = new JTextPane(); } else { listTextArea = new NonWrappingTextPane(); } // Refine the Text Area listTextArea.setFont(new Font("Monospaced", Font.PLAIN, 12)); listTextArea.setEditable(false); // Define the search area entry = new JTextField(10); status = new JLabel("Enter text to search:"); // Initialise the highlighter on the text area hilit = new DefaultHighlighter(); painter = new DefaultHighlighter.DefaultHighlightPainter(HILIT_COLOR); listTextArea.setHighlighter(hilit); entryBg = entry.getBackground(); entry.getDocument().addDocumentListener(this); final InputMap im = entry.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); final ActionMap am = entry.getActionMap(); im.put(KeyStroke.getKeyStroke("ESCAPE"), CANCEL_ACTION); am.put(CANCEL_ACTION, new CancelAction()); // Right click: Cut, Copy, Paste, Select All AbstractPanel.popupText(listTextArea, false, true, false, true); // Define the Scroll Pane for the Text Area final JScrollPane listTextScrollPane = new JScrollPane(listTextArea); listTextScrollPane.setVerticalScrollBarPolicy(20); listTextScrollPane.setHorizontalScrollBarPolicy(30); // Define the progress bar final JProgressBar progressBar = new JProgressBar(); progressBar.setString(" "); progressBar.setStringPainted(true); // Define the bottom panel with the progress bar final JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 15, 15)); bottomPanel.add(status); bottomPanel.add(entry); bottomPanel.add(progressBar); listTextArea.setCaretPosition(0); // doSyntaxHighlight(); /* listTextArea.setEditorKit(new StyledEditorKit() { private static final long serialVersionUID = -6085642347022880064L; @Override public Document createDefaultDocument() { return new TextHighlighter(); } }); */ listPanel.add(listTextScrollPane); // Global Frame Issues pane.add(listPanel, BorderLayout.CENTER); pane.add(bottomPanel, BorderLayout.SOUTH); this.setLocation(parent.getLocationOnScreen().x + 100, parent.getLocationOnScreen().y + 20); this.setSize(SIZE_X, SIZE_Y); setResizable(true); setVisible(true); setMinimumSize(new Dimension(SIZE_X, SIZE_Y)); setDefaultCloseOperation(2); listTextArea.addKeyListener(new KeyAdapter() { @Override public void keyPressed(final KeyEvent ke) { if (ke.getKeyCode() == 27) { WindowViewerFrame.this.dispose(); } if (ke.getKeyCode() == 10) { search(); } } }); entry.addKeyListener(new KeyAdapter() { @Override public void keyPressed(final KeyEvent ke) { if (ke.getKeyCode() == 10) { search(); } } }); class FileLoader extends SwingWorker<String, Object> { // NO_UCD @Override public String doInBackground() { progressBar.setIndeterminate(true); String dbType = JBroFuzz.PREFS.get(JBroFuzzPrefs.DBSETTINGS[11].getId(), "-1"); if (dbType.equals("SQLite") || dbType.equals("CouchDB")) { String sessionId = parent.getFrame().getJBroFuzz().getWindow().getPanelFuzzing() .getSessionName(); if (sessionId == null || sessionId.equals("null")) { sessionId = JBroFuzz.PREFS.get("sessionId", ""); } Logger.log("Reading Session: " + sessionId + " with name: " + name, 3); MessageContainer mc = parent.getFrame().getJBroFuzz().getStorageHandler() .readFuzzFile(name, sessionId, parent.getFrame().getJBroFuzz().getWindow()).get(0); listTextArea.setText("Date: " + mc.getEndDateFull() + "\n" + "FileName: " + mc.getFileName() + "\n" + "URL: " + mc.getTextURL() + "\n" + "Payload: " + mc.getPayload() + "\n" + "EncodedPayload: " + mc.getEncodedPayload() + "\n" + "TextRequest:" + mc.getTextRequest() + "\n" + "Message: " + mc.getMessage() + "\n" + "Status: " + mc.getStatus() + "\n" ); } else { Logger.log("Loading data from file", 3); final File inputFile = new File(parent.getFrame().getJBroFuzz().getWindow().getPanelFuzzing() .getFrame().getJBroFuzz().getStorageHandler().getLocationURIString(), name + ".html"); listTextArea.setText( FileHandler.readFile(inputFile) ); } return "done"; } @Override protected void done() { progressBar.setIndeterminate(false); progressBar.setValue(100); listTextArea.repaint(); } } (new FileLoader()).execute(); }
From source file:projectresurrection.Music.java
public void addSongs(String dir) { Thread t1 = new Thread(new Runnable() { public void run() { File directory = new File(dir); JProgressBar progress = (JProgressBar) pnlAdd.getComponent(3); progress.setValue(0); files = new ArrayList(); List tempSongs = new ArrayList(); Map<String, Map> artists = fileData.get("artists"); getFiles(directory);/*from www .j a va 2 s . c o m*/ List<File> mp3s = new ArrayList(); for (int i = 0; i < files.size(); i++) { if (FilenameUtils.getExtension(files.get(i).getAbsolutePath()).equals("mp3")) { mp3s.add(files.get(i)); } } for (int i = 0; i < mp3s.size(); i++) { try { File file = mp3s.get(i); File tempFile = new File(FOLDER.getAbsolutePath() + "\\" + file.getName()); String name; if (tempFile.exists()) { String prevName = file.getName(); name = ("(1)" + file.getName()); int j = 2; while (new File(FOLDER.getAbsoluteFile() + "\\" + name).exists()) { name = "(" + j + ")" + file.getName(); j++; } file.renameTo(new File(file.getParent() + "\\" + name)); file = new File(file.getParent() + "\\" + name); FileUtils.copyFileToDirectory(new File(file.getAbsolutePath()), FOLDER); file.renameTo(new File(file.getParent() + "\\" + prevName)); file = new File(FOLDER.getAbsolutePath() + "\\" + name); } else { FileUtils.copyFileToDirectory(file.getAbsoluteFile(), FOLDER); file = new File(FOLDER.getAbsolutePath() + "\\" + file.getName()); } Mp3File song = new Mp3File(file.getAbsolutePath()); ID3v2 tag = song.getId3v2Tag(); if (tag.getArtist() == null || tag.getArtist().equals("")) { tag.setArtist("Unknown"); } if (tag.getAlbum() == null || tag.getAlbum().equals("")) { tag.setAlbum("Unknown"); } if (tag.getTitle() == null || tag.getTitle().equals("")) { tag.setTitle("Unknown"); } if (songs.containsKey(tag.getTitle())) { String title = tag.getTitle() + "(1)"; int j = 2; while (tempSongs.contains(title)) { title = tag.getTitle() + "(" + j + ")"; j++; } tag.setTitle(title); } if (tag.getTrack() == null || tag.getTrack().equals("")) { tag.setTrack("-1"); } if (!artists.containsKey(tag.getArtist())) { artists.put(tag.getArtist(), new HashMap<String, Map>()); } if (!artists.get(tag.getArtist()).containsKey(tag.getAlbum())) { artists.get(tag.getArtist()).put(tag.getAlbum(), new HashMap<String, List>()); } ((Map) artists.get(tag.getArtist()).get(tag.getAlbum())).put(tag.getTitle(), Arrays.asList(file.getName(), tag.getTrack(), false)); songs.put(tag.getTitle(), Arrays.asList(file.getName(), tag.getTrack())); progress.setValue(((i + 1) * 100) / mp3s.size()); progress.revalidate(); } catch (Exception e) { e.printStackTrace(System.out); } } fileData = new HashMap(); fileData.put("artists", artists); xmlWrite(MUSIC_FILE, fileData); update(); } }); t1.start(); }