@Override
    public void paint(Graphics g) {
        g.clearRect(0, 0, getWidth(), getHeight()); //clears the screen
        int gridX = getWidth() / gridSizeX;
        int gridY = getHeight() / gridSizeY;
        int actual_grid_size = Math.min(gridX, gridY);
        if (actual_grid_size == 0) {
            return;
        }
        int tWidth = actual_grid_size * gridSizeX;
        int tHeight = actual_grid_size * gridSizeY;

        if (backgroundShow) {
            g.setColor(Color.GRAY);
            for (int i = 0; i < gridSizeX; i++) {
                for (int j = 0; j < gridSizeY; j++) {
                    g.drawLine(i*actual_grid_size, j*actual_grid_size, (i+1)*actual_grid_size, (j+1)*actual_grid_size);
                    g.drawLine(i*actual_grid_size, (j+1)*actual_grid_size, (i+1)*actual_grid_size, j*actual_grid_size);
                }
            }
        }

        for (Layer l : layers) {
            l.drawLayer(g, actual_grid_size, connectBox, gridSizeX, gridSizeY);
        }
        
        currentTool.paintSelf(g, actual_grid_size, null, curColor);

        if (showGrid) {
            g.setColor(Color.black);
            for (int i = 0; i <= actual_grid_size * gridSizeX; i += actual_grid_size) {
                g.drawLine(0, i, tWidth, i);
            }
            g.drawLine(tWidth - 1, 0, tWidth - 1, tHeight - 1);
            for (int i = 0; i <= actual_grid_size * gridSizeY; i += actual_grid_size) {
                g.drawLine(i, 0, i, tHeight);
            }
            g.drawLine(0, tHeight - 1, tWidth - 1, tHeight - 1);
        }
    }