blob: c110b2ba3d90e796b01225fff197451bfe7aa6c4 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1999 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package com.sun.tools.example.debug.gui;
27
28import java.util.*;
29
30import javax.swing.AbstractListModel;
31
32public class MonitorListModel extends AbstractListModel {
33
34 private final List<String> monitors = new ArrayList<String>();
35
36 MonitorListModel(Environment env) {
37
38 // Create listener.
39 MonitorListListener listener = new MonitorListListener();
40 env.getContextManager().addContextListener(listener);
41
42 //### remove listeners on exit!
43 }
44
45 public Object getElementAt(int index) {
46 return monitors.get(index);
47 }
48
49 public int getSize() {
50 return monitors.size();
51 }
52
53 public void add(String expr) {
54 monitors.add(expr);
55 int newIndex = monitors.size()-1; // order important
56 fireIntervalAdded(this, newIndex, newIndex);
57 }
58
59 public void remove(String expr) {
60 int index = monitors.indexOf(expr);
61 remove(index);
62 }
63
64 public void remove(int index) {
65 monitors.remove(index);
66 fireIntervalRemoved(this, index, index);
67 }
68
69 public List<String> monitors() {
70 return Collections.unmodifiableList(monitors);
71 }
72
73 public Iterator iterator() {
74 return monitors().iterator();
75 }
76
77 private void invalidate() {
78 fireContentsChanged(this, 0, monitors.size()-1);
79 }
80
81 private class MonitorListListener implements ContextListener {
82
83 public void currentFrameChanged(CurrentFrameChangedEvent e) {
84 invalidate();
85 }
86 }
87}