Skip to content

Commit

Permalink
#49: scroll to media position in referencing chat
Browse files Browse the repository at this point in the history
  • Loading branch information
lfcnassif committed Jun 25, 2021
1 parent ace420f commit 53756ce
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import dpf.sp.gpinf.indexer.search.IPEDSource;
import dpf.sp.gpinf.indexer.search.ItemId;
import dpf.sp.gpinf.indexer.search.SimilarDocumentSearch;
import dpf.sp.gpinf.indexer.ui.fileViewer.frames.HtmlViewer;
import dpf.sp.gpinf.indexer.ui.fileViewer.frames.Viewer;
import dpf.sp.gpinf.indexer.util.SpinnerDialog;
import iped3.IIPEDSource;
Expand Down Expand Up @@ -398,7 +397,7 @@ public void actionPerformed(ActionEvent e) {
if (chatId != -1) {
String position = item.getMetadata().get(ExtraProperties.PARENT_VIEW_POSITION);
// TODO change viewer api to pass this
HtmlViewer.setPositionToScroll(position);
App.get().getViewerController().getHtmlLinkViewer().setElementIDToScroll(position);
ItemId chatItemId = new ItemId(itemId.getSourceId(), chatId);
int luceneId = App.get().appCase.getLuceneId(chatItemId);
new FileProcessor(luceneId, false).execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import dpf.sp.gpinf.indexer.search.IPEDSearcher;
import dpf.sp.gpinf.indexer.search.MultiSearchResult;
import iped3.search.LuceneSearchResult;
import iped3.util.BasicProps;
import iped3.util.ExtraProperties;

public class ReferencesTableModel extends AbstractTableModel
Expand All @@ -49,6 +50,7 @@ public class ReferencesTableModel extends AbstractTableModel

private LuceneSearchResult results = new LuceneSearchResult(0);
private int selectedIndex = -1;
private String nameToScroll;

@Override
public int getColumnCount() {
Expand Down Expand Up @@ -150,10 +152,13 @@ public void valueChanged(ListSelectionEvent evt) {
selectedIndex = lsm.getMinSelectionIndex();
App.get().getTextViewer().textTable.scrollRectToVisible(new Rectangle());

if (nameToScroll != null) {
App.get().getViewerController().getHtmlLinkViewer().setElementNameToScroll(nameToScroll);
}

FileProcessor parsingTask = new FileProcessor(results.getLuceneIds()[selectedIndex], false);
parsingTask.execute();

App.get().parentItemModel.fireTableDataChanged();
}

public void listReferencingItems(Document doc) {
Expand All @@ -167,8 +172,6 @@ public void listReferencingItems(Document doc) {
String textQuery = ExtraProperties.LINKED_ITEMS + ":(" + hashes + ") ";
textQuery += ExtraProperties.SHARED_HASHES + ":(" + hashes + ")";

System.out.println(textQuery);

try {
IPEDSearcher task = new IPEDSearcher(App.get().appCase, textQuery);
results = task.luceneSearch();
Expand All @@ -182,10 +185,14 @@ public void run() {
App.get().referencesDock.setTitleText(length + Messages.getString("ReferencesTab.Title"));
}
});
nameToScroll = doc.get(BasicProps.HASH);
} else {
nameToScroll = null;
}

} catch (Exception e) {
results = new LuceneSearchResult(0);
nameToScroll = null;
e.printStackTrace();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
public class HtmlViewer extends Viewer {

private static Logger LOGGER = LoggerFactory.getLogger(HtmlViewer.class);
/**
*
*/

private static final long serialVersionUID = 1L;
private JFXPanel jfxPanel;
private static int MAX_SIZE = 10000000;
Expand All @@ -46,7 +44,8 @@ public class HtmlViewer extends Viewer {
+ Messages.getString("HtmlViewer.OpenExternally") //$NON-NLS-1$
+ "</a></body></html>"; //$NON-NLS-1$

private static String positionToScroll;
private static String idToScroll;
private static String nameToScroll;

WebView htmlViewer;
WebEngine webEngine;
Expand All @@ -58,8 +57,12 @@ public class HtmlViewer extends Viewer {
protected Set<String> highlightTerms;

// TODO change viewer api and move this to loadFile method
public static void setPositionToScroll(String position) {
positionToScroll = position;
public void setElementIDToScroll(String id) {
idToScroll = id;
}

public void setElementNameToScroll(String name) {
nameToScroll = name;
}

protected int getMaxHtmlSize() {
Expand Down Expand Up @@ -217,8 +220,8 @@ public void changed(ObservableValue<? extends Worker.State> ov, Worker.State old
currTerm = queryTerms.length > 0 ? 0 : -1;
scrollToNextHit(true);
}
if (doc != null && positionToScroll != null) {
scrollToPosition(positionToScroll);
if (doc != null) {
scrollToPosition();

}
}
Expand All @@ -236,10 +239,18 @@ protected void addJavascriptListener(WebEngine webEngine) {
}
}

private void scrollToPosition(String position) {
private void scrollToPosition() {
try {
webEngine.executeScript("document.getElementById(\"" + position + "\").scrollIntoView(false);"); //$NON-NLS-1$
positionToScroll = null;
if (idToScroll != null) {
webEngine.executeScript("document.getElementById(\"" + idToScroll + "\").scrollIntoView(false);"); //$NON-NLS-1$

} else if (nameToScroll != null) {
webEngine.executeScript("var x = document.getElementsByName(\"" + nameToScroll + "\");"
+ "x[0].scrollIntoView(false);");
}
idToScroll = null;
nameToScroll = null;

} catch (Exception e) {
// ignore
}
Expand Down

0 comments on commit 53756ce

Please sign in to comment.