Exemplo n.º 1
0
 /**
  * Compile this mosaic into an optimal arrangement.
  *
  * @return true if this mosaic is used for images, false if it's empty
  */
 public boolean compile(Component progressComponent) {
   this.progressComponent = progressComponent;
   parts = partsList.toArray(new MosaicPart[partsList.size()]);
   Arrangement arrangement = new Arrangement(maxHeight, parts);
   int lastWidth = -1;
   double widthFactor = Math.log(((double) maxWidth) / minWidth);
   for (int i = 0; i < numWidths; i++) {
     int width;
     if (numWidths > 1) {
       // Increase width geometrically from minWidth to maxWidth
       double f = widthFactor * ((double) i) / (numWidths - 1);
       f = Math.exp(f) * minWidth;
       width = (int) (f + 0.5);
     } else {
       width = maxWidth;
     }
     if (width == lastWidth) {
       continue; // Don't try same width twice
     }
     lastWidth = width;
     arrangement.arrangeWithin(width);
     int pixels = arrangement.getPixelsUsed();
     if (pixels < currPixels) {
       setBestArrangement(arrangement);
     }
   }
   return currPixels > 0;
 }
Exemplo n.º 2
0
 //
 // Sets the best arrangement seen so far to the argument.
 // Copies all needed data from arrangement, so that Arrangement
 // can be subsequently modified.
 //
 void setBestArrangement(Arrangement arrangement) {
   currPixels = arrangement.getPixelsUsed();
   synchronized (parts) {
     arrangement.positionParts(parts);
     currWidth = arrangement.getWidthUsed();
     currHeight = arrangement.getHeightUsed();
   }
   Component c = progressComponent;
   if (c != null) {
     c.repaint(100L);
   }
 }