public static void exportGrafoAsImage(GrafoComponent cmp, File f) throws IOException {
        
        Grafo g = cmp.grafo;
        
        HashMap<Vertice, Point> posizioniOriginali = new HashMap<>();
        int xMin = Integer.MAX_VALUE;
        int xMax = Integer.MIN_VALUE;
        int yMin = Integer.MAX_VALUE;
        int yMax = Integer.MIN_VALUE;
        for(Vertice v : g.getVertici()) {
            posizioniOriginali.put(v, new Point(v.pos.x, v.pos.y));
            if(v.pos.x < xMin) {
                xMin = v.pos.x;
            } else if(v.pos.x > xMax) {
                xMax = v.pos.x;
            }
            if(v.pos.y < yMin) {
                yMin = v.pos.y;
            } else if(v.pos.y > yMax) {
                yMax = v.pos.y;
            }
        }
        
//        System.out.println("X: " + xMin + ":" + xMax);
//        System.out.println("Y: " + yMin + ":" + yMax);
        
        int width = xMax - xMin + 100;
        int height = yMax - yMin + 100;
        
        for(Vertice v : g.getVertici()) {
            v.pos.translate(-xMin + 50, -yMin + 50);
        }
        
        BufferedImage bim = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D g2d = bim.createGraphics();
        g2d.setColor(Color.BLACK);
        cmp.paint(g2d);
        ImageIO.write(bim, "png", f);
        
        for(Vertice v : g.getVertici()) {
            v.pos = posizioniOriginali.get(v);
        }
        
    }