1 7 package org.ejtools.adwt.editor; 8 9 import java.awt.Component ; 10 import java.io.ByteArrayInputStream ; 11 import java.io.ByteArrayOutputStream ; 12 import java.io.IOException ; 13 import java.util.Properties ; 14 15 import javax.swing.JTextArea ; 16 17 24 public class PropertiesEditor extends GenericEditor 25 { 26 27 public PropertiesEditor() 28 { 29 this.value = new Properties (); 30 } 31 32 33 38 public String getAsText() 39 { 40 ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream (); 41 try 42 { 43 ((Properties ) this.value).store(bytearrayoutputstream, ""); 44 } 45 catch (IOException ioe) 46 { 47 } 48 return bytearrayoutputstream.toString(); 49 } 50 51 52 57 public Component getCustomEditor() 58 { 59 return new PropertiesView(); 60 } 61 62 63 68 public void setAsText(String s) 69 { 70 try 71 { 72 ((Properties ) this.value).load(new ByteArrayInputStream (s.getBytes())); 73 this.firePropertyChange(); 74 } 75 catch (IOException ioe) 76 { 77 } 78 } 79 80 81 86 public boolean supportsCustomEditor() 87 { 88 return true; 89 } 90 91 92 98 protected class PropertiesView extends JTextArea 99 { 100 101 public PropertiesView() 102 { 103 super(10, 40); 104 this.setText(PropertiesEditor.this.getAsText()); 105 } 106 } 107 } 108 | Popular Tags |