Class ResultModel

java.lang.Object
com.inet.pdfc.results.ResultModel
All Implemented Interfaces:
Closeable, Serializable, AutoCloseable

public class ResultModel extends Object implements Serializable, Closeable
This class is the central model to access the results of a comparison and to make the result available to any listener and presenter.
A ResultModel wraps an instance of ResultModelData where the persistable data of the comparison result are stored. It is that instance can be used to serialize the result and save it across sessions.
Beyond that, a ResultModel handles several runtime aspects of the comparison result, for example filtering the presentation according to given settings. In general, it makes the comparison result available to listeners which can manipulate or update the result.
Since:
3.0
See Also:
  • Constructor Details

    • ResultModel

      public ResultModel()
      Creates the instance and sets all DiffGroup.GroupTypes to visible.
      Since:
      3.0
    • ResultModel

      public ResultModel(com.inet.pdfc.results.ResultModelData data)
      Creates the instance, sets all DiffGroup.GroupTypes to visible and sets the data.
      Parameters:
      data - the data for this result model
      Since:
      4.0
  • Method Details

    • addChangeListener

      public void addChangeListener(ResultModel.ResultModelChangeListener l)
      Adds a ResultModelChangeListener to this model. This listener will be notified whenever the model is cleared, new differences are added, the comparison has finished or the filter has changed.
      Parameters:
      l - the ResultModelChangeListener to add (not null)
      Since:
      3.0
      See Also:
    • clear

      public void clear()
      Completely clears the model including the page images. Fires a change result of type ResultModel.STATE_CHANGE_TYPE.CLEARED
      Since:
      3.0
    • close

      public void close()
      Clears all in memory and cached data of this ResultModel.
      It's highly recommended to call this method before releasing the instance!
      Not calling close() may result on a notable performance decline since the caching process and memory usage will persist until the next garbage collection cycle.
      Since there is no 'closed' state for the ResultModel the instance will just be empty when this call returns.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Since:
      4.1
    • getComparisonParameters

      public InfoData getComparisonParameters()
      Returns the static data for the current comparison. This includes the source PDF references as well as the configuration of the comparison
      Returns:
      the comparison static data
      Since:
      3.0
    • getDifferences

      public List<DiffGroup> getDifferences(boolean filtered)
      Returns either all or only the visible differences in this mode, depending on the DiffGroup.GroupType visibility settings.
      Parameters:
      filtered - if true, only the type which are visible will be returned, if false all differences known to this model will be returned.
      Returns:
      a list of differences, never null but may be empty
      Since:
      3.0
    • getDifferences

      public int getDifferences(Modification.ModificationType type, boolean filtered)
      Count all differences with the specified modification type.
      Parameters:
      type - the modification type that should be counted
      filtered - if true, only the types which are visible will be returned, if false all differences known to this model will be returned.
      Returns:
      the differences for a Modification.ModificationType
      Since:
      5.0
    • getDifferencesCount

      public int getDifferencesCount(boolean filtered)
      Returns the number of differences held by this model. This number is an approximation to how many changes where done in the documents. It's neither the number of elements which are somehow affected nor the number of DiffGroups in the model. E.G. a DiffGroup of type DiffGroup.GroupType.AddedOrRemoved contains an add and a remove modification, this will be counted as two differences here.
      Parameters:
      filtered - if true, only the type which are visible as by isVisible(VisibilitySetting) will be counted, if false all differences known to this model will be counted.
      Returns:
      the number of differences to be displayed to the user or presenter
      Since:
      3.0
    • getHighlightData

      public HighlightData getHighlightData(String key)
      Return the highlight overlay data for a certain filter or type.
      Parameters:
      key - type to get the Highlight data for
      Returns:
      the highlight overlay data or null, if there is no such filter currently active
      Since:
      4.0
    • getHighlightsForPage

      public List<HighlightData.Highlight> getHighlightsForPage(int pageNr, boolean firstDocument)
      Returns the highlights for a page. Highlights are either annotations of the PDF file itself or created by filter to outline filtered elements.
      Parameters:
      pageNr - the zero-based page number
      firstDocument - true if the first document is references, false for the second one
      Returns:
      the highlights for this page, may be null or empty
      Since:
      3.0
    • getPageCount

      public int getPageCount(boolean first)
      Returns the number of pages CURRENTLY AVAILABLE for one of the documents. This number may increase as new pages are appended to the model.
      Parameters:
      first - true if the first document is references, false for the second one
      Returns:
      the maximum number of pages
      Since:
      4.0
    • getPage

      public ResultPage getPage(int pageIndex, boolean first)
      Returns a page info object for a certain page. This info object contains all informations about the page except the differences on this page since DiffGroups may span several pages. If you'd like to get all differences for a page, please use getDifferences(boolean) and filter all differences with a y-location inside the bounds of a page.
      Parameters:
      pageIndex - the zero-based index of the page
      first - true to get a page of the first document, false to get a page for the second document
      Returns:
      the requested page object, may be a dummy if there is no such page in this document, or null if the index below zero or larger than getPageCount(boolean)
      Since:
      3.0
    • getPageAt

      public ResultPage getPageAt(Point pos, boolean left)
      Returns the page at the specified location or null if there is no page at the specified location.
      Parameters:
      pos - the location
      left - flag indicating the left side document
      Returns:
      the page
      Since:
      3.0
    • getPageImageCache

      public com.inet.pdfc.generator.rendercache.PageImageCache getPageImageCache()
      Returns the page image cache. This is is used by the parser to store the pares pages to. Use this as a source for rendered pages when exporting the result.
      Returns:
      the page image cache
      Since:
      3.0
    • isEmpty

      public boolean isEmpty()
      Returns whether the list of page info objects is empty
      Returns:
      whether the list of page info objects is empty
      Since:
      3.0
    • isTypeVisible

      @Deprecated public boolean isTypeVisible(DiffGroup.GroupType t)
      Deprecated.
      As of i-net PDFC 4.1, use isVisible(VisibilitySetting) instead
      Returns whether differences of a certain DiffGroup.GroupType is shown / used in the presentation of this result model.
      Parameters:
      t - the type to check for
      Returns:
      true, if the type is visible
      Since:
      3.0
    • isVisible

      public boolean isVisible(VisibilitySetting setting)
      Returns whether differences of a certain VisibilitySetting is shown / used in the presentation of this result model.
      Parameters:
      setting - the type to check for
      Returns:
      true, if the type is visible
      Since:
      4.1
    • removeChangeListener

      public void removeChangeListener(ResultModel.ResultModelChangeListener l)
      Removes a ResultModelChangeListener from this model.
      Parameters:
      l - the ResultModelChangeListener to remove (not null)
      Since:
      3.0
      See Also:
    • setHighlightVisibile

      @Deprecated public void setHighlightVisibile(String key, boolean visible)
      Deprecated.
      As of i-net PDFC 4.3, use setSetting(Settings) instead
      Sets a certain type of highlight to visible or hidden. This does not modify the model but will cause the ResultPage.getHighlights() to be filtered according to this setting.
      Parameters:
      key - the key of the filter to plugin to show the highlights for
      visible - true for visible, false to hide
      Since:
      4.0
    • setTypeVisible

      @Deprecated public void setTypeVisible(DiffGroup.GroupType t, boolean visible)
      Deprecated.
      As of i-net PDFC 4.1, use setSetting(Settings) instead
      Defines a difference type as visible or invisible.
      This can be called outside the Event Dispatching Thread. To inform any listeners about the change, the caller must explicitly call the fireStateChange method from inside the EDT
      Parameters:
      t - the type to set
      visible - true for visible
      Since:
      3.0
    • setSetting

      public void setSetting(Settings settings)
      Set setting for this model. With the setting can be change the color and the visibility of GroupTypes.
      Parameters:
      settings - the new setting
      Since:
      4.1
    • setVisible

      @Deprecated public void setVisible(boolean isVisible, VisibilitySetting... visibles)
      Deprecated.
      As of i-net PDFC 4.3, use setSetting(Settings) instead
      Defines a difference type as visible or invisible.
      This can be called outside the Event Dispatching Thread. To inform any listeners about the change, the caller must explicitly call the fireStateChange method from inside the EDT
      Parameters:
      isVisible - true for visible
      visibles - the type to set
      Since:
      4.1
    • getSettings

      public Settings getSettings()
      Returns a copy of the current settings. So, on order to modify the settings you'll have to call setSetting(Settings) afterwards.
      Returns:
      a copy of the current settings
      Since:
      5.0