00001 package instruction.gui.tab; 00002 00003 import instruction.gui.internal.PlanImporterWrapper; 00004 import java.awt.BorderLayout; 00005 import java.awt.ScrollPane; 00006 import java.awt.event.ActionEvent; 00007 import java.awt.event.ActionListener; 00008 import java.awt.event.ComponentEvent; 00009 import java.awt.event.ComponentListener; 00010 import javax.swing.JButton; 00011 import javax.swing.JLabel; 00012 import javax.swing.JPanel; 00013 import javax.swing.JTextPane; 00014 00015 public class InternalViewTab extends InstructionTab { 00016 00017 private static final long serialVersionUID = 3245495709892820570L; 00018 00019 public static String TITLE = "Internal Data Structures"; 00020 00021 ScrollPane scroll = null; 00022 DataStructurePanel dsView = null; 00023 JTextPane text = null; 00024 JPanel buttonPanel = null; 00025 JButton next = null; 00026 JButton prev = null; 00027 JLabel instCount = null; 00028 00029 public InternalViewTab() { 00030 initialize(); 00031 } 00032 00033 public void initialize() { 00034 00035 setLayout( new BorderLayout() ); 00036 00037 dsView = new DataStructurePanel(); 00038 dsView.init(); 00039 // text = new JTextPane(); 00040 00041 00042 00043 addComponentListener( new ComponentListener() { 00044 00045 public void componentHidden( ComponentEvent e ) { 00046 00047 // TODO Auto-generated method stub 00048 00049 } 00050 00051 public void componentMoved( ComponentEvent e ) { 00052 00053 // TODO Auto-generated method stub 00054 00055 } 00056 00057 public void componentResized( ComponentEvent e ) { 00058 00059 // TODO Auto-generated method stub 00060 00061 } 00062 00063 public void componentShown( ComponentEvent e ) { 00064 00065 dsView.setInstructions( PlanImporterWrapper.getImporter().getInstructions() ); 00066 dsView.setActiveInstruction( 0 ); 00067 dsView.redraw(); 00068 instCount.setText( "Instruction No. " + (dsView.getActiveInstruction()+1) + " of " + dsView.getInstructionCount()); 00069 00070 // text.setText( "" ); 00071 // List<Instruction> in = PlanImporterWrapper.getImporter().getInstructions(); 00072 // for (Iterator<Instruction> i = in.iterator(); i.hasNext();) { 00073 // text.setText( text.getText() + "\n\n" + i.next().toString() ); 00074 // } 00075 } 00076 00077 } ); 00078 00079 buttonPanel = new JPanel(); 00080 prev = new JButton("< Prev"); 00081 prev.addActionListener( new ActionListener() { 00082 00083 public void actionPerformed( ActionEvent e ) { 00084 dsView.setActiveInstruction( (dsView.getActiveInstruction() - 1 < 0 ? dsView.getInstructionCount() - 1 : dsView.getActiveInstruction() - 1) % dsView.getInstructionCount() ); 00085 dsView.redraw(); 00086 instCount.setText( "Instruction No. " + (dsView.getActiveInstruction()+1) + " of " + dsView.getInstructionCount()); 00087 } 00088 00089 }); 00090 next = new JButton("Next >"); 00091 next.addActionListener( new ActionListener() { 00092 00093 public void actionPerformed( ActionEvent e ) { 00094 dsView.setActiveInstruction( (dsView.getActiveInstruction() + 1) % dsView.getInstructionCount()); 00095 dsView.redraw(); 00096 instCount.setText( "Instruction No. " + (dsView.getActiveInstruction()+1) + " of " + dsView.getInstructionCount()); 00097 } 00098 00099 }); 00100 00101 instCount = new JLabel(""); 00102 00103 buttonPanel.add( prev ); 00104 buttonPanel.add( instCount ); 00105 buttonPanel.add( next ); 00106 00107 add(buttonPanel, BorderLayout.NORTH); 00108 00109 scroll = new ScrollPane( ); 00110 scroll.add( dsView ); 00111 00112 add( scroll, BorderLayout.CENTER ); 00113 00114 } 00115 00116 }