Example usage for com.itextpdf.text Font setColor

List of usage examples for com.itextpdf.text Font setColor

Introduction

In this page you can find the example usage for com.itextpdf.text Font setColor.

Prototype


public void setColor(final BaseColor color) 

Source Link

Document

Sets the color.

Usage

From source file:se.billes.pdf.renderer.model.text.Phrase.java

License:Open Source License

public void onRender(com.itextpdf.text.Paragraph paragraph) {
    Font font = new Font(getBaseFont(), getFontSize());
    font.setColor(getBaseColor());
    if (getStyle() != null)
        font.setStyle(getStyle());//from w  ww  .j  a v a2 s  . co  m
    String text = getText();
    if (text.length() == 0)
        text = " ";
    text = text.replace(">", ">");
    text = text.replace("&lt;", "<");

    Chunk chunk = new Chunk(text, font);
    if (getParagraph().getHyphenationAuto() != null) {
        chunk.setHyphenation(getParagraph().getHyphenationAuto());
    }
    chunk.setTextRise(getTextRise());
    chunk.setSkew(getSkewAlpha(), getSkewBeta());
    paragraph.add(chunk);
}

From source file:sistemacontrole.MainWindow.java

/**
 * Creates new form MainWindow/*from  w w w.ja  v a 2  s .  c  om*/
 */
public MainWindow() {
    TelaPDF = new GerarPDFWindow();
    TelaPDF.addGerarFuncaoListener(new GerarPDF());
    TelaPDF.pack();
    TelaPDF.setLocationRelativeTo(null);
    TelaPDF.setTitle("Criao de Relatrio");
    TelaPDF.setDefaultCloseOperation(TelaPDF.DISPOSE_ON_CLOSE);
    model = new DefaultTableModel() {
        @Override
        public boolean isCellEditable(int row, int column) {
            //all cells false
            return false;
        }
    };
    pdfTableCascata = new PdfPTable(6);
    Font fontTITULO = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD);
    fontTITULO.setColor(BaseColor.RED);
    Paragraph tipo = new Paragraph("\n" + "Controle", fontTITULO);
    pdfTableCascata.addCell(tipo);
    Paragraph KP = new Paragraph("\n" + "Kp", fontTITULO);
    pdfTableCascata.addCell(KP);
    Paragraph KD = new Paragraph("\n" + "Kd", fontTITULO);
    pdfTableCascata.addCell(KD);
    Paragraph KI = new Paragraph("\n" + "Ki", fontTITULO);
    pdfTableCascata.addCell(KI);
    Paragraph TI = new Paragraph("\n" + "Ti", fontTITULO);
    pdfTableCascata.addCell(TI);
    Paragraph TD = new Paragraph("\n" + "Td", fontTITULO);
    pdfTableCascata.addCell(TD);

    initComponents();

    model.addColumn("SetPoint");
    model.addColumn("Tpico");
    model.addColumn("Tr 100%");
    model.addColumn("Tr 95%");
    model.addColumn("Tr 90%");
    model.addColumn("Ts 2%");
    model.addColumn("Ts 5%");
    model.addColumn("Ts 10%");
    model.addColumn("Mp% Mp");
    model.addColumn("Kp");
    model.addColumn("Ki");
    model.addColumn("Ti");
    model.addColumn("Kd");
    model.addColumn("Td");
    model.addColumn("Control");

    this.colunas = this.tabelaDetalhes.getColumnModel();
    for (int i = 0; i < 15; i++) {
        this.colunas.getColumn(i).setMinWidth(0);
    }
    this.colunas.getColumn(3).setMaxWidth(0);
    this.colunas.getColumn(4).setMaxWidth(0);
    this.colunas.getColumn(5).setMaxWidth(0);
    this.colunas.getColumn(6).setMaxWidth(0);
    this.colunas.getColumn(9).setMaxWidth(0);
    this.colunas.getColumn(10).setMaxWidth(0);
    this.colunas.getColumn(11).setMaxWidth(0);
    this.colunas.getColumn(12).setMaxWidth(0);
    this.colunas.getColumn(13).setMaxWidth(0);
    this.colunas.getColumn(14).setMaxWidth(0);

    //Object ob = new Object[] { "0-10cm"};
    //addNewRow();
    //setValueTable("SetPoint","0-10cm");
    //        model.addRow(new Object[] { "0-10cm", "5s", "3s", "20s", "10s", "14s", "40s", "30s", "20% 2cm" });
    //this.tabelaDetalhes.setValueAt("15s", this.tabelaDetalhes.getRowCount()-1, 7);
}

From source file:sistemacontrole.MainWindow.java

private void pararSinalBtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pararSinalBtActionPerformed
    //salva os grafico
    BufferedImage img = new BufferedImage(PainelEntrada.getWidth(), PainelEntrada.getHeight(),
            BufferedImage.TYPE_INT_RGB);
    PainelEntrada.print(img.getGraphics()); // or: panel.printAll(...);
    try {/*from   w  w w .  j  a  v  a  2 s. c  o m*/
        ImageIO.write(img, "jpg", new File("./Raw_Data/PainelEntrada" + this.registro + ".jpg"));
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    BufferedImage img2 = new BufferedImage(PainelSaida.getWidth(), PainelSaida.getHeight(),
            BufferedImage.TYPE_INT_RGB);
    PainelSaida.print(img2.getGraphics()); // or: panel.printAll(...);
    try {
        ImageIO.write(img2, "jpg", new File("./Raw_Data/PainelSaida" + this.registro + ".jpg"));
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    this.registro++;
    Font fontTITULO2 = new Font(Font.FontFamily.TIMES_ROMAN, 13, Font.NORMAL);
    Font fontTITULO = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD);
    fontTITULO.setColor(BaseColor.RED);

    Font fontDADO = new Font(Font.FontFamily.TIMES_ROMAN, 9, Font.NORMAL);
    if (cascata) {

        Paragraph tipo_VALOR = new Paragraph((this.controleT1), fontDADO);
        Paragraph KP_VALOR = new Paragraph((this.kp_t1), fontDADO);
        Paragraph KD_VALOR = new Paragraph((this.kd_t1), fontDADO);
        Paragraph KI_VALOR = new Paragraph((this.ki_t1), fontDADO);
        Paragraph TI_VALOR = new Paragraph((this.ti_t1), fontDADO);
        Paragraph TD_VALOR = new Paragraph((this.td_t1), fontDADO);
        pdfTableCascata.addCell(tipo_VALOR);
        pdfTableCascata.addCell(KP_VALOR);
        pdfTableCascata.addCell(KD_VALOR);
        pdfTableCascata.addCell(KI_VALOR);
        pdfTableCascata.addCell(TI_VALOR);
        pdfTableCascata.addCell(TD_VALOR);

    }
    // TODO add your handling code here:
}

From source file:sistemacontrole.MainWindow.java

public void GerarPDFFuncao() throws BadElementException, IOException {
    try {/*from  w w w .  j av  a 2 s .  com*/
        //Define as fontes
        Font fontOBS = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.NORMAL);
        Font fontTITULO2 = new Font(Font.FontFamily.TIMES_ROMAN, 13, Font.NORMAL);
        Font fontTITULO = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD);
        fontTITULO.setColor(BaseColor.RED);

        Font fontDADO = new Font(Font.FontFamily.TIMES_ROMAN, 9, Font.NORMAL);
        Document doc = new Document(PageSize.A4.rotate());

        // adiciona imagem ao pdf
        Image Logotipo = Image.getInstance("./src/Imagens/imagem_pdf.png");
        Logotipo.scalePercent((float) 47.5);
        PdfPTable tabelaGrfico = new PdfPTable(2);
        for (int i = 1; i < this.registro; i++) {
            Image LogotipoI = Image.getInstance("./Raw_Data/PainelEntrada" + i + ".jpg");
            Image LogotipoI2 = Image.getInstance("./Raw_Data/PainelSaida" + i + ".jpg");
            tabelaGrfico.addCell(LogotipoI);
            tabelaGrfico.addCell(LogotipoI2);
        }

        int count = this.tabelaDetalhes.getRowCount();

        PdfWriter.getInstance(doc, new FileOutputStream(TelaPDF.CampoNome.getText() + ".pdf"));
        doc.open();
        PdfPTable pdfTable = new PdfPTable(this.tabelaDetalhes.getColumnCount());
        //adding table headers
        for (int i = 0; i < 15; i++) {
            pdfTable.addCell(new Paragraph(this.tabelaDetalhes.getColumnName(i), fontTITULO));
        }

        PdfPTable pdfTableAuxiliar = new PdfPTable(this.tabelaDetalhes.getColumnCount());

        String[][] valores = new String[15][15];
        for (int i = 0; i < 15; i++) {
            for (int j = 0; j < 15; j++) {
                valores[i][j] = "";
            }
        }

        Object[] obj = null;
        int contador = 1;
        for (int i = 0; i < count; i++) {
            for (int j = 0; j < 15; j++) {
                try {
                    System.out.println("Valor: " + tabelaDetalhes.getModel().getValueAt(i, j).toString()
                            + "Contado: " + contador);
                    valores[i][j] = tabelaDetalhes.getModel().getValueAt(i, j).toString();

                } catch (Exception e) {
                    System.out.println("ERRO  DEU  contador: " + contador);
                    contador++;
                }

            }

        }

        for (int i = 0; i < count; i++) {
            for (int j = 0; j < 15; j++) {
                pdfTableAuxiliar.addCell(new Paragraph(valores[i][j], fontDADO));
            }
        }

        Paragraph title = new Paragraph("Sistema de Controle de Tanques - TC Control" + "\n\n", fontTITULO2);
        title.setAlignment(Paragraph.ALIGN_CENTER);

        Calendar calendar = new GregorianCalendar();
        Date trialTime = new Date();
        calendar.setTime(trialTime);
        Paragraph DIA = new Paragraph("Data: " + calendar.get(Calendar.DATE) + "/"
                + (calendar.get(Calendar.MONTH) + 1) + "/" + calendar.get(Calendar.YEAR));
        Paragraph HORA = new Paragraph("Hora: " + calendar.get(Calendar.HOUR_OF_DAY) + ":"
                + calendar.get(Calendar.MINUTE) + ":" + calendar.get(Calendar.SECOND));
        DIA.setAlignment(Paragraph.ALIGN_RIGHT);
        HORA.setAlignment(Paragraph.ALIGN_RIGHT);
        Paragraph espaco = new Paragraph("\n");
        Paragraph aviso = new Paragraph("\nGraficos dos Testes ordenados:");
        aviso.setAlignment(Paragraph.ALIGN_CENTER);

        Paragraph autores = new Paragraph(
                "\n" + "Desenvolvedores: @AlexandeLUZ - @AndersonDIAS - @HigoBESSA - @JaimeDANTAS", fontDADO);
        autores.setAlignment(Paragraph.ALIGN_CENTER);

        Paragraph obs = new Paragraph("\n" + "Observaes: " + TelaPDF.observacoes.getText(), fontOBS);
        obs.setAlignment(Paragraph.ALIGN_CENTER);

        //PARTE DO CASCATA DO TANQUE 1

        Paragraph cascataTitulo = new Paragraph("Parmetros do Tanque 1 (Escravo):  ", fontTITULO2);
        cascataTitulo.setAlignment(Paragraph.ALIGN_CENTER);

        //PdfPTable pdfTableCascata = new PdfPTable(5);
        //                if(cascata){
        //                   
        //                   Paragraph KP = new Paragraph("\n" +
        //                    "Kp" ,fontTITULO);
        //                   pdfTableCascata.addCell(KP);
        //                   Paragraph KD = new Paragraph("\n" +
        //                    "Kd" ,fontTITULO);
        //                   pdfTableCascata.addCell(KD);
        //                   Paragraph KI = new Paragraph("\n" +
        //                    "Ki" ,fontTITULO);
        //                   pdfTableCascata.addCell(KI);
        //                   Paragraph TI = new Paragraph("\n" +
        //                    "Ti" ,fontTITULO);
        //                   pdfTableCascata.addCell(TI);
        //                   Paragraph TD = new Paragraph("\n" +
        //                    "Td" ,fontTITULO);
        //                   pdfTableCascata.addCell(TD);
        //                   Paragraph KP_VALOR = new Paragraph((this.kp_t1),fontDADO);
        //                   Paragraph KD_VALOR = new Paragraph((this.kd_t1),fontDADO);
        //                   Paragraph KI_VALOR = new Paragraph((this.ki_t1),fontDADO);
        //                   Paragraph TI_VALOR = new Paragraph((this.ti_t1),fontDADO);
        //                   Paragraph TD_VALOR = new Paragraph((this.td_t1),fontDADO);
        //                   pdfTableCascata.addCell(KP_VALOR);
        //                   pdfTableCascata.addCell(KD_VALOR);
        //                   pdfTableCascata.addCell(KI_VALOR);
        //                   pdfTableCascata.addCell(TI_VALOR);
        //                   pdfTableCascata.addCell(TD_VALOR);
        //
        //                }

        doc.add(Logotipo);
        doc.add(title);
        doc.add(pdfTable);
        doc.add(pdfTableAuxiliar);
        if (cascata) {
            doc.add(cascataTitulo);
            doc.add(espaco);
            doc.add(pdfTableCascata);
        }
        doc.add(obs);
        doc.add(aviso);
        //doc.add(espaco);
        doc.add(tabelaGrfico);
        doc.add(espaco);
        doc.add(espaco);
        doc.add(DIA);
        doc.add(HORA);
        doc.add(autores);

        doc.close();
        System.out.println("done");
        mostrarAviso("Arquivo criado com sucesso!");
        TelaPDF.setVisible(false);
    } catch (DocumentException ex) {
        Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
        mostrarErro("Erro ao gerar PDF!");
    } catch (FileNotFoundException ex) {
        Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
        mostrarErro("Erro ao gerar PDF!");

    }

}

From source file:utils.PrintUtils.java

public static Font setUpFont(final float size, final int style, final BaseColor color) {
    Font font = new Font();
    font.setStyle(style);/*from   www. j  a v  a 2 s.c om*/
    font.setSize(size);
    font.setColor(color);
    return font;
}