1 package net.suberic.util.gui.propedit; 2 import java.util.*; 3 4 8 public class PropertyTranslatorFilter extends PropertyEditorAdapter implements ConfigurablePropertyEditorListener { 9 10 Map<String ,String > translator = new HashMap<String ,String >(); 11 String sourceProperty = null; 12 PropertyEditorManager manager = null; 13 14 17 public void configureListener(String key, String property, String propertyBase, String editorTemplate, PropertyEditorManager pManager) { 18 manager = pManager; 19 List<String > translatorKeys = manager.getPropertyAsList(key + ".map", ""); 21 for (String translatorKey: translatorKeys) { 22 String [] pair = translatorKey.split("="); 23 if (pair != null && pair.length == 2) { 24 translator.put(pair[0], pair[1]); 26 } 27 } 28 29 sourceProperty = manager.getProperty(key + ".sourceProperty", ""); 30 if (sourceProperty.startsWith(".")) { 31 sourceProperty = propertyBase + sourceProperty; 32 } 33 } 34 35 39 public void propertyInitialized(PropertyEditorUI source, String property, String newValue) { 40 Properties currentProperties = source.getValue(); 42 String currentValue = currentProperties.getProperty(property); 43 if (newValue.equals(currentValue) || currentValue == null || currentValue.equals("")) { 45 if (sourceProperty != null && ! sourceProperty.equals("")) { 46 if (newValue == "") { 48 String testValue = manager.getProperty(sourceProperty, ""); 50 String translatedValue = translator.get(testValue); 52 if (translatedValue != null) { 53 source.setOriginalValue(translatedValue); 55 } 56 } 57 } else { 58 String translatedValue = translator.get(newValue); 59 if (translatedValue != null) { 61 source.setOriginalValue(translatedValue); 62 } 64 } 65 } else { 66 } 68 } 69 70 } 71 | Popular Tags |