View Javadoc
1 package jrre.gui; 2 3 import jrre.event.*; 4 import javax.swing.*; 5 import javax.swing.table.*; 6 import java.util.*; 7 import java.awt.*; 8 import java.awt.event.*; 9 import jrre.types.*; 10 11 import java.beans.*; 12 13 public class OperandStackGUI extends JTable implements ActionListener, VMEventListener { 14 15 private int width; 16 private int height; 17 private int topOfStack; 18 private String[] columnNames = {"Operand Stack"}; 19 //private Type[][] tableData = new Type[10][10]; 20 //private TableModel tableModel = new TableModel(); 21 private ArrayList operandStackFrames; 22 23 public OperandStackGUI(int width, int height){ 24 super(12,1); 25 setSize(width, height); 26 27 this.width = width; 28 this.height = height; 29 30 operandStackFrames = new ArrayList(); 31 32 topOfStack = 12; 33 34 initLayout(); 35 } 36 37 private void initLayout(){ 38 setSize(width,height); 39 setBackground(Color.white); 40 } 41 42 public void actionPerformed(ActionEvent event){ 43 44 System.out.println("In OperandStackGUI: "+event); 45 } 46 47 public void receiveEvent(VMEvent event){ 48 49 if(event instanceof PushOperandEvent) 50 pushOperand(((PushOperandEvent)event).getName()+": "+((PushOperandEvent)event).getValue()); 51 52 else if(event instanceof PopOperandEvent) 53 popOperand(); 54 /* 55 else if(event instanceof PushStackFrameEvent) 56 pushOperandStack((PushStackFrameEvent)event); 57 else if(event instanceof PopStackFrameEvent) 58 popOperandStack((PopStackFrameEvent)event); 59 */ 60 61 } 62 63 private void pushOperandStack(PushStackFrameEvent event){ 64 65 topOfStack = event.getMaxStackSize()+1; 66 DefaultTableModel modelToPush = new DefaultTableModel(); 67 operandStackFrames.add(super.getModel()); 68 super.setModel(modelToPush); 69 70 } 71 72 private void popOperandStack(PopStackFrameEvent event){ 73 74 operandStackFrames.remove(operandStackFrames.size()); 75 76 //topOfStack = ((DefaultTableModel)operandStackFrames.get(operandStackFrames.size())).getRowCount(); 77 super.setModel((DefaultTableModel)operandStackFrames.get(operandStackFrames.size())); 78 } 79 80 private void pushOperand(String variable){ 81 82 //System.out.println("push: "+variable); 83 84 setValueAt(variable, --topOfStack, 0); 85 86 } 87 88 private void popOperand(){ 89 //System.out.println("pop: "); 90 91 setValueAt("", topOfStack++, 0); 92 93 } 94 95 private void pushFrame(){ 96 97 } 98 99 private void popFrame(){ 100 101 } 102 103 }

This page was automatically generated by Maven