00001 package instruction.gui.tab; 00002 00003 import instruction.gui.internal.PlanImporterWrapper; 00004 import instruction.syntaxparser.SyntaxTree; 00005 00006 import java.awt.BorderLayout; 00007 import java.awt.ScrollPane; 00008 import java.awt.event.ActionEvent; 00009 import java.awt.event.ActionListener; 00010 import java.awt.event.ComponentEvent; 00011 import java.awt.event.ComponentListener; 00012 import java.util.List; 00013 import javax.swing.JButton; 00014 import javax.swing.JLabel; 00015 import javax.swing.JPanel; 00016 00017 00018 public class TreeViewTab extends JPanel { 00019 00020 private static final long serialVersionUID = 5838455112176213755L; 00021 00022 public static String TITLE = "Syntax Tree View"; 00023 00024 ScrollPane scroll = null; 00025 SyntaxTreePanel treeView = null; 00026 JPanel buttonPanel = null; 00027 JButton next = null; 00028 JButton prev = null; 00029 JLabel instCount = null; 00030 00031 public TreeViewTab () { 00032 00033 initialize(); 00034 } 00035 00036 public void initialize() { 00037 00038 setLayout( new BorderLayout() ); 00039 00040 treeView = new SyntaxTreePanel(); 00041 treeView.init(); 00042 00043 addComponentListener( new ComponentListener() { 00044 00045 public void componentHidden( ComponentEvent e ) { 00046 } 00047 00048 public void componentMoved( ComponentEvent e ) { 00049 } 00050 00051 public void componentResized( ComponentEvent e ) { 00052 } 00053 00054 00055 public void componentShown( ComponentEvent e ) { 00056 00057 List<SyntaxTree> trees = PlanImporterWrapper.getImporter().getSyntaxTrees(); 00058 00059 if (trees == null || trees.isEmpty()) 00060 return; 00061 00062 00063 treeView.setSyntaxTree( trees ); 00064 treeView.setActiveTree( 0 ); 00065 treeView.redraw(); 00066 instCount.setText( "Parse No. " + (treeView.getActiveTree()+1) + " of " + treeView.getTreeCount() ); 00067 00068 } 00069 00070 } ); 00071 00072 scroll = new ScrollPane( ); 00073 00074 scroll.add( treeView ); 00075 00076 buttonPanel = new JPanel(); 00077 prev = new JButton("< Prev"); 00078 prev.addActionListener( new ActionListener() { 00079 00080 public void actionPerformed( ActionEvent e ) { 00081 treeView.setActiveTree( (treeView.getActiveTree() - 1 < 0 ? treeView.getTreeCount() - 1 : treeView.getActiveTree() - 1) % treeView.getTreeCount() ); 00082 treeView.redraw(); 00083 instCount.setText( "Parse No. " + (treeView.getActiveTree()+1) + " of " + treeView.getTreeCount()); 00084 } 00085 00086 }); 00087 next = new JButton("Next >"); 00088 next.addActionListener( new ActionListener() { 00089 00090 public void actionPerformed( ActionEvent e ) { 00091 treeView.setActiveTree( (treeView.getActiveTree() + 1) % treeView.getTreeCount()); 00092 treeView.redraw(); 00093 instCount.setText( "Parse No. " + (treeView.getActiveTree()+1) + " of " + treeView.getTreeCount()); 00094 } 00095 00096 }); 00097 00098 instCount = new JLabel(""); 00099 00100 buttonPanel.add( prev ); 00101 buttonPanel.add( instCount ); 00102 buttonPanel.add( next ); 00103 00104 add(buttonPanel, BorderLayout.NORTH); 00105 00106 add( scroll, BorderLayout.CENTER ); 00107 } 00108 00109 }