package com.jscape.inet.terminal;

import com.jscape.inet.terminal.events.CellEvent;
import com.jscape.inet.terminal.events.CommandEvent;
import com.jscape.inet.terminal.events.ExceptionEvent;
import com.jscape.inet.terminal.events.TerminalEvent;

import java.util.Observable;

/**
 * Represents default (void) implementation of <code>TerminalListener</code>.
 */

public class TerminalAdapter
        implements TerminalListener {

    //----------------------------------------------------------------------------

    /**
     * Handles exception event.
     *
     * @param event <code>ExceptionEvent</code> object.
     */
    public void onExceptionEvent(ExceptionEvent event) {
    }

    //----------------------------------------------------------------------------

    /**
     * Handles cell event.
     *
     * @param event <code>CellEvent</code> object.
     */
    public void onCellEvent(CellEvent event) {
    }

    //----------------------------------------------------------------------------

    /**
     * Handles command event.
     *
     * @param event <code>CommandEvent</code> object
     */
    public void onCommandEvent(CommandEvent event) {
    }

    //----------------------------------------------------------------------------
    public void update(Observable source, Object event) {
        if (source == null || event == null) {
            throw new NullPointerException("TerminalAdapter.update(): null passed");
        }

        if (!(event instanceof TerminalEvent)) {
            throw new IllegalArgumentException("TerminalAdapter.update(): wrong event type");
        }

        ((TerminalEvent) event).accept(this);
    }

}