<commit_before>package rose.project.passmember.gui;

import rose.project.passmember.util.entry.Entry;
import rose.project.passmember.util.entry.FolderEntry;

import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;
import java.util.NoSuchElementException;

/**
 * Created by <NAME> on 07/04/2017.
 */
public class JTreeWrapper {
    private JTree GUITree;
    private DefaultMutableTreeNode passwordsTree;
    private DefaultMutableTreeNode currentSelectedNode;
    private DefaultTreeModel treeModel;

    public JTreeWrapper() {
        this.passwordsTree = new DefaultMutableTreeNode(new FolderEntry());
        this.currentSelectedNode = this.passwordsTree;
        this.GUITree = new JTree();
        this.treeModel = (DefaultTreeModel) this.getGUITree().getModel();

        this.GUITree.setCellRenderer(new CustomTreeCellRenderer());
    }

    public JTreeWrapper(DefaultMutableTreeNode root) {
        this.passwordsTree = (DefaultMutableTreeNode)root.getRoot(); // just to be sure
        this.currentSelectedNode = this.passwordsTree;
        this.GUITree = new JTree(this.passwordsTree);
        this.treeModel = (DefaultTreeModel) this.getGUITree().getModel();

        this.GUITree.setCellRenderer(new CustomTreeCellRenderer());
    }

    public JTree getGUITree() {
        return this.GUITree;
    }

    public DefaultMutableTreeNode getPasswordsTree() {
        return this.passwordsTree;
    }

    public void addEntry(Entry entry) {
        DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(entry);

        if(!this.currentSelectedNode.isRoot()) { // we always append a new node as child of its parent node
            this.currentSelectedNode = (DefaultMutableTreeNode) this.currentSelectedNode.getParent();
        }

        this.treeModel.insertNodeInto(childNode, this.currentSelectedNode, this.currentSelectedNode.getChildCount());
        this.GUITree.scrollPathToVisible(new TreePath(childNode.getPath()));<commit_msg>[BUG FIX] folders are not stored as a child of the current node's parent anymore<commit_after>package rose.project.passmember.gui;

import rose.project.passmember.util.entry.Entry;
import rose.project.passmember.util.entry.FolderEntry;

import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;
import java.util.NoSuchElementException;

/**
 * Created by <NAME> on 07/04/2017.
 */
public class JTreeWrapper {
    private JTree GUITree;
    private DefaultMutableTreeNode passwordsTree;
    private DefaultMutableTreeNode currentSelectedNode;
    private DefaultTreeModel treeModel;

    public JTreeWrapper() {
        this.passwordsTree = new DefaultMutableTreeNode(new FolderEntry());
        this.currentSelectedNode = this.passwordsTree;
        this.GUITree = new JTree();
        this.treeModel = (DefaultTreeModel) this.getGUITree().getModel();

        this.GUITree.setCellRenderer(new CustomTreeCellRenderer());
    }

    public JTreeWrapper(DefaultMutableTreeNode root) {
        this.passwordsTree = (DefaultMutableTreeNode)root.getRoot(); // just to be sure
        this.currentSelectedNode = this.passwordsTree;
        this.GUITree = new JTree(this.passwordsTree);
        this.treeModel = (DefaultTreeModel) this.getGUITree().getModel();

        this.GUITree.setCellRenderer(new CustomTreeCellRenderer());
    }

    public JTree getGUITree() {
        return this.GUITree;
    }

    public DefaultMutableTreeNode getPasswordsTree() {
        return this.passwordsTree;
    }

    public void addEntry(Entry entry) {
        DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(entry);

        if(!this.currentSelectedNode.isRoot() && !(currentSelectedNode.getUserObject() instanceof FolderEntry)) {
            // we always append a new node as child of its parent node only if it is not a folder that is currently selected
            this.currentSelectedNode = (DefaultMutableTreeNode) this.currentSelectedNode.getParent();
        }

        this.treeModel.insertNodeInto(childNode, this.currentSelectedNode, this.currentSelectedNode.getChildCount());
{'fraction_non_alphanumeric': 0.09471094710947109, 'fraction_numerical': 0.0039360393603936035, 'mean_word_length': 3.738927738927739, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2140599', 'n_tokens_mistral': 1153, 'n_tokens_neox': 1098, 'n_words': 241}