Showing the changes to java/pkg/com/sun/tools/example/debug/gui/MonitorListModel.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,90 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1999, Oracle and/or its affiliates. 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. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| 22 | * or visit www.oracle.com if you need additional information or have any | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | |||
| 26 | package com.sun.tools.example.debug.gui; | ||
| 27 | |||
| 28 | import java.util.*; | ||
| 29 | |||
| 30 | import javax.swing.AbstractListModel; | ||
| 31 | |||
| 32 | public 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 | @Override | ||
| 46 | public Object getElementAt(int index) { | ||
| 47 | return monitors.get(index); | ||
| 48 | } | ||
| 49 | |||
| 50 | @Override | ||
| 51 | public int getSize() { | ||
| 52 | return monitors.size(); | ||
| 53 | } | ||
| 54 | |||
| 55 | public void add(String expr) { | ||
| 56 | monitors.add(expr); | ||
| 57 | int newIndex = monitors.size()-1; // order important | ||
| 58 | fireIntervalAdded(this, newIndex, newIndex); | ||
| 59 | } | ||
| 60 | |||
| 61 | public void remove(String expr) { | ||
| 62 | int index = monitors.indexOf(expr); | ||
| 63 | remove(index); | ||
| 64 | } | ||
| 65 | |||
| 66 | public void remove(int index) { | ||
| 67 | monitors.remove(index); | ||
| 68 | fireIntervalRemoved(this, index, index); | ||
| 69 | } | ||
| 70 | |||
| 71 | public List<String> monitors() { | ||
| 72 | return Collections.unmodifiableList(monitors); | ||
| 73 | } | ||
| 74 | |||
| 75 | public Iterator<?> iterator() { | ||
| 76 | return monitors().iterator(); | ||
| 77 | } | ||
| 78 | |||
| 79 | private void invalidate() { | ||
| 80 | fireContentsChanged(this, 0, monitors.size()-1); | ||
| 81 | } | ||
| 82 | |||
| 83 | private class MonitorListListener implements ContextListener { | ||
| 84 | |||
| 85 | @Override | ||
| 86 | public void currentFrameChanged(final CurrentFrameChangedEvent e) { | ||
| 87 | invalidate(); | ||
| 88 | } | ||
| 89 | } | ||
| 90 | } | ||