Changeset 6476


Ignore:
Timestamp:
06/03/10 19:38:39 (9 years ago)
Author:
curtis
Message:

Add compatibility later for obsolete color options.
This should allow old macros to keep working.

Location:
trunk/components/loci-plugins/src/loci/plugins/in
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/loci-plugins/src/loci/plugins/in/Importer.java

    r6273 r6476  
    113113    options.loadOptions(); 
    114114    options.parseArg(arg); 
     115    options.checkObsoleteOptions(); 
    115116    return options; 
    116117  } 
  • trunk/components/loci-plugins/src/loci/plugins/in/ImporterOptions.java

    r6434 r6476  
    2525 
    2626package loci.plugins.in; 
     27 
     28import ij.Macro; 
    2729 
    2830import java.awt.Color; 
     
    191193  } 
    192194 
     195  /** Handles obsolete macro keys, for backward compatibility. */ 
     196  public void checkObsoleteOptions() { 
     197    String options = Macro.getOptions(); 
     198    boolean mergeChannels = checkKey(options, "merge_channels"); 
     199    boolean rgbColorize = checkKey(options, "rgb_colorize"); 
     200    boolean customColorize = checkKey(options, "custom_colorize"); 
     201    if (mergeChannels) setColorMode(COLOR_MODE_COMPOSITE); 
     202    else if (rgbColorize) setColorMode(COLOR_MODE_COLORIZED); 
     203    else if (customColorize) setColorMode(COLOR_MODE_CUSTOM); 
     204  } 
     205 
    193206  // -- ImporterOptions methods - base options accessors and mutators -- 
    194207 
     
    438451  } 
    439452 
    440   // -- Helper methods - miscellaneous -- 
     453  // -- Helper methods -- 
    441454 
    442455  private <T extends Object> void set(List<T> list, 
     
    452465  } 
    453466 
     467  /** Tests whether the given boolean key is set in the specified options. */ 
     468  private boolean checkKey(String options, String key) { 
     469    if (options == null) return false; 
     470 
     471    // delete anything inside square brackets, for simplicity 
     472    while (true) { 
     473      int lIndex = options.indexOf("["); 
     474      if (lIndex < 0) break; 
     475      int rIndex = options.indexOf("]"); 
     476      if (rIndex < 0) rIndex = options.length() - 1; 
     477      options = options.substring(0, lIndex) + options.substring(rIndex + 1); 
     478    } 
     479 
     480    // split the options string 
     481    final String[] tokens = options.split(" "); 
     482 
     483    // search for a token matching the key 
     484    for (String token : tokens) { 
     485      if (token.equals(key)) return true; 
     486    } 
     487    return false; 
     488  } 
     489 
    454490} 
Note: See TracChangeset for help on using the changeset viewer.