Java 类net.sf.jasperreports.engine.design.JRDesignStaticText 实例源码

项目:openbravo-brazil    文件:ReportDesignBO.java   
private void addFieldHeader(GridColumnVO columnVO) {
  JRDesignBand bHeader = (JRDesignBand) jasperDesign.getColumnHeader();
  JRDesignStaticText text = new JRDesignStaticText();
  text.setText(columnVO.getTitle());
  text.setWidth(columnVO.getWidth());
  text.setHeight(bHeader.getHeight());
  text.setX(px);
  // Set syle
  text.setFontName(gridReportVO.getHeaderBandStyle().getFontName());
  text.setFontSize(new Float(gridReportVO.getHeaderBandStyle().getFontSize()));
  text.setForecolor(gridReportVO.getHeaderBandStyle().getForeColor());
  text.setBold(gridReportVO.getHeaderBandStyle().isBold());
  text.setItalic(gridReportVO.getHeaderBandStyle().isItalic());
  text.setUnderline(gridReportVO.getHeaderBandStyle().isUnderline());
  if (log4j.isDebugEnabled())
    log4j.debug("Field Header, field: " + columnVO.getTitle() + " Width: " + columnVO.getWidth()
        + " X: " + px);
  bHeader.addElement(text);
}
项目:PDFReporter-Studio    文件:DefaultTemplateEngine.java   
/**
 * Find a JRDesignStaticText element having exp as text.
 * 
 * @param band
 * @param exp
 * @return the first matching element or null.
 */
public static JRDesignStaticText findStaticTextElement(JRElementGroup parent, String exp) {
    JRElement[] elements = parent.getElements();
    for (int i = 0; i < elements.length; ++i) {
        JRElement ele = elements[i];
        if (ele instanceof JRDesignStaticText) {
            JRDesignStaticText st = (JRDesignStaticText) ele;
            if (st.getText() != null && st.getText().equalsIgnoreCase(exp)) {
                return st;
            }
        } else if (ele instanceof JRElementGroup) {
            JRDesignStaticText ele2 = findStaticTextElement((JRElementGroup) ele, exp);
            if (ele2 != null)
                return ele2;
        }
    }
    return null;
}
项目:PDFReporter-Studio    文件:PreviewGenerator.java   
/**
 * Create a very minimal jasperdesign where the static text is placed. It is cached
 * since we don't need to create it everytime
 */
private static void createDesign()
 {
      jasperDesign = new JasperDesign();
      JRDesignBand jrBand = new JRDesignBand();
         jasperDesign.setTitle(jrBand);
      textElement = new JRDesignStaticText();
      jasperDesign.setLeftMargin(0);
      jasperDesign.setRightMargin(0);
      jasperDesign.setTopMargin(0);
      jasperDesign.setBottomMargin(0);
      jrBand.addElement(textElement);
      jrBand.setSplitType(SplitTypeEnum.STRETCH);
      textElement.setStretchType(StretchTypeEnum.NO_STRETCH);
      textElement.setPrintRepeatedValues(false);
      textElement.setPrintWhenDetailOverflows(true);
  }
项目:PDFReporter-Studio    文件:ReportGenerator.java   
public static JRDesignStaticText findStaticTextElement(JRElementGroup parent, String exp) {
    JRElement[] elements = parent.getElements();
    for (int i = 0; i < elements.length; ++i) {
        JRElement ele = elements[i];
        if (ele instanceof JRDesignStaticText) {
            JRDesignStaticText st = (JRDesignStaticText) ele;
            if (st.getText() != null && st.getText().equalsIgnoreCase(exp)) {
                return st;
            }
        } else if (ele instanceof JRElementGroup) {
            JRDesignStaticText ele2 = findStaticTextElement((JRElementGroup) ele, exp);
            if (ele2 != null)
                return ele2;
        }
    }
    return null;
}
项目:PDFReporter-Studio    文件:ConvertTextIntoStatic.java   
@Override
public void execute() {
    MStaticText modelText = new MStaticText();

    JRDesignStaticText labelObject = (JRDesignStaticText)modelText.createJRElement(elementToCopy.getJasperDesign());
    JRDesignTextField textObject = (JRDesignTextField)elementToCopy.getValue();

    cloneTextField(labelObject, textObject);


    modelText.setValue(labelObject);
    Rectangle position = new Rectangle(textObject.getX(),textObject.getY(),textObject.getWidth(),textObject.getHeight());

    int oldIndex = ModelUtils.getChildrenPosition(elementToCopy);
    cmd = new CreateElementCommand(parent, modelText, position, oldIndex);
    cmd.setJasperDesign(parent.getJasperDesign());
    cmd.execute();
}
项目:PDFReporter-Studio    文件:ConvertStaticIntoText.java   
@Override
public void execute() {
    MTextField modelText = new MTextField();

    JRDesignStaticText labelObject = (JRDesignStaticText)elementToCopy.getValue();
    JRDesignTextField textObject =  (JRDesignTextField)modelText.createJRElement(elementToCopy.getJasperDesign());

    cloneTextField(textObject, labelObject);

    modelText.setValue(textObject);
    Rectangle position = new Rectangle(labelObject.getX(),labelObject.getY(),labelObject.getWidth(),labelObject.getHeight());

    int oldIndex = ModelUtils.getChildrenPosition(elementToCopy);
    cmd = new CreateElementCommand(parent, modelText, position, oldIndex);
    cmd.setJasperDesign(parent.getJasperDesign());
    cmd.execute();
}
项目:ireport-fork    文件:TextElementPropertiesFactory.java   
/**
 * Convenient way to get all the properties of an element.
 * Properties positions could be reordered to have a better order.
 */
public static List<Sheet.Set> getPropertySets(JRDesignElement element, JasperDesign jd)
{
    List<Sheet.Set> sets = new ArrayList<Sheet.Set>();

    if (element instanceof  JRDesignStaticText)
    {
        sets.add( getStaticTextPropertySet((JRDesignStaticText)element, jd ));
    }
    else if (element instanceof  JRDesignTextField)
    {
        sets.add( getTextFieldPropertySet((JRDesignTextField)element, jd ));
    }

    if (element instanceof  JRDesignTextElement)
    {
        sets.add( getTextPropertySet((JRDesignTextElement)element, jd) );
    }

    return sets;
}
项目:ireport-fork    文件:NewTypesUtils.java   
private JRDesignStaticText createLabel(JasperDesign jd, String text, int w, int h, String styleName)
{
    JRDesignStaticText element = new JRDesignStaticText();
    element.setX(0);
    element.setY(0);
    element.setWidth(w);
    element.setHeight(h);
    element.setText(text);
    element.setHorizontalAlignment( HorizontalAlignEnum.CENTER );
    element.setVerticalAlignment( VerticalAlignEnum.MIDDLE);

    if (styleName != null && jd.getStylesMap().containsKey(styleName))
    {
        element.setStyle( (JRStyle) jd.getStylesMap().get(styleName) );
    }
    return element;
}
项目:ireport-fork    文件:AbstractReportGenerator.java   
/**
 * Find in band a JRDesignStaticText element having exp as text.
 * @param band
 * @param exp
 * @return the first matching element or null.
 */
public static  JRDesignStaticText findStaticTextElement(JRElementGroup parent, String exp)
{
    JRElement[] elements = parent.getElements();
    for (int i=0; i<elements.length; ++i)
    {
        JRElement ele = elements[i];
        if (ele instanceof JRDesignStaticText)
        {
            JRDesignStaticText st = (JRDesignStaticText)ele;
            if (st.getText() != null &&
                st.getText().equalsIgnoreCase(exp))
            {
                return st;
            }
        }
        else if (ele instanceof JRElementGroup)
        {
            JRDesignStaticText ele2 = findStaticTextElement((JRElementGroup)ele, exp);
            if (ele2 != null) return ele2;
        }
    }
    return null;
}
项目:ireport-fork    文件:AbstractReportObjectScene.java   
public void setValue(JRDesignStaticText element,Object val)
{
    String oldValue = element.getText();

    String newValue = val+"";
    if (val == null)
    {
        newValue = "";
    }

    element.setText(newValue);

    ObjectPropertyUndoableEdit opue = new ObjectPropertyUndoableEdit(
            element, "Text", String.class, oldValue, newValue);

    IReportManager.getInstance().addUndoableEdit(opue);

}
项目:kfs    文件:TravelReportFactoryServiceImpl.java   
public JRBand createTitle(final ReportInfo report, final String title) throws Exception {
    final JRDesignBand retval = new JRDesignBand();
    retval.setHeight(93);

    final JRDesignTextField headerLine1 = h1("$P{report}.getInstitution()").toTextField();
    addDesignElementTo(retval, headerLine1, 0, 0, 356, 30);
    final JRDesignStaticText headerLine2 = h5(title + " for # ").toStaticText();
    addDesignElementTo(retval, headerLine2, 0, 31, 426, 24);
    final JRDesignTextField headerLine3 = h5("$P{report}.getTripId()").toTextField();
    addDesignElementTo(retval, headerLine3, 275, 31, 146, 24);
    final JRDesignStaticText headerLine4 = h5("Purpose: ").toStaticText();
    addDesignElementTo(retval, headerLine4, 0, 52, 100, 20);
    final JRDesignStaticText headerLine5 = h5("Dates: ").toStaticText();
    addDesignElementTo(retval, headerLine5, 0, 72, 100, 20);
    final JRDesignTextField headerLine4Field1 = h5("$P{report}.getPurpose()").toTextField();
    addDesignElementTo(retval, headerLine4Field1, 65, 52, 472, 20);
    final JRDesignTextField headerLine5Field1 = h5("$P{report}.getBeginDate()").toTextField(java.util.Date.class);
    addDesignElementTo(retval, headerLine5Field1, 45, 72, 75, 20);
    final JRDesignTextField headerLine5Field2 = h5("$P{report}.getEndDate()").toTextField(java.util.Date.class);
    addDesignElementTo(retval, headerLine5Field2, 150, 72, 75, 20);

    return retval;
}
项目:kfs    文件:TravelReportFactoryServiceImpl.java   
/**
 * Constructs a header for the {@link JRDesignGroup}
 *
 * @return {@link JRBand} instance that is your header
 */
protected JRBand createGroupHeader(final ReportInfo report) {
    final JRDesignBand retval = new JRDesignBand();
    retval.setHeight(PAGEHEADER_HEIGHT * 4);

    final JRDesignTextField expenseType = h4("$F{expenseType}").toTextField();
    addDesignElementTo(retval, expenseType, 0, PAGEHEADER_HEIGHT, CT_HEADER_WIDTH, CELL_HEIGHT + 10);

    final JRDesignStaticText nameField = h5("Expense").toStaticText();
    addDesignElementTo(retval, nameField, (CELL_WIDTH * 3 + 5) * 0, PAGEHEADER_HEIGHT * 2 + CELL_HEIGHT, CELL_WIDTH * 3, CELL_HEIGHT);

    final JRDesignStaticText dateField = h5("Date").toStaticText();
    addDesignElementTo(retval, dateField, (CELL_WIDTH * 3 + 5) * 1, PAGEHEADER_HEIGHT * 2 + CELL_HEIGHT, CELL_WIDTH * 3, CELL_HEIGHT);

    final JRDesignStaticText amountField = h5("Amount").toStaticText();
    addDesignElementTo(retval, amountField, (CELL_WIDTH * 3 + 5) * 2, PAGEHEADER_HEIGHT * 2 + CELL_HEIGHT, CELL_WIDTH * 3, CELL_HEIGHT);

    return retval;
}
项目:jasperreports    文件:JRStaticTextFactory.java   
@Override
public Object createObject(Attributes atts)
{
    JasperDesign jasperDesign = (JasperDesign)digester.peek(digester.getCount() - 2);

    JRDesignStaticText staticText = new JRDesignStaticText(jasperDesign);

    return staticText;
}
项目:jasperreports    文件:EditTextElementCommand.java   
private void applyColumnHeaderData(EditTextElementData textElementData, JRDesignTextElement textElement, boolean execute) {
    if (EditTextElementData.APPLY_TO_HEADING.equals(textElementData.getApplyTo())) {
        if (textElement instanceof JRDesignTextField) {
            JRDesignTextField designTextField = (JRDesignTextField)textElement;
            if (execute) {
                if (oldText == null) {
                    oldText = (designTextField.getExpression()).getText();
                }
                ((JRDesignExpression)designTextField.getExpression()).setText("\"" + JRStringUtil.escapeJavaStringLiteral(textElementData.getHeadingName()) + "\"");
            } else {
                ((JRDesignExpression)designTextField.getExpression()).setText(oldText);
            }

        } else if (textElement instanceof JRDesignStaticText){
            JRDesignStaticText staticText = (JRDesignStaticText)textElement;
            if (execute) {
                if (oldText == null) {
                    oldText = staticText.getText();
                }
                staticText.setText(textElementData.getHeadingName());
            } else {
                staticText.setText(oldText);
            }
        }
    }

    textElement.setFontName(textElementData.getFontName());
    textElement.setFontSize(textElementData.getFloatFontSize());
    textElement.setBold(textElementData.getFontBold());
    textElement.setItalic(textElementData.getFontItalic());
    textElement.setUnderline(textElementData.getFontUnderline());
    textElement.setForecolor(textElementData.getFontColor() != null ? JRColorUtil.getColor("#" + textElementData.getFontColor(), textElement.getForecolor()) : null);
    textElement.setHorizontalTextAlign(HorizontalTextAlignEnum.getByName(textElementData.getFontHAlign()));
    textElement.setBackcolor(textElementData.getFontBackColor() != null ? JRColorUtil.getColor("#" + textElementData.getFontBackColor(), Color.white) : null);
    textElement.setMode(ModeEnum.getByName(textElementData.getMode()));

    if (textElement instanceof JRDesignTextField && TableUtil.hasSingleChunkExpression((JRDesignTextField) textElement)) {
        ((JRDesignTextField) textElement).setPattern(textElementData.getFormatPattern());
    }
}
项目:PDFReporter-Studio    文件:TableTemplateEngine.java   
/**
 * Find a JRDesignStaticText inside a table element having exp as text.
 * 
 * @param parent table where to search
 * @param exp the text of the element
 * @return the first matching element or null.
 */
public static JRDesignStaticText findStaticTextElement(StandardTable parent, String exp) {
    StandardColumn col = getStandadColumn(parent.getColumns().get(0));
    if (col != null){
        JRDesignStaticText result = null;
        if (col.getTableHeader() != null) result = DefaultTemplateEngine.findStaticTextElement(col.getTableHeader(), exp);
        if (col.getColumnHeader() != null && result == null) result = DefaultTemplateEngine.findStaticTextElement(col.getColumnHeader(), exp);
        if (col.getDetailCell() != null && result == null) result = DefaultTemplateEngine.findStaticTextElement(col.getDetailCell(), exp);
        return result;
    }
    return null;
}
项目:PDFReporter-Studio    文件:JasperServerTemplateEngine.java   
/**
 * Find a JRDesignStaticText inside a table element having exp as text.
 * 
 * @param parent table where to search
 * @param exp the text of the element
 * @return the first matching element or null.
 */
public static JRDesignStaticText findStaticTextElement(StandardTable parent, String exp) {
    StandardColumn col = (StandardColumn)parent.getColumns().get(0);
    if (col != null){
        JRDesignStaticText result = DefaultTemplateEngine.findStaticTextElement(col.getTableHeader(), exp);
        if (result == null) result = DefaultTemplateEngine.findStaticTextElement(col.getColumnHeader(), exp);
        if (result == null) result = DefaultTemplateEngine.findStaticTextElement(col.getDetailCell(), exp);
        return result;
    }
    return null;
}
项目:PDFReporter-Studio    文件:MStaticText.java   
@Override
public Object getPropertyValue(Object id) {
    JRDesignStaticText jrElement = (JRDesignStaticText) getValue();
    if (id.equals(JRBaseStaticText.PROPERTY_TEXT))
        return jrElement.getText();
    return super.getPropertyValue(id);
}
项目:PDFReporter-Studio    文件:MStaticText.java   
@Override
public void setPropertyValue(Object id, Object value) {
    JRDesignStaticText jrElement = (JRDesignStaticText) getValue();

    if (id.equals(JRBaseStaticText.PROPERTY_TEXT)){
        jrElement.setText((String) value);
    }   else
        super.setPropertyValue(id, value);
}
项目:PDFReporter-Studio    文件:MStaticText.java   
@Override
public JRDesignElement createJRElement(JasperDesign jasperDesign) {
    JRDesignStaticText jrDesignStaticText = new JRDesignStaticText();
    jrDesignStaticText.setText(Messages.common_static_text);

    DefaultManager.INSTANCE.applyDefault(this.getClass(), jrDesignStaticText);

    return jrDesignStaticText;
}
项目:PDFReporter-Studio    文件:Tag.java   
public static MStaticText createStaticText(String txtExp) {
    MStaticText src = new MStaticText();
    JRDesignStaticText tf = new JRDesignStaticText();
    tf.setText(txtExp);
    src.setValue(tf);
    return src;
}
项目:ireport-fork    文件:TextElementPropertiesFactory.java   
/**
 * Get the static text properties...
 */
public static Sheet.Set getStaticTextPropertySet(JRDesignStaticText element, JasperDesign jd)
{

    //JRDesignDataset dataset = ModelUtils.getElementDataset(element, jd);

    Sheet.Set propertySet = Sheet.createPropertiesSet();
    propertySet.setName("STATIC_TEXT_ELEMENT_PROPERTIES");
    propertySet.setDisplayName("Static text properties");

    propertySet.put(new TextProperty( element ));
    return propertySet;
}
项目:ireport-fork    文件:CreateCrosstabAction.java   
private JRDesignStaticText createLabel(String text, int w, int h)
{
    JRDesignStaticText element = new JRDesignStaticText();
    element.setX(0);
    element.setY(0);
    element.setWidth(w);
    element.setHeight(h);
    element.setText(text);
    element.setHorizontalAlignment( HorizontalAlignEnum.CENTER );
    element.setVerticalAlignment( VerticalAlignEnum.MIDDLE);
    return element;
}
项目:ireport-fork    文件:CreateStaticTextAction.java   
public JRDesignElement createReportElement(JasperDesign jd)
{
    JRDesignStaticText element = new JRDesignStaticText( jd );
    element.setText("Static text");
    element.setWidth(100);
    element.setHeight(20);
    return element;
}
项目:ireport-fork    文件:AbstractReportObjectScene.java   
public String getText (Widget widget) {
     JRDesignElement element = getElement(widget);
     if (element != null && element instanceof JRDesignStaticText)
     {
         return ((JRDesignStaticText)element).getText();
     }
     else if (element != null && element instanceof JRDesignTextField)
     {
         return Misc.getExpressionText( ((JRDesignTextField)element).getExpression() );
     }

     return "";
}
项目:ireport-fork    文件:AbstractReportObjectScene.java   
public void setText (Widget widget, String text) {

    JRDesignElement element = getElement(widget);
     if (element != null && element instanceof JRDesignStaticText)
     {
         setValue((JRDesignStaticText)element, text);
     }
     else if (element != null && element instanceof JRDesignTextField)
     {
         setValue((JRDesignTextField)element, text);
     }
}
项目:ireport-fork    文件:TextProperty.java   
@SuppressWarnings("unchecked")
public TextProperty(JRDesignStaticText staticText)
{
    super(staticText);
    this.staticText = staticText;
    setValue("oneline", Boolean.FALSE);
    setValue("suppressCustomEditor", Boolean.FALSE);
}
项目:kfs    文件:TravelReportFactoryServiceImpl.java   
/**
 * Populate the design of a report. Report's main content container is a design.
 *
 * @param report in
 * @return {@link JasperDesign} out
 * @throws Exception because there is a lot of under-the-hood I/O and reflection going on.
 */
@Override
public JasperDesign designSummary(final ReportInfo report) throws Exception {
    final JasperDesign designObj = new JasperDesign();
    final String reportTitle = getReportTitle(report);
    designObj.setName(reportTitle);
    designObj.setTitle(createTitle(report, reportTitle));

    LOG.info("Summary: Loading report parameters");
    addReportParametersFor(report, designObj);
    designObj.addImport(report.getClass().getName());
    LOG.info("Summary: Loading report fields");
    addReportFieldsFor(report, designObj);

    LOG.info("Summary: Setting report dimensions");
    designObj.setPageWidth(595);
    designObj.setPageHeight(REPORT_HEIGHT);
    designObj.setLeftMargin(MARGIN);
    designObj.setRightMargin(MARGIN);
    designObj.setTopMargin(MARGIN);
    designObj.setBottomMargin(MARGIN);

    LOG.info("Summary: Adding header and footer");
    final JRDesignBand header = new JRDesignBand();
    final JRDesignStaticText headerLine4 = h4("Summary").toStaticText();
    addDesignElementTo(header, headerLine4, 0, PAGEHEADER_HEIGHT, 356, 22);
    header.setHeight(PAGEHEADER_HEIGHT * 2);
    designObj.setPageHeader(header);

    LOG.info("Creating report detail");
    final Field summaryField = getFieldWithAnnotation(report, Summary.class);
    final JRBand summary = createSummary(summaryField);

    if (summary != null) {
        designObj.setSummary(summary);
        return designObj;
    }

    return null;
}
项目:com.opendoorlogistics    文件:ReportBuilderUtils.java   
private static void addColumnHeaderToBand(ODLTableDefinition table, int elementWidth, JRDesignBand chBand) {
    JRDesignStaticText back = new JRDesignStaticText();
    back.setBackcolor(new Color(230, 230, 230));
    back.setWidth(elementWidth);
    back.setHeight(20);
    back.setMode(ModeEnum.OPAQUE);
    chBand.addElement(back);

    List<Double> colWidths = getColumnWidths(table, elementWidth);
    int nc = table.getColumnCount();
    if (nc > 0) {
        double dx=0;
        for (int i = 0; i < nc; i++) {
            JRDesignStaticText text = new JRDesignStaticText();
            int x = (int) Math.round(dx);
            text.setX(x);
            text.setY(4);
            text.setWidth((int) Math.floor(colWidths.get(i)));
            text.setHeight(15);
            text.setText(table.getColumnName(i));
            text.setFontSize(11);
            // int fs = text.getFontSize();
            text.setForecolor(new Color(0, 0, 80));
            text.setBold(true);
            chBand.addElement(text);

            dx += colWidths.get(i);
        }
    }

    JRDesignLine line = new JRDesignLine();
    // line.setX(-ret.getLeftMargin());
    line.setY(19);
    line.setWidth(elementWidth);
    line.setHeight(0);
    line.setPositionType(PositionTypeEnum.FLOAT);
    chBand.addElement(line);
}
项目:com.opendoorlogistics    文件:ReportBuilderUtils.java   
private static void addAlternativeRowBackground(int width, int height, JRDesignBand band) {
    JRDesignStaticText alt = new JRDesignStaticText();
    alt.setBackcolor(new Color(240, 240, 250));
    alt.setPrintWhenExpression(new JRDesignExpression("new java.lang.Boolean(($V{REPORT_COUNT}.intValue() % 2)==0)"));
    alt.setWidth(width);
    alt.setHeight(height);
    alt.setMode(ModeEnum.OPAQUE);
    alt.setStretchType(StretchTypeEnum.RELATIVE_TO_BAND_HEIGHT);
    band.addElement(alt);
}
项目:VaadinUtils    文件:JasperManager.java   
/**
 * add user friendly paramters to the band and report port parameters if not
 * already present
 *
 * @param designFile
 * @param targetBand
 * @param maxY
 * @return
 * @throws JRException
 */
private int addParametersToDisplayReportParameters(JasperDesign designFile, JRDesignBand targetBand, int maxY)
        throws JRException
{
    for (ReportParameter<?> param : reportProperties.getFilterBuilder().getReportParameters())
    {
        if (param.displayInreport())
        {
            for (String parameterName : param.getParameterNames())
            {
                JRDesignStaticText labelElement = new JRDesignStaticText();

                String strippedLabel = param.getLabel(parameterName).replaceAll("ReportParameter", "");

                labelElement.setText(strippedLabel);
                labelElement.setWidth(125);
                labelElement.setHeight(20);
                labelElement.setBackcolor(new Color(208, 208, 208));
                labelElement.setMode(ModeEnum.OPAQUE);
                labelElement.setVerticalAlignment(VerticalAlignEnum.MIDDLE);

                labelElement.setX(0);
                labelElement.setY(maxY);
                labelElement.setFontName("SansSerif");
                labelElement.setFontSize(12);
                targetBand.addElement(labelElement);

                JRDesignTextField valueElement = new JRDesignTextField();
                valueElement.setExpression(new JRDesignExpression("$P{ParamDisplay-" + parameterName + "}"));
                valueElement.setWidth(400);
                valueElement.setHeight(20);
                valueElement.setBackcolor(new Color(208, 208, 208));
                valueElement.setMode(ModeEnum.OPAQUE);

                valueElement.setX(125);
                valueElement.setY(maxY);
                valueElement.setFontName("SansSerif");
                valueElement.setFontSize(12);
                valueElement.setVerticalAlignment(VerticalAlignEnum.MIDDLE);

                targetBand.addElement(valueElement);
                maxY = valueElement.getY() + valueElement.getHeight();

                if (!designFile.getParametersMap().containsKey("ParamDisplay-" + parameterName))
                {
                    JRDesignParameter parameter = new JRDesignParameter();
                    parameter.setName("ParamDisplay-" + parameterName);
                    parameter.setValueClass(String.class);

                    parameter.setForPrompting(false);

                    designFile.addParameter(parameter);
                }
            }
        }
    }
    return maxY;
}
项目:openbravo-brazil    文件:ReportDesignBO.java   
private void defineTitle(String title) throws JRException {
  JRDesignBand bTitulo = (JRDesignBand) jasperDesign.getTitle();
  JRDesignStaticText text = (JRDesignStaticText) bTitulo.getElementByKey("staticTitle");
  text.setText(title);
}
项目:PDFReporter-Studio    文件:TableTemplateEngine.java   
/**
 * Initialize the fields needed to build the style of the report
 */
@Override
protected void processTemplate(JasperDesign jd, List<Object> fields, List<Object> groupFields) {
    //Initialize the styles list
    stylesList = buildStylesList(jd);
    JRDesignComponentElement tableComponent = getTable(jd);
    summaryHeight = jd.getSummary().getHeight();
    /**
     * If the template table is found it will be used to create the style of the real table and of its 
     * content
     */
    if (tableComponent != null){
        StandardTable table = (StandardTable)tableComponent.getComponent();

        tableWidth = tableComponent.getWidth();
        templateGroupWidth = tableComponent.getWidth();
        tableHeight = tableComponent.getHeight();
        columnWidth = table.getColumns().get(0).getWidth();
        tableX = tableComponent.getX();
        tableY = tableComponent.getY();

        generateTableContentList(table);

        if (table.getColumns().size()>0){
            StandardColumn col = getStandadColumn(table.getColumns().get(0));
            boolean tableHeader = col.getTableHeader() != null;
            boolean tableFooter = col.getTableFooter() != null;
            boolean columnHeader = col.getColumnHeader() != null;
            boolean columnFooter = col.getColumnFooter() != null;
            boolean groupHeader = col.getGroupHeaders() != null && col.getGroupHeaders().size()>0; 
            boolean groupFooter = col.getGroupFooters() != null && col.getGroupFooters().size()>0; 
            sections = new TableSections(tableHeader, tableFooter, columnHeader, columnFooter, groupHeader, groupFooter);
            if (tableHeader) sections.setTableHeaderHeight(col.getTableHeader().getHeight());
            if (tableFooter) sections.setTableFooterHeight(col.getTableFooter().getHeight());
            if (columnHeader) sections.setColumnHeaderHeight(col.getColumnHeader().getHeight());
            if (columnFooter) sections.setColumnFooterHeight(col.getColumnFooter().getHeight());
            if (groupHeader) sections.setGroupHeaderHeight(col.getGroupHeaders().get(0).getCell().getHeight());
            if (groupFooter) sections.setGroupHeaderHeight(col.getGroupFooters().get(0).getCell().getHeight());
            sections.setDetailHeight(col.getDetailCell().getHeight());
        }
        removeElement(jd.getSummary(), tableComponent);
    } else {
        //If the table is not found try to build the template with some default values
        JRDesignStaticText colHeaderLabel = DefaultTemplateEngine.findStaticTextElement(jd.getColumnHeader(), "Label"); //$NON-NLS-1$
        JRDesignTextField cellField = DefaultTemplateEngine.findTextFieldElement(jd.getDetailSection().getBands()[0], "Field"); //$NON-NLS-1$
        tableHeaderContent = new ArrayList<JRDesignElement>();
        tableFooterContent = new ArrayList<JRDesignElement>();
        colFooterContent = new ArrayList<JRDesignElement>();
        colHeaderContent = new ArrayList<JRDesignElement>();
        detailContent = new ArrayList<JRDesignElement>();
        tableGroupField = new ArrayList<List<JRDesignElement>>();
        List<JRDesignElement> fakeGroupPlaceHolder = new ArrayList<JRDesignElement>();
        JRDesignTextField groupElement = new MTextField().createJRElement(jd);
        groupElement.setExpression(ExprUtil.setValues(new JRDesignExpression(), "$F{Group1}", "java.Lang.Object"));
        fakeGroupPlaceHolder.add(groupElement);
        tableGroupField.add(fakeGroupPlaceHolder);

        if (colHeaderLabel != null) colHeaderContent.add(colHeaderLabel);
        if (cellField != null) detailContent.add(cellField);

        tableWidth = jd.getPageWidth()-jd.getLeftMargin()-jd.getRightMargin();

        if (jd.getSummary() == null){
            //I need to create the summary where place the table
            jd.setSummary(MBand.createJRBand());
            ((JRDesignBand)jd.getSummary()).setHeight(jd.getDetailSection().getBands()[0].getHeight());
        }
        tableHeight = jd.getSummary().getHeight();
        tableX = 0;
        tableY = 0;
        sections = new TableSections(false, false, true, true, false, false);
        JRDesignElementGroup summaryBand = (JRDesignElementGroup)jd.getSummary();
        for(JRChild child : summaryBand.getChildren())
            summaryBand.removeElement((JRDesignElement)child);
    }

    removeUnwantedBand(jd);
    jd.removeDataset("tableDataset"); //$NON-NLS-1$
}
项目:PDFReporter-Studio    文件:ConvertTextIntoStatic.java   
/**
 * Copy all the common attributes from the text field to the new static text element 
 * 
 * @param labelObject the new static text element, that will substitute the text field
 * @param textObject the substituted text field
 */
private void cloneTextField(JRDesignStaticText labelObject, JRDesignTextField textObject)
{
    labelObject.setText(textObject.getExpression().getText());
    labelObject.setHeight(textObject.getHeight());
    labelObject.setWidth(textObject.getWidth());
    labelObject.setX(textObject.getX());
    labelObject.setY(textObject.getY());
    labelObject.setFontName(textObject.getFontName());
    labelObject.setFontSize(textObject.getFontsize());
    labelObject.setBackcolor(textObject.getBackcolor()); 
    labelObject.setForecolor(textObject.getForecolor());

    JRStyle originStyle = textObject.getStyle();
    labelObject.setStyle(originStyle != null ? (JRStyle)originStyle.clone() : null);

    labelObject.setStyleNameReference(textObject.getStyleNameReference());
    labelObject.setBold(textObject.isBold());
    labelObject.setItalic(textObject.isItalic());
    labelObject.setUnderline(textObject.isUnderline());
    labelObject.setStrikeThrough(textObject.isStrikeThrough());
    labelObject.setHorizontalAlignment(textObject.getHorizontalAlignmentValue());
    labelObject.setVerticalAlignment(textObject.getVerticalAlignmentValue());
    labelObject.setMode(textObject.getModeValue());
    labelObject.setRotation(textObject.getRotationValue());
    labelObject.setStretchType(textObject.getStretchTypeValue());
    labelObject.setKey(textObject.getKey());
    labelObject.setMarkup(textObject.getMarkup());
    labelObject.setPdfEmbedded(textObject.isPdfEmbedded());
    labelObject.setPdfEncoding(textObject.getPdfEncoding());
    labelObject.setPdfFontName(textObject.getPdfFontName());
    labelObject.setPositionType(textObject.getPositionTypeValue());
    labelObject.setPrintInFirstWholeBand(textObject.isPrintInFirstWholeBand());
    labelObject.setPrintRepeatedValues(textObject.isPrintRepeatedValues());
    labelObject.setPrintWhenDetailOverflows(textObject.isPrintWhenDetailOverflows());

    cloneBox(labelObject.getLineBox(), textObject.getLineBox());

    cloneParagraph(labelObject.getParagraph(), textObject.getParagraph());

    JRExpression originExpression = textObject.getPrintWhenExpression();
    labelObject.setPrintWhenExpression(originExpression != null ? (JRExpression)originExpression.clone() : null);

    JRGroup originGroup = textObject.getPrintWhenGroupChanges();
    labelObject.setPrintWhenGroupChanges(originGroup != null ? (JRGroup)originGroup.clone() : null);

    labelObject.setRemoveLineWhenBlank(textObject.isRemoveLineWhenBlank());
}
项目:PDFReporter-Studio    文件:ConvertStaticIntoText.java   
/**
 * Copy all the common attributes from the static text to the new text field element 
 * 
 * @param textObject the new text field element, that will substitute the static text
 * @param labelObject the substituted static text
 */
private void cloneTextField(JRDesignTextField textObject, JRDesignStaticText labelObject)
{
    String staticTextValue = labelObject.getText();
    //If the text is not valid for an expression it will be handled as a string
    if (!isValidExpression(staticTextValue)){
        if (!staticTextValue.startsWith("\"")) staticTextValue = "\"".concat(staticTextValue); //$NON-NLS-1$ //$NON-NLS-2$
        if (!staticTextValue.endsWith("\"")) staticTextValue = staticTextValue.concat("\""); //$NON-NLS-1$ //$NON-NLS-2$
    }
    textObject.setExpression(ExprUtil.setValues(textObject.getExpression(), staticTextValue));

    textObject.setHeight(labelObject.getHeight());
    textObject.setWidth(labelObject.getWidth());
    textObject.setX(labelObject.getX());
    textObject.setY(labelObject.getY());
    textObject.setFontName(labelObject.getFontName());
    textObject.setFontSize(labelObject.getFontsize());
    textObject.setBackcolor(labelObject.getBackcolor()); 
    textObject.setForecolor(labelObject.getForecolor());

    JRStyle originStyle = labelObject.getStyle();
    textObject.setStyle(originStyle != null ? (JRStyle)originStyle.clone() : null);

    textObject.setStyleNameReference(labelObject.getStyleNameReference());
    textObject.setBold(labelObject.isBold());
    textObject.setItalic(labelObject.isItalic());
    textObject.setUnderline(labelObject.isUnderline());
    textObject.setStrikeThrough(labelObject.isStrikeThrough());
    textObject.setHorizontalAlignment(labelObject.getHorizontalAlignmentValue());
    textObject.setVerticalAlignment(labelObject.getVerticalAlignmentValue());
    textObject.setMode(labelObject.getModeValue());
    textObject.setRotation(labelObject.getRotationValue());
    textObject.setStretchType(labelObject.getStretchTypeValue());
    textObject.setKey(labelObject.getKey());
    textObject.setMarkup(labelObject.getMarkup());
    textObject.setPdfEmbedded(labelObject.isPdfEmbedded());
    textObject.setPdfEncoding(labelObject.getPdfEncoding());
    textObject.setPdfFontName(labelObject.getPdfFontName());
    textObject.setPositionType(labelObject.getPositionTypeValue());
    textObject.setPrintInFirstWholeBand(labelObject.isPrintInFirstWholeBand());
    textObject.setPrintRepeatedValues(labelObject.isPrintRepeatedValues());
    textObject.setPrintWhenDetailOverflows(labelObject.isPrintWhenDetailOverflows());

    cloneBox(textObject.getLineBox(),labelObject.getLineBox());

    cloneParagraph(textObject.getParagraph(), labelObject.getParagraph());

    JRExpression originExpression = labelObject.getPrintWhenExpression();
    textObject.setPrintWhenExpression(originExpression != null ? (JRExpression)originExpression.clone() : null);

    JRGroup originGroup = labelObject.getPrintWhenGroupChanges();
    textObject.setPrintWhenGroupChanges(originGroup != null ? (JRGroup)originGroup.clone() : null);

    textObject.setRemoveLineWhenBlank(labelObject.isRemoveLineWhenBlank());
}
项目:ireport-fork    文件:ElementNodeVisitor.java   
/**
 *
 */
public void visitStaticText(JRStaticText staticText)
{
    node = new ElementNode(jasperDesign, (JRDesignStaticText)staticText,doLkp);
    node.setIconBaseWithExtension(ICON_STATIC_TEXT);
}
项目:ireport-fork    文件:TransformElementAction.java   
private List<Integer> getTransformationTypes(JRDesignElement element)
{
    List<Integer> commonTransformationTypes = new ArrayList<Integer>();

    if (element instanceof JRDesignRectangle)
    {
        commonTransformationTypes.add(TRANSFORMATION_TYPE_TO_ELLIPSE);
        commonTransformationTypes.add(TRANSFORMATION_TYPE_TO_FRAME);
    } 

    if (element instanceof JRDesignEllipse)
    {
        commonTransformationTypes.add(TRANSFORMATION_TYPE_TO_RECTANGLE);
    }

    if (element instanceof JRDesignTextField)
    {
        commonTransformationTypes.add(TRANSFORMATION_TYPE_TO_STATICTEXT);
    }

    if (element instanceof JRDesignStaticText)
    {
        commonTransformationTypes.add(TRANSFORMATION_TYPE_TO_TEXTFIELD);
    }

    if (element instanceof JRDesignChart)
    {
        JRDesignChart chartElement = (JRDesignChart)element;
        if (chartElement.getChartType() == JRDesignChart.CHART_TYPE_PIE)
        {
            commonTransformationTypes.add(TRANSFORMATION_TYPE_TO_CHART_PIE3D);
        }
        else if (chartElement.getChartType() == JRDesignChart.CHART_TYPE_PIE3D)
        {
            commonTransformationTypes.add(TRANSFORMATION_TYPE_TO_CHART_PIE);
        }
    }

    //if (element instanceof JRDesignTextField ||
    //    element instanceof JRDesignStaticText) return TRANSFORMATION_TYPE_CATEGORY_CHART;


    return commonTransformationTypes;
}
项目:kfs    文件:RString.java   
public JRDesignStaticText toStaticText() {
    final JRDesignStaticText retval = new JRDesignStaticText();
    setupTextElement(retval);
    retval.setText(str);
    return retval;
}
项目:kfs    文件:TravelReportFactoryServiceImpl.java   
/**
 * A lot like {@link #designReport(ReportInfo)} except it is intended for {@link SubReport}s
 *
 * @param report is an instance of the {@link ReportInfo} which represents a report.
 * @param field {@link Field} instance with a {@link SubReport} annotation
 * @return a {@link JasperDesign} instance used in a {@link JasperReport}
 * @see org.kuali.kfs.module.tem.report.service.TravelReportFactoryService#designReport(org.kuali.kfs.sys.report.ReportInfo)
 */
public JasperDesign designReport(final ReportInfo report, final Field field) throws Exception {
    LOG.info("Designing a subreport for field "+ field.getName());

    LOG.debug("Checking the "+ field.getName()+ " for data");
    try {
        field.setAccessible(true);
        if (field.get(report) == null) {
            return null;
        }
        LOG.debug("Subreport has data. Proceeding to design subreport.");
    }
    catch (Exception e) {
        throw new RuntimeException(e);
    }

    final JasperDesign designObj = new JasperDesign();
    designObj.setName(field.getName());
    designObj.setTitle(createTitle(report, getReportTitle(report)));

    addReportParametersFor(report, designObj);
    designObj.addImport(report.getClass().getName());
    addReportFieldsFor(report, designObj);

    final JRDesignBand titleBand = new JRDesignBand();
    titleBand.setHeight(23);

    final JRDesignStaticText headerLine4 = h4(initialCaps(field.getName())).toStaticText();
    addDesignElementTo(titleBand, headerLine4, 0, 0, 356, 22);

    designObj.setPageHeader(titleBand);

    designObj.setPageWidth(595);
    designObj.setPageHeight(REPORT_HEIGHT);
    designObj.setLeftMargin(MARGIN);
    designObj.setRightMargin(MARGIN);
    designObj.setTopMargin(MARGIN);
    designObj.setBottomMargin(MARGIN);

    if (hasDetail(report)) {
        LOG.debug("Creating detail for subreport");
        designObj.setDetail(createDetail(report, 0));
    }
    else {
        LOG.debug("Creating summary for subreport");
        designObj.setSummary(createSummary(field));
    }

    return designObj;
}
项目:kfs    文件:TravelReportFactoryServiceImpl.java   
/**
 * Determines what to do with a {@link Field} in a {@link ReportInfo} instance by the annotations on that
 * {@link Field} and creates a {@link JRDesignElement} from it.
 *
 *
 * @param param
 * @param field
 * @return {@link JRDesignElement} instance
 * @throws Exception
 */
protected JRChild createElementForField(final ReportInfo report, final Field field) throws Exception {
    LOG.info("Processing field "+ field.getName());
    if (isSubreport(field)) {
        LOG.debug("Creating a report element from field "+ field.getName());
        return createSubreport(report, field);
    }

    if (isCrosstab(field)) {
        LOG.debug("Creating a crosstab from field "+ field.getName());
        final JRDesignCrosstab crosstab       = createCrosstab(report, field);
        final JRDesignCrosstabDataset dataset = new JRDesignCrosstabDataset();
        final JRDesignDatasetRun dsRun        = new JRDesignDatasetRun();
        final JRDesignExpression dsExpression = new JRDesignExpression();
        final String getterName               = "get" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1);
        dsExpression.setText("$P{report}." + getterName + "()");
        dsExpression.setValueClass(JRDataSource.class);
        dsRun.setDatasetName(initialCaps(field.getName()));
        dsRun.setDataSourceExpression(dsExpression);
        dataset.setDatasetRun(dsRun);
        dataset.setDataPreSorted(true);
        crosstab.setDataset(dataset);

        return crosstab;
    }

    if (isSummary(field)) {
        LOG.debug("Building Summary JRDesignBand");
        final JRDesignBand summary = new JRDesignBand();
        final Class dataClass = findDataClassFor(report);

        final JRDesignStaticText header = h3("Summary").toStaticText();
        addDesignElementTo(summary, header, 0, 0, CT_HEADER_WIDTH, PAGEHEADER_HEIGHT);

        int fieldIdx = 0;
        for (final Field dataField : dataClass.getDeclaredFields()) {
            final JRDesignStaticText headerField = h5(dataField.getName()).toStaticText();
            addDesignElementTo(summary, headerField, (CELL_WIDTH * 3 + 5) * fieldIdx, PAGEHEADER_HEIGHT, CELL_WIDTH * 2, CELL_HEIGHT);

            final JRDesignTextField textElement = normal("$F{" + dataField.getName() + "}").toTextField(dataField.getType());
            LOG.debug("Adding summary field "+ dataField.getName()+ " at ("+ (CELL_WIDTH + 5) * fieldIdx+ "+ 0");
            addDesignElementTo(summary, textElement, (CELL_WIDTH * 3 + 5) * fieldIdx, PAGEHEADER_HEIGHT + CELL_HEIGHT, CELL_WIDTH * 3, CELL_HEIGHT);
            fieldIdx++;
        }
        summary.setHeight(SUMMARY_HEIGHT);
        return summary;
    }

    return null;
}
项目:kfs    文件:TravelReportFactoryServiceImpl.java   
/**
 * Creates a crosstab. Intended for use withing a summary. Creates a crosstab and a custom dataset for the
 * crosstab to use in a {@link Summary}
 */
protected JRDesignCrosstab createCrosstab(final ReportInfo report, final Field field) throws Exception {
    final JRDesignCrosstab crosstab = new JRDesignCrosstab();
    LOG.debug("<crosstab>");
    LOG.debug("<reportElement width=\"400\" height=\"" + (SUMMARY_HEIGHT - 25) + "\" />");
    crosstab.setWidth(595);
    crosstab.setHeight(0);

    final JRDesignCellContents nodataCell = new JRDesignCellContents();
    nodataCell.setBackcolor(Color.LIGHT_GRAY);
    nodataCell.setMode(MODE_OPAQUE);

    final JRDesignFrame frame = new JRDesignFrame();
    frame.copyBox(new TravelReportLineBox(nodataCell));
    nodataCell.setBox(frame);

    LOG.debug("<crosstabHeaderCell/>");
    crosstab.setHeaderCell(nodataCell);

    final JRDesignCrosstabRowGroup rowGroup = new JRDesignCrosstabRowGroup();
    final JRDesignCellContents rowHeader = new JRDesignCellContents();
    final JRDesignCellContents rowTotalHeader = new JRDesignCellContents();
    rowHeader.setMode(MODE_OPAQUE);
    rowHeader.setBackcolor(Color.LIGHT_GRAY);

    final JRDesignFrame rowFrame = new JRDesignFrame();
    rowFrame.copyBox(new TravelReportLineBox(rowHeader));
    rowHeader.setBox(rowFrame);

    final JRDesignStaticText rowTotalText = h3("Daily Total").toStaticText();
    addDesignElementTo(rowTotalHeader, rowTotalText, 0, 0, CELL_WIDTH, CELL_HEIGHT);

    final JRDesignTextField rowHeaderField = normal("$V{Expenses}").toTextField();
    addDesignElementTo(rowHeader, rowHeaderField, 0, 0, CT_HEADER_WIDTH, CELL_HEIGHT);
    rowGroup.setName("Expenses");
    rowGroup.setWidth(CT_HEADER_WIDTH);
    rowGroup.setHeader(rowHeader);
    rowGroup.setTotalHeader(rowTotalHeader);
    rowGroup.setBucket(bucket("$F{name}", String.class));

    final JRDesignCrosstabColumnGroup columnGroup = new JRDesignCrosstabColumnGroup();
    final JRDesignCellContents columnHeader = new JRDesignCellContents();
    final JRDesignCellContents columnTotalHeader = new JRDesignCellContents();
    columnHeader.setMode(MODE_OPAQUE);
    columnHeader.setBackcolor(Color.LIGHT_GRAY);

    final JRDesignFrame columnFrame = new JRDesignFrame();
    columnFrame.copyBox(new TravelReportLineBox(columnHeader));
    columnHeader.setBox(columnFrame);

    final JRDesignStaticText columnTotalText = h3("Expense Totals").toStaticText();
    addDesignElementTo(columnTotalHeader, columnTotalText, 0, 0, CELL_WIDTH, CELL_HEIGHT);

    final JRDesignTextField columnHeaderField = normal("$V{Days}").toTextField();
    addDesignElementTo(columnHeader, columnHeaderField, 0, 0, CELL_WIDTH, CELL_HEIGHT);
    columnGroup.setName("Days");
    columnGroup.setHeight(CELL_HEIGHT);
    columnGroup.setHeader(columnHeader);
    columnGroup.setTotalHeader(columnTotalHeader);
    columnGroup.setBucket(bucket("$F{date}", java.lang.String.class));

    LOG.debug("<rowGroup name=\"Expenses\" width=\"400\">");
    crosstab.addRowGroup(rowGroup);
    crosstab.addColumnGroup(columnGroup);

    crosstab.addMeasure(measure("amount"));

    crosstab.addCell(crosstabCell(java.math.BigDecimal.class, "$V{amountMeasure}"));
    crosstab.addCell(crosstabCell(java.math.BigDecimal.class, "$V{amountMeasure}", "Expenses"));
    crosstab.addCell(crosstabCell(java.math.BigDecimal.class, "$V{amountMeasure}", null, "Days"));
    crosstab.addCell(crosstabCell(java.math.BigDecimal.class, "$V{amountMeasure}", "Expenses", "Days"));

    return crosstab;
}