Example usage for javax.swing JScrollPane setVerticalScrollBarPolicy

List of usage examples for javax.swing JScrollPane setVerticalScrollBarPolicy

Introduction

In this page you can find the example usage for javax.swing JScrollPane setVerticalScrollBarPolicy.

Prototype

@BeanProperty(preferred = true, enumerationValues = { "ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED",
        "ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER",
        "ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS" }, description = "The scrollpane vertical scrollbar policy")
public void setVerticalScrollBarPolicy(int policy) 

Source Link

Document

Determines when the vertical scrollbar appears in the scrollpane.

Usage

From source file:org.kepler.gui.PlotsEditorPanel.java

public PlotsEditorPanel(TableauFrame parent, String title) {
    super();/*from   ww  w.jav  a 2 s. co  m*/
    _title = title;
    _frame = parent;
    setBackground(TabManager.BGCOLOR);
    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    plotsPanel = new JPanel();
    plotsPanel.setLayout(new BoxLayout(plotsPanel, BoxLayout.PAGE_AXIS));

    fixGraphics();

    JScrollPane scrollPane = new JScrollPane(plotsPanel);

    scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    this.add(scrollPane, BorderLayout.CENTER);
    JButton addPlotButton = createAddPlotButton();
    this.add(addPlotButton, BorderLayout.PAGE_END);

    // This thread will try to wait until the PlotsPanel is available
    // before adding a plot to it. If a plot is added before the
    // applicable tab pane is available, an NPE will be triggered.
    // The thread will poll for tab pane setup completion every 100 ms,
    // up to a maximum of 10 seconds (100 iterations). If after 10 seconds
    // the tab pane is not available, something has probably gone wrong,
    // and further attempts would do no good.
    new Thread(new Runnable() {
        private void pause(long l) {
            try {
                Thread.sleep(l);
            } catch (InterruptedException ignored) {
            }
        }

        public void run() {
            int maxIterations = 100;
            for (int i = 0; i < maxIterations; i++) {
                log.debug("PlotsEditorPanel thread waiting " + "for TabPane to become available...");
                pause(100);
                if (canAddPlot()) {
                    log.debug("PlotsEditorPanel thread got TabPane, adding Plot.");
                    addPlot();
                    return;
                }
            }
        }
    }).start();
}

From source file:org.nebulaframework.ui.swing.node.NodeMainUI.java

/**
 * Setup Job History Tab Pane//from w w  w  .  ja v a 2s.c o  m
 * 
 * @return JPanel for History tab
 */
private JPanel setupHistory() {

    JPanel historyPanel = new JPanel();
    historyPanel.setLayout(new BorderLayout(10, 10));

    /* -- Job List  -- */
    JPanel jobListPanel = new JPanel();
    historyPanel.add(jobListPanel, BorderLayout.CENTER);

    jobListPanel.setLayout(new BorderLayout(10, 10));
    jobListPanel.setBorder(BorderFactory.createTitledBorder("Grid Jobs"));

    final JList jobList = new JList(historyList);
    JScrollPane jobListScroll = new JScrollPane(jobList);
    jobListPanel.add(jobListScroll, BorderLayout.CENTER);
    jobListScroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    jobListScroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

    addUIElement("history.joblist", jobList);

    jobList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jobList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {

            // Ignore intermediate events
            if (e.getValueIsAdjusting())
                return;

            displayJobInfo(jobList.getSelectedValue());
        }

    });

    JPanel jobInfoPanel = new JPanel();
    historyPanel.add(jobInfoPanel, BorderLayout.SOUTH);

    jobInfoPanel.setLayout(new BorderLayout(10, 10));
    jobInfoPanel.setBorder(BorderFactory.createTitledBorder("Job Information"));

    JPanel centerPanel = new JPanel();

    jobInfoPanel.add(centerPanel, BorderLayout.CENTER);

    centerPanel.setLayout(new GridLayout(0, 4, 10, 10));

    JLabel jobIdLabel = new JLabel("GridJob ID :");
    centerPanel.add(jobIdLabel);
    JLabel jobId = new JLabel("N/A");
    centerPanel.add(jobId);
    addUIElement("history.jobid", jobId); // Add to components map

    JLabel jobNameLabel = new JLabel("GridJob Name :");
    centerPanel.add(jobNameLabel);
    JLabel jobName = new JLabel("N/A");
    centerPanel.add(jobName);
    addUIElement("history.jobname", jobName); // Add to components map

    JLabel startTimeLabel = new JLabel("Start Time :");
    centerPanel.add(startTimeLabel);
    JLabel startTime = new JLabel("N/A");
    centerPanel.add(startTime);
    addUIElement("history.starttime", startTime); // Add to components map

    JLabel durationLabel = new JLabel("Duration :");
    centerPanel.add(durationLabel);
    JLabel duration = new JLabel("N/A");
    centerPanel.add(duration);
    addUIElement("history.duration", duration); // Add to components map

    JLabel tasksLabel = new JLabel("Tasks Executed :");
    centerPanel.add(tasksLabel);
    JLabel tasks = new JLabel("N/A");
    centerPanel.add(tasks);
    addUIElement("history.tasks", tasks); // Add to components map

    JLabel failuresLabel = new JLabel("Failures :");
    centerPanel.add(failuresLabel);
    JLabel failures = new JLabel("N/A");
    centerPanel.add(failures);
    addUIElement("history.failures", failures); // Add to components map

    // Place Holders
    centerPanel.add(new JLabel());
    centerPanel.add(new JLabel());

    return historyPanel;
}

From source file:org.nuclos.client.dbtransfer.DBTransferImport.java

private PanelWizardStep newStep1(final MainFrameTab ifrm) {
    final SpringLocaleDelegate localeDelegate = getSpringLocaleDelegate();
    final PanelWizardStep step = new PanelWizardStep(
            localeDelegate.getMessage("dbtransfer.import.step1.1", "Konfigurationsdatei"),
            localeDelegate.getMessage("dbtransfer.import.step1.2",
                    "Bitte w\u00e4hlen Sie eine Konfigurationsdatei aus."));

    final JLabel lbFile = new JLabel(localeDelegate.getMessage("dbtransfer.import.step1.3", "Datei"));

    utils.initJPanel(step,/*from   w  w w.j  a  v a  2s  .  c o  m*/
            new double[] { TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED,
                    TableLayout.FILL },
            new double[] { 20, TableLayout.PREFERRED, lbFile.getPreferredSize().height, TableLayout.FILL });

    final JButton btnBrowse = new JButton("...");
    //final JProgressBar progressBar = new JProgressBar(0, 230);
    final JCheckBox chbxImportAsNuclon = new JCheckBox(
            localeDelegate.getMessage("configuration.transfer.import.as.nuclon", "Import als Nuclon"));
    chbxImportAsNuclon.setEnabled(false);
    final JEditorPane editWarnings = new JEditorPane();
    editWarnings.setContentType("text/html");
    editWarnings.setEditable(false);
    editWarnings.setBackground(Color.WHITE);

    final JScrollPane scrollWarn = new JScrollPane(editWarnings);
    scrollWarn.setPreferredSize(new Dimension(680, 250));
    scrollWarn.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    scrollWarn.getVerticalScrollBar().setUnitIncrement(20);
    scrollWarn.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollWarn.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    final JScrollPane scrollPrev = new JScrollPane(jpnPreviewContent);
    scrollPrev.setPreferredSize(new Dimension(680, 250));
    scrollPrev.setBorder(new LineBorder(Color.LIGHT_GRAY, 1));
    scrollPrev.getVerticalScrollBar().setUnitIncrement(20);
    scrollPrev.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPrev.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    final JPanel jpnPreview = new JPanel(new BorderLayout());
    jpnPreview.add(jpnPreviewHeader, BorderLayout.NORTH);
    jpnPreview.add(scrollPrev, BorderLayout.CENTER);
    jpnPreview.add(jpnPreviewFooter, BorderLayout.SOUTH);
    jpnPreview.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    jpnPreview.setBackground(Color.WHITE);
    jpnPreviewHeader.setBackground(Color.WHITE);
    jpnPreviewContent.setBackground(Color.WHITE);
    jpnPreviewFooter.setBackground(Color.WHITE);

    final JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.addTab(localeDelegate.getMessage("configuration.transfer.prepare.warnings.tab", "Warnungen"),
            scrollWarn);
    final String sDefaultPreparePreviewTabText = localeDelegate
            .getMessage("configuration.transfer.prepare.preview.tab", "Vorschau der Schema Aenderungen");
    tabbedPane.addTab(sDefaultPreparePreviewTabText, jpnPreview);

    final JLabel lbNewUser = new JLabel();

    step.add(lbFile, "0,0");
    step.add(tfTransferFile, "1,0");
    step.add(btnBrowse, "2,0");
    step.add(chbxImportAsNuclon, "1,1");//step.add(progressBar, "1,1");
    step.add(lbNewUser, "0,2,3,2");
    step.add(tabbedPane, "0,3,3,3");

    tfTransferFile.setEditable(false);

    final ActionListener prepareImportAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ev) {
            ifrm.lockLayerWithProgress(Transfer.TOPIC_CORRELATIONID_PREPARE);

            Thread t = new Thread() {
                @Override
                public void run() {
                    step.setComplete(false);
                    boolean blnTransferWithWarnings = false;
                    //progressBar.setValue(0);
                    //progressBar.setVisible(true);
                    try {
                        String fileName = tfTransferFile.getText();
                        if (StringUtils.isNullOrEmpty(fileName)) {
                            return;
                        }
                        File f = new File(fileName);
                        long size = f.length();

                        final InputStream fin = new BufferedInputStream(new FileInputStream(f));
                        final byte[] transferFile;
                        try {
                            transferFile = utils.getBytes(fin, (int) size);
                        } finally {
                            fin.close();
                        }

                        resetStep2();
                        importTransferObject = getTransferFacadeRemote().prepareTransfer(isNuclon,
                                transferFile);
                        chbxImportAsNuclon.setEnabled(importTransferObject.getTransferOptions()
                                .containsKey(TransferOption.IS_NUCLON_IMPORT_ALLOWED));

                        step.setComplete(!importTransferObject.result.hasCriticals());

                        if (!importTransferObject.result.hasCriticals()
                                && !importTransferObject.result.hasWarnings()) {
                            editWarnings.setText(localeDelegate.getMessage(
                                    "configuration.transfer.prepare.no.warnings", "Keine Warnungen"));
                        } else {
                            editWarnings.setText("<html><body><font color=\"#800000\">"
                                    + importTransferObject.result.getCriticals() + "</font>"
                                    + (importTransferObject.result.hasCriticals() ? "<br />" : "")
                                    + importTransferObject.result.getWarnings() + "</body></html>");
                        }

                        int iPreviewSize = importTransferObject.getPreviewParts().size();
                        blnTransferWithWarnings = setupPreviewPanel(importTransferObject.getPreviewParts());
                        tabbedPane.setTitleAt(1, sDefaultPreparePreviewTabText
                                + (iPreviewSize == 0 ? "" : " (" + iPreviewSize + ")"));
                        lbNewUser.setText(
                                "Neue Benutzer" + ": " + (importTransferObject.getNewUserCount() == 0 ? "keine"
                                        : importTransferObject.getNewUserCount()));
                    } catch (Exception e) {
                        //                              progressBar.setVisible(false);
                        Errors.getInstance().showExceptionDialog(ifrm, e);
                    } finally {
                        btnBrowse.setEnabled(true);
                        //                              progressBar.setVisible(false);
                        ifrm.unlockLayer();
                    }
                    if (blnTransferWithWarnings) {
                        JOptionPane.showMessageDialog(jpnPreviewContent, localeDelegate.getMessage(
                                "dbtransfer.import.step1.19",
                                "Nicht alle Statements knnen durchgefhrt werden!\nBitte kontrollieren Sie die mit rot markierten Eintrge!",
                                "Warning", JOptionPane.WARNING_MESSAGE));
                    }
                }

            };

            t.start();
        }
    };
    final ActionListener browseAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ev) {
            final JFileChooser filechooser = utils.getFileChooser(
                    localeDelegate.getMessage("configuration.transfer.file.nuclet", "Nuclet-Dateien"),
                    ".nuclet");
            final int iBtn = filechooser.showOpenDialog(ifrm);

            if (iBtn == JFileChooser.APPROVE_OPTION) {

                final File file = filechooser.getSelectedFile();
                if (file != null) {
                    tfTransferFile.setText("");
                    btnBrowse.setEnabled(false);
                    //progressBar.setVisible(true);

                    String fileName = file.getPath();
                    if (StringUtils.isNullOrEmpty(fileName)) {
                        return;
                    }

                    tfTransferFile.setText(fileName);

                    prepareImportAction.actionPerformed(new ActionEvent(this, 0, "prepare"));
                }
            }
        }
    };
    final ActionListener importAsNuclonAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            isNuclon = chbxImportAsNuclon.isSelected();
            prepareImportAction.actionPerformed(new ActionEvent(this, 0, "prepare"));
        }
    };
    btnBrowse.addActionListener(browseAction);
    chbxImportAsNuclon.addActionListener(importAsNuclonAction);

    //      progressBar.setVisible(false);

    return step;
}

From source file:org.nuclos.client.dbtransfer.DBTransferImport.java

private PanelWizardStep newStep3(final MainFrameTab ifrm) {
    final SpringLocaleDelegate localeDelegate = getSpringLocaleDelegate();
    final PanelWizardStep step = new PanelWizardStep(
            localeDelegate.getMessage("dbtransfer.import.step3.1", "System Parameter"),
            localeDelegate.getMessage("dbtransfer.import.step3.2",
                    "Bestimmen Sie die Parameter dieses Systems. Sie k\u00f6nnen w\u00e4hlen zwischen dem aktuellen Zustand und dem aus der Konfigurationsdatei importierten Zustand (default). Sollte keine der beiden Vorgaben stimmen, so k\u00f6nnen Sie auch einen anderen Wert setzen.")) {

        @Override/*from  w w w  .j  av  a2s. co  m*/
        public void prepare() {
            setupParameterPanel(importTransferObject.getParameter());
        }

        @Override
        public void applyState() throws InvalidStateException {
            setSelectedIncomingParameter.clear();
            setSelectedCurrentParameter.clear();
            mapSelectedOtherParameter.clear();

            for (ParameterEditor pe : lstParameterEditors) {
                if (pe.isCurrentValue())
                    setSelectedCurrentParameter.add(pe.getName());
                if (pe.isIncomingValue())
                    setSelectedIncomingParameter.add(pe.getName());
                if (pe.isOtherValue())
                    mapSelectedOtherParameter.put(pe.getName(), pe.getValue());
            }
        }
    };
    step.setComplete(true);

    utils.initJPanel(step, new double[] { TableLayout.FILL },
            new double[] { TableLayout.PREFERRED, TableLayout.FILL, TableLayout.PREFERRED });

    rbCurrentAll.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            resetParameterEditors(true);
        }
    });
    rbIncomingAll.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            resetParameterEditors(false);
        }
    });

    final JScrollPane scroll = new JScrollPane(jpnParameter);
    scroll.setPreferredSize(new Dimension(680, 250));
    scroll.setBorder(new LineBorder(Color.LIGHT_GRAY, 1));
    scroll.getVerticalScrollBar().setUnitIncrement(20);
    scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    scroll.getViewport().addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            Dimension parameterPanelSize = new Dimension(scroll.getViewport().getWidth(),
                    jpnParameter.getPreferredSize().height);
            jpnParameter.setPreferredSize(parameterPanelSize);
        }
    });

    step.add(jpnParameterHeader, "0,0");
    step.add(scroll, "0,1");
    step.add(jpnParameterFooter, "0,2");

    return step;
}

From source file:org.nuxeo.launcher.gui.NuxeoFrame.java

/**
 * @param logFile//from   w  w  w.j  a v  a  2  s  .  co m
 */
protected JComponent buildLogPanel(String logFile) {
    ColoredTextPane textArea = new ColoredTextPane();
    textArea.setEditable(false);
    textArea.setAutoscrolls(true);
    textArea.setBackground(new Color(54, 55, 67));
    textArea.setMaxSize(LOG_MAX_SIZE);

    JScrollPane logsScroller = new JScrollPane(textArea);
    logsScroller.setVisible(true);
    logsScroller.setBorder(BorderFactory.createLineBorder(Color.BLACK));
    logsScroller.setAutoscrolls(true);
    logsScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    logsScroller.setWheelScrollingEnabled(true);
    logsScroller.setPreferredSize(new Dimension(450, 160));

    controller.initLogsManagement(logFile, textArea);
    logsScroller.addComponentListener(new LogsPanelListener(logFile));
    return logsScroller;
}

From source file:org.onebusaway.phone.client.SimplePhoneClient.java

private static void setupGui(AgiClientScriptImpl script) {

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    KeyPressHandler handler = new KeyPressHandler(script);

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.addKeyListener(handler);//from   www .ja  v a  2s. c  om

    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridLayout(4, 3));
    panel.add(buttonPanel, BorderLayout.CENTER);

    String buttons = "123456789*0#";

    for (int i = 0; i < buttons.length(); i++)
        addButton(buttonPanel, script, handler, buttons.charAt(i));

    Document document = script.getDocument();

    final JTextArea textArea = new JTextArea(document);
    textArea.setEditable(false);
    textArea.addKeyListener(handler);
    document.addDocumentListener(new ScrollDocumentToEnd(textArea));

    JScrollPane scrollPane = new JScrollPane(textArea);
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    scrollPane.setPreferredSize(new Dimension(300, 100));
    scrollPane.addKeyListener(handler);
    panel.add(scrollPane, BorderLayout.SOUTH);

    frame.getContentPane().add(panel);
    frame.pack();
    frame.setVisible(true);
}

From source file:org.opendatakit.briefcase.ui.ScrollingStatusListDialog.java

private ScrollingStatusListDialog(Frame frame, String title, IFormDefinition form, String statusHtml) {
    super(frame, title + form.getFormName(), true);
    this.form = form;
    AnnotationProcessor.process(this);
    // Create and initialize the buttons.
    JButton cancelButton = new JButton("Close");
    cancelButton.addActionListener(this);
    getRootPane().setDefaultButton(cancelButton);

    editorArea = new JEditorPane("text/plain", statusHtml);
    editorArea.setEditable(false);/*from  w w w .j a v  a2 s.c  o m*/
    //Put the editor pane in a scroll pane.
    JScrollPane editorScrollPane = new JScrollPane(editorArea);
    editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    editorScrollPane.setPreferredSize(new Dimension(400, 300));
    editorScrollPane.setMinimumSize(new Dimension(10, 10));

    // Create a container so that we can add a title around
    // the scroll pane. Can't add a title directly to the
    // scroll pane because its background would be white.
    // Lay out the label and scroll pane from top to bottom.
    JPanel listPane = new JPanel();
    listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS));
    listPane.add(Box.createRigidArea(new Dimension(0, 5)));
    listPane.add(editorScrollPane);
    listPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    // Lay out the buttons from left to right.
    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
    buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
    buttonPane.add(Box.createHorizontalGlue());
    buttonPane.add(cancelButton);

    // Put everything together, using the content pane's BorderLayout.
    Container contentPane = getContentPane();
    contentPane.add(listPane, BorderLayout.CENTER);
    contentPane.add(buttonPane, BorderLayout.PAGE_END);

    // Initialize values.
    pack();
    setLocationRelativeTo(null);
}

From source file:org.openmicroscopy.shoola.util.ui.MessengerDialog.java

/**
 * Builds and lays out the panel hosting the <code>comment</code> details.
 * /*from w  ww .ja  v a 2  s .  c  o m*/
 * @param comment      The comment's text.
 * @param mnemonic       The key-code that indicates a mnemonic key.
 * @return See above.
 */
private JPanel buildCommentAreaPanel(String comment, int mnemonic) {
    JPanel panel = new JPanel();
    panel.setOpaque(false);

    double size[][] = { { TableLayout.FILL }, { 20, TableLayout.FILL } };
    TableLayout layout = new TableLayout(size);
    panel.setLayout(layout);
    JScrollPane areaScrollPane = new JScrollPane(commentArea);
    areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    JLabel label = new JLabel(comment);
    label.setOpaque(false);
    label.setDisplayedMnemonic(mnemonic);
    panel.add(label, "0, 0, LEFT, CENTER");
    panel.add(areaScrollPane, "0, 1");
    return panel;
}

From source file:org.openstatic.placebo.plugins.KeyStore.java

public boolean startup(CoreServer core, String mount_location) {
    System.err.println("KeyStore: Initializing Keystore");
    store = new JSONObject();

    if (core.isSwingOk()) {
        json_box = new JTextPane();
        json_box.setContentType("text/html");
        Font font = new Font("Monospaced", Font.BOLD, 12);
        json_box.setFont(font);//from  ww  w .j  a v a  2 s  .  c  o  m
        JScrollPane scroller = new JScrollPane(json_box);
        scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        core.addPanel("Keystore [" + mount_location + "]", scroller);
        this.swing_mode = true;
    } else {
        this.swing_mode = false;
    }
    return true;
}

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

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

}