⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tableverifydefinition.java

📁 JAVA报表
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
   class="org.jfree.report.function.ElementVisibilitySwitchFunction">
   <properties>
   <property name="element">background</property>
   </properties>
   </function>
   </functions>
   </pre>
   *
   * @return the functions.
   *
   * @throws FunctionInitializeException if there is a problem initialising the functions.
   */
  private ExpressionCollection createFunctions() throws FunctionInitializeException
  {
    final ExpressionCollection functions = new ExpressionCollection();

    final ItemSumFunction sum = new ItemSumFunction();
    sum.setName("sum");
    sum.setProperty("field", "Population");
    sum.setProperty("group", "Continent Group");
    functions.add(sum);

    final ElementVisibilitySwitchFunction backgroundTrigger = new ElementVisibilitySwitchFunction();
    backgroundTrigger.setName("backgroundTrigger");
    backgroundTrigger.setProperty("element", "background");
    functions.add(backgroundTrigger);
    return functions;
  }

  /**
   <pre>
   <groups>

   ... create the groups and add them to the list ...

   </groups>
   </pre>
   *
   * @return the groups.
   */
  private GroupList createGroups()
  {
    final GroupList list = new GroupList();
    list.add(createContinentGroup());
    return list;
  }

  /**
   <pre>
   <group name="Continent Group">
   <groupheader height="18" fontname="Monospaced" fontstyle="bold" fontsize="9" pagebreak="false">
   <label name="Label 5" x="0" y="1" width="76" height="9" alignment="left">CONTINENT:</label>
   <string-field name="Continent Element" x="96" y="1" width="76" height="9" alignment="left"
   fieldname="Continent"/>
   <line name="line1" x1="0" y1="12" x2="0" y2="12" weight="0.5"/>
   </groupheader>
   <groupfooter height="18" fontname="Monospaced" fontstyle="bold" fontsize="9">
   <label name="Label 6" x="0" y="0" width="450" height="12" alignment="left"
   baseline="10">Population:</label>
   <number-function x="260" y="0" width="76" height="12" alignment="right" baseline="10"
   format="#,##0" function="sum"/>
   </groupfooter>
   <fields>
   <field>Continent</field>
   </fields>
   </group>
   </pre>
   *
   * @return the continent group.
   */
  private Group createContinentGroup()
  {
    final Group continentGroup = new Group();
    continentGroup.setName("Continent Group");
    continentGroup.addField("Continent");

    final GroupHeader header = new GroupHeader();

    header.getStyle().setStyleProperty
        (ElementStyleSheet.MINIMUMSIZE, new FloatDimension(0, 18));
    header.getBandDefaults().setFontDefinitionProperty
        (new FontDefinition("Monospaced", 9, true, false, false, false));

    LabelElementFactory factory = new LabelElementFactory();
    factory.setName("Label 5");
    factory.setAbsolutePosition(new Point2D.Float(0, 1));
    factory.setMinimumSize(new FloatDimension(76, 9));
    factory.setHorizontalAlignment(ElementAlignment.LEFT);
    factory.setVerticalAlignment(ElementAlignment.MIDDLE);
    factory.setText("CONTINENT:");
    header.addElement(factory.createElement());

    final TextFieldElementFactory tfactory = new TextFieldElementFactory();
    tfactory.setName("Continent Element");
    tfactory.setAbsolutePosition(new Point2D.Float(96, 1));
    tfactory.setMinimumSize(new FloatDimension(76, 9));
    tfactory.setHorizontalAlignment(ElementAlignment.LEFT);
    tfactory.setVerticalAlignment(ElementAlignment.MIDDLE);
    tfactory.setNullString("<null>");
    tfactory.setFieldname("Continent");
    header.addElement(tfactory.createElement());

    header.addElement(StaticShapeElementFactory.createLineShapeElement
        ("line1", null, new BasicStroke(0.5f), new Line2D.Float(0, 12, 0, 12)));
    continentGroup.setHeader(header);

    final GroupFooter footer = new GroupFooter();
    footer.getStyle().setStyleProperty
        (ElementStyleSheet.MINIMUMSIZE, new FloatDimension(0, 18));
    footer.getBandDefaults().setFontDefinitionProperty
        (new FontDefinition("Monospaced", 9, true, false, false, false));

    factory = new LabelElementFactory();
    factory.setName("Label 6");
    factory.setAbsolutePosition(new Point2D.Float(0, 0));
    factory.setMinimumSize(new FloatDimension(100, 12));
    factory.setHorizontalAlignment(ElementAlignment.LEFT);
    factory.setVerticalAlignment(ElementAlignment.MIDDLE);
    factory.setText("Population:");
    footer.addElement(factory.createElement());

    final NumberFieldElementFactory nfactory = new NumberFieldElementFactory();
    nfactory.setName("anonymous");
    nfactory.setAbsolutePosition(new Point2D.Float(260, 0));
    nfactory.setMinimumSize(new FloatDimension(76, 12));
    nfactory.setHorizontalAlignment(ElementAlignment.LEFT);
    nfactory.setVerticalAlignment(ElementAlignment.MIDDLE);
    nfactory.setNullString("<null>");
    nfactory.setFieldname("sum");
    nfactory.setFormatString("#,##0");
    footer.addElement(nfactory.createElement());
    continentGroup.setFooter(footer);
    return continentGroup;
  }

  /**
   * Creates the report.
   *
   * @return the constructed report.
   *
   * @throws FunctionInitializeException if there was a problem initialising any of the functions.
   */
  public JFreeReport createReport() throws FunctionInitializeException
  {
    final JFreeReport report = new JFreeReport();
    report.setName("Sample Report 1");
    report.setReportFooter(createReportFooter());
    report.setReportHeader(createReportHeader());
    report.setPageFooter(createPageFooter());
    report.setPageHeader(createPageHeader());
    report.setGroups(createGroups());
    report.setItemBand(createItemBand());
    report.setFunctions(createFunctions());
    report.setPropertyMarked("report.date", true);
    return report;
  }

  /**
   * Default constructor.
   */
  public TableVerifyDefinition()
  {
  }

  /**
   * Runs this report and shows a preview dialog.
   *
   * @param args the arguments (ignored).
   * @throws Exception if an error occurs (default: print a stack trace)
   */
  public static void main(final String[] args) throws Exception
  {
    // initialize JFreeReport
    Boot.start();

    final JFreeReport report = new TableVerifyDefinition().createReport();
    report.setData(new SampleData1());

    final PreviewDialog dialog = new PreviewDialog(report);
    dialog.setModal(true);
    dialog.pack();
    dialog.setVisible(true);
    System.exit(0);
  }

  private void addGroupHeader (VerifyPattern pattern, String name)
  {
    // group header
    pattern.addRow("GroupHeader-1-" + name);
    pattern.addCell(new VerifyCell (0, 0, 1, 1));
    pattern.addCell(new VerifyCell (1, 0, 1, 1));
    pattern.addCell(new VerifyCell (2, 0, 1, 1));
    pattern.addCell(new VerifyCell (3, 0, 1, 1));
    pattern.addRow("GroupHeader-2-" + name);
    pattern.addCell(new VerifyCell (0, 1, 1, 1));
    pattern.addCell(new VerifyCell (1, 1, 1, 1));
    pattern.addCell(new VerifyCell (2, 1, 1, 1));
    pattern.addCell(new VerifyCell (3, 1, 1, 1));
    pattern.addRow("GroupHeader-3-" + name);
    pattern.addCell(new VerifyCell (0, 2, 1, 1));
    pattern.addCell(new VerifyCell (1, 2, 1, 1));
    pattern.addCell(new VerifyCell (2, 2, 1, 1));
    pattern.addCell(new VerifyCell (3, 2, 1, 1));
  }

  private void addItemBand (int count, VerifyPattern pattern, String name)
  {
    // itemband
    for (int i = 0; i < count; i++)
    {
      pattern.addRow("ItemBand-" + i + "-" + name);
      pattern.addCell(new VerifyCell (0, 0, 2, 1));
      pattern.addCell(new VerifyCell (2, 0, 1, 1));
      pattern.addCell(new VerifyCell (3, 0, 1, 1));
    }
  }

  private void addGroupFooter (VerifyPattern pattern, String name)
  {
    pattern.addRow("GroupFooter-1-" + name);
    pattern.addCell(new VerifyCell (0, 0, 2, 1));
    pattern.addCell(new VerifyCell (2, 0, 1, 1));
    pattern.addCell(new VerifyCell (3, 0, 1, 1));
  }

  public VerifyPattern createPattern ()
  {
    VerifyPattern pattern = new VerifyPattern();
    // A '0' in the y column indicates a commit operation.
    // page header ..
    pattern.addRow("page-header?");
    pattern.addCell(new VerifyCell (0, 0, 4, 1));
    pattern.addRow("page-header?");
    pattern.addCell(new VerifyCell (0, 1, 1, 1));
    pattern.addCell(new VerifyCell (1, 1, 1, 1));
    pattern.addCell(new VerifyCell (2, 1, 1, 1));
    pattern.addCell(new VerifyCell (3, 1, 1, 1));
    // report header ...
    pattern.addRow("report-header-1");
    pattern.addCell(new VerifyCell (0,0, 4, 1));
    // no commit anymore, as the pageheader is spooled

    // afrika : 2 countries
    addGroupInstance(2, pattern, "Africa");
    // asia : 3 countries
    addGroupInstance(3, pattern, "Asia");
    // australia : 1 countries
    addGroupInstance(1, pattern, "Australia");
    // europe : 14 countries
    addGroupInstance(14, pattern, "Europe");
    // north america : 2 countries
    addGroupInstance(2, pattern, "North America");
    // south america : 1 countries
    addGroupInstance(1, pattern, "South America");

    pattern.addRow("report-footer");
    pattern.addCell(new VerifyCell (0,0, 4, 1));
    pattern.addRow("page-footer");
    pattern.addCell(new VerifyCell (0,0, 4, 1));
    return pattern;
  }

  private void addGroupInstance (int itemcount, VerifyPattern pattern, String name)
  {
    addGroupHeader(pattern, name);
    addItemBand(itemcount, pattern, name);
    addGroupFooter(pattern, name);
  }
}

⌨️ 快捷键说明

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