/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewJFrame.java
 *
 * Created on 03/11/2008, 17:24:51
 */


import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import javax.swing.JOptionPane;

/**
 *
 * @author denisf
 */
public class TesteTamanho extends javax.swing.JFrame {

    public static void main(String[] args) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new TesteTamanho().setVisible(true);
            }
        });
    }

    /** Creates new form NewJFrame */
    public TesteTamanho() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        editor = new javax.swing.JTextArea();
        jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        editor.setColumns(20);
        editor.setRows(5);
        jScrollPane1.setViewportView(editor);

        jButton3.setText("Aleatório");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
                    .addComponent(jButton3))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // Criar um conteúdo aleatório para colocar no jedit
        Random r = new Random();
        Character a = 'a';

        int numLinhas = 2000 + r.nextInt(1000);
        JOptionPane.showMessageDialog(this, "Numero de linhas: " + numLinhas);
        List<String> linhas = new ArrayList<String>(numLinhas);
        for (int l = 0; l < numLinhas; l++) {
            if (r.nextInt(20) < 1) {
                // Linha em branco
                linhas.add("\n");
            } else {
                // Criar uma linha de um tamanho aleatório, entre 50 e 80 caracteres
                int tamanho = 50 + r.nextInt(30);
                StringBuilder linha = new StringBuilder(tamanho + 1);
                for (int j = 0; j < tamanho; j++) {
                    if (r.nextInt(20) < 1) {
                        // Espaço
                        linha.append(' ');
                    } else {
                        linha.append('á');
                    }
                }
                linha.append('\n');
                linhas.add(linha.toString());
            }
        }

        StringBuilder conteudo = new StringBuilder(numLinhas * 80);
        for (String linha : linhas) {
            conteudo.append(linha);
        }
        editor.setText(conteudo.toString());
    }//GEN-LAST:event_jButton3ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea editor;
    private javax.swing.JButton jButton3;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
