KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > tools > example > debug > gui > MonitorListModel


1 /*
2  * @(#)MonitorListModel.java 1.9 05/11/17
3  *
4  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 /*
8  * Copyright (c) 1997-1999 by Sun Microsystems, Inc. All Rights Reserved.
9  *
10  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
11  * modify and redistribute this software in source and binary code form,
12  * provided that i) this copyright notice and license appear on all copies of
13  * the software; and ii) Licensee does not utilize the software in a manner
14  * which is disparaging to Sun.
15  *
16  * This software is provided "AS IS," without a warranty of any kind. ALL
17  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
18  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
19  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
20  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
21  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
22  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
23  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
24  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
25  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGES.
27  *
28  * This software is not designed or intended for use in on-line control of
29  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
30  * the design, construction, operation or maintenance of any nuclear
31  * facility. Licensee represents and warrants that it will not use or
32  * redistribute the Software for such purposes.
33  */

34
35 package com.sun.tools.example.debug.gui;
36
37 import java.util.*;
38
39 import javax.swing.AbstractListModel JavaDoc;
40
41 public class MonitorListModel extends AbstractListModel JavaDoc {
42
43     private final List monitors = new ArrayList();
44     
45     MonitorListModel(Environment env) {
46     
47     // Create listener.
48
MonitorListListener listener = new MonitorListListener();
49     env.getContextManager().addContextListener(listener);
50
51         //### remove listeners on exit!
52
}
53     
54     public Object JavaDoc getElementAt(int index) {
55         return monitors.get(index);
56     }
57     
58     public int getSize() {
59         return monitors.size();
60     }
61
62     public void add(String JavaDoc expr) {
63         monitors.add(expr);
64         int newIndex = monitors.size()-1; // order important
65
fireIntervalAdded(this, newIndex, newIndex);
66     }
67
68     public void remove(String JavaDoc expr) {
69         int index = monitors.indexOf(expr);
70         remove(index);
71     }
72
73     public void remove(int index) {
74         monitors.remove(index);
75         fireIntervalRemoved(this, index, index);
76     }
77
78     public List monitors() {
79         return Collections.unmodifiableList(monitors);
80     }
81
82     public Iterator iterator() {
83         return monitors().iterator();
84     }
85
86     private void invalidate() {
87         fireContentsChanged(this, 0, monitors.size()-1);
88     }
89
90     private class MonitorListListener implements ContextListener {
91
92     public void currentFrameChanged(CurrentFrameChangedEvent e) {
93         invalidate();
94     }
95     }
96 }
97
Popular Tags