1 package net.suberic.pooka.gui; 2 import javax.mail.*; 3 import javax.swing.*; 4 import java.util.Hashtable ; 5 import java.util.Vector ; 6 import java.awt.event.MouseEvent ; 7 import java.awt.print.*; 8 import net.suberic.pooka.*; 9 import net.suberic.util.gui.ConfigurablePopupMenu; 10 import net.suberic.util.thread.*; 11 12 15 16 public class MultiMessageProxy extends MessageProxy { 17 18 int[] rowNumbers; 19 FolderInfo folderInfo; 20 21 27 public MultiMessageProxy(int[] newRowNumbers, MessageProxy[] newMessageProxy, FolderInfo newFolderInfo) { 28 rowNumbers=newRowNumbers; 29 folderInfo = newFolderInfo; 30 31 MessageInfo[] newMessageInfo = new MessageInfo[newMessageProxy.length]; 32 for (int i = 0; i < newMessageProxy.length; i++) 33 newMessageInfo[i] = newMessageProxy[i].getMessageInfo(); 34 35 messageInfo=new MultiMessageInfo(newMessageInfo, folderInfo); 36 37 if (folderInfo != null) { 38 ActionThread storeThread = folderInfo.getFolderThread(); 39 40 defaultActions = new Action[] { 41 new ActionWrapper(new OpenAction(), storeThread), 42 new ActionWrapper(new DeleteAction(), storeThread), 43 new ActionWrapper(new MoveAction(), storeThread), 44 new ActionWrapper(new CopyAction(), storeThread), 45 new ActionWrapper(new PrintAction(), storeThread), 46 new ActionWrapper(new CacheMessageAction(), storeThread), 47 new ActionWrapper(new MessageFilterAction(), storeThread), 48 new ActionWrapper(new SpamAction(), storeThread) 49 }; 50 } else { 51 defaultActions = new Action[] { 52 new OpenAction(), 53 new DeleteAction(), 54 new MoveAction(), 55 new CopyAction(), 56 new PrintAction(), 57 new MessageFilterAction(), 58 new SpamAction() 59 }; 60 } 61 62 commands = new Hashtable (); 63 64 Action[] actions = getActions(); 65 if (actions != null) { 66 for (int i = 0; i < actions.length; i++) { 67 Action a = actions[i]; 68 commands.put(a.getValue(Action.NAME), a); 69 } 70 } 71 72 } 73 74 77 public void openWindow() { 78 MultiMessageInfo multi = getMulti(); 79 for (int i = 0; i < multi.getMessageCount(); i++) { 80 multi.getMessageInfo(i).getMessageProxy().openWindow(); 81 } 82 } 83 84 88 public void showPopupMenu(JComponent component, MouseEvent e) { 89 ConfigurablePopupMenu popupMenu = new ConfigurablePopupMenu(); 90 if (folderInfo instanceof net.suberic.pooka.cache.CachingFolderInfo && ! ((net.suberic.pooka.cache.CachingFolderInfo) folderInfo).getCacheHeadersOnly()) { 91 popupMenu.configureComponent("MessageProxy.cachingPopupMenu", Pooka.getResources()); 92 } else { 93 popupMenu.configureComponent("MessageProxy.popupMenu", Pooka.getResources()); 94 95 } 96 popupMenu.setActive(getActions()); 97 popupMenu.show(component, e.getX(), e.getY()); 98 99 } 100 101 105 106 public void printMessage() { 107 PrinterJob job = PrinterJob.getPrinterJob (); 108 Book book = new Book (); 109 PageFormat pf = job.pageDialog (job.defaultPage ()); 110 MultiMessageInfo multi = getMulti(); 111 for (int i = 0; i < getMulti().getMessageCount(); i++) { 112 MessagePrinter printer = new MessagePrinter(multi.getMessageInfo(i), book.getNumberOfPages()); 113 book.append (printer, pf); 114 } 115 job.setPageable (book); 116 final PrinterJob externalJob = job; 117 if (job.printDialog ()) { 118 Thread printThread = new Thread (new Runnable () { 119 public void run() { 120 try { 121 externalJob.print (); 122 } 123 catch (PrinterException ex) { 124 ex.printStackTrace (); 125 } 126 } 127 }, "printing thread"); 128 printThread.start(); 129 130 } 131 } 132 133 136 public void setDeleteInProgress(boolean newValue) { 137 boolean orig = mDeleteInProgress; 138 mDeleteInProgress = newValue; 139 if (orig != mDeleteInProgress) { 140 MultiMessageInfo multi = getMulti(); 141 for (int i = 0; i < multi.getMessageCount(); i++) { 142 MessageProxy current = multi.getMessageInfo(i).getMessageProxy(); 143 current.setDeleteInProgress(newValue); 144 } 145 } 146 } 147 148 151 public MultiMessageInfo getMulti() { 152 return (MultiMessageInfo)messageInfo; 153 } 154 155 } 156 157 | Popular Tags |