package com.macmillan.nmeyers; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; /* * SelectMethod.java: Part of the PerfAnal tool * * This class implements a dialog for selecting a method, by name, * from the profiled methods. * * Author: Nathan Meyers, nmeyers@javalinux.net * $Id: SelectMethod.java,v 1.5 1999/11/10 03:36:14 nathanm Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * with this program. If not, the license is available from the * GNU project, at http://www.gnu.org. */ class SelectMethod extends JDialog { JList list; PerfTree.FindMethod findMethod; SelectMethod(JFrame owner, PerfTree.FindMethod fm, HashMap procedures) { super(owner, "Select a Method to Analyze", true); // For performance reasons, we keep procedures in a hashmap instead // of treemap, and sort when we need to Object[] procs = procedures.values().toArray(); Arrays.sort(procs); list = new JList(procs); list.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { setVisible(false); Object result = list.getSelectedValue(); if (result != null) findMethod.findMethod(result.toString()); } } }); findMethod = fm; getContentPane().add(new JScrollPane(list), BorderLayout.CENTER); Box box = Box.createHorizontalBox(); getContentPane().add(box, BorderLayout.SOUTH); box.add(Box.createGlue()); JButton button = new JButton("OK"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); Object result = list.getSelectedValue(); if (result != null) findMethod.findMethod(result.toString()); } }); box.add(button); getRootPane().setDefaultButton(button); box.add(Box.createGlue()); button = new JButton("Cancel"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); } }); box.add(button); box.add(Box.createGlue()); pack(); } }