Exemple #1
0
  public CellStyle(Writer styleWriter, JRExporterGridCell gridCell) {
    super(styleWriter);

    JRPrintElement element = gridCell.getElement();

    if (element != null && element.getModeValue() == ModeEnum.OPAQUE) {
      // fill = "solid";
      backcolor = JRColorUtil.getColorHexa(element.getBackcolor());
    } else {
      // fill = "none";
      if (gridCell.getBackcolor() != null) {
        backcolor = JRColorUtil.getColorHexa(gridCell.getBackcolor());
      }
    }

    RotationEnum rotation =
        element instanceof JRPrintText
            ? ((JRPrintText) element).getRotationValue()
            : RotationEnum.NONE;
    VerticalAlignEnum vAlign = VerticalAlignEnum.TOP;
    HorizontalAlignEnum hAlign = HorizontalAlignEnum.LEFT;

    JRAlignment alignment = element instanceof JRAlignment ? (JRAlignment) element : null;
    if (alignment != null) {
      vAlign = alignment.getVerticalAlignmentValue();
      hAlign = alignment.getHorizontalAlignmentValue();
    }

    horizontalAlignment = ParagraphStyle.getHorizontalAlignment(hAlign, vAlign, rotation);
    verticalAlignment = ParagraphStyle.getVerticalAlignment(hAlign, vAlign, rotation);

    setBox(gridCell.getBox());
  }
  /** Request the painting of the border */
  @Override
  public void paint(Graphics graphics) {
    try {
      Graphics2D g = ComponentFigure.getG2D(graphics);
      if (g != null) {

        Rectangle b = getBounds();

        JRPrintElement pe = new JRBasePrintText(null);
        pe.setX(b.x + 10);
        pe.setY(b.y + 10);
        pe.setWidth(b.width - 20);
        pe.setHeight(b.height - 20);
        if (section.getElement() instanceof ILineBox && section.getElement() != null)
          bd.drawBox(g, ((ILineBox) section.getElement()).getBoxContainer().getLineBox(), pe);
        else if (section.getElement() instanceof MStyle) {
          MStyle styleModel = (MStyle) section.getElement();
          bd.drawBox(g, ((JRStyle) styleModel.getValue()).getLineBox(), pe);
        }
      } else {
        graphics.drawRectangle(0, 0, 100, 100);
      }
    } catch (Exception e) {
      // when a font is missing exception is thrown by DrawVisitor
      // FIXME: maybe draw something, else?
      e.printStackTrace();
    }
  }
 public Color getCellBackcolor() {
   Color color;
   JRPrintElement element = getElement();
   if (element != null && element.getMode() == JRElement.MODE_OPAQUE) {
     color = element.getBackcolor();
   } else {
     color = backcolor;
   }
   return color;
 }
  public void visit(JRPrintFrame frame, T arg) {
    visitElement(frame, arg);

    if (deep) {
      List<JRPrintElement> elements = frame.getElements();
      if (elements != null) {
        for (JRPrintElement element : elements) {
          element.accept(this, arg);
        }
      }
    }
  }
  /** @throws IOException */
  protected void exportReportElement(JRPrintElement element) throws IOException {
    xmlWriter.startElement(JRXmlConstants.ELEMENT_reportElement);
    xmlWriter.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_key, element.getKey());
    JRStyle style = element.getStyle();
    if (style != null) {
      xmlWriter.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_style, style.getName());
    }
    xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_mode, element.getOwnModeValue());
    xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_x, element.getX() + getOffsetX());
    xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_y, element.getY() + getOffsetY());
    xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_width, element.getWidth());
    xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_height, element.getHeight());
    xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_forecolor, element.getOwnForecolor());
    xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_backcolor, element.getOwnBackcolor());
    JROrigin origin = element.getOrigin();
    if (origin != null) {
      xmlWriter.addAttribute(
          JRXmlConstants.ATTRIBUTE_origin, jasperPrint.getOriginsMap().get(origin));
    }

    int elementId = element.getSourceElementId();
    if (elementId != JRPrintElement.UNSET_SOURCE_ELEMENT_ID) {
      xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_srcId, elementId);
    }

    exportProperties(element);

    xmlWriter.closeElement();
  }