Package com.inet.pdfc.results
Class ResultModel
- java.lang.Object
-
- com.inet.pdfc.results.ResultModel
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Serializable,java.lang.AutoCloseable
public class ResultModel extends java.lang.Object implements java.io.Serializable, java.io.CloseableThis 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 ofResultModelDatawhere 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:
ResultModelData, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classResultModel.ChangeInfoEvent object with a page range for both documents where the differences data has changedstatic interfaceResultModel.ResultModelChangeListenerDefines a listener for the result modelstatic classResultModel.STATE_CHANGE_TYPEDefines the type of model change in an update event
-
Constructor Summary
Constructors Constructor Description ResultModel()Creates the instance and sets allDiffGroup.GroupTypes to visible.ResultModel(com.inet.pdfc.results.ResultModelData data)Creates the instance, sets allDiffGroup.GroupTypes to visible and sets the data.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddChangeListener(ResultModel.ResultModelChangeListener l)Adds aResultModelChangeListenerto this model.voidclear()Completely clears the model including the page images.voidclose()Clears all in memory and cached data of thisResultModel.
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 theResultModelthe instance will just be empty when this call returns.InfoDatagetComparisonParameters()Returns the static data for the current comparison.java.util.List<DiffGroup>getDifferences(boolean filtered)Returns either all or only the visible differences in this mode, depending on theDiffGroup.GroupTypevisibility settings.intgetDifferences(Modification.ModificationType type, boolean filtered)Count all differences with the specified modification type.intgetDifferencesCount(boolean filtered)Returns the number of differences held by this model.HighlightDatagetHighlightData(java.lang.String key)Return the highlight overlay data for a certain filter or type.java.util.List<HighlightData.Highlight>getHighlightsForPage(int pageNr, boolean firstDocument)Returns the highlights for a page.ResultPagegetPage(int pageIndex, boolean first)Returns a page info object for a certain page.ResultPagegetPageAt(java.awt.Point pos, boolean left)Returns the page at the specified location ornullif there is no page at the specified location.intgetPageCount(boolean first)Returns the number of pages CURRENTLY AVAILABLE for one of the documents.com.inet.pdfc.generator.rendercache.PageImageCachegetPageImageCache()Returns the page image cache.SettingsgetSettings()Returns a copy of the current settings.booleanisEmpty()Returns whether the list of page info objects is emptybooleanisTypeVisible(DiffGroup.GroupType t)Deprecated.As of i-net PDFC 4.1, useisVisible(VisibilitySetting)insteadbooleanisVisible(VisibilitySetting setting)Returns whether differences of a certainVisibilitySettingis shown / used in the presentation of this result model.voidremoveChangeListener(ResultModel.ResultModelChangeListener l)Removes aResultModelChangeListenerfrom this model.voidsetHighlightVisibile(java.lang.String key, boolean visible)Deprecated.As of i-net PDFC 4.3, usesetSetting(Settings)insteadvoidsetSetting(Settings settings)Set setting for this model.voidsetTypeVisible(DiffGroup.GroupType t, boolean visible)Deprecated.As of i-net PDFC 4.1, usesetSetting(Settings)insteadvoidsetVisible(boolean isVisible, VisibilitySetting... visibles)Deprecated.As of i-net PDFC 4.3, usesetSetting(Settings)instead
-
-
-
Constructor Detail
-
ResultModel
public ResultModel()
Creates the instance and sets allDiffGroup.GroupTypes to visible.- Since:
- 3.0
-
ResultModel
public ResultModel(com.inet.pdfc.results.ResultModelData data)
Creates the instance, sets allDiffGroup.GroupTypes to visible and sets the data.- Parameters:
data- the data for this result model- Since:
- 4.0
-
-
Method Detail
-
addChangeListener
public void addChangeListener(ResultModel.ResultModelChangeListener l)
Adds aResultModelChangeListenerto 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- theResultModelChangeListenerto add (not null)- Since:
- 3.0
- See Also:
removeChangeListener(com.inet.pdfc.results.ResultModel.ResultModelChangeListener)
-
clear
public void clear()
Completely clears the model including the page images. Fires a change result of typeResultModel.STATE_CHANGE_TYPE.CLEARED- Since:
- 3.0
-
close
public void close()
Clears all in memory and cached data of thisResultModel.
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 theResultModelthe instance will just be empty when this call returns.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.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 java.util.List<DiffGroup> getDifferences(boolean filtered)
Returns either all or only the visible differences in this mode, depending on theDiffGroup.GroupTypevisibility settings.- Parameters:
filtered- iftrue, only the type which are visible will be returned, iffalseall differences known to this model will be returned.- Returns:
- a list of differences, never
nullbut 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 countedfiltered- iftrue, only the types which are visible will be returned, iffalseall 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 ofDiffGroups in the model. E.G. aDiffGroupof typeDiffGroup.GroupType.AddedOrRemovedcontains an add and a remove modification, this will be counted as two differences here.- Parameters:
filtered- iftrue, only the type which are visible as byisVisible(VisibilitySetting)will be counted, iffalseall 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(java.lang.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 java.util.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 numberfirstDocument- true if the first document is references, false for the second one- Returns:
- the highlights for this page, may be
nullor 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-trueif the first document is references,falsefor 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 sinceDiffGroups may span several pages. If you'd like to get all differences for a page, please usegetDifferences(boolean)and filter all differences with a y-location inside the bounds of a page.- Parameters:
pageIndex- the zero-based index of the pagefirst-trueto get a page of the first document,falseto 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
nullif the index below zero or larger thangetPageCount(boolean) - Since:
- 3.0
-
getPageAt
public ResultPage getPageAt(java.awt.Point pos, boolean left)
Returns the page at the specified location ornullif there is no page at the specified location.- Parameters:
pos- the locationleft- 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, useisVisible(VisibilitySetting)insteadReturns whether differences of a certainDiffGroup.GroupTypeis 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 certainVisibilitySettingis 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 aResultModelChangeListenerfrom this model.- Parameters:
l- theResultModelChangeListenerto remove (not null)- Since:
- 3.0
- See Also:
addChangeListener(com.inet.pdfc.results.ResultModel.ResultModelChangeListener)
-
setHighlightVisibile
@Deprecated public void setHighlightVisibile(java.lang.String key, boolean visible)Deprecated.As of i-net PDFC 4.3, usesetSetting(Settings)insteadSets a certain type of highlight to visible or hidden. This does not modify the model but will cause theResultPage.getHighlights()to be filtered according to this setting.- Parameters:
key- the key of the filter to plugin to show the highlights forvisible-truefor visible,falseto hide- Since:
- 4.0
-
setTypeVisible
@Deprecated public void setTypeVisible(DiffGroup.GroupType t, boolean visible)
Deprecated.As of i-net PDFC 4.1, usesetSetting(Settings)insteadDefines 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 setvisible- 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, usesetSetting(Settings)insteadDefines 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 visiblevisibles- 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 callsetSetting(Settings)afterwards.- Returns:
- a copy of the current settings
- Since:
- 5.0
-
-