public void summaryRowSelection(final ReportEvent event) {
    if (FunctionUtilities.isDefinedGroup(getCrosstabFilterGroup(), event)) {
      final String targetName = getName().substring(1);
      final Object expressionValue = getDataRow().get(targetName);
      final Object tableModelValue = getDataRow().get("validate-" + targetName);

      currentDataItem = event.getState().getCurrentDataItem();
      long sequenceCounter = event.getState().getCrosstabColumnSequenceCounter(3);

      if (!equalNumeric(expressionValue, tableModelValue)) {
        logger.debug(
            String.format(
                "!*%12s %3d:%d# %s - %s",
                targetName, currentDataItem, sequenceCounter, expressionValue, tableModelValue));
        if (failHard) {
          Assert.assertEquals(tableModelValue, expressionValue);
        }
      } else {
        logger.debug(
            String.format(
                " *%12s %3d:%d# %s - %s",
                targetName, currentDataItem, sequenceCounter, expressionValue, tableModelValue));
      }
    }
  }
コード例 #2
0
 public void summaryRowSelection(final ReportEvent event) {
   if (FunctionUtilities.isDefinedGroup(getCrosstabFilterGroup(), event)) {
     final int groupIndex = event.getState().getCurrentGroupIndex();
     this.lastGroupSequenceNumber =
         (int) event.getState().getCrosstabColumnSequenceCounter(groupIndex);
   }
 }
コード例 #3
0
  public void summaryRowSelection(final ReportEvent event) {
    if (rowbandingOnGroup == false) {
      return;
    }

    if (StringUtils.isEmpty(group)) {
      final Group group = event.getReport().getGroup(event.getState().getCurrentGroupIndex());
      if (group instanceof CrosstabRowGroup) {
        final GroupBody body = group.getBody();
        if (body instanceof CrosstabColumnGroupBody) {
          if (Boolean.TRUE.equals(
              group.getAttribute(
                  AttributeNames.Crosstab.NAMESPACE, AttributeNames.Crosstab.PRINT_SUMMARY))) {
            triggerVisibleStateCrosstab(event);
          }
        }
      }
    } else {
      if (FunctionUtilities.isDefinedGroup(group, event)) {
        final Group group = event.getReport().getGroup(event.getState().getCurrentGroupIndex());
        if (Boolean.TRUE.equals(
            group.getAttribute(
                AttributeNames.Crosstab.NAMESPACE, AttributeNames.Crosstab.PRINT_SUMMARY))) {
          triggerVisibleStateCrosstab(event);
        }
      }
    }
  }
コード例 #4
0
  private DataRow extractDataRow(final ReportEvent event) {
    if (event.isDeepTraversing() == false) {
      return getDataRow();
    }

    return event.getOriginatingState().getDataRow();
  }
コード例 #5
0
  /**
   * Create a image according to the current state, simple and silly ...
   *
   * @param event the report event.
   */
  public void pageStarted(final ReportEvent event) {
    final BufferedImage image = new BufferedImage(150, 50, BufferedImage.TYPE_INT_ARGB);
    final Graphics2D g2 = image.createGraphics();
    final JButton bt = new JButton("A Button");
    bt.setSize(90, 20);
    final JRadioButton radio = new JRadioButton("A radio button");
    radio.setSize(100, 20);

    g2.setColor(Color.darkGray);
    bt.paint(g2);
    g2.setColor(Color.blue);
    g2.setTransform(AffineTransform.getTranslateInstance(20, 20));
    radio.paint(g2);
    g2.setTransform(AffineTransform.getTranslateInstance(0, 0));
    g2.setPaint(Color.green);
    g2.setFont(new Font("Serif", Font.PLAIN, 10));
    g2.drawString(
        "You are viewing a graphics of JFreeReport on index " + event.getState().getCurrentRow(),
        10,
        10);
    g2.dispose();
    try {
      functionValue = new DefaultImageReference(image);
    } catch (IOException e) {
      functionValue = null;
    }
  }
コード例 #6
0
  /**
   * Receives notification that report generation has completed, the report footer was printed, no
   * more output is done. This is a helper event to shut down the output service.
   *
   * @param event The event.
   */
  public void reportDone(final ReportEvent event) {
    if (event.isDeepTraversing()) {
      return;
    }

    if (FunctionUtilities.isDefinedPrepareRunLevel(this, event)) {
      final Iterator iterator = dataStorage.entrySet().iterator();
      while (iterator.hasNext()) {
        final Map.Entry entry = (Map.Entry) iterator.next();
        final String key = (String) entry.getKey();
        final IndexDataHolder data = (IndexDataHolder) entry.getValue();
        model.addRow(
            new Object[] {
              data.getData(),
              data.getPagesText(indexSeparator, condensedStyle),
              data.getPages(),
              key
            });
      }
    } else if (FunctionUtilities.isLayoutLevel(event)) {
      final int rowCount = model.getRowCount();
      for (int i = 0; i < rowCount; i++) {
        final String key = (String) model.getValueAt(i, 3);
        final IndexDataHolder dataHolder = dataStorage.get(key);
        model.setValueAt(dataHolder.getPagesText(indexSeparator, condensedStyle), i, 1);
        model.setValueAt(dataHolder.getPages(), i, 2);
      }
    }
  }
コード例 #7
0
  /**
   * Receives notification that the report has started.
   *
   * @param event the event.
   */
  public void reportStarted(final ReportEvent event) {
    if (event.isDeepTraversing()) {
      return;
    }

    pageFunction.reportStarted(event);
  }
コード例 #8
0
  public void groupStarted(final ReportEvent event) {
    if (rowbandingOnGroup == false) {
      return;
    }

    if (StringUtils.isEmpty(group)) {
      final Group group = event.getReport().getGroup(event.getState().getCurrentGroupIndex());
      if (group instanceof CrosstabRowGroup) {
        final GroupBody body = group.getBody();
        if (body instanceof CrosstabColumnGroupBody) {
          triggerVisibleStateCrosstab(event);
        }
      }
    } else {
      if (FunctionUtilities.isDefinedGroup(group, event)) {
        triggerVisibleStateCrosstab(event);
      }
    }
  }
  public void itemsAdvanced(final ReportEvent event) {
    final String targetName = getName().substring(1);
    final Object expressionValue = getDataRow().get(targetName);
    final Object tableModelValue = getDataRow().get("validate-" + targetName);

    currentDataItem = event.getState().getCurrentDataItem();
    long sequenceCounter = event.getState().getCrosstabColumnSequenceCounter(3);

    if (!equalNumeric(expressionValue, tableModelValue)) {
      logger.debug(
          String.format(
              "! %12s %3d:%d# %s - %s",
              targetName, currentDataItem, sequenceCounter, expressionValue, tableModelValue));
      if (failHard) {
        Assert.assertEquals(tableModelValue, expressionValue);
      }
    } else {
      logger.debug(
          String.format(
              "  %12s %3d:%d# %s - %s",
              targetName, currentDataItem, sequenceCounter, expressionValue, tableModelValue));
    }
  }
コード例 #10
0
  /**
   * Receives notification that a row of data is being processed.
   *
   * @param event the event.
   */
  public void itemsAdvanced(final ReportEvent event) {
    if (event.isDeepTraversing()) {
      if ("index".equals(event.getOriginatingState().getReport().getMetaData().getName())) {
        return;
      }
    }

    final Object o = computeDataValue(event);
    if (o == null) {
      return;
    }

    if (FunctionUtilities.isDefinedPrepareRunLevel(this, event)) {
      dataStorage.put(String.valueOf(o), new IndexDataHolder(o));
    } else if (FunctionUtilities.isLayoutLevel(event)) {
      final IndexDataHolder o1 = dataStorage.get(String.valueOf(o));
      if (o1 == null) {
        throw new IllegalStateException(
            "Unable to compute index: Function values changed between prepare and layout run");
      }
      o1.addPage(pageFunction.getPage());
    }
  }
コード例 #11
0
  /**
   * Receives notification that report generation initializes the current run.
   *
   * <p>The event carries a ReportState.Started state. Use this to initialize the report.
   *
   * @param event The event.
   */
  public void reportInitialized(final ReportEvent event) {
    if (event.isDeepTraversing()) {
      return;
    }

    if (initialized == false) {
      initialized = true;
      model.addColumn("item-data", Object.class);
      model.addColumn("item-pages", String.class);
      model.addColumn("item-pages-array", Integer[].class);
      model.addColumn("item-key", String.class);
    }

    pageFunction.reportInitialized(event);
  }
コード例 #12
0
  /**
   * Triggers the visible state of the specified itemband element. If the named element was visible
   * at the last call, it gets now invisible and vice versa. This creates the effect, that an
   * element is printed every other line.
   *
   * @param event the current report event.
   */
  private void triggerVisibleState(final ReportEvent event) {
    // avoid divide by zero exception
    if (numberOfElements == 0) {
      return;
    }

    if ((count % numberOfElements) == 0) {
      trigger = (!trigger);
    }
    count += 1;

    final ItemBand itemBand = event.getReport().getItemBand();
    if (itemBand == null) {
      return;
    }

    if (element == null) {
      if (trigger) {
        itemBand.getStyle().setStyleProperty(ElementStyleKeys.BACKGROUND_COLOR, visibleBackground);
      } else {
        itemBand
            .getStyle()
            .setStyleProperty(ElementStyleKeys.BACKGROUND_COLOR, invisibleBackground);
      }
    } else {
      final Element[] e = FunctionUtilities.findAllElements(itemBand, getElement());
      if (e.length > 0) {
        for (int i = 0; i < e.length; i++) {
          if (trigger) {
            e[i].getStyle().setStyleProperty(ElementStyleKeys.BACKGROUND_COLOR, visibleBackground);
          } else {
            e[i].getStyle()
                .setStyleProperty(ElementStyleKeys.BACKGROUND_COLOR, invisibleBackground);
          }
        }
      } else {
        if (warned == false) {
          RowBandingFunction.logger.warn(
              "The Band does not contain an element named " + getElement());
          warned = true;
        }
      }
    }
  }
コード例 #13
0
  /**
   * Receives notification that a row of data is being processed. Reads the data from the field
   * defined for this function and calculates the minimum value.
   *
   * @param event Information about the event.
   */
  public void itemsAdvanced(final ReportEvent event) {
    if (field == null) {
      return;
    }

    final Object fieldValue = event.getDataRow().get(getField());
    if (fieldValue instanceof Comparable == false) {
      return;
    }
    try {
      final Comparable compare = (Comparable) fieldValue;

      final Comparable oldValue = min.get(lastGroupSequenceNumber);
      if (oldValue == null || oldValue.compareTo(compare) > 0) {
        min.set(lastGroupSequenceNumber, compare);
      }
    } catch (Exception e) {
      ItemMinFunction.logger.error("ItemMinFunction.advanceItems(): problem adding number.");
    }
  }
コード例 #14
0
  /**
   * Triggers the visible state of the specified itemband element. If the named element was visible
   * at the last call, it gets now invisible and vice versa. This creates the effect, that an
   * element is printed every other line.
   *
   * @param event the current report event.
   */
  private void triggerVisibleStateCrosstab(final ReportEvent event) {
    if ((count % numberOfElements) == 0) {
      trigger = (!trigger);
    }
    count += 1;

    final CrosstabCellBody cellBody = event.getReport().getCrosstabCellBody();
    if (cellBody == null) {
      return;
    }

    if (element == null) {
      final int elementCount = cellBody.getElementCount();
      for (int i = 1; i < elementCount; i += 1) {
        final Element cell = cellBody.getElement(i);
        if (trigger) {
          cell.getStyle().setStyleProperty(ElementStyleKeys.BACKGROUND_COLOR, visibleBackground);
        } else {
          cell.getStyle().setStyleProperty(ElementStyleKeys.BACKGROUND_COLOR, invisibleBackground);
        }
      }
    } else {
      final Element[] e = FunctionUtilities.findAllElements(cellBody, getElement());
      if (e.length > 0) {
        for (int i = 0; i < e.length; i++) {
          if (trigger) {
            e[i].getStyle().setStyleProperty(ElementStyleKeys.BACKGROUND_COLOR, visibleBackground);
          } else {
            e[i].getStyle()
                .setStyleProperty(ElementStyleKeys.BACKGROUND_COLOR, invisibleBackground);
          }
        }
      } else {
        if (warned == false) {
          RowBandingFunction.logger.warn(
              "The cell-body does not contain an element named " + getElement());
          warned = true;
        }
      }
    }
  }
コード例 #15
0
 public String toString() {
   return "ReportStateKey{"
       + "sc="
       + sequenceCounter
       + ", cursor="
       + cursor
       + ", groupLevel="
       + groupLevel
       + ", subreport="
       + subreport
       + ", stateCode="
       + ReportEvent.translateStateCode(stateCode)
       + ", restoreState="
       + restoreState
       + ", inlineSubReport="
       + inlineSubReportState
       + ", stateCodeRaw=0x"
       + Integer.toHexString(stateCode)
       + ", parent="
       + parent
       + '}';
 }