public SearchLayer(Dimension dim, GridLayer roadsLayer) {
        setSize(dim);
        this.roads = roadsLayer;
        visInfo = VisInfo.getInstance();
        initComponents();

        addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent me) {

                node = visInfo.findNode(me.getX(), me.getY(), getSize());
                if (node != null) {
                    if (ctx != null) {
                        if (searchFinished) {
                            updateLayer(); //clean canvas
                            searchFinished = false;
                        } else {
                            stopSearch();
                        }
                    }
                    final Node n = node;
                    highlightPoint(n, startPoint);
                    repaint();
                } else {
                    return;
                }

                if (from == null || (from != null && to != null)) {
                    from = node;
                    to = null;
                } else {
                    to = node;
                    if (node != null) {
                        node = null;
                        runSearch(from, to, alg);
                    }
                }
            }
        });
    }