simplepagelayoutdelegate.java

来自「swing编写的库存管理程序。毕业设计类」· Java 代码 · 共 654 行 · 第 1/2 页

JAVA
654
字号
      // mark the current position to calculate the maxBand-Height
      worker.setTopPageContentPosition(worker.getCursorPosition());
    }
    catch (FunctionProcessingException fe)
    {
      throw fe;
    }
    catch (Exception e)
    {
      throw new FunctionProcessingException("PageStarted failed", e);
    }
  }

  /**
   * Receives notification that a page is completed.
   *
   * @param event The event.
   */
  public void pageFinished(final ReportEvent event)
  {
    try
    {
      worker.setReservedSpace(0);
      final Band b = event.getReport().getPageFooter();
      if (event.getState().getCurrentPage() == 1)
      {
        if (b.getStyle().getBooleanStyleProperty(BandStyleSheet.DISPLAY_ON_FIRSTPAGE) == true)
        {
          worker.printBottom(b);
        }
      }
      else if (isLastPagebreak())
      {
        if (b.getStyle().getBooleanStyleProperty(BandStyleSheet.DISPLAY_ON_LASTPAGE) == true)
        {
          worker.printBottom(b);
        }
      }
      else
      {
        worker.printBottom(b);
      }
    }
    catch (FunctionProcessingException fe)
    {
      throw fe;
    }
    catch (Exception e)
    {
      throw new FunctionProcessingException("PageFinished failed", e);
    }
  }

  /**
   * Receives notification that a page was canceled by the ReportProcessor.
   * This method is called, when a page was removed from the report after
   * it was generated.
   *
   * @param event The event.
   */
  public void pageCanceled(final ReportEvent event)
  {
    // this method is left empty, we dont handle canceled pages.
  }

  /**
   * 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)
  {
    // we don't handle the report initialized event.
  }

  /**
   * Receives notification that report generation has started.
   * <P>
   * The event carries a ReportState.Started state.
   * Use this to prepare the report header.
   *
   * @param event The event.
   */
  public void reportStarted(final ReportEvent event)
  {
    // activating this state after the page has ended is invalid.
    if (worker.isPageEnded())
    {
      throw new IllegalStateException("Assertation: ReportStarted cannot have ended page");
    }
    try
    {
      setCurrentEffectiveGroupIndex(-1);
      worker.print(event.getReport().getReportHeader(), 
        SimplePageLayoutWorker.BAND_PRINTED, SimplePageLayoutWorker.PAGEBREAK_BEFORE_HANDLED);
    }
    catch (FunctionProcessingException fe)
    {
      throw fe;
    }
    catch (Exception e)
    {
      throw new FunctionProcessingException("ReportStarted failed", e);
    }
  }

  /**
   * Receives notification that report generation has finished (the last record is read and all
   * groups are closed).
   *
   * @param event The event.
   */
  public void reportFinished(final ReportEvent event)
  {
    // activating this state after the page has ended is invalid.
    if (worker.isPageEnded())
    {
      throw new IllegalStateException("AssertationFailed: Page is closed.");
    }
    try
    {
      setCurrentEffectiveGroupIndex(getCurrentEffectiveGroupIndex()- 1);

      final Object prepareRun =
          event.getState().getProperty(JFreeReport.REPORT_PREPARERUN_PROPERTY,
              Boolean.FALSE);
      if (prepareRun.equals(Boolean.TRUE))
      {
        setMaxPage(event.getState().getCurrentPage());
      }

      // force that this last pagebreak ...
      setLastPagebreak(true);

      final Band b = event.getReport().getReportFooter();
      worker.print(b, SimplePageLayoutWorker.BAND_PRINTED,
        SimplePageLayoutWorker.PAGEBREAK_BEFORE_HANDLED);
    }
    catch (FunctionProcessingException fe)
    {
      throw fe;
    }
    catch (Exception e)
    {
      throw new FunctionProcessingException("ReportFinished failed", e);
    }
  }

  /**
   * 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)
  {
    // this event is not handled by this implementation.
    // the pagelayouter must make sure, that the report footer is really printed.
  }

  /**
   * Receives notification that a new group has started.
   * <P>
   * The group can be determined by the report state's getCurrentGroup() function.
   *
   * @param event The event.
   */
  public void groupStarted(final ReportEvent event)
  {
    // activating this state after the page has ended is invalid.
    if (worker.isPageEnded())
    {
      throw new IllegalStateException("AssertationFailed: Page is closed.");
    }
    try
    {
      setCurrentEffectiveGroupIndex(getCurrentEffectiveGroupIndex() + 1);

      final int gidx = event.getState().getCurrentGroupIndex();
      final Group g = event.getReport().getGroup(gidx);
      final Band b = g.getHeader();
      worker.print(b, SimplePageLayoutWorker.BAND_PRINTED, 
        SimplePageLayoutWorker.PAGEBREAK_BEFORE_HANDLED);
    }
    catch (FunctionProcessingException fe)
    {
      throw fe;
    }
    catch (Exception e)
    {
      throw new FunctionProcessingException("GroupStarted failed", e);
    }
  }

  /**
   * Receives notification that a group is finished.
   * <P>
   * The group can be determined by the report state's getCurrentGroup() function.
   *
   * @param event The event.
   */
  public void groupFinished(final ReportEvent event)
  {
    // activating this state after the page has ended is invalid.
    if (worker.isPageEnded())
    {
      throw new IllegalStateException("AssertationFailed: Page is closed.");
    }
    try
    {
      //currentEffectiveGroupIndex -= 1;
      setGroupFinishPending(true);

      final int gidx = event.getState().getCurrentGroupIndex();
      final Group g = event.getReport().getGroup(gidx);
      final Band b = g.getFooter();
      if (worker.print(b, SimplePageLayoutWorker.BAND_PRINTED,
        SimplePageLayoutWorker.PAGEBREAK_BEFORE_HANDLED))
      {
        setGroupFinishPending(false);
        setCurrentEffectiveGroupIndex(getCurrentEffectiveGroupIndex() - 1);
      }
    }
    catch (FunctionProcessingException fe)
    {
      throw fe;
    }
    catch (Exception e)
    {
      throw new FunctionProcessingException("GroupFinished failed", e);
    }
  }

  /**
   * Receives notification that a group of item bands is about to be processed.
   * <P>
   * The next events will be itemsAdvanced events until the itemsFinished event is raised.
   *
   * @param event The event.
   */
  public void itemsStarted(final ReportEvent event)
  {
    // activating this state after the page has ended is invalid.
    if (worker.isPageEnded())
    {
      throw new IllegalStateException("AssertationFailed: Page is closed.");
    }
    setCurrentEffectiveGroupIndex(getCurrentEffectiveGroupIndex() + 1);
  }

  /**
   * Receives notification that a group of item bands has been completed.
   * <P>
   * The itemBand is finished, the report starts to close open groups.
   *
   * @param event The event.
   */
  public void itemsFinished(final ReportEvent event)
  {
    // activating this state after the page has ended is invalid.
    if (worker.isPageEnded())
    {
      throw new IllegalStateException("AssertationFailed: Page is closed.");
    }
    setCurrentEffectiveGroupIndex(getCurrentEffectiveGroupIndex() - 1);
  }

  /**
   * Receives notification that a new row has been read.
   * <P>
   * This event is raised before an ItemBand is printed.
   *
   * @param event The event.
   */
  public void itemsAdvanced(final ReportEvent event)
  {
    // activating this state after the page has ended is invalid.
    if (worker.isPageEnded())
    {
      throw new IllegalStateException("AssertationFailed: Page is closed.");
    }

    try
    {
      worker.print(event.getReport().getItemBand(), 
        SimplePageLayoutWorker.BAND_PRINTED, SimplePageLayoutWorker.PAGEBREAK_BEFORE_HANDLED);
    }
    catch (FunctionProcessingException fe)
    {
      throw fe;
    }
    catch (Exception e)
    {
      throw new FunctionProcessingException("ItemsAdvanced failed", e);
    }
  }

  /**
   * Checks, whether the printing of the last group footer was delayed.
   * This influences the repeating group headers.
   * <p>
   * This is part of a Q&D hack and will be removed in 0.8.5, when a
   * proper pagebreak handing gets implemented.
   *
   * @return true, if the printing of the last group footer is still
   * pending, false otherwise.
   */
  protected boolean isGroupFinishPending()
  {
    return groupFinishPending;
  }

  /**
   * Defines, whether the printing of the current group footer is pending.
   * <p>
   * Will be removed in release 0.8.5
   *
   * @param groupFinishPending true or false
   */
  protected void setGroupFinishPending(boolean groupFinishPending)
  {
    this.groupFinishPending = groupFinishPending;
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?