List of usage examples for javax.swing JProgressBar setString
@BeanProperty(visualUpdate = true, description = "Specifies the progress string to paint") public void setString(String s)
From source file:org.owasp.jbrofuzz.ui.viewers.WindowViewerFrame.java
/** * <p>/*ww w .j a v a 2 s .c om*/ * 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:org.spoutcraft.launcher.util.Utils.java
public static String executePost(String targetURL, String urlParameters, JProgressBar progress) throws PermissionDeniedException { URLConnection connection = null; try {//from ww w . ja v a 2s . c o m URL url = new URL(targetURL); connection = url.openConnection(); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestProperty("Content-Length", Integer.toString(urlParameters.getBytes().length)); connection.setRequestProperty("Content-Language", "en-US"); connection.setUseCaches(false); connection.setDoInput(true); connection.setDoOutput(true); connection.setConnectTimeout(10000); connection.connect(); DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); wr.writeBytes(urlParameters); wr.flush(); wr.close(); InputStream is = connection.getInputStream(); BufferedReader rd = new BufferedReader(new InputStreamReader(is)); StringBuilder response = new StringBuilder(); String line; while ((line = rd.readLine()) != null) { response.append(line); response.append('\r'); } rd.close(); return response.toString(); } catch (SocketException e) { if (e.getMessage().equalsIgnoreCase("Permission denied: connect")) { throw new PermissionDeniedException("Permission to login was denied"); } } catch (Exception e) { String message = "Login failed..."; progress.setString(message); } return null; }