001    package ui.renderer;
002    
003    import java.util.List;
004    import java.util.ArrayList;
005    import javax.swing.Icon;
006    import javax.swing.ImageIcon;
007    
008    public class LineIcon {
009    
010      protected float startWavelength;
011      protected Icon absorptionIcon;
012      protected Icon emissionIcon;
013    
014      private static List<LineIcon> icons = new ArrayList<LineIcon>(); // center min max band  icon
015    
016      static {
017        icons.add(new LineIcon(3700f, "black"));   // 2000    0-3700 3700 "black"
018        icons.add(new LineIcon(4100f, "purple"));  // 4000 3700-4100  400 "purple"
019        icons.add(new LineIcon(4650f, "blue"));    // 4350 4100-4650  500 "blue"
020        icons.add(new LineIcon(5000f, "cyan"));    // 4800 4650-5000  350 "cyan"
021        icons.add(new LineIcon(5600f, "green"));   // 5250 5000-5600  600 "green"
022        icons.add(new LineIcon(5950f, "yellow"));  // 5800 5600-5950  350 "yellow"
023        icons.add(new LineIcon(6300f, "orange"));  // 6100 5950-6300  350 "orange"
024        icons.add(new LineIcon(7100f, "red"));     // 6600 6300-7100  800 "red"
025        icons.add(new LineIcon(7500f, "brown"));   // 7300 7100-7500  400 "brown"
026        icons.add(new LineIcon(9999999.0f, "black")); //   7500-inf   inf "black"
027      }
028    
029      public LineIcon(float aStartWavelength, String anIconName) {
030        startWavelength = aStartWavelength;
031        absorptionIcon = getImageIcon("images/absorption-" + anIconName + ".gif");
032        emissionIcon = getImageIcon("images/emission-" + anIconName + ".gif");
033      }
034    
035      public float getStartWavelength() {
036        return startWavelength;
037      }
038    
039      Icon getAbsorptionIcon() {
040        return absorptionIcon;
041      }
042    
043      Icon getEmissionIcon() {
044        return emissionIcon;
045      }
046    
047      public Icon getIcon(boolean emission) {
048        if (emission)
049          return getEmissionIcon();
050        else
051          return getAbsorptionIcon();
052      }
053    
054      protected static Icon getIcon(float wavelength, boolean emission) {
055        for (LineIcon lineIcon : icons) if (wavelength < lineIcon.getStartWavelength()) return lineIcon.getIcon(emission);
056        return icons.get(0).getIcon(emission);
057      }
058    
059      public static ImageIcon getImageIcon(String fileName) {
060        // TODO: handle case when images are a part of a resource such as a JAR file etc...
061        return new ImageIcon(fileName);
062      }
063    
064    }