Convert to newer collection classes and parameterized types.

git-svn-id: svn://10.0.0.236/trunk@250523 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
nboyd%atg.com 2008-04-20 18:14:32 +00:00
parent 613268de65
commit f9d8a7d772
2 changed files with 84 additions and 59 deletions

View File

@ -158,17 +158,20 @@ public class Dim {
/**
* Table mapping URLs to information about the script source.
*/
private final Hashtable urlToSourceInfo = new Hashtable();
private final Map<String,SourceInfo> urlToSourceInfo =
Collections.synchronizedMap(new HashMap<String,SourceInfo>());
/**
* Table mapping function names to information about the function.
*/
private final Hashtable functionNames = new Hashtable();
private final Map<String,FunctionSource> functionNames =
Collections.synchronizedMap(new HashMap<String,FunctionSource>());
/**
* Table mapping functions to information about the function.
*/
private final Hashtable functionToSource = new Hashtable();
private final Map<DebuggableScript,FunctionSource> functionToSource =
Collections.synchronizedMap(new HashMap<DebuggableScript,FunctionSource>());
/**
* ContextFactory.Listener instance attached to {@link #contextFactory}.
@ -380,23 +383,16 @@ public class Dim {
* Returns the FunctionSource object for the given function or script.
*/
private FunctionSource functionSource(DebuggableScript fnOrScript) {
return (FunctionSource)functionToSource.get(fnOrScript);
return functionToSource.get(fnOrScript);
}
/**
* Returns an array of all function names.
*/
public String[] functionNames() {
String[] a;
synchronized (urlToSourceInfo) {
Enumeration e = functionNames.keys();
a = new String[functionNames.size()];
int i = 0;
while (e.hasMoreElements()) {
a[i++] = (String)e.nextElement();
}
return functionNames.keySet().toArray(new String[functionNames.size()]);
}
return a;
}
/**
@ -495,9 +491,7 @@ public class Dim {
* Clears all breakpoints.
*/
public void clearAllBreakpoints() {
Enumeration e = urlToSourceInfo.elements();
while (e.hasMoreElements()) {
SourceInfo si = (SourceInfo)e.nextElement();
for (SourceInfo si: urlToSourceInfo.values()) {
si.removeAllBreakpoints();
}
}

View File

@ -45,10 +45,39 @@ import javax.swing.*;
import javax.swing.text.*;
import javax.swing.event.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.EventQueue;
import java.awt.ActiveEvent;
import java.awt.AWTEvent;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.MenuComponent;
import java.awt.Point;
import java.awt.Polygon;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.*;
import java.util.*;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.EventListener;
import java.util.EventObject;
import java.util.Map;
import java.util.HashMap;
import java.util.Properties;
import java.io.*;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreePath;
@ -123,12 +152,15 @@ public class SwingGui extends JFrame implements GuiCallback {
/**
* Hash table of internal frame names to the internal frames themselves.
*/
private Hashtable toplevels = new Hashtable();
private final Map<String,JFrame> toplevels =
Collections.synchronizedMap(new HashMap<String,JFrame>());
/**
* Hash table of script URLs to their internal frames.
*/
private Hashtable fileWindows = new Hashtable();
private final Map<String,FileWindow> fileWindows =
Collections.synchronizedMap(new HashMap<String,FileWindow>());
/**
* The {@link FileWindow} that last had the focus.
@ -348,7 +380,7 @@ public class SwingGui extends JFrame implements GuiCallback {
if (url == null || url.equals("<stdin>")) {
return null;
}
return (FileWindow)fileWindows.get(url);
return fileWindows.get(url);
}
/**
@ -595,14 +627,14 @@ public class SwingGui extends JFrame implements GuiCallback {
Dim.ContextData contextData = lastFrame.contextData();
JComboBox ctx = context.context;
Vector toolTips = context.toolTips;
List<String> toolTips = context.toolTips;
context.disableUpdate();
int frameCount = contextData.frameCount();
ctx.removeAllItems();
// workaround for JDK 1.4 bug that caches selected value even after
// removeAllItems() is called
ctx.setSelectedItem(null);
toolTips.removeAllElements();
toolTips.clear();
for (int i = 0; i < frameCount; i++) {
Dim.StackFrame frame = contextData.getFrame(i);
String url = frame.getUrl();
@ -614,7 +646,7 @@ public class SwingGui extends JFrame implements GuiCallback {
String location = "\"" + shortName + "\", line " + lineNumber;
ctx.insertItemAt(location, i);
location = "\"" + url + "\", line " + lineNumber;
toolTips.addElement(location);
toolTips.add(location);
}
context.enableUpdate();
ctx.setSelectedIndex(0);
@ -999,7 +1031,7 @@ class EvalTextArea
/**
* History of expressions that have been evaluated
*/
private Vector history;
private List<String> history;
/**
* Index of the selected history item.
@ -1016,7 +1048,7 @@ class EvalTextArea
*/
public EvalTextArea(SwingGui debugGui) {
this.debugGui = debugGui;
history = new java.util.Vector();
history = Collections.synchronizedList(new ArrayList<String>());
Document doc = getDocument();
doc.addDocumentListener(this);
addKeyListener(this);
@ -1049,7 +1081,7 @@ class EvalTextArea
String text = segment.toString();
if (debugGui.dim.stringIsCompilableUnit(text)) {
if (text.trim().length() > 0) {
history.addElement(text);
history.add(text);
historyIndex = history.size();
}
append("\n");
@ -1110,7 +1142,7 @@ class EvalTextArea
historyIndex = history.size() -1;
}
if (historyIndex >= 0) {
String str = (String)history.elementAt(historyIndex);
String str = history.get(historyIndex);
int len = getDocument().getLength();
replaceRange(str, outputMark, len);
int caretPos = outputMark + str.length();
@ -1129,7 +1161,7 @@ class EvalTextArea
if (historyIndex < 0) {historyIndex = 0;}
int len = getDocument().getLength();
if (historyIndex < history.size()) {
String str = (String)history.elementAt(historyIndex);
String str = history.get(historyIndex);
replaceRange(str, outputMark, len);
caretPos = outputMark + str.length();
} else {
@ -1609,7 +1641,7 @@ class MoreWindows extends JDialog implements ActionListener {
/**
* Creates a new MoreWindows.
*/
MoreWindows(SwingGui frame, Hashtable fileWindows, String title,
MoreWindows(SwingGui frame, Map<String,FileWindow> fileWindows, String title,
String labelText) {
super(frame, title, true);
this.swingGui = frame;
@ -1625,9 +1657,7 @@ class MoreWindows extends JDialog implements ActionListener {
DefaultListModel model = (DefaultListModel)list.getModel();
model.clear();
//model.fireIntervalRemoved(model, 0, size);
Enumeration e = fileWindows.keys();
while (e.hasMoreElements()) {
String data = e.nextElement().toString();
for (String data: fileWindows.keySet()) {
model.addElement(data);
}
list.setSelectedIndex(0);
@ -2277,24 +2307,24 @@ class MyTableModel extends AbstractTableModel {
private SwingGui debugGui;
/**
* Vector of watched expressions.
* List of watched expressions.
*/
private Vector expressions;
private List<String> expressions;
/**
* Vector of values from evaluated from {@link #expressions}.
* List of values from evaluated from {@link #expressions}.
*/
private Vector values;
private List<String> values;
/**
* Creates a new MyTableModel.
*/
public MyTableModel(SwingGui debugGui) {
this.debugGui = debugGui;
expressions = new Vector();
values = new Vector();
expressions.addElement("");
values.addElement("");
expressions = Collections.synchronizedList(new ArrayList<String>());
values = Collections.synchronizedList(new ArrayList<String>());
expressions.add("");
values.add("");
}
/**
@ -2337,9 +2367,9 @@ class MyTableModel extends AbstractTableModel {
public Object getValueAt(int row, int column) {
switch (column) {
case 0:
return expressions.elementAt(row);
return expressions.get(row);
case 1:
return values.elementAt(row);
return values.get(row);
}
return "";
}
@ -2351,17 +2381,17 @@ class MyTableModel extends AbstractTableModel {
switch (column) {
case 0:
String expr = value.toString();
expressions.setElementAt(expr, row);
expressions.set(row, expr);
String result = "";
if (expr.length() > 0) {
result = debugGui.dim.eval(expr);
if (result == null) result = "";
}
values.setElementAt(result, row);
values.set(row, result);
updateModel();
if (row + 1 == expressions.size()) {
expressions.addElement("");
values.addElement("");
expressions.add("");
values.add("");
fireTableRowsInserted(row + 1, row + 1);
}
break;
@ -2376,8 +2406,7 @@ class MyTableModel extends AbstractTableModel {
*/
void updateModel() {
for (int i = 0; i < expressions.size(); ++i) {
Object value = expressions.elementAt(i);
String expr = value.toString();
String expr = expressions.get(i);
String result = "";
if (expr.length() > 0) {
result = debugGui.dim.eval(expr);
@ -2386,7 +2415,7 @@ class MyTableModel extends AbstractTableModel {
result = "";
}
result = result.replace('\n', ' ');
values.setElementAt(result, i);
values.set(i, result);
}
fireTableDataChanged();
}
@ -2429,7 +2458,7 @@ class VariableModel implements TreeTableModel {
/**
* Tree column types.
*/
private static final Class[] cTypes =
private static final Class<?>[] cTypes =
{ TreeTableModel.class, String.class };
/**
@ -2567,7 +2596,7 @@ class VariableModel implements TreeTableModel {
/**
* Returns the type of value stored in the given column.
*/
public Class getColumnClass(int column) {
public Class<?> getColumnClass(int column) {
return cTypes[column];
}
@ -2616,7 +2645,7 @@ class VariableModel implements TreeTableModel {
if (ids == null || ids.length == 0) {
children = CHILDLESS;
} else {
Arrays.sort(ids, new Comparator() {
Arrays.sort(ids, new Comparator<Object>() {
public int compare(Object l, Object r)
{
if (l instanceof String) {
@ -2822,7 +2851,7 @@ class ContextWindow extends JPanel implements ActionListener {
/**
* Tool tips for the stack frames.
*/
Vector toolTips;
List<String> toolTips;
/**
* Tabbed pane for "this" and "locals".
@ -2888,7 +2917,7 @@ class ContextWindow extends JPanel implements ActionListener {
JLabel label = new JLabel("Context:");
context = new JComboBox();
context.setLightWeightPopupEnabled(false);
toolTips = new java.util.Vector();
toolTips = Collections.synchronizedList(new java.util.ArrayList<String>());
label.setBorder(context.getBorder());
context.addActionListener(this);
context.setActionCommand("ContextSwitch");
@ -3136,7 +3165,7 @@ class ContextWindow extends JPanel implements ActionListener {
Dim.ContextData contextData = debugGui.dim.currentContextData();
if (contextData == null) { return; }
int frameIndex = context.getSelectedIndex();
context.setToolTipText(toolTips.elementAt(frameIndex).toString());
context.setToolTipText(toolTips.get(frameIndex));
int frameCount = contextData.frameCount();
if (frameIndex >= frameCount) {
return;
@ -3172,12 +3201,14 @@ class Menubar extends JMenuBar implements ActionListener {
/**
* Items that are enabled only when interrupted.
*/
private Vector interruptOnlyItems = new Vector();
private List<JMenuItem> interruptOnlyItems =
Collections.synchronizedList(new ArrayList<JMenuItem>());
/**
* Items that are enabled only when running.
*/
private Vector runOnlyItems = new Vector();
private List<JMenuItem> runOnlyItems =
Collections.synchronizedList(new ArrayList<JMenuItem>());
/**
* The debugger GUI.
@ -3427,12 +3458,12 @@ class Menubar extends JMenuBar implements ActionListener {
*/
public void updateEnabled(boolean interrupted) {
for (int i = 0; i != interruptOnlyItems.size(); ++i) {
JMenuItem item = (JMenuItem)interruptOnlyItems.elementAt(i);
JMenuItem item = interruptOnlyItems.get(i);
item.setEnabled(interrupted);
}
for (int i = 0; i != runOnlyItems.size(); ++i) {
JMenuItem item = (JMenuItem)runOnlyItems.elementAt(i);
JMenuItem item = runOnlyItems.get(i);
item.setEnabled(!interrupted);
}
}