<commit_before>package com.cjmalloy.torrentfs.editor.ui.swing.component;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

import javax.swing.JTabbedPane;

import com.cjmalloy.torrentfs.editor.controller.Controller;
import com.cjmalloy.torrentfs.editor.controller.EditorFileController;
import com.cjmalloy.torrentfs.editor.controller.MainController;
import com.cjmalloy.torrentfs.editor.event.DoErrorMessage;
import com.cjmalloy.torrentfs.editor.model.EditorFileModel;
import com.cjmalloy.torrentfs.editor.model.EditorFileModel.Facet;
import com.cjmalloy.torrentfs.editor.ui.swing.HasWidget;
import com.cjmalloy.torrentfs.editor.ui.swing.component.FacetEditor.FileEditorFactory;
import com.google.common.eventbus.Subscribe;


public class FileEditor implements HasWidget
{
    private static final ResourceBundle R = ResourceBundle.getBundle("com.cjmalloy.torrentfs.editor.i18n.MessageBundle");

    private JTabbedPane tabs;

    private EditorFileController controller;

    private List<Facet> facets = new ArrayList<>();
    private List<FacetEditor> facetEditors = new ArrayList<>();
    private int currentFacet;

    public FileEditor(EditorFileModel model)
    {
        this.controller = MainController.get().editor.getController(model);

        for (Facet facet : model.supportedFacets)
        {
            FacetEditor c;
            try
            {
                c = FileEditorFactory.create(facet, controller);
                facetEditors.add(c);
                getWidget().addTab(getTitle(facet), c.getWidget());
            }
            catch (IOException e)
            {
                e.printStackTrace();
                Controller.EVENT_BUS.post(new DoErrorMessage(e.getMessage()));
            }
        }
        Controller.EVENT_BUS.register(this);
    }

    public void close()
    {
        Controller.EVENT_BUS.unregister(this);
        for (FacetEditor e : facetEditors)
        {
            e.close();
        }
        tabs.removeAll();
        facetEditors.clear();
    }

    @Override
    public JTabbedPane getWidget()
    {
        if (tabs == null)
        {
            tabs = new JTabbedPane();
            tabs.setTabPlacement(JTabbedPane.BOTTOM);
        }
        return tabs;
    }

    @Subscribe
    public void update(EditorFileModel model)
    {
        if (controller.model != model) return;

        for (Facet facet : model.supportedFacets)
        {
            if (facets.contains(facet)) continue;

            FacetEditor c;
            try
            {
                c = FileEditorFactory.create(facet, controller);
                facets.add(facet);<commit_msg>Bugfixes for file editor updates.<commit_after>package com.cjmalloy.torrentfs.editor.ui.swing.component;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

import javax.swing.JTabbedPane;

import com.cjmalloy.torrentfs.editor.controller.Controller;
import com.cjmalloy.torrentfs.editor.controller.EditorFileController;
import com.cjmalloy.torrentfs.editor.controller.MainController;
import com.cjmalloy.torrentfs.editor.event.DoErrorMessage;
import com.cjmalloy.torrentfs.editor.model.EditorFileModel;
import com.cjmalloy.torrentfs.editor.model.EditorFileModel.Facet;
import com.cjmalloy.torrentfs.editor.ui.swing.HasWidget;
import com.cjmalloy.torrentfs.editor.ui.swing.component.FacetEditor.FileEditorFactory;
import com.google.common.eventbus.Subscribe;


public class FileEditor implements HasWidget
{
    private static final ResourceBundle R = ResourceBundle.getBundle("com.cjmalloy.torrentfs.editor.i18n.MessageBundle");

    private JTabbedPane tabs;

    private EditorFileController controller;

    private List<Facet> facets = new ArrayList<>();
    private List<FacetEditor> facetEditors = new ArrayList<>();
    private int currentFacet;

    public FileEditor(EditorFileModel model)
    {
        this.controller = MainController.get().editor.getController(model);
        update(model);
        Controller.EVENT_BUS.register(this);
    }

    public void close()
    {
        Controller.EVENT_BUS.unregister(this);
        for (FacetEditor e : facetEditors)
        {
            e.close();
        }
        tabs.removeAll();
        facets.clear();
        facetEditors.clear();
    }

    @Override
    public JTabbedPane getWidget()
    {
        if (tabs == null)
        {
            tabs = new JTabbedPane();
            tabs.setTabPlacement(JTabbedPane.BOTTOM);
        }
        return tabs;
    }

    @Subscribe
    public void update(EditorFileModel model)
    {
        if (controller.model != model) return;

        for (Facet facet : model.supportedFacets)
        {
            if (facets.contains(facet)) continue;

            FacetEditor c;
            try
            {
                c = FileEditorFactory.create(facet, controller);
                facets.add(facet);
{'fraction_non_alphanumeric': 0.09768378650553877, 'fraction_numerical': 0.0008056394763343404, 'mean_word_length': 2.673076923076923, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '6205649', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1427, 'n_words': 250}