1 package net.suberic.pooka.gui; 2 import java.awt.Component ; 3 import javax.swing.*; 4 import javax.mail.Message ; 5 import javax.mail.search.SearchTerm ; 6 import java.util.MissingResourceException ; 7 import java.util.Vector ; 8 import net.suberic.pooka.Pooka; 9 import net.suberic.pooka.SearchTermManager; 10 11 25 public class SearchTermIconManager { 26 SearchTerm [] terms; 27 Component [] icons; 28 protected Component blankImage = new JLabel(); 29 30 public SearchTermIconManager(String definitionProperty) { 31 SearchTermManager manager = Pooka.getSearchManager(); 32 createTermsAndIcons(definitionProperty, manager); 33 ((JLabel)blankImage).setOpaque(true); 34 } 35 36 39 private void createTermsAndIcons(String property, SearchTermManager manager) { 40 Vector iconVector = new Vector (); 42 Vector termVector = new Vector (); 43 44 Vector items = Pooka.getResources().getPropertyAsVector(property + ".value", ""); 45 for (int i = 0; i < items.size(); i++) { 46 String subProperty = property + "." + (String ) items.elementAt(i); 47 Component currentIcon = loadImage(Pooka.getProperty(subProperty + ".icon", "")); 48 if (currentIcon != null) { 49 SearchTerm currentTerm = null; 50 try { 51 currentTerm = createSearchTerm(subProperty , manager); 52 } catch (java.text.ParseException pe) { 53 54 } 55 if (currentTerm != null) { 56 iconVector.add(currentIcon); 57 termVector.add(currentTerm); 58 } 59 } 60 } 61 62 terms = new SearchTerm [termVector.size()]; 63 icons = new Component [iconVector.size()]; 64 for (int i = 0; i < termVector.size() ; i++) { 65 terms[i] = (SearchTerm )termVector.elementAt(i); 66 icons[i] = (Component )iconVector.elementAt(i); 67 } 68 } 69 70 73 public Component getIcon(int value) { 74 if (value < 0 || value >= icons.length || icons[value] == null) { 75 return blankImage; 76 } else 77 return icons[value]; 78 } 79 80 86 public int getValue(Message m) { 87 if (terms != null) { 88 for (int i = 0; i < terms.length; i++) { 89 if (terms[i] != null && terms[i].match(m)) 90 return i; 91 } 92 return terms.length; 93 } else 94 return -1; 95 } 96 97 100 public SearchTerm createSearchTerm(String propertyName, SearchTermManager manager) throws java.text.ParseException { 101 return manager.generateSearchTermFromProperty(propertyName); 102 } 103 104 107 public Component loadImage(String imageKey) { 108 Component returnValue = null; 109 ImageIcon icon = Pooka.getUIFactory().getIconManager().getIcon(imageKey); 110 if (icon != null) { 111 returnValue = new JLabel(icon); 112 ((JLabel)returnValue).setOpaque(true); 113 114 } else { 115 returnValue = null; 116 } 117 118 return returnValue; 119 } 120 121 } 122 | Popular Tags |