1 38 39 import java.awt.*; 40 import javax.mail.*; 41 import javax.swing.*; 42 import javax.swing.event.*; 43 import javax.swing.table.*; 44 45 50 51 public class FolderViewer extends JPanel { 52 53 FolderModel model = new FolderModel(); 54 JScrollPane scrollpane; 55 JTable table; 56 57 public FolderViewer() { 58 this(null); 59 } 60 61 public FolderViewer(Folder what) { 62 super(new GridLayout(1,1)); 63 64 table = new JTable(model); 65 table.setShowGrid(false); 66 67 scrollpane = new JScrollPane(table); 68 69 setFolder(what); 71 72 table.getSelectionModel().addListSelectionListener( 74 new FolderPressed()); 75 scrollpane.setPreferredSize(new Dimension(700, 300)); 76 add(scrollpane); 77 } 78 79 84 public void setFolder(Folder what) { 85 try { 86 table.getSelectionModel().clearSelection(); 87 if (SimpleClient.mv != null) 88 SimpleClient.mv.setMessage(null); 89 model.setFolder(what); 90 scrollpane.invalidate(); 91 scrollpane.validate(); 92 } catch (MessagingException me) { 93 me.printStackTrace(); 94 } 95 } 96 97 class FolderPressed implements ListSelectionListener { 98 99 public void valueChanged(ListSelectionEvent e) { 100 if (model != null && !e.getValueIsAdjusting()) { 101 ListSelectionModel lm = (ListSelectionModel) e.getSource(); 102 int which = lm.getMaxSelectionIndex(); 103 if (which != -1) { 104 Message msg = model.getMessage(which); 106 SimpleClient.mv.setMessage(msg); 107 } 108 } 109 } 110 } 111 } 112 | Popular Tags |