/*
TODO... work in progress, singlrton project nmanager
 */
package org.neuroph.easyneurons;

import org.neuroph.core.NeuralNetwork;
import org.neuroph.core.learning.TrainingSet;
import org.neuroph.util.plugins.LabelsPlugin;

/**
 *
 * @author zoran
 */
public class ProjectManager {

    public static ProjectManager instance;
    private EasyNeuronsProject easyNeuronsProject;

    public ProjectManager(EasyNeuronsProject easyNeuronsProject) {
        this.easyNeuronsProject = easyNeuronsProject;
        this.instance = this;
    }

    public static ProjectManager getInstance() {
        return instance;
    }

    public void addNewNetworkToProject(NeuralNetwork nnet) {
        int count = easyNeuronsProject.getNeuralNetworks().size() + 1;
        LabelsPlugin labels = (LabelsPlugin) nnet.getPlugin("LabelsPlugin");
        if ((labels.getLabel(nnet) == null) || (labels.getLabel(nnet).equals(""))) {
            labels.setLabel(nnet, "NewNetwork" + count);
        }

        this.addNetworkToProject(nnet);
    }

    public void addNetworkToProject(NeuralNetwork nnet) {
        easyNeuronsProject.addNeuralNetwork(nnet);
        EasyNeuronsApplicationView.getInstance().updateProjectTree();
        EasyNeuronsApplicationView.getInstance().openNetworkViewFrame(nnet);
    }

    public void updateTrainingSets(TrainingSet trainingSet) {
        if (!easyNeuronsProject.getTrainingSets().contains(trainingSet)) {
            easyNeuronsProject.addTrainingSet(trainingSet);
        }
        EasyNeuronsApplicationView.getInstance().updateProjectTree();
    }
}
