Example usage for com.itextpdf.text.pdf PdfPTable setWidths

List of usage examples for com.itextpdf.text.pdf PdfPTable setWidths

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPTable setWidths.

Prototype

public void setWidths(final int relativeWidths[]) throws DocumentException 

Source Link

Document

Sets the relative widths of the table.

Usage

From source file:employee.payroll.system.MainMenu.java

private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed
    JFileChooser dialog = new JFileChooser();
    dialog.setSelectedFile(new File("Employees Report.pdf"));
    int dialogResult = dialog.showSaveDialog(null);
    if (dialogResult == JFileChooser.APPROVE_OPTION) {
        String filePath = dialog.getSelectedFile().getPath();

        try {//from  w w  w .  j  a v a2s.com
            // TODO add your handling code here:

            String sql = "select * from Staff_information";

            pst = conn.prepareStatement(sql);
            rs = pst.executeQuery();

            Document myDocument = new Document();
            PdfWriter myWriter = PdfWriter.getInstance(myDocument, new FileOutputStream(filePath));
            PdfPTable table = new PdfPTable(13);
            myDocument.open();

            float[] columnWidths = new float[] { 3, 8, 7, 5, 5, 9, 8, 9, 6, 6, 6, 8, 8 };
            table.setWidths(columnWidths);

            table.setWidthPercentage(100); //set table width to 100%

            myDocument.add(new Paragraph("Employees List",
                    FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD)));
            myDocument.add(new Paragraph(new Date().toString()));
            myDocument.add(new Paragraph(
                    "-------------------------------------------------------------------------------------------"));
            table.addCell(new PdfPCell(
                    new Paragraph("ID", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("First Name", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Surname", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(new Paragraph("Date of Birth",
                    FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Email", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Telephone", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Address", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Department", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Gender", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Salary", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Status", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Date Hired", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Job Title", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));

            while (rs.next()) {

                table.addCell(new PdfPCell(new Paragraph(rs.getString(1),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(2),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(3),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(4),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(5),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(6),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(7),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(8),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(10),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(11),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(16),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(17),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(18),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));

            }

            myDocument.add(table);
            myDocument.add(new Paragraph(
                    "--------------------------------------------------------------------------------------------"));
            myDocument.close();
            JOptionPane.showMessageDialog(null, "Report was successfully generated");

        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);

        } finally {

            try {
                rs.close();
                pst.close();

            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e);

            }
        }
    }

}

From source file:employee.payroll.system.MainMenu.java

private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
    // TODO add your handling code here:
    JFileChooser dialog = new JFileChooser();
    dialog.setSelectedFile(new File("Employee Allowance Report.pdf"));
    int dialogResult = dialog.showSaveDialog(null);
    if (dialogResult == JFileChooser.APPROVE_OPTION) {
        String filePath = dialog.getSelectedFile().getPath();

        try {//  ww  w.jav  a 2s.  co m
            // TODO add your handling code here:

            String sql = "select * from Allowance";

            pst = conn.prepareStatement(sql);
            rs = pst.executeQuery();

            Document myDocument = new Document();
            PdfWriter myWriter = PdfWriter.getInstance(myDocument, new FileOutputStream(filePath));
            PdfPTable table = new PdfPTable(11);
            myDocument.open();

            float[] columnWidths = new float[] { 3, 7, 7, 5, 5, 9, 6, 5, 8, 8, 8 };
            table.setWidths(columnWidths);

            table.setWidthPercentage(100); //set table width to 100%

            myDocument.add(new Paragraph("Employees Allowance List",
                    FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD)));
            myDocument.add(new Paragraph(new Date().toString()));
            myDocument.add(new Paragraph(
                    "-------------------------------------------------------------------------------------------"));
            table.addCell(new PdfPCell(
                    new Paragraph("ID", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Overtime", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Medical", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Bonus", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Other", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Employee ID", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Salary", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Rate", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Allowance", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("First Name", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Surname", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));

            while (rs.next()) {

                table.addCell(new PdfPCell(new Paragraph(rs.getString(1),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(2),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(3),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(4),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(5),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(6),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(7),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(8),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(9),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(10),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(11),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));

            }

            myDocument.add(table);
            myDocument.add(new Paragraph(
                    "--------------------------------------------------------------------------------------------"));
            myDocument.close();
            JOptionPane.showMessageDialog(null, "Report was successfully generated");

        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);

        } finally {

            try {
                rs.close();
                pst.close();

            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e);

            }
        }
    }

}

From source file:employee.payroll.system.MainMenu.java

private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
    // TODO add your handling code here:

    JFileChooser dialog = new JFileChooser();
    dialog.setSelectedFile(new File("Employee Deduction Report.pdf"));
    int dialogResult = dialog.showSaveDialog(null);
    if (dialogResult == JFileChooser.APPROVE_OPTION) {
        String filePath = dialog.getSelectedFile().getPath();

        try {/*from  w  ww.j a v  a2s .  c om*/
            // TODO add your handling code here:

            String sql = "select * from Deductions";

            pst = conn.prepareStatement(sql);
            rs = pst.executeQuery();

            Document myDocument = new Document();
            PdfWriter myWriter = PdfWriter.getInstance(myDocument, new FileOutputStream(filePath));
            PdfPTable table = new PdfPTable(8);
            myDocument.open();

            float[] columnWidths = new float[] { 3, 7, 7, 5, 5, 9, 6, 5 };
            table.setWidths(columnWidths);

            table.setWidthPercentage(100); //set table width to 100%

            myDocument.add(new Paragraph("Employees Deduction List",
                    FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD)));
            myDocument.add(new Paragraph(new Date().toString()));
            myDocument.add(new Paragraph(
                    "-------------------------------------------------------------------------------------------"));
            table.addCell(new PdfPCell(
                    new Paragraph("ID", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("First Name", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Surname", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Salary", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(new Paragraph("Deduction Amount",
                    FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(new Paragraph("Deduction Reason",
                    FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Employee ID", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Created By", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));

            while (rs.next()) {
                table.addCell(new PdfPCell(new Paragraph(rs.getString(1),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(2),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(3),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(4),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(5),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(6),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(7),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(8),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));

            }

            myDocument.add(table);
            myDocument.add(new Paragraph(
                    "--------------------------------------------------------------------------------------------"));
            myDocument.close();
            JOptionPane.showMessageDialog(null, "Report was successfully generated");

        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);

        } finally {

            try {
                rs.close();
                pst.close();

            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e);

            }
        }
    }

}

From source file:employeepayroll.mainMenu.java

private void emp_td_rpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_emp_td_rpActionPerformed
    // TODO add your handling code here:
    JFileChooser dialog = new JFileChooser();
    dialog.setSelectedFile(new File("Employee Allowance Report.pdf"));
    int dialogResult = dialog.showSaveDialog(null);
    if (dialogResult == JFileChooser.APPROVE_OPTION) {
        String filePath = dialog.getSelectedFile().getPath();

        try {/*from   w  ww . j  av  a  2 s . c o m*/
            String sql = "select * from Allowance";
            pst = conn.prepareStatement(sql);
            rs = pst.executeQuery();
            Document myDocument = new Document();
            PdfWriter myWriter = PdfWriter.getInstance(myDocument, new FileOutputStream(filePath));
            PdfPTable table = new PdfPTable(11);
            myDocument.open();
            float[] columnWidths = new float[] { 3, 7, 7, 5, 5, 9, 6, 5, 8, 8, 8 };
            table.setWidths(columnWidths);
            table.setWidthPercentage(100); //set table width to 100%
            myDocument.add(new Paragraph("Employees Allowance List",
                    FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD)));
            myDocument.add(new Paragraph(new Date().toString()));
            myDocument.add(new Paragraph(
                    "-------------------------------------------------------------------------------------------"));
            table.addCell(new PdfPCell(
                    new Paragraph("ID", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Overtime", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Medical", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Bonus", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Other", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Employee ID", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Salary", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Rate", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Allowance", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("First Name", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Surname", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            while (rs.next()) {
                table.addCell(new PdfPCell(new Paragraph(rs.getString(1),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(2),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(3),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(4),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(5),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(6),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(7),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(8),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(9),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(10),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(11),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
            }
            myDocument.add(table);
            myDocument.add(new Paragraph(
                    "--------------------------------------------------------------------------------------------"));
            myDocument.close();
            JOptionPane.showMessageDialog(null, "Allowance Report was successfully generated");
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);
        } finally {
            try {
                rs.close();
                pst.close();
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e);
            }
        }
    }
}

From source file:employeepayroll.mainMenu.java

private void emp_ta_rpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_emp_ta_rpActionPerformed
    // TODO add your handling code here:
    JFileChooser dialog = new JFileChooser();
    dialog.setSelectedFile(new File("Employees Report.pdf"));
    int dialogResult = dialog.showSaveDialog(null);
    if (dialogResult == JFileChooser.APPROVE_OPTION) {
        String filePath = dialog.getSelectedFile().getPath();
        try {/*from  w w w  . j  a  v a  2s .  c om*/
            String sql = "select * from emp_info";
            pst = conn.prepareStatement(sql);
            rs = pst.executeQuery();
            Document myDocument = new Document();
            PdfWriter myWriter = PdfWriter.getInstance(myDocument, new FileOutputStream(filePath));
            PdfPTable table = new PdfPTable(13);
            myDocument.open();
            float[] columnWidths = new float[] { 3, 8, 7, 5, 5, 9, 8, 9, 6, 6, 6, 8, 8 };
            table.setWidths(columnWidths);
            table.setWidthPercentage(100); //set table width to 100%
            myDocument.add(new Paragraph("Employees List",
                    FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD)));
            myDocument.add(new Paragraph(new Date().toString()));
            myDocument.add(new Paragraph(
                    "-------------------------------------------------------------------------------------------"));
            table.addCell(new PdfPCell(
                    new Paragraph("ID", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("First Name", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Surname", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(new Paragraph("Date of Birth",
                    FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Email", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Telephone", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Address", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Department", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Gender", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Salary", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Status", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Date Hired", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Job Title", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));

            while (rs.next()) {
                table.addCell(new PdfPCell(new Paragraph(rs.getString(1),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(2),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(3),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(4),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(5),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(6),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(7),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(8),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(10),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(11),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(16),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(17),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(18),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
            }
            myDocument.add(table);
            myDocument.add(new Paragraph(
                    "--------------------------------------------------------------------------------------------"));
            myDocument.close();
            JOptionPane.showMessageDialog(null, "Report was successfully generated");
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);
        } finally {

            try {
                rs.close();
                pst.close();
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e);
            }
        }
    }
}

From source file:employeepayroll.mainMenu.java

private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
    // TODO add your handling code here:
    JFileChooser dialog = new JFileChooser();
    dialog.setSelectedFile(new File("Employee Deduction Report.pdf"));
    int dialogResult = dialog.showSaveDialog(null);
    if (dialogResult == JFileChooser.APPROVE_OPTION) {
        String filePath = dialog.getSelectedFile().getPath();
        try {/*w w  w . j av a 2s.c  o m*/
            String sql = "select * from Deductions";
            pst = conn.prepareStatement(sql);
            rs = pst.executeQuery();
            Document myDocument = new Document();
            PdfWriter myWriter = PdfWriter.getInstance(myDocument, new FileOutputStream(filePath));
            PdfPTable table = new PdfPTable(8);
            myDocument.open();
            float[] columnWidths = new float[] { 3, 7, 7, 5, 5, 9, 6, 5 };
            table.setWidths(columnWidths);
            table.setWidthPercentage(100); //set table width to 100%
            myDocument.add(new Paragraph("Employees Deduction List",
                    FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD)));
            myDocument.add(new Paragraph(new Date().toString()));
            myDocument.add(new Paragraph(
                    "-------------------------------------------------------------------------------------------"));
            table.addCell(new PdfPCell(
                    new Paragraph("ID", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("First Name", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Surname", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Salary", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(new Paragraph("Deduction Amount",
                    FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(new Paragraph("Deduction Reason",
                    FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Employee ID", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Created By", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            while (rs.next()) {
                table.addCell(new PdfPCell(new Paragraph(rs.getString(1),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(2),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(3),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(4),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(5),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(6),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(7),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(8),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
            }
            myDocument.add(table);
            myDocument.add(new Paragraph(
                    "--------------------------------------------------------------------------------------------"));
            myDocument.close();
            JOptionPane.showMessageDialog(null, "Deductions Report was successfully generated");
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);
        } finally {
            try {
                rs.close();
                pst.close();
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e);
            }
        }
    }
}

From source file:ems.memu.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed

    JFileChooser dialog = new JFileChooser();
    dialog.setSelectedFile(new File("Employees Report.pdf"));
    int dialogResult = dialog.showSaveDialog(null);
    if (dialogResult == JFileChooser.APPROVE_OPTION) {
        String filePath = dialog.getSelectedFile().getPath();

        try {//from  w ww .  j  av  a 2s. c om
            // TODO add your handling code here:

            String sql = "select * from empinfo";

            pst = conn.prepareStatement(sql);
            rs = pst.executeQuery();

            Document myDocument = new Document();
            PdfWriter myWriter = PdfWriter.getInstance(myDocument, new FileOutputStream(filePath));
            PdfPTable table = new PdfPTable(13);
            myDocument.open();

            float[] columnWidths = new float[] { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 };
            table.setWidths(columnWidths);

            table.setWidthPercentage(100); //set table width to 100%

            myDocument.add(new Paragraph("Employees List",
                    FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD)));
            myDocument.add(new Paragraph(new Date().toString()));
            myDocument.add(new Paragraph(
                    "-------------------------------------------------------------------------------------------"));
            table.addCell(new PdfPCell(
                    new Paragraph("ID", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("First Name", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Surname", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(new Paragraph("Date of Birth",
                    FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Email", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Telephone", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Address", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Department", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Gender", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Salary", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Status", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Date Hired", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Job Title", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD))));

            while (rs.next()) {

                table.addCell(new PdfPCell(new Paragraph(rs.getString(1),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(2),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(3),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(4),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(5),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(6),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(7),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(11),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(17),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(14),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(16),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(13),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(15),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN))));

            }

            myDocument.add(table);
            myDocument.add(new Paragraph(
                    "--------------------------------------------------------------------------------------------"));
            myDocument.close();
            JOptionPane.showMessageDialog(null, "Report was successfully generated");

        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);

        } finally {

            try {
                rs.close();
                pst.close();

            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e);

            }
        }
    }
}

From source file:ems.memu.java

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
    JFileChooser dialog = new JFileChooser();
    dialog.setSelectedFile(new File("Employee Deduction Report.pdf"));
    int dialogResult = dialog.showSaveDialog(null);
    if (dialogResult == JFileChooser.APPROVE_OPTION) {
        String filePath = dialog.getSelectedFile().getPath();

        try {//from   w ww  . j av a 2s.c  o m
            // TODO add your handling code here:

            String sql = "select * from deduction";

            pst = conn.prepareStatement(sql);
            rs = pst.executeQuery();

            Document myDocument = new Document();
            PdfWriter myWriter = PdfWriter.getInstance(myDocument, new FileOutputStream(filePath));
            PdfPTable table = new PdfPTable(7);
            myDocument.open();

            float[] columnWidths = new float[] { 8, 8, 8, 8, 8, 8, 8 };
            table.setWidths(columnWidths);

            table.setWidthPercentage(100); //set table width to 100%

            myDocument.add(new Paragraph("Employees Deduction List",
                    FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD)));
            myDocument.add(new Paragraph(new Date().toString()));
            myDocument.add(new Paragraph(
                    "-------------------------------------------------------------------------------------------"));
            table.addCell(new PdfPCell(
                    new Paragraph("ID", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("First Name", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Surname", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Salary", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(new Paragraph("Deduction Amount",
                    FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(new Paragraph("Deduction Reason",
                    FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));
            table.addCell(new PdfPCell(
                    new Paragraph("Employee ID", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD))));

            while (rs.next()) {
                table.addCell(new PdfPCell(new Paragraph(rs.getString(1),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(2),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(3),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(4),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(5),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(6),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));
                table.addCell(new PdfPCell(new Paragraph(rs.getString(7),
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN))));

            }

            myDocument.add(table);
            myDocument.add(new Paragraph(
                    "--------------------------------------------------------------------------------------------"));
            myDocument.close();
            JOptionPane.showMessageDialog(null, "Report was successfully generated");

        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);

        } finally {

            try {
                rs.close();
                pst.close();

            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e);

            }
        }
    }

}

From source file:es.baudlord.pcpartpicker.controller.BuildViewController.java

License:Open Source License

@FXML
public void onBillAction(ActionEvent event) {
    if (build.isComplete()) {
        try {//from w w  w.  j  av a  2 s. co m
            FileChooser chooser = new FileChooser();
            chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("PDF", "*.pdf"));
            File file = chooser.showSaveDialog(((Node) event.getSource()).getScene().getWindow());
            if (file == null)
                return;
            Document document = new Document();
            PdfWriter.getInstance(document, new FileOutputStream(file));
            document.open();
            // Begin header generation
            PdfPTable table = new PdfPTable(2);
            table.setWidths(new int[] { 3, 7 });
            com.itextpdf.text.Image image = com.itextpdf.text.Image
                    .getInstance(App.class.getResource("img/logo.png"));
            image.scaleToFit(100f, 100f);
            PdfPCell cell = new PdfPCell(image);
            cell.setBorder(0);
            PdfPCell cell2 = new PdfPCell(
                    new Paragraph("Hipster PC Store", new Font(Font.FontFamily.HELVETICA, 30)));
            cell2.setBorder(0);
            cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
            table.addCell(cell2);
            document.add(table);
            // End header generation
            document.add(build.createPdfPTable(new Font(Font.FontFamily.COURIER, 7)));
            // Begin generate date warning
            Calendar cal = Calendar.getInstance();
            Instant now = cal.toInstant();
            cal.add(Calendar.DAY_OF_MONTH, 7);
            Instant end = cal.toInstant();
            DateTimeFormatter localFormat = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT)
                    .withZone(ZoneId.systemDefault());
            Paragraph p1 = new Paragraph(GENERAL_BUNDLE.getString("bill.date.warning"),
                    new Font(Font.FontFamily.COURIER, 10, Font.BOLD));
            Paragraph p2 = new Paragraph(
                    GENERAL_BUNDLE.getString("bill.date.emitted") + " " + localFormat.format(now) + "\n"
                            + GENERAL_BUNDLE.getString("bill.date.valid") + " " + localFormat.format(end),
                    new Font(Font.FontFamily.COURIER, 10));
            p1.setAlignment(Element.ALIGN_CENTER);
            p2.setAlignment(Element.ALIGN_CENTER);
            document.add(p1);
            document.add(p2);
            // End generate date warning
            document.close();
            Alert dialog = new Alert(Alert.AlertType.CONFIRMATION);
            dialog.setTitle(GENERAL_BUNDLE.getString("bill.generated")); // TODO: translate
            dialog.setHeaderText(GENERAL_BUNDLE.getString("bill.validity"));
            dialog.getButtonTypes().setAll(ButtonType.CLOSE,
                    new ButtonType(GENERAL_BUNDLE.getString("button.Print"), ButtonBar.ButtonData.FINISH),
                    new ButtonType(GENERAL_BUNDLE.getString("button.ShowPDF"), ButtonBar.ButtonData.OK_DONE));
            dialog.showAndWait();
            if (dialog.getResult() != null) {
                ButtonBar.ButtonData result = dialog.getResult().getButtonData();
                if (result.equals(ButtonBar.ButtonData.FINISH)) {
                    Desktop.getDesktop().print(file);
                } else if (result.equals(ButtonBar.ButtonData.OK_DONE)) {
                    Desktop.getDesktop().open(file);
                }
            }
        } catch (DocumentException | IOException e) {
            e.printStackTrace();
        }
    } else {
        Alert dialog = new Alert(Alert.AlertType.WARNING);
        dialog.getButtonTypes().setAll(
                new ButtonType(GENERAL_BUNDLE.getString("button.tryAgain"), ButtonBar.ButtonData.OK_DONE),
                ButtonType.CANCEL);
        dialog.setTitle(GENERAL_BUNDLE.getString("dialog.build.incomplete"));
        List<Product.Category> missing = build.getMissingMandatoryParts();
        dialog.setHeaderText(GENERAL_BUNDLE.getString("dialog.build.needed"));
        final HBox content = new HBox(10);
        missing.forEach(category -> {
            Button button = new Button(App.PART_NAMES_BUNDLE.getString(category.toString()));
            button.setGraphic(Category.getGraphic(category, 30));
            button.setContentDisplay(ContentDisplay.TOP);
            button.setId(category.toString());
            button.setOnAction(actionEvent -> {
                try {
                    Part part = pickNewPart(category);
                    if (part != null) {
                        saved.set(false);
                        build.add(part);
                        displayBuild();
                        if (Category.isStorage(category)) {
                            content.getChildren()
                                    .removeIf(node -> node.getId().equals(Product.Category.HDD_SSD.toString())
                                            || node.getId().equals(Product.Category.HDD.toString()));
                            content.autosize();
                        } else {
                            content.getChildren().remove(button);
                        }
                        dialog.getDialogPane().getScene().getWindow().sizeToScene();
                        if (content.getChildren().isEmpty()) {
                            buttonBill.fire();
                            dialog.close();
                        }
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            });
            content.getChildren().add(button);
        });
        dialog.getDialogPane().setContent(content);
        dialog.showAndWait();
        ButtonType result = dialog.getResult();
        if (result != null && result.getButtonData().equals(ButtonBar.ButtonData.OK_DONE)) {
            dialog.hide();
            onBillAction(event);
        }
    }
}

From source file:es.baudlord.pcpartpicker.model.Build.java

License:Open Source License

public PdfPTable createPdfPTable(Font font) throws DocumentException {
    List<PdfPCell> cellList = new ArrayList<>();

    cellList.addAll(Arrays.asList(new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("column.Name"), font)),
            new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("column.UnitPrice"), font)),
            new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("column.Amount"), font)),
            new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("column.Price"), font))));

    for (Product.Category c : Product.Category.values()) {
        ArrayList<Part> parts = getParts(c);
        if (parts.isEmpty())
            continue;

        parts.forEach(product -> cellList
                .addAll(Arrays.asList(new PdfPCell(new Phrase(product.getDescription(), font)),
                        new PdfPCell(new Phrase(Coin.formatNet(product.getPrice()), font)),
                        new PdfPCell(new Phrase(String.valueOf(product.getAmount()), font)),
                        new PdfPCell(new Phrase(Coin.formatNet(product.getTotalPrice()), font)))));
    }/* ww  w  .ja  v a2 s  . c  o m*/
    PdfPCell line = new PdfPCell(new Phrase(""));
    line.setColspan(4);
    cellList.add(line);

    double totalPrice = this.getTotalPrice();
    font.setSize(font.getSize() + 2);

    PdfPCell total = new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("total.price").toUpperCase(), font));
    total.setColspan(3);
    cellList.addAll(Arrays.asList(total, new PdfPCell(new Phrase(Coin.formatNet(totalPrice), font))));

    PdfPCell totalTax = new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("total.tax").toUpperCase(), font));
    totalTax.setColspan(3);
    cellList.addAll(Arrays.asList(totalTax, new PdfPCell(new Phrase(Coin.formatTax(totalPrice), font))));

    PdfPCell totalPvp = new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("total.pvp").toUpperCase(), font));
    totalPvp.setColspan(3);
    cellList.addAll(Arrays.asList(totalPvp, new PdfPCell(new Phrase(Coin.formatGross(totalPrice), font))));

    PdfPTable table = new PdfPTable(4);
    table.setWidths(new int[] { 50, 10, 5, 10 });
    table.setHeaderRows(1);

    for (int i = 0; i < table.getNumberOfColumns(); i++) {
        cellList.get(i).setBorder(Rectangle.BOTTOM);
        table.addCell(cellList.get(i));
    }
    for (int i = table.getNumberOfColumns(); i < cellList.size() - 6; i++) {
        cellList.get(i).setBorder(0);
        table.addCell(cellList.get(i));
    }
    for (int i = cellList.size() - 6; i < cellList.size() - 4; i++) {
        cellList.get(i).setBorder(Rectangle.TOP);
        table.addCell(cellList.get(i));
    }
    for (int i = cellList.size() - 4; i < cellList.size(); i++) {
        cellList.get(i).setBorder(0);
        table.addCell(cellList.get(i));
    }

    return table;
}