1 package SnowMailClient.view.attachments; 2 3 import SnowMailClient.utils.*; 4 import snow.utils.gui.*; 5 import snow.utils.storage.*; 6 import SnowMailClient.model.*; 7 import SnowMailClient.view.html.*; 8 import SnowMailClient.html.HTMLTextExtractor; 9 import SnowMailClient.*; 10 import SnowMailClient.model.multipart.*; 11 import SnowMailClient.view.*; 12 import SnowMailClient.Language.Language; 13 14 import java.awt.*; 15 import java.awt.event.*; 16 import javax.swing.*; 17 import javax.swing.tree.*; 18 import javax.swing.event.*; 19 import java.io.*; 20 import java.util.*; 21 22 23 public class AttachmentBar extends JPanel 24 { 25 GridLayout3 gl3; 26 public AttachmentBar() 27 { 28 super(); 29 gl3 = new GridLayout3(3, this); this.setOpaque(false); 32 this.setBorder(null); 33 34 } 36 37 38 public void setMessage(MimeTreePanel mtp, MailMessage message) 39 { 40 int availableW = 400; 41 try 42 { 43 availableW = SnowMailClientApp.getInstance().getMailView().getWidth(); 44 if(availableW<=0) availableW = 500; 45 } catch(Exception ignore) {} 46 47 removeAll(); 48 gl3 = new GridLayout3(3, this); 50 if(message==null) return; 51 52 53 54 MimeTreeModel mtm = message.getMimeTree(); 55 Vector<MimePart> atts = mtm.getAllAttachments(); 56 int totLineWidth = 0; 57 for(MimePart mp : atts) 58 { 59 JButton attButton = createAttachmentButton(mtp, message, mp); 60 if(attButton.getText().length()>20) 61 { 62 } 64 gl3.add(attButton, false); 66 totLineWidth += (int) attButton.getPreferredSize().getWidth(); 67 if(totLineWidth>=availableW) 68 { 69 totLineWidth = 0; 70 } 72 } 73 this.setPreferredSize(null); 74 updateUI(); 75 76 } 78 79 80 82 private JButton createAttachmentButton(final MimeTreePanel mtp, final MailMessage message, final MimePart mp) 83 { 84 String attName = mp.getName(); 85 if(attName.length()>30) attName = attName.substring(0,30)+"..."; 86 final JButton attButton = new JButton(attName); 87 GUIUtils.setSmallDimensions(attButton); 88 attButton.setPreferredSize( 89 new Dimension((int) attButton.getPreferredSize().getWidth(), 90 attButton.getFont().getSize()*3/2)); 91 92 attButton.addActionListener(new ActionListener() 94 { 95 public void actionPerformed(ActionEvent ae) 96 { 97 JPopupMenu popup = new JPopupMenu("Attachment popup"); 98 99 if(mp.lookIfContentIsAnImage()) 100 { 101 JMenuItem jmViewImage = new JMenuItem(Language.translate("View image")); 102 popup.add(jmViewImage); 103 jmViewImage.addActionListener(new ActionListener() 104 { 105 public void actionPerformed(ActionEvent ee) 106 { 107 new ImageViewer(SnowMailClientApp.getInstance(), mp); 108 } 109 }); 110 } 111 112 JMenuItem miSave = new JMenuItem(Language.translate("Save")); 113 popup.add(miSave); 114 miSave.addActionListener(new ActionListener() 115 { 116 public void actionPerformed(ActionEvent ae) 117 { 118 mtp.saveMimePart( mp ); 119 } 120 }); 121 122 if(mp.getContentTYPE()==MimePart.ContentType.MESSAGE) 123 { 124 JMenuItem jmCreateAsNewMessage = new JMenuItem(Language.translate("Create as new message")); 126 popup.add(jmCreateAsNewMessage); 127 jmCreateAsNewMessage.addActionListener(new ActionListener() 128 { 129 public void actionPerformed(ActionEvent ee) 130 { 131 MailMessage mess = new MailMessage(); 132 mess.parse(mp.getBodyAsText()); 133 SnowMailClientApp.getInstance().getFolderView().getMailFolder().addMessage(mess); 134 } 135 }); 136 } 137 138 { 141 JMenuItem miDelete = new JMenuItem(Language.translate("Delete"), new Icons.CrossIcon(10,10,true)); 142 popup.add(miDelete); 143 miDelete.addActionListener(new ActionListener() 144 { 145 public void actionPerformed(ActionEvent ae) 146 { 147 mtp.deleteMimePart( mp ); 148 152 153 mtp.setHasChanged(); 154 } 156 }); 157 158 } 159 160 popup.show(attButton, 0, attButton.getFont().getSize()); 161 162 } 163 }); 164 165 return attButton; 166 } 167 168 169 170 } | Popular Tags |