Package jsynoptic.plugins.circuit.boxes

Source Code of jsynoptic.plugins.circuit.boxes.Receiver

package jsynoptic.plugins.circuit.boxes;

import java.awt.Color;
import java.awt.Polygon;

import jsynoptic.plugins.circuit.CircuitGate;
import jsynoptic.plugins.circuit.CircuitPlugin;
import jsynoptic.plugins.circuit.ColoredSignal;
import jsynoptic.plugins.circuit.Signal;

import simtools.diagram.gate.Gate;
import simtools.shapes.AbstractShape;
import simtools.ui.MenuResourceBundle;
import simtools.ui.ResourceFinder;

/**
*
* This component is able to display a colored signal
* @author zxpletran007
*
*/
public class Receiver  extends CircuitBox {

    private static final long serialVersionUID = 4197349194308401664L;
    public static MenuResourceBundle resources = ResourceFinder.getMenu(CircuitPlugin.class);
   
    protected transient Color receivedColor = null;
    protected CircuitGate in;

   
    public Receiver(int ox, int oy, int width, int height) {
        super(ox, oy, width, height);
        addGate(in = new CircuitGate(this, Gate.WEST,  "In", true));
        this.receivedColor = null;
    }

   
    /* (non-Javadoc)
     * @see jsynoptic.plugins.circuit.RectangleCircuitComponent#createSymbol()
     */
    protected Polygon[] createSymbol(){
        Polygon[] res = new Polygon[2];
        res[0] = new Polygon(new int[] {2,5,5,7,5,5,2},new int[] {4,4,3,5,7,6,6},7);
        res[1] = new Polygon(new int[] {6,6,7,7,6,6,8,8},new int[] {2,3,3,7,7,8,8,2},8);
       
        return res;
    }

    protected AbstractShape cloneShape() {
        Receiver res = (Receiver) super.cloneShape();
        res.receivedColor = null;
       
        res.in = (CircuitGate)in.cloneGate(res);
        res.addGate(res.in);

        return res;
    }
   
    /* (non-Javadoc)
     * @see jsynoptic.builtin.Abstract1DShape#getDrawColor()
     */
    public Color getFillColor(){
        return  (receivedColor!=null) ? receivedColor : super.getFillColor();
    }


    /**
     * A input gate has a new signal
     * @param gate
     */
    public void signalHasBeenReceived(CircuitGate gate) {
        Signal signal = gate.getCurrentSignal();

        if (signal instanceof ColoredSignal){
            receivedColor = ((ColoredSignal)signal).getColor();
        } else {
            receivedColor = null;
        }
        notifyChange(null);
    }

    private void readObject(java.io.ObjectInputStream in) throws java.lang.ClassNotFoundException, java.io.IOException {
        in.defaultReadObject();
        receivedColor = null;
    }


    /* (non-Javadoc)
     * @see simtools.shapes.AbstractShape#getShapeName()
     */
    public String getShapeName(){
        return resources.getString("Receiver");
    }
   

    public CircuitGate getIn() {
        return in;
    }
   
    public Color getReceivedColor() {
        return receivedColor;
    }


}
TOP

Related Classes of jsynoptic.plugins.circuit.boxes.Receiver

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.