1 import java.awt.BorderLayout ; 2 import java.io.File ; 3 import java.net.MalformedURLException ; 4 5 import javax.swing.JPanel ; 6 import javax.swing.JTextField ; 7 8 import org.columba.core.facade.Facade; 9 import org.columba.core.gui.plugin.AbstractConfigPlugin; 10 import org.columba.core.xml.XmlElement; 11 import org.columba.core.xml.XmlIO; 12 13 19 public class ConfigExample extends AbstractConfigPlugin { 20 21 JTextField textField; 22 XmlElement parent; 23 24 XmlIO xmlFile; 25 28 public ConfigExample() { 29 super(); 30 31 File file = Facade.getPluginConfigFile("org.columba.example.ConfigExample"); 33 try { 34 xmlFile = new XmlIO(file.toURL()); 35 xmlFile.load(); 36 37 parent = xmlFile.getRoot(); 38 } catch (MalformedURLException e) { 39 e.printStackTrace(); 40 } 41 42 } 43 44 47 public void updateComponents(boolean b) { 48 49 50 if (b) { 51 54 XmlElement text = parent.getElement("/config/text"); 56 57 String attribute = text.getAttribute("value"); 59 60 textField.setText(attribute); 61 62 } else { 63 66 XmlElement text = parent.getElement("/config/text"); 67 text.addAttribute("value", textField.getText()); 68 69 try 70 { 71 xmlFile.save(); 72 73 } catch ( Exception ex) 74 { 75 ex.printStackTrace(); 76 } 77 } 78 79 } 80 81 84 public JPanel createPanel() { 85 86 JPanel panel = new JPanel (); 87 panel.setLayout(new BorderLayout ()); 88 89 textField = new JTextField (20); 90 panel.add(textField, BorderLayout.CENTER); 91 92 return panel; 93 } 94 95 } 96 | Popular Tags |