Class SwingReportView

All Implemented Interfaces:
ReportView, ViewerComponent, ImageObserver, MenuContainer, Serializable, Accessible

public class SwingReportView extends JPanel implements ReportView
The Swing implementation of ReportView, a container for a NavigationView, a ReportScrollView, and a StatusBar. By default, the SwingReportView consists of a SwingNavigationView containing a group tree, search view, etc., on the left, a SwingReportScrollView on the right, and a SwingStatusBar below both. It offers various methods of page navigation and settings
To obtain an instance of a SwingReportView, use the methods SwingReportViewer.addNewReportView(RenderData) and SwingReportViewer.createReportView(RenderData).
Also, similarly to SwingReportViewer, a SwingReportView object is highly customizable. It is possible to hide components or place your own components in place of the navigation view or status bar. Here are a couple of examples of what could be done with a SwingReportView:

Hide the navigation view

If your report view does not have a group tree, or does not need a navigation view, you might want to hide the navigation view. To do this, simply extract it with extractNavigationView(). This will cause the navigation view to be hidden. If you should later still want to get a reference to the navigation view object, this is possible using getNavigationView().

"Wrap" the status bar in an own component

Using the methods "extractStatusBar" and "insertAtStatusBarPosition" this is quite simple:

 StatusBar oldStatusBar = myView.extractStatusBar();
 
 // We have now extracted the old status bar from the view - it should now no longer be
 // visible in the report view. Now, we place this status bar into our own component.
 // Let's say our own component has a green button called "TestGreen".
 
 JPanel newStatusBar = new JPanel( new FlowLayout() );
 JButton test = new JButton( "TestGreen" );
 test.setBackground( Color.GREEN );
 newStatusBar.add( woohoo );
 newStatusBar.add( oldStatusBar );
 
 // Now we take advantage of the "insertAtStatusBarPosition" method, which places the component
 // we pass into the old status bar position.
 
 myView.insertAtStatusBarPosition( newStatusBar );
 

Export the report to a file

Once again, this is quite simple using the given "export" method, combined with the various export constants from the interface ReportView:

 myView.export( ReportView.EXPORT_PDF, "C:/test.pdf" );
 

Cause the report to be re-rendered and refreshed

 myView.refresh();
 
Since:
7.0
See Also:
  • Method Details

    • showError

      public void showError(Throwable th)
      Displays an error box showing the Throwable's error message. If a ViewerException is thrown, the special messages and properties of the ViewerException are shown. Otherwise, only the getMessage() as well as the stack trace are shown.
      Specified by:
      showError in interface ReportView
      Parameters:
      th - Throwable to display in an error box. Best if this Throwable is a ViewerException.
      Since:
      7.0
    • getNavigationView

      public NavigationView getNavigationView()
      Returns this ReportView's NavigationView, that is, the element containing this ReportView's SearchView, GroupView and/or IndexView.
      Specified by:
      getNavigationView in interface ReportView
      Returns:
      NavigationView belonging to this ReportView.
      Since:
      7.0
    • getStatusBar

      public StatusBar getStatusBar()
      Returns this ReportView's StatusBar, the element which can display messages or progress bars.
      Specified by:
      getStatusBar in interface ReportView
      Returns:
      StatusBar belonging to this ReportView
      Since:
      7.0
    • extractStatusBar

      public StatusBar extractStatusBar()
      Removes the status bar GUI component from the ReportView and returns it. If the status bar has already been extracted, nothing happens, and in this case this method is equivalent to getStatusBar().
      Specified by:
      extractStatusBar in interface ReportView
      Returns:
      StatusBar of this ReportView
      Since:
      7.0
    • extractNavigationView

      public NavigationView extractNavigationView()
      Removes the navigation view GUI component from the ReportView and returns it. If the navigation view has already been extracted, nothing happens, and in this case this method is equivalent to getNavigationView().
      Specified by:
      extractNavigationView in interface ReportView
      Returns:
      NavigationView of this ReportView
      Since:
      7.0
    • reload

      public void reload()
      Causes this ReportView to reload its pages and show them again, using the already fetched data if possible - if not, this causes a fetching of the report data.
      Specified by:
      reload in interface ReportView
      Since:
      7.0
      See Also:
    • refresh

      public void refresh()
      Causes this ReportView to refresh its pages by re-fetching the report data - this causes a re-rendering of the report data. If "promptOnRefresh" is set, this will cause the prompts to be fetched again as well.
      Specified by:
      refresh in interface ReportView
      Since:
      7.0
      See Also:
    • cancel

      public void cancel()
      This cancels the loading of the current report in case it is still loading. It will cancel the render process on the server as well. The effect is similar to the stop button of the load progress component. If the current loading status is ReportView.STATUS_FINISHED or ReportView.STATUS_CANCELED, this method has no effect.
      Specified by:
      cancel in interface ReportView
      Since:
      12.0
    • nextPage

      public void nextPage()
      Navigates one step forward in the report - if this is not possible (e.g. the current page is already the last page of the report), this method does nothing.
      Specified by:
      nextPage in interface ReportView
      Since:
      7.0
    • prevPage

      public void prevPage()
      Navigates one step back in the report - if this is not possible (e.g. the current page is already the first page of the report), this method does nothing.
      Specified by:
      prevPage in interface ReportView
      Since:
      7.0
    • goToPage

      public void goToPage(int pageNumber)
      Causes the page indicated by the parameter pageNum to be displayed in this ReportView. If this page does not exist in the report, calling this method will do nothing at all. Note this is an asynchronous call - the page will be displayed at some point, but it is not guaranteed that the page is actually visible as soon as this method returns.
      Specified by:
      goToPage in interface ReportView
      Parameters:
      pageNumber - Number of page (starting at 1) to be displayed in this ReportView.
      Since:
      7.0
    • goToLastPage

      public void goToLastPage()
      Navigates directly to the last page in the report - if the current page is already the last page of the report, or if the total page count is not known as of yet (that is, the report is still being rendered), this method does nothing. Note this is an asynchronous call - the page will be displayed at some point, but it is not guaranteed that the page is actually visible as soon as this method returns.
      Specified by:
      goToLastPage in interface ReportView
      Since:
      7.0
    • setViewMode

      public void setViewMode(int i)
      Sets the type of view this ReportView is to take and causes this view to be displayed immediately. By default, possible values are: ReportView.SINGLE_PAGE - only one page is shown at a time. ReportView.SINGLE_CONTINUOUS - the report can be scrolled through in its entirety, with each page being shown above the next. ReportView.DOUBLE_PAGE - only two pages are shown at a time, next to each other. ReportView.DOUBLE_CONTINUOUS - the report can be scrolled through in its entirety, however showing the pages two by two.
      Specified by:
      setViewMode in interface ReportView
      Parameters:
      i - Layout type to display in this ReportView.
      Since:
      7.0
      See Also:
    • getDefaultAttributeSet

      public HashPrintRequestAttributeSet getDefaultAttributeSet(int fromPage, int toPage)
      Creates and returns a HashPrintRequestAttributeSet for the given page(s) with the default printing attributes. If the first page was not loaded then it will wait until the first page is available.
      Specified by:
      getDefaultAttributeSet in interface ReportView
      Parameters:
      fromPage - Number of the first page for which to create the HashPrintRequestAttributeSet. The first page of a report has the value 1.
      toPage - Number of the last page for which to create the HashPrintRequestAttributeSet. A value of -1 means to create the AttributeSet for all pages starting at startPage.
      Returns:
      The list of printing attributes for the given pages.
      Since:
      7.0
      See Also:
    • print

      public Progress print(int fromPage, int toPage, boolean showPrintDialog)
      Prints the current report in the page range with or without any dialogs. If the first page was not loaded then it will wait until the first page is available.
      Specified by:
      print in interface ReportView
      Parameters:
      fromPage - the index of the start page to be printed, the first page is 1.
      toPage - the index of the last page to be printed. A value of -1 means all pages.
      showPrintDialog - if true, a print dialog is showing.
      Returns:
      PrinterJobProgress of the running printing job.
      Since:
      7.0
      See Also:
    • print

      public PrinterJobProgress print(int fromPage, int toPage, PrinterJob pjob)
      Prints the current report to a PrinterJob without any dialogs. It uses the default PrintRequestAttributeSet of the view. If the first page was not loaded then it will wait until the first page is available.
      Specified by:
      print in interface ReportView
      Parameters:
      fromPage - the index of the start page to be printed, the first page is 1.
      toPage - the index of the last page to be printed. A value of -1 means all pages.
      pjob - A java.awt.print.PrinterJob object.
      Returns:
      PrinterJobProgress of the running printing job.
      Since:
      7.0
      See Also:
    • print

      public PrinterJobProgress print(PrinterJob printerJob, PrintRequestAttributeSet attributeSet)
      Creates a new PrinterJobProgress with the given attributes and start it.
      Specified by:
      print in interface ReportView
      Parameters:
      printerJob - The PrinterJob with the target PrintService.
      attributeSet - attributeSet A list of attributes that can override values in the report design, for example paper format, paper orientation and page margins.
      Returns:
      a PrinterJobProgress
      See Also:
    • showPrintDialog

      public static boolean showPrintDialog(Component parentComponent, PrinterJob printerJob, HashPrintRequestAttributeSet attributeSet)
      Shows the viewer print dialog. This dialog will modify the PrinterJob and the AttributeSet, depending on the user input. The viewer print dialog supports some additional features which are not in Java's cross platform print dialog.
      Parameters:
      parentComponent - a parent component, used for showing the dialog as a modal dialog. Can be null.
      printerJob - a PrinterJob with the selected PrintService. On output the PrintService is updated. This parameter may not be null.
      attributeSet - print attributes that are to be shown in the dialog. Once the dialog is closed, the contents are updated to reflect user choices. This parameter may not be null.
      Returns:
      true if the user clicks "print" and false if the user cancels the dialog.
      Throws:
      ViewerException - if no print services are available.
      Since:
      8.0
      See Also:
    • export

      public ExportProgress export()
      Exports the report connected to this report view. At first the export dialog will be displayed. If the user does not cancel the export in the dialog, the export progress will be started after the export dialog has been closed.
      Specified by:
      export in interface ReportView
      Returns:
      ExportProgress of running export
      Since:
      7.0
      See Also:
    • export

      public ExportProgress export(int format, String filename)
      Exports the report connected to this report view into the given file.
      Export formats creating multiple files, e.g. HTML and SVG, creating a sub directory with the name of the first file. All files will be saved in that directory expecting the first file.
      This method use the default value for all properties expecting the export format. To export a report into a file without preview in the Java viewer we recommend to use the Engine directly instead of using the Viewer API because the Java viewer have to request the first report page in the Java viewer format before it can request the report in the specified export format.
      Specified by:
      export in interface ReportView
      Parameters:
      format - The export format in that the report will be exported.
      filename - Name of the file in that the report will be exported.
      Returns:
      ExportProgress of running export
      Since:
      7.0
      See Also:
    • export

      public ExportProgress export(Properties exportProperties)
      Exports the report connected to this report view into the given file.
      This method use the default value for all not specified properties. For a complete list of report URL properties see the documentation.
      To export a report into a file without preview in the Java viewer we recommend to use the Engine directly instead of using the Viewer API because the Java viewer have to request the first report page in the Java viewer format before it can request the report in the specified export format.
      Specified by:
      export in interface ReportView
      Parameters:
      exportProperties - Properties for the export, including format, file and other properties if they are available for the selected format.
      Returns:
      ExportProgress of running export
      Since:
      7.0
      See Also:
    • isExportEnabled

      public boolean isExportEnabled()
      Returns if at least one export format is enabled for this ReportView.
      Specified by:
      isExportEnabled in interface ReportView
      Returns:
      exportEnabled Export enabled for this report; true if at least one format is enabled, false otherwise
      Since:
      7.0
    • setMouseActionMode

      public void setMouseActionMode(int hand)
      Sets the mode this ReportView is to be in for mouse actions such as clicking and dragging. By default, possible values are: ReportView.MODE_HAND - Click and drag causes a scrolling of the page along with the mouse movement. ReportView.MODE_TEXT - Click and drag causes a text selection, line by line. ReportView.MODE_SNAPSHOT - Click and drag causes an image snapshot within a box at release of the mouse button.
      Specified by:
      setMouseActionMode in interface ReportView
      Parameters:
      hand - Mouse mode to be used in the ReportView.
      Since:
      7.0
      See Also:
    • hasGroupTree

      public boolean hasGroupTree()
      Returns whether or not this report view is set to show a group tree. If it is false, the report view will not show any group tree. Note this says nothing about whether or not the report actually has groups or not.
      Specified by:
      hasGroupTree in interface ReportView
      Returns:
      Whether this report view is to show a group tree or not if the report should have groups
      Since:
      7.0
    • setHasGroupTree

      public void setHasGroupTree(boolean hasGroupTree)
      Sets this report view to whether or not it is to show a group tree. If this is false, the report view should not show any group tree, regardless of whether or not its report has groups.
      Specified by:
      setHasGroupTree in interface ReportView
      Parameters:
      hasGroupTree - Is this report view to show a group tree?
      Since:
      7.0
      See Also:
    • setZoomFactor

      public void setZoomFactor(float factor)
      Sets the zoom factor to this value. Only values greater than 0 are allowed. This value is not a percentage value, that is, 2.0 is 2x view, 0.25 is 1/4 view, etc.
      If the value is less than MIN_ZOOM_FACTOR, this has the same effect as calling setZoomFactor(MIN_ZOOM_FACTOR).
      If the value is greater than MAX_ZOOM_FACTOR, this has the same effect as calling setZoomFactor(MAX_ZOOM_FACTOR).
      If you want to zoom relative to the page's size, you shouldn't use this method but rather ReportView.setAutomaticZoomType(int)
      Specified by:
      setZoomFactor in interface ReportView
      Parameters:
      factor - Factor to zoom to - 1.0 as 100%, 2.0 as 200%, etc.
      Since:
      7.0
      See Also:
    • setAutomaticZoomType

      public void setAutomaticZoomType(int type)
      Sets the type of zoom to use in the report view when the ReportView is displayed anew (for example after resizing the display). By default, possible values are: ReportView.ZOOM_MANUAL - always use the set zoom factor (settable with setZoom(float factor)) ReportView.ZOOM_TO_PAGEWIDTH - always zoom in or out far enough to see the full width of a page. ReportView.ZOOM_TO_PAGEHEIGHT - always zoom in or out far enough to see the full height of a page. ReportView.ZOOM_TO_FULLPAGE - always zoom in or out far enough to see the full page - this is equivalent to ZOOM_TO_PAGEHEIGHT when the page is a portrait view, or to ZOOM_TO_PAGEWIDTH when the page is a landscape view.
      Specified by:
      setAutomaticZoomType in interface ReportView
      Parameters:
      type - Zoom type to use when displaying the ReportView.
      Since:
      7.0
      See Also:
    • getZoomFactor

      public float getZoomFactor()
      Returns the currently set zoom factor of this ReportView - this is not a percentage value, that is, 1.0 is 1x, 2.0 is 2x view, 0.25 is 1/4 view, etc.
      Specified by:
      getZoomFactor in interface ReportView
      Returns:
      The zoom factor currently set for this ReportView.
      Since:
      7.0
    • getCurrentPage

      public int getCurrentPage()
      Returns the number of the "current page" being displayed in this ReportView. If more than one PageView is visible, this returns the lowest page visible at this time. If no PageView is visible, this returns 0.
      Specified by:
      getCurrentPage in interface ReportView
      Returns:
      Number of the first page currently visible in this ReportView, or 0 if no page is visible.
      Since:
      7.0
    • getTotalPages

      public int getTotalPages()
      Returns the total number of pages this report has. If the total number of pages is as of yet unknown (for example if the report is still being rendered), this will return TOTAL_PAGE_COUNT_UNKNOWN.
      Specified by:
      getTotalPages in interface ReportView
      Returns:
      Total number of pages in the report, or TOTAL_PAGE_COUNT_UNKNOWN if still unknown.
      Since:
      7.0
      See Also:
    • getComponent

      public Component getComponent()
      All public graphical components of the viewer must implement this method, which returns the actual AWT component so that it can be added to containers, etc.
      For example, if you have a "ReportViewer" and would like to add it to your own JFrame, simply call: myFrame.add(viewer.getComponent())
      Specified by:
      getComponent in interface ViewerComponent
      Returns:
      Actual AWT component of this object.
      Since:
      7.0
    • replaceStatusBar

      public void replaceStatusBar(Component component)
      Inserts the given component at the position of the status bar. If a status bar component is already there (which is by default), the component is replaced by the given component. Note the status bar itself remains referenced (getStatusBar will return the same object even after calling this method), this method simply places adds a java.awt.Component in its place. If the given component is null, the status bar will simply be removed, equivalent to calling extractStatusBar.
      Specified by:
      replaceStatusBar in interface ReportView
      Parameters:
      component - Component to position at the status bar position, null if the status bar is simply to be removed.
      Since:
      7.0
    • replaceNavigationView

      public void replaceNavigationView(Component component)
      Inserts the given component at the position of the navigation view. If a navigation view component is already there (which is by default), the component is replaced by the given component. Note the navigation view itself remains referenced (getNavigationView will return the same object even after calling this method) - this method simply places adds a java.awt.Component in its place. If the given component is null, the navigation view will simply be removed, equivalent to calling extractNavigationView.
      Specified by:
      replaceNavigationView in interface ReportView
      Parameters:
      component - Component to position at the navigation view position, null if the navigation view is simply to be removed
      Since:
      7.0
    • getViewMode

      public int getViewMode()
      Returns which type of layout view this ReportView is to take. By default, possible values are: ReportView.SINGLE_PAGE - only one page is shown at a time. (This is the default setting) ReportView.SINGLE_CONTINUOUS - the report can be scrolled through in its entirety, with each page being shown above the next. ReportView.DOUBLE_PAGE - only two pages are shown at a time, next to each other. ReportView.DOUBLE_CONTINUOUS - the report can be scrolled through in its entirety, however showing the pages two by two.
      Specified by:
      getViewMode in interface ReportView
      Returns:
      Layout type used by this ReportView
      Since:
      7.0
      See Also:
    • getAutomaticZoomType

      public int getAutomaticZoomType()
      Returns which type of automatic zoom is used in the report view whenever the ReportView is displayed anew, for example after resizing the display. By default, possible values are: ReportView.ZOOM_MANUAL - always use the set zoom factor (default setting. Zoom factor is settable with setZoom(float factor)) ReportView.ZOOM_TO_PAGEWIDTH - always zoom in or out far enough to see the full width of a page. ReportView.ZOOM_TO_PAGEHEIGHT - always zoom in or out far enough to see the full height of a page. ReportView.ZOOM_TO_FULLPAGE - always zoom in or out far enough to see the full page - this is equivalent to ZOOM_TO_PAGEHEIGHT when the page is a portrait view, or to ZOOM_TO_PAGEWIDTH when the page is a landscape view.
      Specified by:
      getAutomaticZoomType in interface ReportView
      Returns:
      Currently chosen automatic zoom type used by this ReportView
      Since:
      7.0
      See Also:
    • getMouseActionMode

      public int getMouseActionMode()
      Returns the currently selected mode for mouse actions such as clicking and dragging in this ReportView. By default, possible values are: ReportView.MODE_HAND - Click and drag causes a scrolling of the page along with the mouse movement. ReportView.MODE_TEXT - Click and drag causes a text selection, line by line. ReportView.MODE_SNAPSHOT - Click and drag causes an image snapshot within a box at release of the mouse button.
      Specified by:
      getMouseActionMode in interface ReportView
      Returns:
      The currently selected mode for mouse actions such as clicking and dragging within this ReportView
      Since:
      7.0
      See Also:
    • getReportData

      public RenderData getReportData()
      Returns the RenderData object belonging to this ReportView. The RenderData object is the source of report data for this ReportView. If this is null, the ReportView has no connection to a RenderData source and should be considered obsolete.
      Specified by:
      getReportData in interface ReportView
      Returns:
      The RenderData object belonging to this ReportView
      Since:
      7.0
    • getReportViewer

      public ReportViewer getReportViewer()
      Returns the parent ReportViewer for this component.
      Specified by:
      getReportViewer in interface ReportView
      Returns:
      the parent ReportViewer for this component
      Since:
      7.0
    • getReportTitle

      public String getReportTitle()
      Returns the title of this report if it is known. If not known, the title returned will be null.
      Specified by:
      getReportTitle in interface ReportView
      Returns:
      The report title of this report if known. Will return null if not known
      Since:
      7.0
      See Also:
    • getLoadingStatus

      public int getLoadingStatus()
      Fetches the current "loading status" of this report view. By default, possible values are:
      • ReportView.STATUS_INITIALIZED - means the report view is loading for the first time, no pages have been loaded yet.
      • ReportView.STATUS_LOADING - means at least one page has been loaded and the report view is currently fetching the other pages of the report if there are any.
      • ReportView.STATUS_FINISHED - means the report has been successfully loaded.
      • ReportView.STATUS_CANCELED - means the loading has been canceled by the user.
      Specified by:
      getLoadingStatus in interface ReportView
      Returns:
      Current loading status of the report view.
      Since:
      7.0
      See Also:
    • setAutoRefresh

      public void setAutoRefresh(int millis)
      Sets the auto-refresh time for this report view. This will cause this view to be refreshed every millis milliseconds. Note that if the report has prompts, its prompts will not be re-requested at each auto-refresh. Also, a refresh will be skipped if the prompt dialog is currently open, if the report is already currently being refreshed, if the report was manually canceled or if it was stopped due to an error.
      Specified by:
      setAutoRefresh in interface ReportView
      Parameters:
      millis - number of milliseconds for auto-refresh cycle, 0 to turn off auto-refresh
    • isDrilldownEnabled

      public boolean isDrilldownEnabled()
      Returns whether this report view should allow drill downs on its groups if it has any. If not, right clicking a group node will not offer "drill down" as an option. The default value for this is "true" unless set differently in ReportView.setDrilldownEnabled(boolean) and/or as a ViewerSettings entry.
      Specified by:
      isDrilldownEnabled in interface ReportView
      Returns:
      whether this report view should allow drill downs on its groups
    • setDrilldownEnabled

      public void setDrilldownEnabled(boolean enabled)
      Sets whether this report view should allow drill downs on its groups if it has any. If not, right clicking a group node will not offer "drill down" as an option. The default value for this is "true" unless set differently as a ViewerSettings entry.
      Specified by:
      setDrilldownEnabled in interface ReportView
      Parameters:
      enabled - true if it is to be enabled
    • isPageLimitExceeded

      public boolean isPageLimitExceeded()
      Returns whether this report view has more pages than the server page limit for a report allows for (causing the later pages to be truncated from the report).
      Specified by:
      isPageLimitExceeded in interface ReportView
      Returns:
      whether this report view has more pages than the server page limit
    • setPageLimitExceeded

      public void setPageLimitExceeded(boolean pageLimitExceeded)
      sets the "page limit exceeded" flag which determines whether the toolbar will display the total page count with a "+".
      Parameters:
      pageLimitExceeded - true if page limit was exceeded
      Since:
      10.1
    • isReportSuppressed

      public boolean isReportSuppressed()
      Returns whether this report was suppressed because it has no rows.
      Specified by:
      isReportSuppressed in interface ReportView
      Returns:
      true, if no rows.