Class TextSegmentWindow

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, EventListener, Accessible, RootPaneContainer, WindowConstants, Memory.Listener, SimulatorListener

public class TextSegmentWindow extends JInternalFrame implements SimulatorListener, Memory.Listener
Creates the Text Segment window in the Execute tab of the UI.
Author:
Team JSpim
See Also:
  • Constructor Details

    • TextSegmentWindow

      public TextSegmentWindow(VenusUI gui)
      Constructor, sets up a new JInternalFrame.
  • Method Details

    • setupTable

      public void setupTable()
      Method to be called once the user compiles the program. Should convert the lines of code over to the table rows and columns.
    • getProgramArguments

      public List<String> getProgramArguments()
      Get program arguments from text field at the bottom of the text segment window.
      Returns:
      The list of program arguments.
    • addProgramArgumentsPanel

      public void addProgramArgumentsPanel()
      Allow the user to enter program arguments in a panel at the bottom of the text segment window.
    • removeProgramArgumentsPanel

      public void removeProgramArgumentsPanel()
      Hide the panel for entering program arguments.
    • clearWindow

      public void clearWindow()
      Remove all components.
    • registerTableModelListener

      public void registerTableModelListener(TableModelListener listener)
      Assign listener to Table model. Used for breakpoints, since that is the only editable column in the table. Since table model objects are transient (get a new one with each successful assemble), this method will simply keep the identity of the listener then add it as a listener each time a new table model object is created. Limit 1 listener.
    • updateCodeAddresses

      public void updateCodeAddresses()
      Redisplay the addresses. This should only be done when address display base is modified (e.g. between base 16 hex and base 10 dec).
    • updateBasicStatements

      public void updateBasicStatements()
      Redisplay the basic statements. This should only be done when address or value display base is modified (e.g. between base 16 hex and base 10 dec).
    • memoryWritten

      public void memoryWritten(int address, int length, int value, int wordAddress, int wordValue)
      Description copied from interface: Memory.Listener
      Invoked upon any write operation which is relevant to this listener's active range. Does nothing by default.
      Specified by:
      memoryWritten in interface Memory.Listener
      Parameters:
      address - The address which was written to.
      length - The number of bytes written. Will always be 1 (single byte), Memory.BYTES_PER_HALFWORD, or Memory.BYTES_PER_WORD.
      value - The value which was written.
      wordAddress - The address of the word affected by the operation.
      wordValue - The resulting value of the word.
    • simulatorStarted

      public void simulatorStarted(SimulatorStartEvent event)
      Description copied from interface: SimulatorListener
      Called when the simulator begins execution of a program.
      Specified by:
      simulatorStarted in interface SimulatorListener
      Parameters:
      event - The event which occurred.
    • simulatorPaused

      public void simulatorPaused(SimulatorPauseEvent event)
      Description copied from interface: SimulatorListener
      Called when the simulator stops execution of a program due to pausing.
      Specified by:
      simulatorPaused in interface SimulatorListener
      Parameters:
      event - The event which occurred.
    • simulatorFinished

      public void simulatorFinished(SimulatorFinishEvent event)
      Description copied from interface: SimulatorListener
      Called when the simulator stops execution of a program due to termination or finishing.
      Specified by:
      simulatorFinished in interface SimulatorListener
      Parameters:
      event - The event which occurred.
    • simulatorStepped

      public void simulatorStepped()
      Description copied from interface: SimulatorListener
      Called when the simulator has finished executing an instruction, but only if the run speed is not unlimited.

      Note: For very fast run speeds, GUI listeners may not receive all step events. This is an intentional feature to prevent overloading of the GUI event queue.

      Specified by:
      simulatorStepped in interface SimulatorListener
    • resetModifiedSourceCode

      public void resetModifiedSourceCode()
      Called by RunResetAction to restore display of any table rows that were overwritten due to self-modifying code feature.
    • getBreakpointCount

      public int getBreakpointCount()
      Returns number of breakpoints currently set.
      Returns:
      number of current breakpoints
    • getSortedBreakPointsArray

      public int[] getSortedBreakPointsArray()
      Returns array of current breakpoints, each represented by a MIPS program counter address. These are stored in the BREAK_COLUMN of the table model.
      Returns:
      int array of breakpoints, sorted by PC address, or null if there are none.
    • clearAllBreakpoints

      public void clearAllBreakpoints()
      Clears all breakpoints that have been set since last assemble, and updates the display of the breakpoint column.
    • scrollToRow

      public void scrollToRow(int row)
    • updateHighlighting

      public void updateHighlighting()
      Highlights the source code line whose address matches the current program counter value. This is used for stepping through code execution and when reaching breakpoints.
    • selectStepAtAddress

      public void selectStepAtAddress(int address)
      Scroll the viewport so the step (table row) at the given text segment address is visible, vertically centered if possible, and selected. Developed July 2007 for new feature that shows source code step where label is defined when that label is clicked on in the Label Window.
      Parameters:
      address - text segment address of source code step.
    • toggleBreakpoints

      public void toggleBreakpoints()
      Enable or disable all items in the Breakpoints column.
    • startObservingMemory

      public void startObservingMemory()
      Convenience method to add this as a listener of the text segment in memory.
    • stopObservingMemory

      public void stopObservingMemory()
      Convenience method to remove this as a listener of memory.
    • updateListeningStatus

      public void updateListeningStatus()
      Convenience method to remove this as a listener of memory, then add again if the self-modifying code feature is enabled in the settings.
    • findRowForAddress

      public int findRowForAddress(int address) throws IndexOutOfBoundsException
      Helper method to find the table row corresponding to the given text segment address. This method is called by a couple different public methods.
      Parameters:
      address - The address to find the row for.
      Returns:
      The table row corresponding to this address.
      Throws:
      IndexOutOfBoundsException - Thrown if the address does not correspond to any row in the table.
    • updateUI

      public void updateUI()
      For whatever reason, FlatLaf seems to forget what the frame icon is set to after this method is called. So, this method has been overwritten to set the frame icon back to null as desired.
      Overrides:
      updateUI in class JInternalFrame