Skip to content

Package: FolderViewer$FolderPressed

FolderViewer$FolderPressed

nameinstructionbranchcomplexitylinemethod
FolderViewer.FolderPressed(FolderViewer)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
valueChanged(ListSelectionEvent)
M: 27 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2021 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: import java.awt.*;
12: import jakarta.mail.*;
13: import javax.swing.*;
14: import javax.swing.event.*;
15: import javax.swing.table.*;
16:
17: /**
18: * @author        Christopher Cotton
19: * @author        Bill Shannon
20: */
21:
22: public class FolderViewer extends JPanel {
23:
24: FolderModel model = new FolderModel();
25: JScrollPane scrollpane;
26: JTable table;
27:
28: public FolderViewer() {
29:         this(null);
30: }
31:
32: public FolderViewer(Folder what) {
33:         super(new GridLayout(1,1));
34:
35:         table = new JTable(model);
36:         table.setShowGrid(false);
37:
38:         scrollpane = new JScrollPane(table);
39:
40:         // setup the folder we were given
41:         setFolder(what);
42:         
43:         // find out what is pressed
44:         table.getSelectionModel().addListSelectionListener(
45:          new FolderPressed());
46:         scrollpane.setPreferredSize(new Dimension(700, 300));
47:         add(scrollpane);
48: }
49:
50: /**
51: * Change the current Folder for the Viewer
52: *
53: * @param what        the folder to be viewed
54: */
55: public void setFolder(Folder what) {
56:         try {
57:          table.getSelectionModel().clearSelection();
58:          if (SimpleClient.mv != null)
59:                 SimpleClient.mv.setMessage(null);
60:          model.setFolder(what);
61:          scrollpane.invalidate();
62:          scrollpane.validate();
63:         } catch (MessagingException me) {
64:          me.printStackTrace();
65:         }
66: }
67:
68: class FolderPressed implements ListSelectionListener {
69:
70:         public void valueChanged(ListSelectionEvent e) {
71:•         if (model != null && !e.getValueIsAdjusting()) {
72:                 ListSelectionModel lm = (ListSelectionModel) e.getSource();
73:                 int which = lm.getMaxSelectionIndex();
74:•                if (which != -1) {
75:                  // get the message and display it
76:                  Message msg = model.getMessage(which);
77:                  SimpleClient.mv.setMessage(msg);
78:                 }
79:          }
80:         }
81: }
82: }