Skip to content

Package: FolderViewer

FolderViewer

nameinstructionbranchcomplexitylinemethod
FolderViewer()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
FolderViewer(Folder)
M: 55 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
setFolder(Folder)
M: 24 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Distribution License v. 1.0, which is available at
6: * http://www.eclipse.org/org/documents/edl-v10.php.
7: *
8: * SPDX-License-Identifier: BSD-3-Clause
9: */
10:
11: package example.client;
12:
13: import jakarta.mail.Folder;
14: import jakarta.mail.Message;
15: import jakarta.mail.MessagingException;
16:
17: import javax.swing.*;
18: import javax.swing.event.ListSelectionEvent;
19: import javax.swing.event.ListSelectionListener;
20: import java.awt.*;
21:
22: /**
23: * @author Christopher Cotton
24: * @author Bill Shannon
25: */
26: public class FolderViewer extends JPanel {
27:
28: FolderModel model = new FolderModel();
29: JScrollPane scrollpane;
30: JTable table;
31:
32: public FolderViewer() {
33: this(null);
34: }
35:
36: public FolderViewer(Folder what) {
37: super(new GridLayout(1, 1));
38:
39: table = new JTable(model);
40: table.setShowGrid(false);
41:
42: scrollpane = new JScrollPane(table);
43:
44: // setup the folder we were given
45: setFolder(what);
46:
47: // find out what is pressed
48: table.getSelectionModel().addListSelectionListener(
49: new FolderPressed());
50: scrollpane.setPreferredSize(new Dimension(700, 300));
51: add(scrollpane);
52: }
53:
54: /**
55: * Change the current Folder for the Viewer
56: *
57: * @param what the folder to be viewed
58: */
59: public void setFolder(Folder what) {
60: try {
61: table.getSelectionModel().clearSelection();
62:• if (SimpleClient.mv != null)
63: SimpleClient.mv.setMessage(null);
64: model.setFolder(what);
65: scrollpane.invalidate();
66: scrollpane.validate();
67: } catch (MessagingException me) {
68: me.printStackTrace();
69: }
70: }
71:
72: class FolderPressed implements ListSelectionListener {
73:
74: public void valueChanged(ListSelectionEvent e) {
75: if (model != null && !e.getValueIsAdjusting()) {
76: ListSelectionModel lm = (ListSelectionModel) e.getSource();
77: int which = lm.getMaxSelectionIndex();
78: if (which != -1) {
79: // get the message and display it
80: Message msg = model.getMessage(which);
81: SimpleClient.mv.setMessage(msg);
82: }
83: }
84: }
85: }
86: }