KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > jdb > BreakpointPanel


1 /*
2  * BreakpointPanel.java
3  *
4  * Copyright (C) 2002-2003 Peter Graves
5  * $Id: BreakpointPanel.java,v 1.3 2003/05/23 17:43:26 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.j.jdb;
23
24 import java.awt.Component JavaDoc;
25 import java.awt.event.KeyEvent JavaDoc;
26 import java.awt.event.KeyListener JavaDoc;
27 import java.util.Vector JavaDoc;
28 import javax.swing.JList JavaDoc;
29 import javax.swing.JScrollPane JavaDoc;
30 import org.armedbear.j.Buffer;
31 import org.armedbear.j.Editor;
32 import org.armedbear.j.File;
33
34 public final class BreakpointPanel implements BreakpointListener, KeyListener JavaDoc
35 {
36     private final Jdb jdb;
37     private final JdbControlDialog dialog;
38     private final JList JavaDoc list;
39     private final JScrollPane JavaDoc scrollPane;
40
41     public BreakpointPanel(Jdb jdb, JdbControlDialog dialog)
42     {
43         this.jdb = jdb;
44         this.dialog = dialog;
45         Vector JavaDoc v = new Vector JavaDoc(jdb.getBreakpoints());
46         list = new JList JavaDoc(v);
47         scrollPane = new JScrollPane JavaDoc(list);
48         jdb.addBreakpointListener(this);
49         list.addKeyListener(this);
50     }
51
52     public Component JavaDoc getComponent()
53     {
54         return scrollPane;
55     }
56
57     public void breakpointChanged()
58     {
59         list.setListData(new Vector JavaDoc(jdb.getBreakpoints()));
60         list.setSelectedIndex(-1);
61     }
62
63     public void keyPressed(KeyEvent JavaDoc e)
64     {
65         final int keyCode = e.getKeyCode();
66         // Mask off the bits we don't care about (Java 1.4).
67
final int modifiers = e.getModifiers() & 0x0f;
68         if (modifiers != 0)
69             return;
70         if (keyCode == KeyEvent.VK_DELETE) {
71             int index = list.getSelectedIndex();
72             if (index >= 0) {
73                 Object JavaDoc obj = jdb.getBreakpoints().get(index);
74                 if (obj instanceof ResolvableBreakpoint) {
75                     ResolvableBreakpoint bp = (ResolvableBreakpoint) obj;
76                     jdb.log("clear " + bp.getLocationString());
77                     jdb.deleteBreakpoint(bp);
78                     File file = bp.getFile();
79                     if (file != null) {
80                         Buffer buffer = Editor.getBufferList().findBuffer(file);
81                         if (buffer != null)
82                             buffer.repaint();
83                     }
84                     jdb.saveSession();
85                     jdb.fireBreakpointChanged();
86                     if (index >= list.getModel().getSize())
87                         --index;
88                     list.setSelectedIndex(index);
89                 }
90             }
91         }
92     }
93
94     public void keyTyped(KeyEvent JavaDoc e) {}
95
96     public void keyReleased(KeyEvent JavaDoc e) {}
97 }
98
Popular Tags