1 22 23 package org.aspectj.debugger.gui; 24 25 import org.aspectj.debugger.base.*; 26 import org.aspectj.util.gui.*; 27 28 import java.awt.*; 29 import java.awt.event.*; 30 import java.io.*; 31 import java.util.*; 32 import java.util.List ; 33 import javax.swing.*; 34 import javax.swing.event.*; 35 36 import com.sun.jdi.*; 37 38 40 43 46 57 66 70 75 89 103 113 114 130 142 151 158 161 166 177 194 198 207 216 225 234 248 261 273 281 283 286 289 300 309 313 318 332 345 366 378 386 394 395 398 403 414 431 435 444 453 462 471 485 511 518 527 535 541 544 547 550 555 567 581 585 591 597 616 635 662 679 693 abstract class AJPopupMenu extends JPopupMenu 694 implements ListSelectionListener, 695 AdjustmentListener 696 { 697 698 private boolean scrolling = false; 699 private JList list; 700 private Object selection; 701 702 public AJPopupMenu(String s, Vector v) { 703 this(s, v.toArray()); 704 } 705 706 public AJPopupMenu(String s, Object [] items) { 707 super(s); 708 709 list = new JList(items); 710 list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 711 list.addListSelectionListener(this); 712 713 JScrollPane scroll = new JScrollPane(list); 714 scroll.getVerticalScrollBar().addAdjustmentListener(this); 715 add(scroll); 716 } 717 718 public abstract void doSomething(Object s); 719 720 public Object getSelection() { 721 return selection; 722 } 723 724 public void valueChanged(ListSelectionEvent e) { 725 if (e.getValueIsAdjusting()) { 726 int index = list.getMaxSelectionIndex(); 727 selection = list.getModel().getElementAt(index); 728 scrolling = false; 729 } else { 730 doSomething(selection); 731 setVisible(false); 732 } 733 } 734 735 public void adjustmentValueChanged(AdjustmentEvent e) { 736 scrolling = true; 737 } 738 } 739 740 class ClassTextField extends JTextField { 741 ClassTextField(int i) { 742 super(i); 743 } 744 } 745 746 class SourceTextField extends JTextField { 747 SourceTextField(int i) { 748 super(i); 749 } 750 } 751 752 public class BreakpointDialog extends CenteredJDialog { 753 754 public boolean isSetting() { return true; } 755 756 757 static final int CLASS1_COLS = 20; 758 static final int LINE_COLS = 5; 759 760 final String job = isSetting() ? "Set" : "Clear"; 761 762 String classMethodMsg = job + " a method breakpoint"; 763 ClassTextField classText1 = new ClassTextField(CLASS1_COLS); 764 JTextField lineText = new JTextField(LINE_COLS); 765 766 static final int CLASS2_COLS = 20; 767 static final int METHOD_COLS = 20; 768 static final int PARAMS_COLS = 42; 769 770 String classLineMsg = job + " a class-line breakpoint"; 771 JTextField classText2 = new JTextField(CLASS2_COLS); 772 JTextField methodText = new JTextField(METHOD_COLS); 773 JTextField paramsText = new JTextField(PARAMS_COLS); 774 775 static final int SOURCE_COLS = 20; 776 777 String sourceLineMsg = job + " a source-line breakpoint"; 778 SourceTextField sourceText = new SourceTextField(SOURCE_COLS); 779 JTextField lineText2 = new JTextField(LINE_COLS); 780 781 public BreakpointDialog(Frame frame) { 782 super(frame, "", true); 783 setTitle(job + " a Breakpoint"); 784 785 JPanel mainPanel = new JPanel(); 786 mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); 787 mainPanel.add(classMethodPanel()); 788 mainPanel.add(classLinePanel()); 789 mainPanel.add(sourceLinePanel()); 790 mainPanel.add(buttonPanel()); 791 792 setResizable(false); 793 setContentPane(mainPanel); 794 setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 795 } 796 797 JPanel classLinePanel() { 798 KeyListener potato = new KeyAdapter() { 799 public void keyPressed(KeyEvent e) { 800 if (e.getKeyCode() == KeyEvent.VK_ENTER) { 801 setClassLineBreakpoint(); 802 } 803 }}; 804 classText1.addKeyListener(potato); 805 lineText.addKeyListener(potato); 806 807 JPanel classTextPanel1 = new JPanel(); 808 classTextPanel1.setLayout(new BoxLayout(classTextPanel1, BoxLayout.Y_AXIS)); 809 classTextPanel1.add(Box.createHorizontalGlue()); 810 classTextPanel1.add(classText1); 811 classTextPanel1.setBorder(BorderFactory.createTitledBorder( 812 BorderFactory.createEmptyBorder(0,0,0,0), "Class")); 813 JPanel lineTextPanel = new JPanel(); 814 lineTextPanel.setLayout(new BoxLayout(lineTextPanel, BoxLayout.Y_AXIS)); 815 lineTextPanel.add(Box.createHorizontalGlue()); 816 lineTextPanel.add(lineText); 817 lineTextPanel.setBorder(BorderFactory.createTitledBorder( 818 BorderFactory.createEmptyBorder(0,0,0,0), "Line")); 819 JPanel mainPanel1 = new JPanel(); 820 mainPanel1.setLayout(new BoxLayout(mainPanel1, BoxLayout.X_AXIS)); 821 mainPanel1.add(classTextPanel1); 822 mainPanel1.add(lineTextPanel); 823 JButton jobButton = null; 824 if (isSetting()) { 825 jobButton = new JButton("Set"); 826 jobButton.addActionListener(new ActionListener() { 827 public void actionPerformed(ActionEvent e) { 828 setClassLineBreakpoint(); 829 }}); 830 } else { 831 jobButton = new JButton("Clear"); 832 jobButton.addActionListener(new ActionListener() { 833 public void actionPerformed(ActionEvent e) { 834 classLineClear(); 835 }}); 836 } 837 JPanel buttonPanel1 = new JPanel(); 838 buttonPanel1.setLayout(new BoxLayout(buttonPanel1, BoxLayout.X_AXIS)); 839 buttonPanel1.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); 840 buttonPanel1.add(Box.createHorizontalGlue()); 841 buttonPanel1.add(jobButton); 842 JPanel classLinePanel = new JPanel(); 843 classLinePanel.setLayout(new BorderLayout()); 844 classLinePanel.add(mainPanel1, BorderLayout.CENTER); 845 classLinePanel.add(buttonPanel1, BorderLayout.SOUTH); 846 classLinePanel.setBorder(BorderFactory.createTitledBorder(classLineMsg)); 847 return classLinePanel; 848 } 849 850 JPanel classMethodPanel() { 851 KeyListener george = new KeyAdapter() { 852 public void keyPressed(KeyEvent e) { 853 if (e.getKeyCode() == KeyEvent.VK_ENTER) { 854 setClassMethodBreakpoint(); 855 } 856 }}; 857 classText2.addKeyListener(george); 858 methodText.addKeyListener(george); 859 paramsText.addKeyListener(george); 860 861 JPanel classTextPanel2 = new JPanel(); 862 classTextPanel2.setLayout(new BoxLayout(classTextPanel2, BoxLayout.Y_AXIS)); 863 classTextPanel2.add(Box.createHorizontalGlue()); 864 classTextPanel2.add(classText2); 865 classTextPanel2.setBorder(BorderFactory.createTitledBorder( 866 BorderFactory.createEmptyBorder(0,0,0,0), "Class")); 867 JPanel methodTextPanel = new JPanel(); 868 methodTextPanel.setLayout(new BoxLayout(methodTextPanel, BoxLayout.Y_AXIS)); 869 methodTextPanel.add(Box.createHorizontalGlue()); 870 methodTextPanel.add(methodText); 871 methodTextPanel.setBorder(BorderFactory.createTitledBorder( 872 BorderFactory.createEmptyBorder(0,0,0,0), "Method")); 873 JPanel topPanel = new JPanel(); 874 topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.X_AXIS)); 875 topPanel.add(classTextPanel2); 876 topPanel.add(methodTextPanel); 877 878 JPanel paramsTextPanel = new JPanel(); 879 paramsTextPanel.setLayout(new BoxLayout(paramsTextPanel, BoxLayout.Y_AXIS)); 880 paramsTextPanel.add(Box.createHorizontalGlue()); 881 paramsTextPanel.add(paramsText); 882 paramsTextPanel.setBorder(BorderFactory.createTitledBorder( 883 BorderFactory.createEmptyBorder(0,0,0,0), "Parameters")); 884 JPanel bottomPanel = new JPanel(); 885 bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.X_AXIS)); 886 bottomPanel.add(paramsTextPanel); 887 JPanel middlePanel = new JPanel(); 888 middlePanel.setLayout(new BoxLayout(middlePanel, BoxLayout.Y_AXIS)); 889 middlePanel.add(topPanel); 890 middlePanel.add(bottomPanel); 891 JButton jobButton = null; 892 if (isSetting()) { 893 jobButton = new JButton("Set"); 894 jobButton.addActionListener(new ActionListener() { 895 public void actionPerformed(ActionEvent e) { 896 setClassMethodBreakpoint(); 897 }}); 898 } else { 899 jobButton = new JButton("Clear"); 900 jobButton.addActionListener(new ActionListener() { 901 public void actionPerformed(ActionEvent e) { 902 classMethodClear(); 903 }}); 904 } 905 JPanel buttonPanel2 = new JPanel(); 906 buttonPanel2.setLayout(new BoxLayout(buttonPanel2, BoxLayout.X_AXIS)); 907 buttonPanel2.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); 908 buttonPanel2.add(Box.createHorizontalGlue()); 909 buttonPanel2.add(jobButton); 910 JPanel classMethodPanel = new JPanel(); 911 classMethodPanel.setLayout(new BorderLayout()); 912 classMethodPanel.add(middlePanel, BorderLayout.CENTER); 913 classMethodPanel.add(buttonPanel2, BorderLayout.SOUTH); 914 classMethodPanel.setBorder(BorderFactory.createTitledBorder(classMethodMsg)); 915 return classMethodPanel; 916 } 917 918 JPanel sourceLinePanel() { 919 KeyListener potato = new KeyAdapter() { 920 public void keyPressed(KeyEvent e) { 921 if (e.getKeyCode() == KeyEvent.VK_ENTER) { 922 setSourceLineBreakpoint(); 923 } 924 }}; 925 sourceText.addKeyListener(potato); 926 lineText2.addKeyListener(potato); 927 928 JPanel classTextPanel1 = new JPanel(); 929 classTextPanel1.setLayout(new BoxLayout(classTextPanel1, BoxLayout.Y_AXIS)); 930 classTextPanel1.add(Box.createHorizontalGlue()); 931 classTextPanel1.add(sourceText); 932 classTextPanel1.setBorder(BorderFactory.createTitledBorder( 933 BorderFactory.createEmptyBorder(0,0,0,0), "Source")); 934 JPanel lineTextPanel = new JPanel(); 935 lineTextPanel.setLayout(new BoxLayout(lineTextPanel, BoxLayout.Y_AXIS)); 936 lineTextPanel.add(Box.createHorizontalGlue()); 937 lineTextPanel.add(lineText2); 938 lineTextPanel.setBorder(BorderFactory.createTitledBorder( 939 BorderFactory.createEmptyBorder(0,0,0,0), "Line")); 940 JPanel mainPanel1 = new JPanel(); 941 mainPanel1.setLayout(new BoxLayout(mainPanel1, BoxLayout.X_AXIS)); 942 mainPanel1.add(classTextPanel1); 943 mainPanel1.add(lineTextPanel); 944 JButton jobButton = null; 945 if (isSetting()) { 946 jobButton = new JButton("Set"); 947 jobButton.addActionListener(new ActionListener() { 948 public void actionPerformed(ActionEvent e) { 949 setSourceLineBreakpoint(); 950 }}); 951 } else { 952 jobButton = new JButton("Clear"); 953 jobButton.addActionListener(new ActionListener() { 954 public void actionPerformed(ActionEvent e) { 955 sourceLineClear(); 956 }}); 957 } 958 JPanel buttonPanel1 = new JPanel(); 959 buttonPanel1.setLayout(new BoxLayout(buttonPanel1, BoxLayout.X_AXIS)); 960 buttonPanel1.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); 961 buttonPanel1.add(Box.createHorizontalGlue()); 962 buttonPanel1.add(jobButton); 963 JPanel sourceLinePanel = new JPanel(); 964 sourceLinePanel.setLayout(new BorderLayout()); 965 sourceLinePanel.add(mainPanel1, BorderLayout.CENTER); 966 sourceLinePanel.add(buttonPanel1, BorderLayout.SOUTH); 967 sourceLinePanel.setBorder(BorderFactory.createTitledBorder(sourceLineMsg)); 968 return sourceLinePanel; 969 } 970 971 JPanel buttonPanel() { 972 JButton cancelButton = new JButton("Cancel"); 973 cancelButton.addActionListener(new ActionListener() { 974 public void actionPerformed(ActionEvent e) { 975 cancel(); 976 }}); 977 JPanel buttonPanel = new JPanel(); 978 buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); 979 buttonPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); 980 buttonPanel.add(Box.createHorizontalGlue()); 981 buttonPanel.add(cancelButton); 982 return buttonPanel; 983 } 984 985 986 public BreakpointDialog() { 987 this(null); 988 } 989 990 public void show() { 991 pack(); 992 super.show(); 993 } 994 995 String getClass1() { 996 return classText1.getText(); 997 } 998 999 String getClass2() { 1000 return classText2.getText(); 1001 } 1002 1003 private void setClassLineBreakpoint() { 1004 String className = classText1.getText(); 1005 int line = -1; 1006 try { 1007 line = Integer.parseInt(lineText.getText()); 1008 } catch (NumberFormatException e) { 1009 AJUtil.warn("The line field must contain a number"); 1010 return; 1011 } 1012 String cmd = "stop at " + className + ":" + line; 1013 ComponentRepository.getCommandLine().executeCommand(cmd); 1014 hide(); 1015 } 1016 1017 private void classLineClear() { 1018 classText1.setText(""); 1019 lineText.setText(""); 1020 } 1021 1022 private void setSourceLineBreakpoint() { 1023 String sourceName = sourceText.getText(); 1024 int line = -1; 1025 try { 1026 line = Integer.parseInt(lineText2.getText()); 1027 } catch (NumberFormatException e) { 1028 AJUtil.warn("The line field must contain a number"); 1029 return; 1030 } 1031 String cmd = "stop on " + sourceName + ":" + line; 1032 ComponentRepository.getCommandLine().executeCommand(cmd); 1033 hide(); 1034 } 1035 1036 private void sourceLineClear() { 1037 sourceText.setText(""); 1038 lineText2.setText(""); 1039 } 1040 1041 private void setClassMethodBreakpoint() { 1042 String cmd = "stop in "; 1043 String className = classText2.getText(); 1044 String method = methodText.getText(); 1045 String params = ""; 1046 StringTokenizer tok = new StringTokenizer(paramsText.getText(), " ;,"); 1047 params += "("; 1048 while (tok.hasMoreTokens()) { 1049 params += tok.nextToken(); 1050 params += (tok.hasMoreTokens() ? "," : ""); 1051 } 1052 params += ")"; 1053 cmd += className + "." + method + params; 1054 ComponentRepository.getCommandLine().executeCommand(cmd); 1055 hide(); 1056 } 1057 1058 private void classMethodClear() { 1059 classText2.setText(""); 1060 methodText.setText(""); 1061 paramsText.setText(""); 1062 } 1063 1064 private void cancel() { 1065 hide(); 1066 } 1067 1068 public static void main(String [] args) { 1069 BreakpointDialog d = new BreakpointDialog(); 1070 d.show(); 1071 } 1072} 1073 | Popular Tags |