<commit_before>/*
 * Copyright 2008-2010 by <NAME>
 *
 *     This file is part of Java Melody.
 *
 * Java Melody is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Java Melody is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Java Melody.  If not, see <http://www.gnu.org/licenses/>.
 */
package net.bull.javamelody;

import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.Map;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import net.bull.javamelody.swing.MButton;
import net.bull.javamelody.swing.Utilities;
import net.bull.javamelody.swing.util.MSwingUtilities;

/**
 * Panel des graphiques principaux.
 * @author <NAME>
 */
class ChartsPanel extends MelodyPanel {
	static final ImageIcon PLUS_ICON = ImageIconCache.getImageIcon("bullets/plus.png");
	static final ImageIcon MINUS_ICON = ImageIconCache.getImageIcon("bullets/minus.png");

	private static final long serialVersionUID = 1L;

	private static final Cursor HAND_CURSOR = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
	private static final int NB_COLS = 3;
	private static final int CHART_HEIGHT = 50;
	private static final int CHART_WIDTH = 200;

	private JPanel otherJRobinsPanel;

	ChartsPanel(RemoteCollector remoteCollector) throws IOException {
		super(remoteCollector);

		final Map<String, byte[]> jrobins = getRemoteCollector().collectJRobins(CHART_WIDTH,
				CHART_HEIGHT);
		final JPanel mainJRobinsPanel = createJRobinPanel(jrobins);
		add(mainJRobinsPanel, BorderLayout.NORTH);
		add(createButtonsPanel(), BorderLayout.CENTER);
	}

	private JPanel createJRobinPanel(Map<String, byte[]> jrobins) {
		final JPanel centerPanel = new JPanel(new GridLayout(-1, NB_COLS));
		centerPanel.setOpaque(false);<commit_msg>ajout SwingWorker pour afficher le reste de l'écran et pour éviter de faire attendre rien que pour les graphiques<commit_after>/*
 * Copyright 2008-2010 by <NAME>
 *
 *     This file is part of Java Melody.
 *
 * Java Melody is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Java Melody is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Java Melody.  If not, see <http://www.gnu.org/licenses/>.
 */
package net.bull.javamelody;

import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.Map;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.SwingWorker;

import net.bull.javamelody.swing.MButton;
import net.bull.javamelody.swing.Utilities;
import net.bull.javamelody.swing.util.MSwingUtilities;

/**
 * Panel des graphiques principaux.
 * @author <NAME>
 */
class ChartsPanel extends MelodyPanel {
	static final ImageIcon PLUS_ICON = ImageIconCache.getImageIcon("bullets/plus.png");
	static final ImageIcon MINUS_ICON = ImageIconCache.getImageIcon("bullets/minus.png");

	private static final long serialVersionUID = 1L;

	private static final Cursor HAND_CURSOR = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
	private static final ImageIcon THROBBER_ICON = new ImageIcon(
			ChartsPanel.class.getResource("/icons/throbber.gif"));
	private static final int NB_COLS = 3;
	private static final int CHART_HEIGHT = 50;
	private static final int CHART_WIDTH = 200;

	private JPanel otherJRobinsPanel;

	ChartsPanel(RemoteCollector remoteCollector) {
		super(remoteCollector);

		final JLabel throbberLabel = new JLabel(THROBBER_ICON);
		add(throbberLabel, BorderLayout.NORTH);
		add(createButtonsPanel(), BorderLayout.CENTER);

		// SwingWorker pour afficher le reste de l'écran et pour éviter de faire attendre rien que pour les graphiques
		final SwingWorker<Map<String, byte[]>, Object> swingWorker = new SwingWorker<Map<String, byte[]>, Object>() {
			@Override
			protected Map<String, byte[]> doInBackground() throws IOException {
				return getRemoteCollector().collectJRobins(CHART_WIDTH, CHART_HEIGHT);
			}

			@Override
			protected void done() {
				try {
					final Map<String, byte[]> jrobins = get();
					final JPanel mainJRobinsPanel = createJRobinPanel(jrobins);
					remove(throbberLabel);
					add(mainJRobinsPanel, BorderLayout.NORTH);
					revalidate();
				} catch (final Exception e) {
					MSwingUtilities.showException(e);
				}
			}
		};
		swingWorker.execute();
	}

	final JPanel createJRobinPanel(Map<String, byte[]> jrobins) {
		final JPanel centerPanel = new JPanel(new GridLayout(-1, NB_COLS));
		centerPanel.setOpaque(false);
{'fraction_non_alphanumeric': 0.08844133099824869, 'fraction_numerical': 0.005954465849387041, 'mean_word_length': 4.786220871327254, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, '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': '4670357', 'n_tokens_mistral': 1845, 'n_tokens_neox': 1705, 'n_words': 543}