hotspot/agent/src/share/classes/sun/jvm/hotspot/bugspot/StackTracePanel.java
changeset 15832 6c7a82c0b538
parent 15831 18835185e71e
parent 15830 f89fb3fb1554
child 15834 89c34ec6d638
equal deleted inserted replaced
15831:18835185e71e 15832:6c7a82c0b538
     1 /*
       
     2  * Copyright (c) 2001, 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.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  *
       
    23  */
       
    24 
       
    25 package sun.jvm.hotspot.bugspot;
       
    26 
       
    27 import java.awt.*;
       
    28 import java.awt.event.*;
       
    29 import java.util.*;
       
    30 import javax.swing.*;
       
    31 import sun.jvm.hotspot.debugger.cdbg.*;
       
    32 import sun.jvm.hotspot.runtime.*;
       
    33 import sun.jvm.hotspot.ui.*;
       
    34 
       
    35 /** This panel contains a ListBox with all of the stack frames in a
       
    36     given thread. When a given entry is selected, an event is
       
    37     fired. */
       
    38 
       
    39 public class StackTracePanel extends JPanel {
       
    40   public interface Listener {
       
    41     public void frameChanged(CFrame fr, JavaVFrame jfr);
       
    42   }
       
    43 
       
    44   class Model extends AbstractListModel implements ComboBoxModel {
       
    45     private Object selectedItem;
       
    46     public Object getElementAt(int index) {
       
    47       if (trace == null) return null;
       
    48       return trace.get(index);
       
    49     }
       
    50     public int getSize() {
       
    51       if (trace == null) return 0;
       
    52       return trace.size();
       
    53     }
       
    54     public Object getSelectedItem() {
       
    55       return selectedItem;
       
    56     }
       
    57     public void setSelectedItem(Object item) {
       
    58       selectedItem = item;
       
    59     }
       
    60     public void dataChanged() {
       
    61       fireContentsChanged(this, 0, trace.size());
       
    62     }
       
    63   }
       
    64 
       
    65   private java.util.List trace;
       
    66   private Model model;
       
    67   private JComboBox list;
       
    68   private java.util.List listeners;
       
    69 
       
    70   public StackTracePanel() {
       
    71     super();
       
    72 
       
    73     model = new Model();
       
    74 
       
    75     // Build user interface
       
    76     setLayout(new BorderLayout());
       
    77     setBorder(GraphicsUtilities.newBorder(5));
       
    78     list = new JComboBox(model);
       
    79     list.setPrototypeDisplayValue("ZZZZZZZZZZZZZZZZZZZZZZZZZZZZ");
       
    80     add(list, BorderLayout.CENTER);
       
    81 
       
    82     // Add selection listener
       
    83     list.addItemListener(new ItemListener() {
       
    84         public void itemStateChanged(ItemEvent e) {
       
    85           if (e.getStateChange() == ItemEvent.SELECTED) {
       
    86             fireFrameChanged();
       
    87           }
       
    88         }
       
    89       });
       
    90   }
       
    91 
       
    92   /** Takes a List of StackTraceEntry objects */
       
    93   public void setTrace(java.util.List trace) {
       
    94     this.trace = trace;
       
    95     model.dataChanged();
       
    96     list.setSelectedIndex(0);
       
    97     fireFrameChanged();
       
    98   }
       
    99 
       
   100   public void addListener(Listener listener) {
       
   101     if (listeners == null) {
       
   102       listeners = new ArrayList();
       
   103     }
       
   104     listeners.add(listener);
       
   105   }
       
   106 
       
   107   protected void fireFrameChanged() {
       
   108     if (listeners != null) {
       
   109       StackTraceEntry entry = (StackTraceEntry) trace.get(list.getSelectedIndex());
       
   110       for (Iterator iter = listeners.iterator(); iter.hasNext(); ) {
       
   111         ((Listener) iter.next()).frameChanged(entry.getCFrame(), entry.getJavaFrame());
       
   112       }
       
   113     }
       
   114   }
       
   115 }