Changeset 4175


Ignore:
Timestamp:
07/08/08 15:12:03 (12 years ago)
Author:
curtis
Message:

Fix some bugs and add more constructor options,
including null linked component and left/right padding.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/gui/CacheIndicator.java

    r4048 r4175  
    4040  // -- Constants -- 
    4141 
     42  private static final int COMPONENT_WIDTH = 5; 
    4243  private static final int COMPONENT_HEIGHT = 5; 
    4344 
    4445  // -- Fields -- 
    4546 
     47  private Cache cache; 
     48  private int axis; 
    4649  private Component comp; 
    47   private int axis; 
    48   private Cache cache; 
     50  private int lPad, rPad; 
    4951 
    5052  // -- Constructor -- 
     53 
     54  /** Creates a new cache indicator for the given cache. */ 
     55  public CacheIndicator(Cache cache, int axis) { 
     56    this(cache, axis, null, 0, 0); 
     57  } 
    5158 
    5259  /** 
     
    5562   * given, and the indicator will mimic its width (minus padding). 
    5663   */ 
    57   public CacheIndicator(Component c) { 
    58     comp = c; 
    59     axis = -1; 
     64  public CacheIndicator(Cache cache, int axis, 
     65    Component comp, int lPad, int rPad) 
     66  { 
     67    this.cache = cache; 
     68    this.axis = axis; 
     69    this.comp = comp; 
     70    this.lPad = lPad; 
     71    this.rPad = rPad; 
     72    cache.addCacheListener(this); 
    6073    setBackground(Color.WHITE); 
    61   } 
    62  
    63   // -- CacheIndicator API methods -- 
    64  
    65   public void setAxis(int axis) { 
    66     this.axis = axis; 
    67     repaint(); 
    6874  } 
    6975 
     
    7379//    super.paintComponent(g); 
    7480    g.setColor(Color.BLACK); 
    75     g.drawRect(0, 0, getWidth() - 1, COMPONENT_HEIGHT - 1); 
     81    int xStart = lPad, width = getWidth() - lPad - rPad; 
     82    g.drawRect(xStart, 0, width - 1, COMPONENT_HEIGHT - 1); 
    7683 
    7784    int[] lengths = cache.getStrategy().getLengths(); 
     
    8087    if (cacheLength == 0) return; 
    8188 
    82     int pixelsPerIndex = (getWidth() - 2) / (cacheLength + 1); 
    83     int remainder = (getWidth() - 2) - (pixelsPerIndex * cacheLength); 
     89    int pixelsPerIndex = (width - 2) / (cacheLength + 1); 
     90    int remainder = (width - 2) - (pixelsPerIndex * cacheLength); 
    8491 
    8592    try { 
     
    93100      System.arraycopy(currentPos, 0, pos, 0, pos.length); 
    94101 
    95       int start = 1; 
     102      int start = xStart + 1; 
    96103      for (int i=0; i<cacheLength; i++) { 
    97104        pos[axis] = i; 
     
    131138 
    132139  public Dimension getPreferredSize() { 
    133     return new Dimension(comp.getPreferredSize().width, COMPONENT_HEIGHT); 
     140    int w = comp == null ? COMPONENT_WIDTH : comp.getPreferredSize().width; 
     141    return new Dimension(w, COMPONENT_HEIGHT); 
    134142  } 
    135143 
    136144  public Dimension getMinimumSize() { 
    137     return new Dimension(comp.getMinimumSize().width, COMPONENT_HEIGHT); 
     145    int w = comp == null ? COMPONENT_WIDTH : comp.getMinimumSize().width; 
     146    return new Dimension(w, COMPONENT_HEIGHT); 
    138147  } 
    139148 
    140149  public Dimension getMaximumSize() { 
    141     return new Dimension(comp.getMaximumSize().width, COMPONENT_HEIGHT); 
     150    int w = comp == null ? Integer.MAX_VALUE : comp.getMaximumSize().width; 
     151    return new Dimension(w, COMPONENT_HEIGHT); 
    142152  } 
    143153 
Note: See TracChangeset for help on using the changeset viewer.