Example usage for javax.swing JProgressBar setStringPainted

List of usage examples for javax.swing JProgressBar setStringPainted

Introduction

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

Prototype

@BeanProperty(visualUpdate = true, description = "Whether the progress bar should render a string.")
public void setStringPainted(boolean b) 

Source Link

Document

Sets the value of the stringPainted property, which determines whether the progress bar should render a progress string.

Usage

From source file:com.entertailion.java.fling.FlingFrame.java

/**
 * Create a progress indicator/*from w ww  .  j ava  2 s  . c  o  m*/
 */
private void createProgressDialog() {
    progressDialog = new JDialog(this, resourceBundle.getString("progress.title"), true);
    JProgressBar progressBar = new JProgressBar(0, 100);
    progressBar.setStringPainted(true);
    progressBar.setIndeterminate(true);
    progressDialog.add(BorderLayout.CENTER, progressBar);
    progressDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    progressDialog.setSize(300, 75);
    progressDialog.setLocationRelativeTo(this);
}

From source file:UI.MainViewPanel.java

public JProgressBar getPanel7(Metric7 m7) {

    JProgressBar openPortBar = new JProgressBar(0, 100);
    openPortBar.setValue(m7.totalCriticalCount);
    openPortBar.setBorder(BorderFactory.createLineBorder(Color.BLACK));
    UIDefaults defaults = new UIDefaults();

    Painter foregroundPainter = new MyPainter(new Color(230, 219, 27));
    Painter backgroundPainter = new MyPainter(chartBackgroundColor);
    defaults.put("ProgressBar[Enabled].foregroundPainter", foregroundPainter);
    defaults.put("ProgressBar[Enabled+Finished].foregroundPainter", foregroundPainter);
    defaults.put("ProgressBar[Enabled].backgroundPainter", backgroundPainter);

    openPortBar.putClientProperty("Nimbus.Overrides.InheritDefaults", Boolean.TRUE);
    openPortBar.putClientProperty("Nimbus.Overrides", defaults);

    openPortBar.setString("" + m7.totalCriticalCount);
    openPortBar.setStringPainted(true);

    return openPortBar;
}

From source file:org.nebulaframework.ui.swing.cluster.ClusterMainUI.java

/**
 * Creates a tab pane for the given GridJob.
 * //from  w w  w . j a  va  2s  .c  om
 * @param jobId JobId
 */
protected void createJobTab(final String jobId) {

    // Request Job Profile
    final InternalClusterJobService jobService = ClusterManager.getInstance().getJobService();
    final GridJobProfile profile = jobService.getProfile(jobId);

    // Job Start Time
    final long startTime = System.currentTimeMillis();

    final JPanel jobPanel = new JPanel();
    jobPanel.setLayout(new BorderLayout(10, 10));

    // Progess Panel
    JPanel progressPanel = new JPanel();
    progressPanel.setLayout(new BorderLayout(10, 10));
    progressPanel.setBorder(BorderFactory.createTitledBorder("Progress"));
    jobPanel.add(progressPanel, BorderLayout.NORTH);

    final JProgressBar progressBar = new JProgressBar();
    progressBar.setStringPainted(true);
    progressPanel.add(progressBar, BorderLayout.CENTER);
    addUIElement("jobs." + jobId + ".progress", progressBar); // Add to components map

    // Buttons Panel
    JPanel buttonsPanel = new JPanel();
    jobPanel.add(buttonsPanel, BorderLayout.SOUTH);
    buttonsPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));

    // Terminate Button
    JButton terminateButton = new JButton("Terminate");
    terminateButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            new Thread(new Runnable() {

                public void run() {

                    // Job Name = Class Name
                    String name = profile.getJob().getClass().getSimpleName();

                    // Request user confirmation
                    int option = JOptionPane.showConfirmDialog(ClusterMainUI.this,
                            "Are you sure to terminate GridJob " + name + "?", "Nebula - Terminate GridJob",
                            JOptionPane.YES_NO_OPTION);

                    if (option == JOptionPane.NO_OPTION)
                        return;

                    // Attempt Cancel
                    boolean result = profile.getFuture().cancel();

                    // Notify results
                    if (result) {
                        JOptionPane.showMessageDialog(ClusterMainUI.this,
                                "Grid Job '" + name + "terminated successfully.", "Nebula - Job Terminated",
                                JOptionPane.INFORMATION_MESSAGE);
                    } else {
                        JOptionPane.showMessageDialog(ClusterMainUI.this,
                                "Failed to terminate Grid Job '" + name, "Nebula - Job Termination Failed",
                                JOptionPane.WARNING_MESSAGE);
                    }
                }

            }).start();
        }
    });
    buttonsPanel.add(terminateButton);
    addUIElement("jobs." + jobId + ".terminate", terminateButton); // Add to components map

    // Close Tab Button
    JButton closeButton = new JButton("Close Tab");
    closeButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    removeJobTab(jobId);
                }
            });
        }
    });
    closeButton.setEnabled(false);

    buttonsPanel.add(closeButton);
    addUIElement("jobs." + jobId + ".closetab", closeButton); // Add to components map

    JPanel centerPanel = new JPanel();
    centerPanel.setLayout(new GridBagLayout());
    jobPanel.add(centerPanel, BorderLayout.CENTER);

    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 1.0;
    c.weightx = 1.0;

    /* -- Job Information -- */

    JPanel jobInfoPanel = new JPanel();
    jobInfoPanel.setBorder(BorderFactory.createTitledBorder("Job Information"));
    jobInfoPanel.setLayout(new GridBagLayout());
    c.gridy = 0;
    c.ipady = 30;
    centerPanel.add(jobInfoPanel, c);

    GridBagConstraints c1 = new GridBagConstraints();
    c1.fill = GridBagConstraints.BOTH;
    c1.weightx = 1;
    c1.weighty = 1;

    // Name
    jobInfoPanel.add(new JLabel("Name :"), c1);
    JLabel jobNameLabel = new JLabel();
    jobInfoPanel.add(jobNameLabel, c1);
    jobNameLabel.setText(profile.getJob().getClass().getSimpleName());
    addUIElement("jobs." + jobId + ".job.name", jobNameLabel); // Add to components map

    // Gap
    jobInfoPanel.add(new JLabel(), c1);

    // Type
    jobInfoPanel.add(new JLabel("Type :"), c1);
    JLabel jobType = new JLabel();
    jobType.setText(getJobType(profile.getJob()));
    jobInfoPanel.add(jobType, c1);
    addUIElement("jobs." + jobId + ".job.type", jobType); // Add to components map

    // Job Class Name
    c1.gridy = 1;
    c1.gridwidth = 1;
    jobInfoPanel.add(new JLabel("GridJob Class :"), c1);
    c1.gridwidth = GridBagConstraints.REMAINDER;
    JLabel jobClassLabel = new JLabel();
    jobClassLabel.setText(profile.getJob().getClass().getName());
    jobInfoPanel.add(jobClassLabel, c1);
    addUIElement("jobs." + jobId + ".job.class", jobClassLabel); // Add to components map

    /* -- Execution Information -- */

    JPanel executionInfoPanel = new JPanel();
    executionInfoPanel.setBorder(BorderFactory.createTitledBorder("Execution Statistics"));
    executionInfoPanel.setLayout(new GridBagLayout());
    c.gridy = 1;
    c.ipady = 30;
    centerPanel.add(executionInfoPanel, c);

    GridBagConstraints c3 = new GridBagConstraints();
    c3.weightx = 1;
    c3.weighty = 1;
    c3.fill = GridBagConstraints.BOTH;

    // Start Time
    executionInfoPanel.add(new JLabel("Job Status :"), c3);
    final JLabel statusLabel = new JLabel("Initializing");
    executionInfoPanel.add(statusLabel, c3);
    addUIElement("jobs." + jobId + ".execution.status", statusLabel); // Add to components map

    // Status Update Listener
    profile.getFuture().addGridJobStateListener(new GridJobStateListener() {
        public void stateChanged(final GridJobState newState) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    statusLabel.setText(StringUtils.capitalize(newState.toString().toLowerCase()));
                }
            });
        }
    });

    executionInfoPanel.add(new JLabel(), c3); // Space Holder

    // Percent Complete
    executionInfoPanel.add(new JLabel("Completed % :"), c3);
    final JLabel percentLabel = new JLabel("-N/A-");
    executionInfoPanel.add(percentLabel, c3);
    addUIElement("jobs." + jobId + ".execution.percentage", percentLabel); // Add to components map

    c3.gridy = 1;

    // Start Time
    executionInfoPanel.add(new JLabel("Start Time :"), c3);
    JLabel startTimeLabel = new JLabel(DateFormat.getInstance().format(new Date(startTime)));
    executionInfoPanel.add(startTimeLabel, c3);
    addUIElement("jobs." + jobId + ".execution.starttime", startTimeLabel); // Add to components map

    executionInfoPanel.add(new JLabel(), c3); // Space Holder

    // Elapsed Time
    executionInfoPanel.add(new JLabel("Elapsed Time :"), c3);
    JLabel elapsedTimeLabel = new JLabel("-N/A-");
    executionInfoPanel.add(elapsedTimeLabel, c3);
    addUIElement("jobs." + jobId + ".execution.elapsedtime", elapsedTimeLabel); // Add to components map

    c3.gridy = 2;

    // Tasks Deployed (Count)
    executionInfoPanel.add(new JLabel("Tasks Deployed :"), c3);
    JLabel tasksDeployedLabel = new JLabel("-N/A-");
    executionInfoPanel.add(tasksDeployedLabel, c3);
    addUIElement("jobs." + jobId + ".execution.tasks", tasksDeployedLabel); // Add to components map

    executionInfoPanel.add(new JLabel(), c3); // Space Holder

    // Results Collected (Count)
    executionInfoPanel.add(new JLabel("Results Collected :"), c3);
    JLabel resultsCollectedLabel = new JLabel("-N/A-");
    executionInfoPanel.add(resultsCollectedLabel, c3);
    addUIElement("jobs." + jobId + ".execution.results", resultsCollectedLabel); // Add to components map

    c3.gridy = 3;

    // Remaining Tasks (Count)
    executionInfoPanel.add(new JLabel("Remaining Tasks :"), c3);
    JLabel remainingTasksLabel = new JLabel("-N/A-");
    executionInfoPanel.add(remainingTasksLabel, c3);
    addUIElement("jobs." + jobId + ".execution.remaining", remainingTasksLabel); // Add to components map

    executionInfoPanel.add(new JLabel(), c3); // Space Holder

    // Failed Tasks (Count)
    executionInfoPanel.add(new JLabel("Failed Tasks :"), c3);
    JLabel failedTasksLabel = new JLabel("-N/A-");
    executionInfoPanel.add(failedTasksLabel, c3);
    addUIElement("jobs." + jobId + ".execution.failed", failedTasksLabel); // Add to components map

    /* -- Submitter Information -- */
    UUID ownerId = profile.getOwner();
    GridNodeDelegate owner = ClusterManager.getInstance().getClusterRegistrationService()
            .getGridNodeDelegate(ownerId);

    JPanel ownerInfoPanel = new JPanel();
    ownerInfoPanel.setBorder(BorderFactory.createTitledBorder("Owner Information"));
    ownerInfoPanel.setLayout(new GridBagLayout());
    c.gridy = 2;
    c.ipady = 10;
    centerPanel.add(ownerInfoPanel, c);

    GridBagConstraints c2 = new GridBagConstraints();

    c2.fill = GridBagConstraints.BOTH;
    c2.weightx = 1;
    c2.weighty = 1;

    // Host Name
    ownerInfoPanel.add(new JLabel("Host Name :"), c2);
    JLabel hostNameLabel = new JLabel(owner.getProfile().getName());
    ownerInfoPanel.add(hostNameLabel, c2);
    addUIElement("jobs." + jobId + ".owner.hostname", hostNameLabel); // Add to components map

    // Gap
    ownerInfoPanel.add(new JLabel(), c2);

    // Host IP Address
    ownerInfoPanel.add(new JLabel("Host IP :"), c2);
    JLabel hostIPLabel = new JLabel(owner.getProfile().getIpAddress());
    ownerInfoPanel.add(hostIPLabel, c2);
    addUIElement("jobs." + jobId + ".owner.hostip", hostIPLabel); // Add to components map

    // Owner UUID
    c2.gridy = 1;
    c2.gridx = 0;
    ownerInfoPanel.add(new JLabel("Owner ID :"), c2);
    JLabel ownerIdLabel = new JLabel(profile.getOwner().toString());
    c2.gridx = 1;
    c2.gridwidth = 4;
    ownerInfoPanel.add(ownerIdLabel, c2);
    addUIElement("jobs." + jobId + ".owner.id", ownerIdLabel); // Add to components map

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            // Create Tab
            addUIElement("jobs." + jobId, jobPanel);
            JTabbedPane tabs = getUIElement("tabs");
            tabs.addTab(profile.getJob().getClass().getSimpleName(), jobPanel);
            tabs.revalidate();
        }
    });

    // Execution Information Updater Thread
    new Thread(new Runnable() {

        boolean initialized = false;
        boolean unbounded = false;

        public void run() {

            // Unbounded, No Progress Supported
            if ((!initialized) && profile.getJob() instanceof UnboundedGridJob<?>) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        progressBar.setIndeterminate(true);
                        progressBar.setStringPainted(false);

                        // Infinity Symbol
                        percentLabel.setText(String.valueOf('\u221e'));

                    }
                });
                initialized = true;
                unbounded = true;
            }

            // Update Job Info
            while (true) {

                try {
                    // 500ms Interval
                    Thread.sleep(500);

                } catch (InterruptedException e) {
                    log.warn("Interrupted Progress Updater Thread", e);
                }

                final int totalCount = profile.getTotalTasks();
                final int tasksRem = profile.getTaskCount();
                final int resCount = profile.getResultCount();
                final int failCount = profile.getFailedCount();

                showBusyIcon();

                // Task Information
                JLabel totalTaskLabel = getUIElement("jobs." + jobId + ".execution.tasks");
                totalTaskLabel.setText(String.valueOf(totalCount));

                // Result Count
                JLabel resCountLabel = getUIElement("jobs." + jobId + ".execution.results");
                resCountLabel.setText(String.valueOf(resCount));

                // Remaining Task Count
                JLabel remLabel = getUIElement("jobs." + jobId + ".execution.remaining");
                remLabel.setText(String.valueOf(tasksRem));

                // Failed Task Count
                JLabel failedLabel = getUIElement("jobs." + jobId + ".execution.failed");
                failedLabel.setText(String.valueOf(failCount));

                // Elapsed Time
                JLabel elapsedLabel = getUIElement("jobs." + jobId + ".execution.elapsedtime");
                elapsedLabel.setText(TimeUtils.timeDifference(startTime));

                // Job State
                final JLabel statusLabel = getUIElement("jobs." + jobId + ".execution.status");

                // If not in Executing Mode
                if ((!profile.getFuture().isJobFinished())
                        && profile.getFuture().getState() != GridJobState.EXECUTING) {
                    SwingUtilities.invokeLater(new Runnable() {
                        public void run() {

                            // Progress Bar
                            progressBar.setIndeterminate(true);
                            progressBar.setStringPainted(false);

                            // Status Text
                            String state = profile.getFuture().getState().toString();
                            statusLabel.setText(StringUtils.capitalize(state.toLowerCase()));

                            // Percentage Label
                            percentLabel.setText(String.valueOf('\u221e'));
                        }
                    });
                } else { // Executing Mode : Progress Information

                    // Job Finished, Stop
                    if (profile.getFuture().isJobFinished()) {
                        showIdleIcon();
                        return;
                    }

                    // Double check for status label
                    if (!statusLabel.getText().equalsIgnoreCase("executing")) {
                        SwingUtilities.invokeLater(new Runnable() {

                            @Override
                            public void run() {
                                String newstate = profile.getFuture().getState().toString();
                                statusLabel.setText(StringUtils.capitalize(newstate.toLowerCase()));
                            }

                        });
                    }

                    if (!unbounded) {

                        final int percentage = (int) (profile.percentage() * 100);

                        //final int failCount = profile.get
                        SwingUtilities.invokeLater(new Runnable() {
                            public void run() {

                                // If finished at this point, do not update
                                if (progressBar.getValue() == 100) {
                                    return;
                                }

                                // If ProgressBar is in indeterminate
                                if (progressBar.isIndeterminate()) {
                                    progressBar.setIndeterminate(false);
                                    progressBar.setStringPainted(true);
                                }

                                // Update Progress Bar / Percent Label
                                progressBar.setValue(percentage);
                                percentLabel.setText(percentage + " %");

                            }
                        });
                    }
                }

            }
        }
    }).start();

    // Job End Hook to Execute Job End Actions
    ServiceEventsSupport.addServiceHook(new ServiceHookCallback() {

        public void onServiceEvent(final ServiceMessage event) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {

                    JButton close = getUIElement("jobs." + jobId + ".closetab");
                    JButton terminate = getUIElement("jobs." + jobId + ".terminate");
                    terminate.setEnabled(false);
                    close.setEnabled(true);

                    JProgressBar progress = getUIElement("jobs." + jobId + ".progress");
                    JLabel percentage = getUIElement("jobs." + jobId + ".execution.percentage");

                    progress.setEnabled(false);

                    // If Successfully Finished
                    if (event.getType() == ServiceMessageType.JOB_END) {

                        if (profile.getFuture().getState() != GridJobState.FAILED) {
                            // If Not Job Failed
                            progress.setValue(100);
                            percentage.setText("100 %");
                        } else {
                            // If Failed
                            percentage.setText("N/A");
                        }

                        // Stop (if) Indeterminate Progress Bar
                        if (progress.isIndeterminate()) {
                            progress.setIndeterminate(false);
                            progress.setStringPainted(true);
                        }
                    } else if (event.getType() == ServiceMessageType.JOB_CANCEL) {

                        if (progress.isIndeterminate()) {
                            progress.setIndeterminate(false);
                            progress.setStringPainted(false);
                            percentage.setText("N/A");
                        }
                    }

                    showIdleIcon();
                }
            });
        }

    }, jobId, ServiceMessageType.JOB_CANCEL, ServiceMessageType.JOB_END);
}

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

/**
 * @param min/*from  w  w  w .  j a v a2s  .  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.deegree.tools.rendering.viewer.File3dImporter.java

public static List<WorldRenderableObject> open(Frame parent, String fileName) {

    if (fileName == null || "".equals(fileName.trim())) {
        throw new InvalidParameterException("the file name may not be null or empty");
    }/*from  w ww  .  j  av  a2 s .  c  o m*/
    fileName = fileName.trim();

    CityGMLImporter openFile2;
    XMLInputFactory fac = XMLInputFactory.newInstance();
    InputStream in = null;
    try {
        XMLStreamReader reader = fac.createXMLStreamReader(in = new FileInputStream(fileName));
        reader.next();
        String ns = "http://www.opengis.net/citygml/1.0";
        openFile2 = new CityGMLImporter(null, null, null, reader.getNamespaceURI().equals(ns));
    } catch (Throwable t) {
        openFile2 = new CityGMLImporter(null, null, null, false);
    } finally {
        IOUtils.closeQuietly(in);
    }

    final CityGMLImporter openFile = openFile2;

    final JDialog dialog = new JDialog(parent, "Loading", true);

    dialog.getContentPane().setLayout(new BorderLayout());
    dialog.getContentPane().add(
            new JLabel("<HTML>Loading file:<br>" + fileName + "<br>Please wait!</HTML>", SwingConstants.CENTER),
            BorderLayout.NORTH);
    final JProgressBar progressBar = new JProgressBar();
    progressBar.setStringPainted(true);
    progressBar.setIndeterminate(false);
    dialog.getContentPane().add(progressBar, BorderLayout.CENTER);

    dialog.pack();
    dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    dialog.setResizable(false);
    dialog.setLocationRelativeTo(parent);

    final Thread openThread = new Thread() {
        /**
         * Opens the file in a separate thread.
         */
        @Override
        public void run() {
            // openFile.openFile( progressBar );
            if (dialog.isDisplayable()) {
                dialog.setVisible(false);
                dialog.dispose();
            }
        }
    };
    openThread.start();

    dialog.setVisible(true);
    List<WorldRenderableObject> result = null;
    try {
        result = openFile.importFromFile(fileName, 6, 2);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    gm = openFile.getQmList();

    //
    // if ( result != null ) {
    // openGLEventListener.addDataObjectToScene( result );
    // File f = new File( fileName );
    // setTitle( WIN_TITLE + f.getName() );
    // } else {
    // showExceptionDialog( "The file: " + fileName
    // + " could not be read,\nSee error log for detailed information." );
    // }
    return result;
}

From source file:org.gofleet.module.routing.RoutingMap.java

private void newPlan(LatLon from) {
    JDialog d = new JDialog(basicWindow.getFrame(), "Generating New Plan");
    try {/* www  .  j  ava 2 s . co  m*/
        JFileChooser fc = new JFileChooser();
        fc.addChoosableFileFilter(new RoutingFilter());
        fc.setAcceptAllFileFilterUsed(true);
        int returnVal = fc.showOpenDialog(basicWindow.getFrame());
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            log.debug("Opening: " + file.getName());

            JProgressBar progressBar = new JProgressBar(0, getNumberLines(file) * 2);
            progressBar.setValue(0);
            progressBar.setPreferredSize(new Dimension(150, 50));
            progressBar.setStringPainted(true);

            d.add(progressBar);
            d.pack();
            d.setVisible(true);

            TSPPlan[] param = processFile(file, progressBar);

            Map<String, String> values = getValues(from);

            double[] origin = new double[2];
            origin[0] = new Double(values.get("origin_x"));
            origin[1] = new Double(values.get("origin_y"));

            TSPPlan[] res = calculateRouteOnWS(new Integer(values.get("maxDistance")),
                    new Integer(values.get("maxTime")), origin, new Integer(values.get("startTime")), param,
                    new Integer(values.get("timeSpentOnStop")));

            progressBar.setValue(progressBar.getMaximum() - res.length);

            processTSPPlan(res, progressBar);

        } else {
            log.trace("Open command cancelled by user.");
        }
    } catch (Throwable t) {
        log.error("Error computing new plan", t);
        JOptionPane.showMessageDialog(basicWindow.getFrame(),
                "<html><p>" + i18n.getString("Main.Error") + ":</p><p>" + t.toString() + "</p><html>",
                i18n.getString("Main.Error"), JOptionPane.ERROR_MESSAGE);
    } finally {
        d.setVisible(false);
        d.dispose();
    }

}

From source file:org.owasp.jbrofuzz.ui.viewers.WindowViewerFrame.java

/**
 * <p>/* w w w  .  j a va2s.  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();

}