public void mouseClicked(MouseEvent e) {
            super.mouseClicked(e);
                try{
                    newNeuronButton.removeActionListener(newNeuronL);
                    newNeuron.removeActionListener(newNeuronL);
                    setCursor(defaultCursor);
                    int posX = e.getX()-15;
                    int posY = e.getY()-75;
                    if(posX < bg.getX() || posY < bg.getY() || posX > bg.getWidth() || posY>bg.getHeight()){
                        JOptionPane.showMessageDialog(PathFinder.this, "Du måste klicka på kartan!");
                    }else{
                        JPanel neuronPanel = new JPanel(new GridLayout(2,1));
                        JLabel neuronLabel = new JLabel("Vad ska platsen heta?");
                        JTextField neuronField = new JTextField(10);
                        neuronPanel.add(neuronLabel);
                        neuronPanel.add(neuronField);
                        int result = JOptionPane.showOptionDialog(PathFinder.this, neuronPanel,
                                "Ny plats",JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[]{"OK", "Cancel"}, neuronField);
                        if (result == JOptionPane.OK_OPTION){
                            String neuronName = neuronField.getText();
                            if ((neuronName !=null) & (neuronName.length() > 0)) {
                                Neuron newestNeuron = new Neuron(posX,posY,neuronName,PathFinder.this);
                                layerPanel.add(newestNeuron);
                                layerPanel.moveToFront(newestNeuron);
                                neuronListGraph.add(newestNeuron);
                                hasChanges =  true;
                                allowNewNeuron = true;
                                validate();
                                repaint();
                                pack();
                            }
                        }
                    }
                    newNeuronButton.addActionListener(newNeuronL);
                    newNeuron.addActionListener(newNeuronL);
                }catch(NullPointerException n){
                    JOptionPane.showMessageDialog(win, "Du måste ange ett namn!");
                }

            removeMouseListener(mListener);
        }
    }
    private class NewNeuronListener implements ActionListener ,Serializable{
        @Override
        public void actionPerformed(ActionEvent e) {
                setCursor(crosshairCursor); //setCursor(int) is depricated
                addMouseListener(mListener);
        }
    }
    private class MyWindowListener extends WindowAdapter implements ActionListener,Serializable {
        @Override
        public void windowClosing(WindowEvent e) {
            super.windowClosing(e);
            handleExit();
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            handleExit();
        }
        private void handleExit() {
            if(!hasChanges){
                System.exit(0);
            }
            Boolean[] result = confirmExit(win);
            if (result[1]) { //användaren ville spara
                try {
                    save();
                }catch(Exception saveError) {
                    JOptionPane.showMessageDialog(win,saveError,"Något gick fel",JOptionPane.ERROR_MESSAGE);
                    result[0]=false;
                }
            }
            if (result[0]) {  //användaren ville exita
                System.exit(0);
            }
        }
    }
    private class EditPathListener implements ActionListener,Serializable{
        @Override
        public void actionPerformed(ActionEvent e) {
            editPath();
        }
    }
    private class ShowPathListener implements ActionListener,Serializable{
        public void alert(Neuron n1,Neuron n2){
            int answer = JOptionPane.showConfirmDialog(win,
                    "Finns ingen förbindelse mellan,"+n1.getName()+" och "+n2.getName()+"vill du skapa en?", "Ooops!",
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            if (answer == JOptionPane.YES_OPTION) {
                createNewPath();
            }
        }
        @Override
        public void actionPerformed(ActionEvent e) {
            Neuron n1 = null;
            Neuron n2 = null;
            try{
                NeuronPair pair = getSelectedNeuronPair();
                n1 = (Neuron)pair.getN1();
                n2 = (Neuron)pair.getN2();
                pair = neuronListGraph.getNeuronPair(n1,n2);
                neuronListGraph.showViewEdgeDialog(win, pair);
            }catch (NoSuchElementException | NullPointerException nee){
                alert(getFirstSelectedNeuron(),getLastSelectedNeuron());
            }
        }
    }
    private class FindPathListener implements ActionListener,Serializable{
        @Override
        public void actionPerformed(ActionEvent e) {
            if(!GraphMethods.pathExists(neuronListGraph, getFirstSelectedNeuron(), getLastSelectedNeuron(), neuronListGraph)){
                JOptionPane.showMessageDialog(win,"Finns tyvärr ingen väg");
                return;
            }
            displayPath();
        }
    }
    @Override
    public void repaint(long time, int x, int y, int width, int height) {

        super.repaint(time, x, y, width, height);
    }
    private void displayPath() {
        //Fetches a list of Edges really but we neither cant(not allowed due to specs) or need to cast them here anyway
        List<?> path = GraphMethods.getPath(neuronListGraph, getFirstSelectedNeuron(), getLastSelectedNeuron(), neuronListGraph);

        //for the jlist we need them in an object array
        Object[] arr = convertListToArray(path);
        //since we are not allowed to cast to edges here we have to send it to the graphmethods that does the work for us
        int totalTime = GraphMethods.getTotalPathTime(path);
        //init components
        JList<Object> list = new JList<>(arr);
        JScrollPane listScroller = new JScrollPane(list);
        JButton editThisPath = new JButton("Ändra vald förbindelse");
        JDialog dialog = new JDialog(win,"Snabbaste vägen tog "+totalTime,true); //I just happend to think JDialogs are the cutest option

        list.clearSelection();//just to make sure if some randow bug could appear
        list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);//only one selected is allowed
        //styles, because default is boring right?
        list.setBackground(new Color(0, 136, 204));
        list.setForeground(new Color(230, 230, 230));
        list.setFont(new Font("Serif", Font.PLAIN, 20));
        list.setMinimumSize(new Dimension(dialog.getWidth(), 100));

        editThisPath.setBackground(new Color(98, 196, 98));
        editThisPath.setForeground(Color.WHITE);

        dialog.add(listScroller, BorderLayout.PAGE_START);//kompass options etc is "depricated" but still working old style so I _try_ to remember that everywher
        dialog.add(editThisPath, BorderLayout.CENTER);
        editThisPath.addActionListener(new ListPathListener(dialog, path, list));
        dialog.pack();
        dialog.setVisible(true);
    }
    private class ListPathListener implements ActionListener,Serializable {
        private JList<?> list;
        private List<?> path;
        private JDialog dialog;

        private ListPathListener(JDialog dialog,List<?> path, JList<?> list) {
            this.list = list;
            this.path = path;
            this.dialog = dialog;
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            int index = list.getSelectedIndex();
            for (int i = 0; i < path.size(); i++) {
                if(index==i){
                    NeuronPair<Neuron> found = neuronListGraph.findEdge(path.get(i));
                    if(found != null){
                        neuronListGraph.showEditEdgeDialog(win, found);
                        dialog.pack();
                    }
                }
            }

        }
    }
    private class NewPathListener implements ActionListener,Serializable{
        @Override
        public void actionPerformed(ActionEvent e) {
             NeuronPair np = neuronListGraph.getNeuronPair(getFirstSelectedNeuron(),getLastSelectedNeuron());
            if(np==null)
                createNewPath();
            else
                JOptionPane.showMessageDialog(win, "Det finns tyvärr redan en förbindelse");
        }
    }
    private class ExitListener implements ActionListener,Serializable {
        @Override
        public void actionPerformed(ActionEvent e) {
            if(hasChanges)
                confirmExit(win, true);
            else
                System.exit(0);
        }