Changeset 2883


Ignore:
Timestamp:
06/18/07 13:30:25 (12 years ago)
Author:
curtis
Message:

Clean up code and add javadocs; eliminate reliance on dubious
(probably platform-specific) file chooser property.

File:
1 edited

Legend:

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

    r2881 r2883  
    3838 
    3939/** 
    40  * PreviewPane is a ... 
     40 * PreviewPane is a panel for use as a JFileChooser accessory, displaying 
     41 * a thumbnail for the selected image, loaded in a separate thread. 
    4142 */ 
    4243public class PreviewPane extends JPanel 
     
    4647  // -- Fields -- 
    4748 
    48   private IFormatReader reader; 
    49   private JLabel iconLabel, resLabel, zctLabel, typeLabel; 
    50   private Thread loader; 
    51   private boolean loaderAlive; 
     49  /** Reader for use when loading thumbnails. */ 
     50  protected IFormatReader reader; 
     51 
     52  /** Labels containing thumbnail and dimensional information. */ 
     53  protected JLabel iconLabel, resLabel, zctLabel, typeLabel; 
     54 
     55  /** Thumbnail loading thread. */ 
     56  protected Thread loader; 
     57 
     58  /** Flag indicating whether loader thread should keep running. */ 
     59  protected boolean loaderAlive; 
     60 
     61  /** Current ID to load. */ 
     62  protected String loadId; 
     63 
     64  /** Last ID loaded. */ 
     65  protected String lastId; 
    5266 
    5367  // -- Constructors -- 
    5468 
    55   public PreviewPane() { 
    56     this(null); 
    57   } 
    58  
     69  /** Constructs a preview pane for the given file chooser. */ 
    5970  public PreviewPane(JFileChooser jc) { 
    6071    super(); 
     
    8293      jc.setAccessory(this); 
    8394      jc.addPropertyChangeListener(this); 
    84     } 
    85   } 
    86  
    87   // -- Componenet API methods -- 
    88  
    89   public Dimension getPreferredSize() { 
    90     Dimension prefSize = super.getPreferredSize(); 
    91     return new Dimension(128, prefSize.height); 
    92   } 
    93  
    94   // -- PropertyChangeListener API methods -- 
    95  
    96   public void propertyChange(PropertyChangeEvent e) { 
    97     String prop = e.getPropertyName(); 
    98     if (prop.equals("AccessibleDescription")) { 
     95 
    9996      // start separate loader thread 
    10097      loaderAlive = true; 
     
    10299      loader.start(); 
    103100    } 
    104     else if (prop.equals("JFileChooserDialogIsClosingProperty")) { 
    105       // stop separate loader thread 
     101  } 
     102 
     103  // -- Componenet API methods -- 
     104 
     105  /* @see java.awt.Component.getPreferredSize() */ 
     106  public Dimension getPreferredSize() { 
     107    Dimension prefSize = super.getPreferredSize(); 
     108    return new Dimension(128, prefSize.height); 
     109  } 
     110 
     111  // -- PropertyChangeListener API methods -- 
     112 
     113  /** 
     114   * Property change event, to listen for when a new 
     115   * file is selected, or the file chooser closes. 
     116   */ 
     117  public void propertyChange(PropertyChangeEvent e) { 
     118    String prop = e.getPropertyName(); 
     119    if (prop.equals("JFileChooserDialogIsClosingProperty")) { 
     120      // notify loader thread that it should stop 
    106121      loaderAlive = false; 
    107       try { loader.join(); } 
    108       catch (InterruptedException exc) { LogTools.trace(exc); } 
    109122    } 
    110123 
     
    119132  // -- Runnable API methods -- 
    120133 
    121   protected String loadId, lastId; 
    122  
     134  /** Thumbnail loading routine. */ 
    123135  public void run() { 
    124136    while (loaderAlive) { 
     
    153165 
    154166      iconLabel.setIcon(id == null ? null : 
    155         new ImageIcon(makeImage(reader, "Loading..."))); 
     167        new ImageIcon(makeImage("Loading..."))); 
    156168      resLabel.setText(reader.getSizeX() + " x " + reader.getSizeY()); 
    157169      zctLabel.setText(reader.getSizeZ() + "Z x " + 
     
    169181      catch (IOException exc) { LogTools.trace(exc); } 
    170182      iconLabel.setIcon(new ImageIcon(thumb == null ? 
    171         makeImage(reader, "Failed") : thumb)); 
     183        makeImage("Failed") : thumb)); 
    172184      repaint(); 
    173185    } 
    174186  } 
    175187 
    176   public BufferedImage makeImage(IFormatReader reader, String message) { 
     188  // -- Helper methods -- 
     189 
     190  /** 
     191   * Creates a blank image with the given message painted on top (e.g., 
     192   * a loading or error message), matching the size of the active reader's 
     193   * thumbnails. 
     194   */ 
     195  private BufferedImage makeImage(String message) { 
    177196    int w = reader.getThumbSizeX(), h = reader.getThumbSizeY(); 
    178197    if (w < 128) w = 128; 
Note: See TracChangeset for help on using the changeset viewer.