Source code: org/altara/mars/swingui/ChangeListPanel.java
1 /* MARS Network Monitor Swing User Interface
2 Copyright (C) 1999 Brian H. Trammell
3 Copyright (C) 2002 Leapfrog Research & Development, LLC
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, it is available at
17 http:///www.gnu.org/copyleft/gpl.html, or by writing to the
18 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20 */
21
22 package org.altara.mars.swingui;
23
24 import org.altara.util.*;
25 import org.altara.mars.*;
26 import org.altara.mars.engine.*;
27 import org.altara.mars.plugin.*;
28 import java.util.*;
29 import java.awt.*;
30 import java.awt.event.*;
31 import javax.swing.*;
32 import javax.swing.tree.*;
33 import javax.swing.event.*;
34 import javax.swing.border.*;
35
36 /** Contains the change list and its control(s).
37 */
38
39 public class ChangeListPanel extends JPanel {
40
41 public ChangeListPanel(Controller controller) {
42 // create the change list
43 final ChangeListModel clm = new ChangeListModel();
44 controller.addStatusChangeListener(
45 new StatusChangeThreadAdapter(clm));
46 JList changeList = new JList(clm);
47 JScrollPane changeListSP = new JScrollPane(changeList);
48 // set up various list options
49 changeListSP.setBorder(new TitledBorder("Recent Changes"));
50 // set up the renderer for the change list
51 ChangeListRenderer clr = new ChangeListRenderer();
52 changeList.setCellRenderer(clr);
53
54 // create a button to clear the history
55 JButton clearBtn = new JButton("Clear History");
56 clearBtn.addActionListener(new ActionListener() {
57 public void actionPerformed(ActionEvent ae) {
58 clm.clear();
59 }
60 });
61
62 // set up the layout manager
63 setLayout(new GridBagLayout());
64 GridBagConstraints c = new GridBagConstraints();
65 c.anchor = c.NORTHWEST; c.fill = c.BOTH;
66 c.weightx = 1.0; c.weighty = 0.0;
67 c.insets = new Insets(4,4,6,4);
68 c.gridwidth = 1; c.gridheight = 1;
69
70 // lay out the panel
71 c.gridx = 0; c.gridy = 0; c.weighty = 1.0;
72 add(changeListSP,c);
73 c.gridx = 0; c.gridy = 1; c.weighty = 0.0;
74 c.fill = c.VERTICAL; c.anchor = c.SOUTHEAST;
75 add(clearBtn,c);
76 }
77 }
78