1 package org.columba.mail.gui.composer; 2 3 import java.awt.BorderLayout ; 4 import java.awt.Color ; 5 import java.awt.Font ; 6 import java.awt.event.ActionEvent ; 7 import java.awt.event.ActionListener ; 8 import java.awt.event.ItemEvent ; 9 import java.awt.event.ItemListener ; 10 import java.awt.event.MouseEvent ; 11 import java.awt.event.MouseListener ; 12 import java.io.BufferedReader ; 13 import java.io.File ; 14 import java.io.FileReader ; 15 import java.io.IOException ; 16 import java.util.Observable ; 17 import java.util.Observer ; 18 19 import javax.swing.BorderFactory ; 20 import javax.swing.JButton ; 21 import javax.swing.JPanel ; 22 import javax.swing.JTextArea ; 23 import javax.swing.UIManager ; 24 import javax.swing.text.JTextComponent ; 25 26 import org.columba.core.config.Config; 27 import org.columba.core.gui.base.RoundedBorder; 28 import org.columba.core.gui.util.FontProperties; 29 import org.columba.core.xml.XmlElement; 30 import org.columba.mail.config.AccountItem; 31 import org.columba.mail.gui.config.account.EditSignatureAction; 32 33 public class SignatureView extends JPanel implements MouseListener , 34 ItemListener , Observer { 35 36 private ComposerController controller; 37 38 private AccountItem item; 39 40 private JTextComponent textPane; 41 42 private JButton button; 43 44 public SignatureView(ComposerController controller) { 45 super(); 46 47 this.controller = controller; 48 49 setLayout(new BorderLayout ()); 50 51 setBackground(UIManager.getColor("TextArea.background")); 52 53 setBorder(BorderFactory 54 .createEmptyBorder(8,8,8,8)); 55 56 JPanel centerPanel = new JPanel (); 57 centerPanel.setBackground(UIManager.getColor("TextArea.background")); 58 59 centerPanel.setBorder(BorderFactory.createCompoundBorder( new RoundedBorder(new Color ( 60 220, 220, 220)), BorderFactory 61 .createEmptyBorder(8,8,8,8))); 62 centerPanel.setLayout(new BorderLayout ()); 63 64 add(centerPanel, BorderLayout.CENTER); 65 66 72 button = new JButton ("Edit Signature..."); 73 button.addActionListener(new ActionListener () { 74 public void actionPerformed(ActionEvent event) { 75 new EditSignatureAction(SignatureView.this.controller, item) 76 .actionPerformed(null); 77 } 78 }); 79 80 JPanel topPanel = new JPanel (); 81 82 topPanel.setBackground(UIManager.getColor("TextArea.background")); 83 topPanel.setLayout(new BorderLayout ()); 84 topPanel.setBorder(BorderFactory.createEmptyBorder(0,0,8,0)); 85 86 topPanel.add(button, BorderLayout.WEST); 87 88 centerPanel.add(topPanel, BorderLayout.NORTH); 89 90 textPane = new JTextArea (); 91 92 centerPanel.add(textPane, BorderLayout.CENTER); 93 94 textPane.setEditable(false); 95 textPane.setBackground(UIManager.getColor("TextArea.background")); 96 textPane.addMouseListener(this); 98 99 Font font = FontProperties.getTextFont(); 100 setFont(font); 101 102 XmlElement options = Config.getInstance().get("options").getElement( 103 "/options"); 104 XmlElement gui = options.getElement("gui"); 105 XmlElement fonts = gui.getElement("fonts"); 106 107 if (fonts == null) { 108 fonts = gui.addSubElement("fonts"); 109 } 110 111 fonts.addObserver(this); 113 114 item = (AccountItem) controller.getAccountController().getView() 115 .getSelectedItem(); 116 117 if (item.getIdentity().getSignature() != null) 118 readSignature(item.getIdentity().getSignature()); 119 120 controller.getAccountController().getView().addItemListener(this); 122 123 item.getIdentity().addObserver(this); 125 126 } 127 128 public void itemStateChanged(ItemEvent e) { 129 if (e.getStateChange() == ItemEvent.SELECTED) { 130 131 item.getIdentity().removeObserver(this); 133 134 item = (AccountItem) controller.getAccountController().getView() 135 .getSelectedItem(); 136 if (item.getIdentity().getSignature() != null) { 137 readSignature(item.getIdentity().getSignature()); 138 } else { 139 textPane.setText(""); 140 } 141 142 item.getIdentity().addObserver(this); 144 145 } 146 147 } 148 149 155 private void readSignature(File signatureFile) { 156 StringBuffer strbuf = new StringBuffer (); 157 158 try { 159 BufferedReader in = new BufferedReader ( 160 new FileReader (signatureFile)); 161 String str; 162 163 while ((str = in.readLine()) != null) { 164 strbuf.append(str + "\n"); 165 } 166 167 in.close(); 168 169 textPane.setText(strbuf.toString()); 170 171 } catch (IOException ex) { 172 textPane.setText(""); 173 } 174 } 175 176 public void mouseClicked(MouseEvent event) { 177 if ((event.getModifiers() & MouseEvent.BUTTON1_MASK) != 0 178 && item != null) { 179 if (event.getClickCount() >= 2) { 180 new EditSignatureAction(controller, item).actionPerformed(null); 181 } 182 } 183 } 184 185 public void mouseEntered(MouseEvent e) { 186 188 } 189 190 public void mouseExited(MouseEvent e) { 191 193 } 194 195 public void mousePressed(MouseEvent e) { 196 198 } 199 200 public void mouseReleased(MouseEvent e) { 201 203 } 204 205 211 public void update(Observable arg0, Object arg1) { 212 Font font = FontProperties.getTextFont(); 213 setFont(font); 214 215 readSignature(item.getIdentity().getSignature()); 216 } 217 218 } 219 | Popular Tags |