1 package SnowMailClient.model.accounts; 2 3 import SnowMailClient.utils.*; 4 import snow.utils.storage.*; 5 6 import java.util.*; 7 import javax.swing.*; 8 import javax.swing.text.*; 9 import java.awt.*; 10 import java.awt.event.*; 11 12 13 15 public final class AccountLog implements Vectorizable 16 { 17 18 public DefaultStyledDocument doc = new DefaultStyledDocument(); 19 20 21 public int maxLength = 30000; 23 24 public AccountLog() 25 { 26 initStyles(); 28 } 29 30 31 public void appendReadLine(String str, boolean wasEncrypted) 32 { 33 if(wasEncrypted) 34 { 35 appendStyled("R> "+str+"\n", "readEncrypted"); 36 } 37 else 38 { 39 appendStyled("R> "+str+"\n", "readNotEncrypted"); 40 } 41 } 42 43 44 public void appendSendLine(String str, boolean wasEncrypted) 45 { 46 if(wasEncrypted) 47 { 48 appendStyled("S> "+str+"\n", "sendEncrypted"); 49 } 50 else 51 { 52 appendStyled("S> "+str+"\n", "sendNotEncrypted"); 53 } 54 } 55 56 57 58 public void appendComment(String str) 59 { 60 appendStyled(str+"\n","comment"); 61 } 62 63 64 public void appendError(String str) 65 { 66 appendStyled(str+"\n","error"); 67 } 68 69 70 public void appendLine(String str) 71 { 72 appendStyled(str+"\n","regular"); 73 } 74 75 public void append(String str) 76 { 77 appendStyled(str,"regular"); 78 } 79 80 public void appendStyled(String str, String style) 81 { 82 if (doc != null) 83 { 84 try 85 { 86 doc.insertString(doc.getLength(), str, doc.getStyle(style)); 87 } 88 catch (BadLocationException e) { e.printStackTrace(); } 89 checkLength(); 90 } 91 } 92 93 94 95 public void checkLength() 96 { 97 if(doc.getLength()>maxLength) 98 { 99 try 100 { 101 doc.remove(0, doc.getLength()-maxLength); 102 } 103 catch (BadLocationException e) { e.printStackTrace(); } 104 } 105 } 106 107 108 109 protected void initStyles() 110 { 111 Style def = StyleContext.getDefaultStyleContext(). 113 getStyle(StyleContext.DEFAULT_STYLE); 114 115 StyleConstants.setFontSize(def, 11); 116 117 Style regular = doc.addStyle("regular", def); 118 StyleConstants.setFontFamily(def, "SansSerif"); 119 120 Style s = doc.addStyle("italic", regular); 121 StyleConstants.setItalic(s, true); 122 123 s = doc.addStyle("bold", regular); 124 StyleConstants.setBold(s, true); 125 126 s = doc.addStyle("small", regular); 127 StyleConstants.setFontSize(s, 9); 128 129 s = doc.addStyle("large", regular); 130 StyleConstants.setFontSize(s, 16); 131 132 s = doc.addStyle("readEncrypted", regular); 133 StyleConstants.setForeground(s, new Color(0f,0.8f,0f)); 134 135 s = doc.addStyle("sendEncrypted", regular); 136 StyleConstants.setForeground(s, new Color(0f,0.8f,0f)); 137 StyleConstants.setBold(s, true); 138 StyleConstants.setItalic(s, true); 139 140 s = doc.addStyle("comment", regular); 141 StyleConstants.setForeground(s, new Color(0f,0.0f,0.8f)); 142 StyleConstants.setBold(s, true); 143 StyleConstants.setItalic(s, true); 144 145 s = doc.addStyle("error", regular); 146 StyleConstants.setForeground(s, new Color(0.9f,0.0f,0.0f)); 147 StyleConstants.setBold(s, true); 148 StyleConstants.setItalic(s, true); 149 150 s = doc.addStyle("readNotEncrypted", regular); 151 StyleConstants.setForeground(s, new Color(255,153,0)); 152 153 s = doc.addStyle("sendNotEncrypted", regular); 154 StyleConstants.setForeground(s, new Color(255,153,0)); 155 StyleConstants.setBold(s, true); 156 StyleConstants.setItalic(s, true); 157 158 } 159 160 161 162 165 public void createFromVectorRepresentation(Vector<Object > v) throws VectorizeException 166 { 167 try 168 { 169 doc.insertString(doc.getLength(), (String ) v.get(0), doc.getStyle("small")); 171 } 172 catch (BadLocationException e) { e.printStackTrace(); } 173 } 174 175 public Vector<Object > getVectorRepresentation() throws VectorizeException 178 { 179 Vector<Object > v = new Vector<Object >(); 180 try 181 { 182 v.addElement(doc.getText(0,doc.getLength())); 184 } 185 catch(Exception e) 186 { 187 e.printStackTrace(); 188 } 189 return v; 190 } 191 192 193 } | Popular Tags |