package gui;

import graph.SequenceGraph;
import gui.sub_controllers.FileController;
import gui.sub_controllers.PanningController;
import gui.sub_controllers.SpecificGenomeProperties;
import parser.GfaParser;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Observable;
import java.util.Observer;

/**
 * Created by eric on 8-6-17.
 */
public class DrawableCanvas extends Observable implements Observer {


    private static DrawableCanvas canvas = new DrawableCanvas();

    private GfaParser parser;

    private MenuController mc;

    private  SpecificGenomeProperties specificGenomeProperties;


    private DrawableCanvas() {

    }


    public static DrawableCanvas getInstance() {
        return canvas;
    }
//            if (o instanceof GfaParser) {
//        if (arg instanceof Integer) {
//            try {
//                childArray = parser.getChildArray();
//                parentArray = parser.getParentArray();
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//            System.out.println(nodeId);
//            System.out.println(renderRange);
//            graph = new SequenceGraph();
//            graph.createSubGraph(nodeId, renderRange, parentArray, childArray);
//            sequenceHashMap = parser.getSequenceHashMap();
//            assignSequenceLenghts();
//            drawer = new GraphDrawer(graph, gc);
//            drawer.moveShapes(0.0);
//            progressBarController.done();
//        }
//    }

    public void setSpecificGenomeProperties(SpecificGenomeProperties sgp) {
        this.specificGenomeProperties = sgp;
    }
    @Override
    public void update(Observable o, Object arg) {
        if (o instanceof FileController) {
            {
                if (arg instanceof Integer) {
                    if ( ( (Integer) arg) == 0) {
                        try {
                            int[] childArray = parser.getChildArray();
                            HashMap<Integer, String> allGenomes = parser.getAllGenomesMapReversed();

                            int [] parentArray = parser.getParentArray();
                            SequenceGraph graph = new SequenceGraph(parentArray, childArray, getParser().getSequenceHashMap());
                            graph.createSubGraph(1, 1000);
                            GraphDrawer.getInstance().setGraph(graph);
                            GraphDrawer.getInstance().moveShapes(0.0);
                            setChanged();
                            notifyObservers(parser.getFilePath());
                            setChanged();
                        } catch (IOException e) {
                            e.printStackTrace();
                    }

                    }
                }
            }
        }



    }


    public void setMenuController(MenuController mc) {
        this.mc = mc;
        this.addObserver(mc);
    }
    public void setParser(GfaParser parser) {
        this.parser = parser;

    }

    public GfaParser getParser() {
        return this.parser;
    }

    public SpecificGenomeProperties getSpecificGenomeProperties() {
        return this.specificGenomeProperties;
    }
}

@@ -761,785 +761,8 @@
   %7D%0A
-//            if (o instanceof GfaParser) %7B%0A//        if (arg instanceof Integer) %7B%0A//            try %7B%0A//                childArray = parser.getChildArray();%0A//                parentArray = parser.getParentArray();%0A//            %7D catch (IOException e) %7B%0A//                e.printStackTrace();%0A//            %7D%0A//            System.out.println(nodeId);%0A//            System.out.println(renderRange);%0A//            graph = new SequenceGraph();%0A//            graph.createSubGraph(nodeId, renderRange, parentArray, childArray);%0A//            sequenceHashMap = parser.getSequenceHashMap();%0A//            assignSequenceLenghts();%0A//            drawer = new GraphDrawer(graph, gc);%0A//            drawer.moveShapes(0.0);%0A//            progressBarController.done();%0A//        %7D%0A//    %7D
 %0A%0A  

refactor drawable canvas