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

📄 jfreereportdemo.java

📁 swing编写的库存管理程序。毕业设计类
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        new URLDemoHandler("/org/jfree/report/demo/report3.xml")));

    list.add(new DemoDefinition(createExampleName(4), data4,
        new URLDemoHandler("/org/jfree/report/demo/report4.xml")));

    list.add(new DemoDefinition("Report created by API", data1, new DemoHandler()
    {
      public void performPreview(final DemoDefinition def)
      {
        previewAPIReport(def.getData());
      }
    }));

    list.add(new DemoDefinition("Example 1 - using Extended Report Definition format", data1,
        new URLDemoHandler("/org/jfree/report/demo/report1a.xml")));

    list.add(new DemoDefinition("Example 2 - with Image-Function", data2,
        new URLDemoHandler("/org/jfree/report/demo/report2a.xml")));

    list.add(new DemoDefinition("ItemHideFunction-Demo", data2,
        new URLDemoHandler("/org/jfree/report/demo/report2b.xml")));

    list.add(new DemoDefinition("Dynamic-Demo", data2,
        new URLDemoHandler("/org/jfree/report/demo/report2c.xml")));

    list.add(new DemoDefinition("Band in Band Stacking", data2, new DemoHandler()
    {
      public void performPreview(final DemoDefinition def)
      {
        previewBandInBandStacking();
      }
    }));

    list.add(new DemoDefinition("Shape and Drawable", new DefaultTableModel(),
        new URLDemoHandler("/org/jfree/report/demo/shape-and-drawable.xml")));

    list.add(new DemoDefinition("Example 2 - table with cell borders", data2,
        new URLDemoHandler("/org/jfree/report/demo/report2d.xml")));

    return list;
  }

  /**
   * Returns a list of the available demos.
   *
   * @return The list.
   */
  public List getAvailableDemos()
  {
    return availableDemos;
  }

  /**
   * Forms the localized example string.
   *
   * @param ex  the example number.
   *
   * @return the string.
   */
  protected String createExampleName(final int ex)
  {
    return MessageFormat.format(getResources().getString("example"),
        new Object[]{new Integer(ex)});
  }

  /**
   * Handles a request to preview a report.  First determines which data set is visible, then
   * calls the appropriate preview method.
   */
  protected void attemptPreview()
  {
    final int index = tabbedPane.getSelectedIndex();
    final DemoDefinition dd = (DemoDefinition) getAvailableDemos().get(index);
    dd.getHandler().performPreview(dd);
  }

  /**
   * Preview a report created by using the API.
   *
   * @param data  the data for the report.
   */
  protected void previewAPIReport(final TableModel data)
  {
    try
    {
      final JFreeReport report1 = new SampleReport1().createReport();
      report1.setData(data);

      final PreviewFrame frame1 = new PreviewFrame(report1);
      frame1.pack();
      RefineryUtilities.positionFrameRandomly(frame1);
      frame1.setVisible(true);
      frame1.requestFocus();
    }
    catch (Exception e)
    {
      showExceptionDialog("report.definitionfailure", e);
    }
  }

  /**
   * Preview.
   */
  protected void previewBandInBandStacking()
  {
    try
    {
      final JFreeReport report1 = new SampleReport2().createReport();
      report1.setData(new DefaultTableModel());

      final PreviewFrame frame1 = new PreviewFrame(report1);
      frame1.pack();
      RefineryUtilities.positionFrameRandomly(frame1);
      frame1.setVisible(true);
      frame1.requestFocus();
    }
    catch (Exception e)
    {
      showExceptionDialog("report.definitionfailure", e);
    }
  }

  /**
   * Displays a preview frame for report defined in the file specified by <code>urlname</code>.
   * The contents of the url are parsed and the report is fed into a new PreviewPane.
   * The given TableModel is assigned to the report as report data source.
   * <p>
   * If the report contains external references in specified in relative urls, the urls
   * are loaded using the reports parent directory as content base.
   *
   * @param urlname  the filename from where to load the report
   * @param data  the datamodel for the report
   */
  public void preview(final String urlname, final TableModel data)
  {
    final URL in = getClass().getResource(urlname);
    if (in == null)
    {
      JOptionPane.showMessageDialog(this,
          MessageFormat.format(getResources().getString("report.definitionnotfound"),
              new Object[]{urlname}),
          getResources().getString("error"), JOptionPane.ERROR_MESSAGE);
      return;
    }

    Log.debug("Processing Report: " + in);
    final ReportGenerator gen = ReportGenerator.getInstance();

    try
    {
      final JFreeReport report1 = gen.parseReport(in, in);
      if (report1 == null)
      {
        JOptionPane.showMessageDialog(this,
            MessageFormat.format(getResources().getString("report.definitionnull"),
                new Object[]{urlname}),
            getResources().getString("error"), JOptionPane.ERROR_MESSAGE);
        return;
      }

      report1.setData(data);
      //report1.getReportConfiguration().setStrictErrorHandling(false);  // DG
      final PreviewFrame frame1 = new PreviewFrame(report1);
      frame1.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
      frame1.pack();
      RefineryUtilities.positionFrameRandomly(frame1);
      frame1.setVisible(true);
      frame1.requestFocus();
    }
    catch (Exception e)
    {
      showExceptionDialog("report.definitionfailure", e);
    }
  }

  /**
   * Returns the preferred size of the frame.
   *
   * @return the preferred size.
   */
  public Dimension getPreferredSize()
  {
    return new Dimension(440, 300);
  }

  /**
   * Displays information about the application.
   */
  public void displayAbout()
  {
    if (aboutFrame == null)
    {
      aboutFrame = new AboutFrame(getResources().getString("action.about.name"),
          JFreeReport.getInfo());

      aboutFrame.pack();
      RefineryUtilities.centerFrameOnScreen(aboutFrame);
    }
    aboutFrame.setVisible(true);
    aboutFrame.requestFocus();
  }

  /**
   * Create the actions used in the demo.
   */
  private void createActions()
  {
    aboutAction = new DemoAboutAction();
  }

  /**
   * Creates and returns a menu-bar for the frame.
   *
   * @return the menu bar.
   */
  private JMenuBar createMenuBar()
  {

    // create the menus
    final JMenuBar menuBar = new JMenuBar();
    menuBar.setBorder(null);
    // first the file menu
    final JMenu fileMenu = createJMenuItem("menu.file");

    final JMenuItem printItem = new ActionMenuItem(getPreviewAction());
    final KeyStroke accelerator = (KeyStroke)
        getPreviewAction().getValue(ActionDowngrade.ACCELERATOR_KEY);
    if (accelerator != null)
    {
      printItem.setAccelerator(accelerator);
    }
    fileMenu.add(printItem);

    fileMenu.add(new JSeparator());

    final JMenuItem exitItem = new ActionMenuItem(getCloseAction());
    fileMenu.add(exitItem);

    // then the help menu
    final JMenu helpMenu = createJMenuItem("menu.help");

    final JMenuItem aboutItem = new ActionMenuItem(aboutAction);
    helpMenu.add(aboutItem);

    // finally, glue together the menu and return it
    menuBar.add(fileMenu);
    menuBar.add(helpMenu);

    return menuBar;
  }

  /**
   * Creates a new button based on the action. The button will be floating enabled,
   * so that the buttons borders are only visible when the mouse has entered the button area.
   *
   * @param action  the action.
   *
   * @return a button based on the action.
   */
  protected JButton createButton(final Action action)
  {
    final ActionButton button = new ActionButton(action);
    button.setMargin(new Insets(0, 0, 0, 0));
    button.setText(null);
    FloatingButtonEnabler.getInstance().addButton(button);
    return button;
  }

  /**
   * Creates the demos toolbar.
   *
   * @return the toolbar.
   */
  private JToolBar createToolBar()
  {
    final JToolBar toolbar = new JToolBar();
    toolbar.setBorder(BorderFactory.createEmptyBorder(4, 0, 4, 0));

    toolbar.add(createButton(getPreviewAction()));
    toolbar.addSeparator();
    toolbar.add(createButton(aboutAction));

    return toolbar;
  }

  ////////////////////////////////////////////////////////////////////////////////////////////////
  ////////////////////////////////////////////////////////////////////////////////////////////////

  /**
   * The starting point for the demonstration application.
   *
   * @param args ignored.
   */
  public static void main(final String[] args)
  {
    // initialize JFreeReport 
    Boot.start();

    try
    {
      try
      {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      }
      catch (Exception e)
      {
        Log.info("Look and feel problem.");
      }

      final JFreeReportDemo frame = new JFreeReportDemo();
      frame.pack();
      frame.setBounds(100, 100, 700, 400);
      RefineryUtilities.centerFrameOnScreen(frame);
      frame.setVisible(true);
    }
    catch (Throwable th)
    {
      th.printStackTrace();
    }
  }
}

⌨️ 快捷键说明

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