private int getSumOfColorValues(Cube cube, Colors colorWithLongestDistance) {
   int sum = 0;
   for (Pixel p : cube.getHistogram().getHistogram()) {
     sum += p.getCount();
   }
   return sum;
 }
    public void paintComponent(Graphics g) {

      int lengthOfQuader = windowLength / palette.size();
      int x = 0;
      for (Pixel pixel : palette) {
        Color c = new Color(pixel.getR(), pixel.getG(), pixel.getB());
        g.setColor(c);
        g.fillRect(x * lengthOfQuader, 0, lengthOfQuader, windowHeight);
        x++;
      }
    }
  private ArrayList<Cube> medianCut(Histogram histogram, int countfOfCubes) {
    ArrayList<Cube> cubeList = new ArrayList<>();

    Cube initialCube = new Cube(histogram);
    initialCube.shrink();
    cubeList.add(initialCube);

    do {
      Cube cube = this.getBiggestCube(cubeList);
      cubeList.remove(cube);
      Colors colorWithLongestDistance = cube.getLongestDistance();

      sortHistogram(cube, colorWithLongestDistance);

      int colorValueSum = this.getSumOfColorValues(cube, colorWithLongestDistance);

      Histogram histogramOfChildCube1 = new Histogram();
      Histogram histogramOfChildCube2 = new Histogram();

      int sum = 0;
      for (Pixel p : cube.getHistogram().getHistogram()) {
        sum += p.getCount();
        if (sum <= colorValueSum / 2) {
          histogramOfChildCube1.add(p);
        } else {
          histogramOfChildCube2.add(p);
        }
      }

      Cube childCube1 = new Cube(histogramOfChildCube1);
      childCube1.shrink();
      Cube childCube2 = new Cube(histogramOfChildCube2);
      childCube2.shrink();

      cubeList.add(childCube1);
      cubeList.add(childCube2);
    } while (cubeList.size() < countfOfCubes);
    return cubeList;
  }