<commit_before>/*
 * Copyright 2014 JBoss by Red Hat.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.optaplanner.benchmark.impl.aggregator.swingui;

import java.awt.Color;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Enumeration;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;

import static org.optaplanner.benchmark.impl.aggregator.swingui.MixedCheckBox.MixedCheckBoxStatus.*;

public class CheckBoxTree extends JTree {

    public CheckBoxTree(DefaultMutableTreeNode root) {
        super(root);
        addMouseListener(new CheckboxTreeMouseListener(this));
        setCellRenderer(new CheckboxTreeCellRenderer());
        setToggleClickCount(0);
    }

        public void expandAllNodes() {
        for (int i = 0; i < getRowCount(); i++) {
            expandRow(i);
        }
    }

    public void collapseAllNodes() {
        // clear all sub-expansions
        for (int i = getRowCount() - 1; i > 0; i--) {
            collapseRow(i);
        }
    }

    private static class CheckboxTreeMouseListener extends MouseAdapter {

        private CheckBoxTree tree;

        public CheckboxTreeMouseListener(CheckBoxTree tree) {
            this.tree = tree;
        }

        @Override
        public void mousePressed(MouseEvent e) {
            TreePath path = tree.getPathForLocation(e.getX(), e.getY());
            if (path != null) {
                DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) path.getLastPathComponent();
                MixedCheckBox checkBox = (MixedCheckBox) currentNode.getUserObject();
                switch (checkBox.getStatus()) {
                    case CHECKED: {
                        checkBox.setStatus(UNCHECKED);
                        selectChildren(currentNode, UNCHECKED);
                        TreeNode[] ancestorNodes = currentNode.getPath();<commit_msg>Fixed formatting<commit_after>/*
 * Copyright 2014 JBoss by Red Hat.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.optaplanner.benchmark.impl.aggregator.swingui;

import java.awt.Color;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Enumeration;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;

import static org.optaplanner.benchmark.impl.aggregator.swingui.MixedCheckBox.MixedCheckBoxStatus.*;

public class CheckBoxTree extends JTree {

    public CheckBoxTree(DefaultMutableTreeNode root) {
        super(root);
        addMouseListener(new CheckboxTreeMouseListener(this));
        setCellRenderer(new CheckboxTreeCellRenderer());
        setToggleClickCount(0);
    }

    public void expandAllNodes() {
        for (int i = 0; i < getRowCount(); i++) {
            expandRow(i);
        }
    }

    public void collapseAllNodes() {
        // clear all sub-expansions
        for (int i = getRowCount() - 1; i > 0; i--) {
            collapseRow(i);
        }
    }

    private static class CheckboxTreeMouseListener extends MouseAdapter {

        private CheckBoxTree tree;

        public CheckboxTreeMouseListener(CheckBoxTree tree) {
            this.tree = tree;
        }

        @Override
        public void mousePressed(MouseEvent e) {
            TreePath path = tree.getPathForLocation(e.getX(), e.getY());
            if (path != null) {
                DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) path.getLastPathComponent();
                MixedCheckBox checkBox = (MixedCheckBox) currentNode.getUserObject();
                switch (checkBox.getStatus()) {
                    case CHECKED: {
                        checkBox.setStatus(UNCHECKED);
                        selectChildren(currentNode, UNCHECKED);
                        TreeNode[] ancestorNodes = currentNode.getPath();
{'fraction_non_alphanumeric': 0.08858536585365853, 'fraction_numerical': 0.0046829268292682925, 'mean_word_length': 2.78023598820059, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6208254', 'n_tokens_mistral': 1403, 'n_tokens_neox': 1345, 'n_words': 388}