KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > FolderViewer


1 /*
2  * @(#)FolderViewer.java 1.12 05/11/16
3  *
4  * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * - Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * - Redistribution in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * Neither the name of Sun Microsystems, Inc. or the names of contributors
18  * may be used to endorse or promote products derived from this software
19  * without specific prior written permission.
20  *
21  * This software is provided "AS IS," without a warranty of any kind. ALL
22  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
23  * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
24  * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND
25  * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES OR LIABILITIES
26  * SUFFERED BY LICENSEE AS A RESULT OF OR RELATING TO USE, MODIFICATION
27  * OR DISTRIBUTION OF THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
28  * SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
29  * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
30  * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
31  * ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS
32  * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
33  *
34  * You acknowledge that Software is not designed, licensed or intended
35  * for use in the design, construction, operation or maintenance of any
36  * nuclear facility.
37  */

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 /**
46  * @version 1.12, 05/11/16
47  * @author Christopher Cotton
48  * @author Bill Shannon
49  */

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     // setup the folder we were given
70
setFolder(what);
71     
72     // find out what is pressed
73
table.getSelectionModel().addListSelectionListener(
74         new FolderPressed());
75     scrollpane.setPreferredSize(new Dimension(700, 300));
76     add(scrollpane);
77     }
78
79     /**
80      * Change the current Folder for the Viewer
81      *
82      * @param what the folder to be viewed
83      */

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             // get the message and display it
105
Message msg = model.getMessage(which);
106             SimpleClient.mv.setMessage(msg);
107         }
108         }
109     }
110     }
111 }
112
Popular Tags