FileDocCategorySizeDatePackage
Scale.javaAPI DocAzureus 3.0.3.42465Sat May 20 05:36:16 BST 2006org.gudy.azureus2.ui.swt.components.graphics

Scale

public class Scale extends Object
author
Olivier

Fields Summary
private int
pixelsPerLevel
private int
max
private int
nbLevels
private int
displayedMax
private int
nbPixels
int
scaleFactor
int
powFactor
Constructors Summary
Methods Summary
private voidcomputeValues()

    int targetNbLevels = nbPixels / pixelsPerLevel;
    if(targetNbLevels < 1)
      targetNbLevels = 1;
    scaleFactor = max / targetNbLevels;
    powFactor = 1;
    while(scaleFactor >= 10) {
      powFactor = 10 * powFactor;
      scaleFactor = scaleFactor / 10;
    }
    if(scaleFactor >= 5)
      scaleFactor = 5;
    else if(scaleFactor >= 2)
      scaleFactor = 2;
    else
      scaleFactor = 1;
    
    nbLevels = max / (scaleFactor * powFactor) + 1;
    displayedMax = scaleFactor * powFactor * nbLevels;    
  
public intgetMax()

    return this.max;
  
public int[]getScaleValues()

    int[] result = new int[nbLevels+1];
    for(int i = 0 ; i < nbLevels + 1 ; i++) {
      result[i] = i * scaleFactor * powFactor;
    }
    return result;
  
public intgetScaledValue(int value)

    return(int)( ((long)value * nbPixels) / displayedMax );
  
public voidsetMax(int max)

  
      
    this.max = max;  
    if(max < 1)
      max = 1;
    computeValues();
  
public voidsetNbPixels(int nbPixels)

    this.nbPixels = nbPixels;
    if(nbPixels < 1)
      nbPixels = 1;
    computeValues();