sepinf-inc / IPED

IPED Digital Forensic Tool. It is an open source software that can be used to process and analyze digital evidence, often seized at crime scenes by law enforcement or in a corporate investigation by private examiners.
Other
958 stars 219 forks source link

Filtering and copying to clipboard the results of Metadata panel filter #479

Closed leosol closed 3 years ago

leosol commented 3 years ago

Hey guys, do you think that the addition (to MetadataPanel.java) of a JTextField to filter visible results and a button to copy to clipboard could be useful?

You can see what I propose here: https://drive.google.com/file/d/14U4kqNgeFCHj5bcLblYyusdHXVGDpWXG/view

Motivation 1: might be useful when you search for some part of URLs, parts of phone numbers. Its better than scrolling. Motivation 2: the results could be just copied and pasted to your forensic report with the new button. If you select all items, copy and paste works but the window freezes when the case has lots of items.

Implementation seems to be simple. I guess, it could be done with a very small modification. Just tried this on my fork:

private void filterResults() {
    if(StringUtils.isEmpty(this.listFilter.getText())) {
        populateList();
    } else {
        if (array == null)
            return;
        ArrayList<ValueCount> filtered = new ArrayList<MetadataPanel.ValueCount>();
        String searchValue = this.listFilter.getText();
        for (ValueCount valueCount : array) {
            String val = (valueCount.getVal()!=null?valueCount.getVal():"").toLowerCase();
            if(val.contains(searchValue)) {
                filtered.add(valueCount);
            }
        }
        ValueCount[] filteredArray = filtered.toArray(new ValueCount[] {});
        updateList(filteredArray);
    }
}
private void copyResultsToClipboard() {
    StringBuffer strBuffer = new StringBuffer();
    for (int i=0;i<list.getModel().getSize();i++) {
        ValueCount item = list.getModel().getElementAt(i);
        String val = (item.getVal() != null ? item.getVal() : "");
        strBuffer.append(val.toString());
        strBuffer.append(System.lineSeparator());
    }
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(strBuffer.toString()), null);
}

    //Something like this needs to be added to constructor
    JPanel l5 = new JPanel(new BorderLayout());
    label = new JLabel("Filtrar");
    label.setPreferredSize(new Dimension(90, 20));
    l5.add(label, BorderLayout.WEST);
    l5.add(listFilter, BorderLayout.CENTER);

    JPanel l6 = new JPanel(new BorderLayout());
    l6.add(copyResultToClipboard, BorderLayout.CENTER);

    listFilter.addActionListener(this);
    copyResultToClipboard.addActionListener(this);
lfcnassif commented 3 years ago

That is very useful, thanks! Did you try with large cases and lots of values in the list? Did the UI freeze? That should be avoided and maybe the code would need some optimization.

edit: I mean, was the UI responsive while typing in the JTextField filter?

lfcnassif commented 3 years ago

Sorry, read your code with more attention now, the filter text is used when the results are updated. I though the list was filtered while typing in the JTextField, like the column manager JTextField filter. If that does not take too much time to filter the results (the code was optimized to load result values on demand while scrolling, it does not load all of them at once), I agree to integrate.

lfcnassif commented 3 years ago

I don't know how long your current approach is taking, but if it is too much, limiting to a prefix filter could be very fast.

leosol commented 3 years ago

Did some tests hitting "enter" after typing some text into the filter box. Also, did the same with the copy to clipboard button. Looks pretty good! There were 254997 indexed items in my report. In this report, if I try to copy and paste all CPFs (person ids - 325 items) to clipboard, I have to select them all. This triggers the query to the engine, but its okay and it can handle pretty fast. If I do the same with the more than 20k URL matches, the engine can't handle the search fast. I didn't measure this but I guess it took more than 4 minutes to respond.

The item "bufferSize" below is the number of chars inside the instance of a StringBufer just before sending to clipboard. The duration is calculated by taking diff of Instant.now in the start/end of each method, then logged to stdin

filterResults# elements: 325 filtered: 253 Duration: PT0.006S filterResults# elements: 325 filtered: 213 Duration: PT0.001S filterResults# elements: 325 filtered: 213 Duration: PT0.001S filterResults# elements: 325 filtered: 0 Duration: PT0.001S filterResults# elements: 20331 filtered: 14130 Duration: PT0.022S filterResults# elements: 20331 filtered: 18442 Duration: PT0.02S filterResults# elements: 20331 filtered: 134 Duration: PT0.019S copyResultsToClipboard# bufferSize: 18316 Duration: PT0.011S copyResultsToClipboard# bufferSize: 1941 Duration: PT0.002S copyResultsToClipboard# bufferSize: 1941 Duration: PT0.001S copyResultsToClipboard# bufferSize: 1941 Duration: PT0.001S copyResultsToClipboard# bufferSize: 1941 Duration: PT0.001S copyResultsToClipboard# bufferSize: 1941 Duration: PT0.001S copyResultsToClipboard# bufferSize: 43946 Duration: PT0.009S copyResultsToClipboard# bufferSize: 188 Duration: PT0S copyResultsToClipboard# bufferSize: 188 Duration: PT0.001S copyResultsToClipboard# bufferSize: 188 Duration: PT0S

lfcnassif commented 3 years ago

Looks good! Could you send a PR with the proposed changes or do you prefer me to include them in code base?

lfcnassif commented 3 years ago

closed by #485