1 19 package org.openharmonise.him.metadata.range.swing.relatedevents; 20 21 import java.awt.Color ; 22 import java.awt.event.*; 23 import java.awt.event.KeyListener ; 24 import java.util.List ; 25 26 import javax.swing.JTextArea ; 27 28 import org.openharmonise.vfs.metadata.*; 29 import org.openharmonise.vfs.metadata.range.*; 30 import org.openharmonise.vfs.metadata.value.*; 31 32 33 38 public class RelatedEventText extends JTextArea implements KeyListener { 39 40 private PropertyInstance m_propInst = null; 41 42 private static final String INVALID_TEXT = "--Invalid--"; 43 44 47 public RelatedEventText(PropertyInstance propInst) { 48 super(); 49 m_propInst = propInst; 50 setup(); 51 } 52 53 56 private void setup() { 57 this.setRows(3); 58 this.setColumns(30); 59 60 List vals = m_propInst.getValues(); 61 62 if(vals.size() > 0) { 63 StringValue val = (StringValue) vals.get(0); 64 if(val.getValue().length() > 0) { 65 this.setText(val.getValue()); 66 } 67 } else { 68 setForeground(Color.RED); 69 setText(INVALID_TEXT); 70 } 71 72 this.addKeyListener(this); 73 } 74 75 78 public void keyPressed(KeyEvent e) { 79 } 80 81 84 public void keyReleased(KeyEvent e) { 85 String sValue = getText(); 86 87 List vals = m_propInst.getValues(); 88 StringValue val = null; 89 if(vals.size()>0) { 90 val = (StringValue) vals.get(0); 91 } else { 92 val = (StringValue)m_propInst.getNewValueInstance(); 93 } 94 if(sValue != null && sValue.length() > 0) { 95 val.setValue(sValue); 96 m_propInst.setValue(val); 97 } else { 98 m_propInst.removeValue(val); 99 } 100 101 firePropertyChange(RelatedEventValueDisplay.PROPERTY_METADATA_CHANGE, null, null); 102 } 103 104 107 public void keyTyped(KeyEvent e) { 108 } 109 110 113 public boolean isMetadataValid() { 114 boolean bIsValid = false; 115 Property prop = m_propInst.getDefinition(); 116 117 StringRange range = (StringRange)prop.getRange(); 118 119 List vals = m_propInst.getValues(); 120 121 if(vals.size() > 0) { 122 bIsValid = range.validate(vals).isValid(); 123 } else { 124 bIsValid = false; 125 this.setText(INVALID_TEXT); 126 } 127 128 if(bIsValid == false) { 129 setForeground(Color.RED); 130 } else { 131 setForeground(Color.BLACK); 132 } 133 134 revalidate(); 135 136 return bIsValid; 137 } 138 139 } | Popular Tags |