Example usage for com.lowagie.text Font BOLD

List of usage examples for com.lowagie.text Font BOLD

Introduction

In this page you can find the example usage for com.lowagie.text Font BOLD.

Prototype

int BOLD

To view the source code for com.lowagie.text Font BOLD.

Click Source Link

Document

this is a possible style.

Usage

From source file:org.sigmah.server.endpoint.export.sigmah.exporter.ProjectReportExporter.java

License:Open Source License

/**
 * Adds the given section to the RTF document.
 * @param section Section to add.// w  w w.  j a  va 2s . c o  m
 * @param prefix Current index (for example: 3.1.1).
 * @param index Local index.
 * @param parent Parent element.
 * @throws DocumentException
 */
private void addSection(ProjectReportSectionDTO section, StringBuilder prefix, int index, Object parent)
        throws DocumentException, IOException {

    // Adding the title to the document
    final TextElementArray thisSection;
    if (parent instanceof Document) {
        // Style
        final Paragraph paragraph = new Paragraph(section.getName());
        paragraph.getFont().setSize(16);
        paragraph.getFont().setStyle(Font.BOLD);

        // New chapter
        final Chapter chapter = new Chapter(paragraph, index);
        thisSection = chapter;

    } else if (parent instanceof Chapter) {
        // Style
        final Paragraph paragraph = new Paragraph(section.getName());
        paragraph.getFont().setSize(14);
        paragraph.getFont().setStyle(Font.BOLD);

        // New section
        final Section chapterSection = ((Chapter) parent).addSection(paragraph);
        thisSection = chapterSection;

    } else if (parent instanceof TextElementArray) {
        // Style
        final Paragraph paragraph = new Paragraph(prefix.toString() + ' ' + section.getName());
        paragraph.getFont().setSize(12);
        paragraph.getFont().setStyle(Font.BOLD);

        // New paragraph
        ((TextElementArray) parent).add(paragraph);
        thisSection = (TextElementArray) parent;

    } else
        thisSection = null;

    // Adding the content of this section
    int subIndex = 1;
    final int prefixLength = prefix.length();

    final StyleSheet stylesheet = new StyleSheet();
    stylesheet.loadTagStyle(HtmlTags.PARAGRAPH, "margin", "0");
    stylesheet.loadTagStyle(HtmlTags.PARAGRAPH, "padding", "0");
    stylesheet.loadTagStyle(HtmlTags.DIV, "margin", "0");
    stylesheet.loadTagStyle(HtmlTags.DIV, "padding", "0");

    for (final ProjectReportContent child : section.getChildren()) {

        if (child instanceof ProjectReportSectionDTO) {
            prefix.append(index).append('.');

            addSection((ProjectReportSectionDTO) child, prefix, subIndex, thisSection);
            subIndex++;

            prefix.setLength(prefixLength);

        } else if (child instanceof RichTextElementDTO) {

            final String value = ((RichTextElementDTO) child).getText();
            if (value != null && !"".equals(value)) {

                // HTML parsing.
                final List<Element> elements = HTMLWorker.parseToList(new StringReader(value), stylesheet);

                for (final Element element : elements)
                    thisSection.add(element);
            }
        }
    }

    // Adding the chapter to the document
    if (thisSection instanceof Chapter && parent instanceof Document)
        ((Document) parent).add((Chapter) thisSection);
}

From source file:org.sigmah.server.report.renderer.itext.ThemeHelper.java

License:Open Source License

public static Paragraph elementTitle(String title) {
    Paragraph para = new Paragraph(title);
    para.setFont(new Font(Font.TIMES_ROMAN, 13, Font.BOLD, new Color(79, 129, 189)));
    para.setSpacingBefore(10);/*from   w  w  w.j a  va 2s.  c o m*/
    return para;
}

From source file:org.silverpeas.components.almanach.control.AlmanachPdfGenerator.java

License:Open Source License

private static void generateAlmanach(Chapter chapter, AlmanachSessionController almanach,
        List<DisplayableEventOccurrence> occurrences, String mode) {

    boolean monthScope = AlmanachPdfGenerator.PDF_MONTH_EVENTSONLY.equals(mode)
            || AlmanachPdfGenerator.PDF_MONTH_ALLDAYS.equals(mode);
    boolean yearScope = AlmanachPdfGenerator.PDF_YEAR_EVENTSONLY.equals(mode);

    int currentDay = -1;
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(almanach.getCurrentDay());
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    int currentMonth = calendar.get(Calendar.MONTH);
    int currentYear = calendar.get(Calendar.YEAR);

    if (yearScope) {
        // start from begin of current year
        calendar.set(Calendar.MONTH, 0);
    }/*from   w  ww  .j  ava 2s .  c o m*/

    // for each day of the current month
    while ((monthScope && currentMonth == calendar.get(Calendar.MONTH))
            || (yearScope && currentYear == calendar.get(Calendar.YEAR))) {
        Section section = null;
        if (AlmanachPdfGenerator.PDF_MONTH_ALLDAYS.equals(mode)) {
            section = chapter.addSection(generateParagraph(calendar, almanach), 0);
        }

        Font titleTextFont = new Font(Font.BOLD, 12, Font.SYMBOL, new Color(0, 0, 0));

        // get the events of the current day
        for (DisplayableEventOccurrence occurrence : occurrences) {
            EventDetail event = occurrence.getEventDetail();
            String theDay = DateUtil.date2SQLDate(calendar.getTime());
            String startDay = DateUtil.date2SQLDate(occurrence.getStartDate().asDate());
            String startHour = event.getStartHour();
            String endHour = event.getEndHour();

            if (startDay.compareTo(theDay) > 0) {
                continue;
            }

            String endDay = startDay;
            if (event.getEndDate() != null) {
                endDay = DateUtil.date2SQLDate(occurrence.getEndDate().asDate());
            }

            if (endDay.compareTo(theDay) < 0) {
                continue;
            }

            if (calendar.get(Calendar.DAY_OF_MONTH) != currentDay) {
                if (AlmanachPdfGenerator.PDF_MONTH_EVENTSONLY.equals(mode)
                        || AlmanachPdfGenerator.PDF_YEAR_EVENTSONLY.equals(mode)) {
                    section = chapter.addSection(generateParagraph(calendar, almanach), 0);
                }
                currentDay = calendar.get(Calendar.DAY_OF_MONTH);
            }

            Font textFont;
            if (event.getPriority() == 0) {
                textFont = new Font(Font.HELVETICA, 10, Font.NORMAL, new Color(0, 0, 0));
            } else {
                textFont = new Font(Font.HELVETICA, 10, Font.BOLD, new Color(0, 0, 0));
            }

            String eventTitle = event.getTitle();
            if (startDay.compareTo(theDay) == 0 && startHour != null && startHour.length() != 0) {
                eventTitle += " (" + startHour;
                if (endDay.compareTo(theDay) == 0 && endHour != null && endHour.length() != 0) {
                    eventTitle += "-" + endHour;
                }
                eventTitle += ")";
            }

            section.add(new Paragraph(eventTitle, titleTextFont));
            if (StringUtil.isDefined(event.getPlace())) {
                section.add(new Paragraph(event.getPlace(), titleTextFont));
            }
            if (StringUtil.isDefined(event.getDescription(almanach.getLanguage()))) {
                section.add(new Paragraph(event.getDescription(almanach.getLanguage()), textFont));
            }
            section.add(new Paragraph("\n"));

        } // end for
        calendar.add(Calendar.DAY_OF_MONTH, 1);
    }
}

From source file:org.silverpeas.components.kmelia.workflowextensions.SendInKmelia.java

License:Open Source License

private void generatePDFStepContent(HistoryStep step, com.lowagie.text.Document document) {
    try {//from w  ww  . j  a  v a2 s.  c o m
        Form form;
        if ("#question#".equals(step.getAction()) || "#response#".equals(step.getAction())) {
            // TODO
            form = null;
        } else {
            form = getProcessInstance().getProcessModel().getPresentationForm(step.getAction(), getRole(),
                    getLanguage());
        }

        XmlForm xmlForm = (XmlForm) form;
        if (xmlForm != null && step.getActionRecord() != null) {
            DataRecord data = step.getActionRecord();

            // Force simpletext displayers because itext cannot display HTML Form fields (select,
            // radio...)
            float[] colsWidth = { 25, 75 };
            PdfPTable tableContent = new PdfPTable(colsWidth);
            tableContent.setWidthPercentage(100);
            String fieldValue = "";
            Font fontLabel = new Font(Font.HELVETICA, 10, Font.BOLD);
            Font fontValue = new Font(Font.HELVETICA, 10, Font.NORMAL);
            List<FieldTemplate> fieldTemplates = xmlForm.getFieldTemplates();
            for (FieldTemplate fieldTemplate1 : fieldTemplates) {
                try {
                    GenericFieldTemplate fieldTemplate = (GenericFieldTemplate) fieldTemplate1;

                    String fieldLabel = fieldTemplate.getLabel("fr");
                    Field field = data.getField(fieldTemplate.getFieldName());
                    String componentId = step.getProcessInstance().getProcessModel().getModelId();

                    // wysiwyg field
                    if ("wysiwyg".equals(fieldTemplate.getDisplayerName())) {
                        String file = WysiwygFCKFieldDisplayer.getFile(componentId,
                                getProcessInstance().getInstanceId(), fieldTemplate.getFieldName(),
                                getLanguage());

                        // Extract the text content of the html code
                        Source source = new Source(new FileInputStream(file));
                        fieldValue = source.getTextExtractor().toString();
                    } // Field file type
                    else if (FileField.TYPE.equals(fieldTemplate.getDisplayerName())
                            && StringUtil.isDefined(field.getValue())) {
                        SimpleDocument doc = AttachmentServiceProvider.getAttachmentService()
                                .searchDocumentById(new SimpleDocumentPK(field.getValue(), componentId), null);
                        if (doc != null) {
                            fieldValue = doc.getFilename();
                        }
                    } // Field date type
                    else if ("date".equals(fieldTemplate.getTypeName())) {
                        fieldValue = DateUtil.getOutputDate(field.getValue(), "fr");
                    } // Others fields type
                    else {
                        fieldTemplate.setDisplayerName("simpletext");
                        fieldValue = field.getValue(getLanguage());
                    }

                    PdfPCell cell = new PdfPCell(new Phrase(fieldLabel, fontLabel));
                    cell.setBorderWidth(0);
                    cell.setPaddingBottom(5);
                    tableContent.addCell(cell);

                    cell = new PdfPCell(new Phrase(fieldValue, fontValue));
                    cell.setBorderWidth(0);
                    cell.setPaddingBottom(5);
                    tableContent.addCell(cell);
                } catch (Exception e) {
                    SilverLogger.getLogger(this).error(e.getMessage(), e);
                }
            }
            document.add(tableContent);
        }
    } catch (Exception e) {
        SilverLogger.getLogger(this).error(e.getMessage(), e);
    }
}

From source file:org.sonar.report.pdf.DefaultPDFReporter.java

License:Open Source License

private void printDashboard(Project project, Section section) throws DocumentException {
    PdfPTable dashboard = new PdfPTable(3);
    dashboard.getDefaultCell().setBorderColor(Color.WHITE);
    Font titleFont = new Font(Font.TIMES_ROMAN, 14, Font.BOLD, Color.BLACK);
    Font dataFont = new Font(Font.TIMES_ROMAN, 14, Font.BOLD, Color.GRAY);
    Font dataFont2 = new Font(Font.TIMES_ROMAN, 10, Font.BOLD, new Color(100, 150, 190));

    PdfPTable linesOfCode = new PdfPTable(1);
    linesOfCode.getDefaultCell().setBorderColor(Color.WHITE);
    linesOfCode.addCell(new Phrase(getTextProperty("general.lines_of_code"), titleFont));
    linesOfCode.addCell(new Phrase(project.getMeasure("ncss").getFormatValue(), dataFont));
    linesOfCode.addCell(/*from   w w w . j av a 2  s .  c o m*/
            new Phrase(project.getMeasure("packages_count").getFormatValue() + " packages", dataFont2));
    linesOfCode
            .addCell(new Phrase(project.getMeasure("classes_count").getFormatValue() + " classes", dataFont2));
    linesOfCode.addCell(
            new Phrase(project.getMeasure("functions_count").getFormatValue() + " methods", dataFont2));
    linesOfCode.addCell(new Phrase(
            project.getMeasure("duplicated_lines_ratio").getFormatValue() + " duplicated lines", dataFont2));

    PdfPTable comments = new PdfPTable(1);
    comments.getDefaultCell().setBorderColor(Color.WHITE);
    comments.addCell(new Phrase(getTextProperty("general.comments"), titleFont));
    comments.addCell(new Phrase(project.getMeasure("comment_ratio").getFormatValue(), dataFont));
    comments.addCell(
            new Phrase(project.getMeasure("comment_lines").getFormatValue() + " comment lines", dataFont2));

    PdfPTable codeCoverage = new PdfPTable(1);
    codeCoverage.getDefaultCell().setBorderColor(Color.WHITE);
    codeCoverage.addCell(new Phrase(getTextProperty("general.test_count"), titleFont));
    codeCoverage.addCell(new Phrase(project.getMeasure("test_count").getFormatValue(), dataFont));
    codeCoverage.addCell(
            new Phrase(project.getMeasure("test_success_percentage").getFormatValue() + " success", dataFont2));
    codeCoverage
            .addCell(new Phrase(project.getMeasure("code_coverage").getFormatValue() + " coverage", dataFont2));

    PdfPTable complexity = new PdfPTable(1);
    complexity.getDefaultCell().setBorderColor(Color.WHITE);
    complexity.addCell(new Phrase(getTextProperty("general.complexity"), titleFont));
    complexity.addCell(new Phrase(project.getMeasure("ccn_function").getFormatValue(), dataFont));
    complexity.addCell(new Phrase(project.getMeasure("ccn_class").getFormatValue() + " /class", dataFont2));
    complexity.addCell(new Phrase(project.getMeasure("ccn").getFormatValue() + " decision points", dataFont2));

    PdfPTable rulesCompliance = new PdfPTable(1);
    rulesCompliance.getDefaultCell().setBorderColor(Color.WHITE);
    rulesCompliance.addCell(new Phrase(getTextProperty("general.rules_compliance"), titleFont));
    rulesCompliance.addCell(new Phrase(project.getMeasure("rules_compliance").getFormatValue(), dataFont));

    PdfPTable violations = new PdfPTable(1);
    violations.getDefaultCell().setBorderColor(Color.WHITE);
    violations.addCell(new Phrase(getTextProperty("general.violations"), titleFont));
    violations.addCell(new Phrase(project.getMeasure("rules_violations").getFormatValue(), dataFont));

    dashboard.addCell(linesOfCode);
    dashboard.addCell(comments);
    dashboard.addCell(codeCoverage);
    dashboard.addCell(complexity);
    dashboard.addCell(rulesCompliance);
    dashboard.addCell(violations);
    dashboard.setSpacingBefore(8);
    section.add(dashboard);
    Image ccnDistGraph = getCCNDistribution(project);
    if (ccnDistGraph != null) {
        section.add(ccnDistGraph);
        Paragraph imageFoot = new Paragraph(getTextProperty("metrics.ccn_classes_count_distribution"),
                Style.FOOT_FONT);
        imageFoot.setAlignment(Paragraph.ALIGN_CENTER);
        section.add(imageFoot);
    }
}

From source file:org.tellervo.desktop.gui.dbbrowse.MetadataBrowser.java

License:Open Source License

/**
 * Called to enable editing/*  www.  j  a v  a2s .co m*/
 * Responsible for loading the duplicate copy into the editor
 * 
 * @param enable
 */
@SuppressWarnings("unchecked")
protected void enableEditing(boolean enable) {

    propertiesTable.setEditable(enable);

    // show/hide our buttons
    editEntitySave.setEnabled(true);
    editEntityCancel.setEnabled(true);
    editEntitySave.setVisible(enable);
    editEntityCancel.setVisible(enable);

    if (currentEntity == null) {
        editEntityText.setText(null);
    } else {
        editEntityText.setFont(editEntityText.getFont().deriveFont(Font.BOLD));
        editEntityText.setText(enable
                ? I18n.getText("metadata.currentlyEditingThis") + " "
                        + TridasTreeViewPanel.getFriendlyClassName(currentEntityType).toLowerCase()
                : I18n.getText("metadata.clickLockToEdit") + " "
                        + TridasTreeViewPanel.getFriendlyClassName(currentEntityType).toLowerCase());
    }
    editEntity.setSelected(enable);

    if (enable) {
        if (currentEntity == null)
            return;

        if (currentEntity instanceof ITridasSeries)
            temporaryEditingEntity = TridasCloner.cloneSeriesRefValues((ITridasSeries) currentEntity,
                    (Class<? extends ITridasSeries>) currentEntity.getClass());
        else
            temporaryEditingEntity = TridasCloner.clone(currentEntity, currentEntity.getClass());

        if (temporaryEditingEntity != null)
            propertiesPanel.readFromObject(temporaryEditingEntity);
    } else {
        temporaryEditingEntity = null;

        // don't display anything if we have nothing!
        if (currentEntity != null) {
            propertiesPanel.readFromObject(currentEntity);
        } else {
            return;
        }
    }

}

From source file:org.tellervo.desktop.io.ImportDialog.java

License:Open Source License

/**
 * Called to enable editing//from  w  w  w  . j a v a 2s. c o  m
 * Responsible for loading the duplicate copy into the editor
 * 
 * @param enable
 */
@SuppressWarnings("unchecked")
protected void enableEditing(boolean enable) {

    propertiesTable.setEditable(enable);

    // show/hide our buttons
    editEntitySave.setEnabled(true);
    editEntityCancel.setEnabled(true);
    editEntitySave.setVisible(enable);
    editEntityCancel.setVisible(enable);

    if (currentEntity == null) {
        editEntityText.setText(null);
    } else {
        editEntityText.setFont(editEntityText.getFont().deriveFont(Font.BOLD));
        editEntityText.setText(enable
                ? I18n.getText("metadata.currentlyEditingThis") + " "
                        + TridasTreeViewPanel.getFriendlyClassName(currentEntityType).toLowerCase()
                : I18n.getText("metadata.clickLockToEdit") + " "
                        + TridasTreeViewPanel.getFriendlyClassName(currentEntityType).toLowerCase());
    }
    editEntity.setSelected(enable);

    if (enable) {
        if (currentEntity == null)
            return;

        if (currentEntity instanceof ITridasSeries)
            temporaryEditingEntity = TridasCloner.cloneSeriesRefValues((ITridasSeries) currentEntity,
                    (Class<? extends ITridasSeries>) currentEntity.getClass());
        else
            temporaryEditingEntity = TridasCloner.clone(currentEntity, currentEntity.getClass());

        if (temporaryEditingEntity != null)
            propertiesPanel.readFromObject(temporaryEditingEntity);
    } else {
        temporaryEditingEntity = null;

        // don't display anything if we have nothingk!
        if (currentEntity != null) {
            propertiesPanel.readFromObject(currentEntity);
        } else {
            return;
        }
    }

}

From source file:org.tellervo.desktop.io.view.ImportView.java

License:Open Source License

/**
 * Called to enable editing/*from  ww  w .ja  v a2 s .c  o m*/
 * Responsible for loading the duplicate copy into the editor
 * 
 * @param enabled
 */
protected void enableEditing(boolean enabled) {
    propertiesTable.setEditable(enabled);

    String entityname = "entity";
    try {
        entityname = TridasTreeViewPanel.getFriendlyClassName(model.getSelectedRow().getCurrentEntityClass());
    } catch (Exception e) {
    }

    editEntityText.setFont(editEntityText.getFont().deriveFont(Font.BOLD));
    editEntityText.setText(enabled ? I18n.getText("metadata.currentlyEditingThis") + " " + entityname
            : I18n.getText("metadata.clickLockToEdit") + " " + entityname);

    editEntity.setSelected(enabled);

    if (enabled) {
        // Remove any 'preview' watermark
        propertiesTable.setHasWatermark(false);
    }

    // disable choosing other stuff while we're editing
    // but only if something else doesn't disable it first
    if (topChooser.isEnabled()) {
        topChooser.setEnabled(!enabled);
        changeButton.setEnabled(!enabled);
    }

    // show/hide our buttons
    editEntitySave.setEnabled(true);
    editEntityCancel.setEnabled(true);
    editEntitySave.setVisible(enabled);
    editEntityCancel.setVisible(enabled);
}

From source file:org.tellervo.desktop.tridasv2.ui.TridasMetadataPanel.java

License:Open Source License

/**
 * Called to enable editing// ww  w  .j a va2 s . co  m
 * Responsible for loading the duplicate copy into the editor
 * 
 * @param enabled
 */
@SuppressWarnings("unchecked")
protected void enableEditing(boolean enabled) {
    propertiesTable.setEditable(enabled);

    lblEditEntityText.setFont(lblEditEntityText.getFont().deriveFont(Font.BOLD));
    lblEditEntityText
            .setText(enabled ? I18n.getText("metadata.currentlyEditingThis") + " " + currentMode.getTitle()
                    : I18n.getText("metadata.clickLockToEdit") + " " + currentMode.getTitle());

    if (enabled) {
        ITridas currentEntity = currentMode.getEntity(sample);
        if (currentEntity instanceof ITridasSeries)
            temporaryEditingEntity = TridasCloner.cloneSeriesRefValues((ITridasSeries) currentEntity,
                    (Class<? extends ITridasSeries>) currentEntity.getClass());
        else
            temporaryEditingEntity = TridasCloner.clone(currentEntity, currentEntity.getClass());

        // user chose to edit without choosing 'new', so be nice and make a new one for them
        if (temporaryEditingEntity == null && cboTopChooser.getSelectedItem() == EntityListComboBox.NEW_ITEM) {
            temporaryEditingEntity = currentMode.newInstance(sample);
            populateNewEntity(currentMode, temporaryEditingEntity);
        }

        if (temporaryEditingEntity != null)
            propertiesPanel.readFromObject(temporaryEditingEntity);
        currentMode.clearChanged();
    } else {
        temporaryEditingEntity = null;

        // don't display anything if we have nothingk!
        ITridas entity = currentMode.getEntity(sample);
        if (entity != null)
            propertiesPanel.readFromObject(entity);
    }

    // disable choosing other stuff while we're editing
    // but only if something else doesn't disable it first
    if (cboTopChooser.isEnabled())
        cboTopChooser.setEnabled(!enabled);
    btnSelectEntity.setEnabled(!enabled);

    // show/hide our buttons
    btnEditEntitySave.setEnabled(true);
    btnEditEntityCancel.setEnabled(true);
    btnEditEntitySave.setVisible(enabled);
    btnEditEntityCancel.setVisible(enabled);
}

From source file:org.unitime.timetable.util.PdfFont.java

License:Open Source License

private static Font createFont(float size, boolean fixed, boolean bold, boolean italic) {
    String font = null;/*from   w w w . ja  va2  s . co m*/
    if (fixed)
        font = ApplicationProperty.PdfFontFixed.value();
    else if (bold) {
        if (italic)
            font = ApplicationProperty.PdfFontBoldItalic.value();
        else
            font = ApplicationProperty.PdfFontBold.value();
    } else if (italic)
        font = ApplicationProperty.PdfFontItalic.value();
    else
        font = ApplicationProperty.PdfFontNormal.value();
    if (font != null && !font.isEmpty()) {
        try {
            BaseFont base = BaseFont.createFont(font, BaseFont.IDENTITY_H, true);
            if (base != null)
                return new Font(base, size);
        } catch (Throwable t) {
        }
    }
    font = (fixed ? ApplicationProperty.PdfFontFixed.value() : ApplicationProperty.PdfFontNormal.value());
    if (font != null && !font.isEmpty()) {
        try {
            BaseFont base = BaseFont.createFont(font, BaseFont.IDENTITY_H, true);
            if (base != null)
                return new Font(base, size, italic && bold ? Font.BOLDITALIC
                        : italic ? Font.ITALIC : bold ? Font.BOLD : Font.NORMAL);
        } catch (Throwable t) {
        }
    }
    if (fixed)
        return FontFactory.getFont(bold ? italic ? FontFactory.COURIER_BOLDOBLIQUE : FontFactory.COURIER_BOLD
                : italic ? FontFactory.COURIER_OBLIQUE : FontFactory.COURIER, size);
    else
        return FontFactory
                .getFont(bold ? italic ? FontFactory.HELVETICA_BOLDOBLIQUE : FontFactory.HELVETICA_BOLD
                        : italic ? FontFactory.HELVETICA_OBLIQUE : FontFactory.HELVETICA, size);
}