All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bidib.wizard.model.dmx.DmxChannel Maven / Gradle / Ivy

There is a newer version: 2.0.26
Show newest version
package org.bidib.wizard.model.dmx;

import java.awt.Color;

import com.jgoodies.binding.beans.Model;

public class DmxChannel extends Model {
    private static final long serialVersionUID = 1L;

    public static final String PROPERTY_DMX_CHANNEL_WRAPPER = "dmxChannelWrapper";

    public static final String PROPERTY_INITIAL_STATE = "intialState";

    public static final String PROPERTY_LINE_COLOR = "lineColor";

    public static final String PROPERTY_CHANNEL_NAME = "channelName";

    private int initialState;

    private Color lineColor;

    private String channelName;

    private final DmxDimmer dmxDimmer;

    private DmxChannelWrapper dmxChannelWrapper;

    public DmxChannel(final DmxDimmer dmxDimmer, final DmxChannelWrapper dmxChannelWrapper) {
        this.dmxDimmer = dmxDimmer;
        this.dmxChannelWrapper = dmxChannelWrapper;
    }

    public DmxChannel withDmxChannelWrapper(DmxChannelWrapper dmxChannelWrapper) {
        setDmxChannelWrapper(dmxChannelWrapper);
        return this;
    }

    public DmxChannel withInitialState(int initialState) {
        setInitialState(initialState);
        return this;
    }

    public DmxChannel withLineColor(Color lineColor) {
        setLineColor(lineColor);
        return this;
    }

    public DmxChannel withChannelName(String channelName) {
        setChannelName(channelName);
        return this;
    }

    public DmxDimmer getDmxDimmer() {
        return this.dmxDimmer;
    }

    public void setDmxChannelWrapper(DmxChannelWrapper dmxChannelWrapper) {
        DmxChannelWrapper oldValue = this.dmxChannelWrapper;
        this.dmxChannelWrapper = dmxChannelWrapper;

        firePropertyChange(PROPERTY_DMX_CHANNEL_WRAPPER, oldValue, this.dmxChannelWrapper);
    }

    public DmxChannelWrapper getDmxChannelWrapper() {
        return dmxChannelWrapper;
    }

    public static DmxChannel from(final DmxChannel source) {
        final DmxChannel dmxChannel =
            new DmxChannel(source.dmxDimmer, source.dmxChannelWrapper)
                .withInitialState(source.initialState).withLineColor(source.lineColor)
                .withChannelName(source.channelName);
        return dmxChannel;
    }

    public void to(final DmxChannel target) {
        target
            .withDmxChannelWrapper(dmxChannelWrapper).withInitialState(this.initialState).withLineColor(this.lineColor)
            .withChannelName(this.channelName);
    }

    /**
     * @return the dmxChannelId
     */
    private Integer getDmxChannelId() {
        if (dmxChannelWrapper != null) {
            return dmxChannelWrapper.getDmxChannelId();
        }
        return null;
    }

    /**
     * @return the initialState
     */
    public int getInitialState() {
        return initialState;
    }

    /**
     * @param initialState
     *            the initialState to set
     */
    public void setInitialState(int initialState) {
        int oldValue = this.initialState;

        this.initialState = initialState;

        firePropertyChange(PROPERTY_INITIAL_STATE, oldValue, this.initialState);
    }

    /**
     * @return the lineColor
     */
    public Color getLineColor() {
        return lineColor;
    }

    /**
     * @param lineColor
     *            the lineColor to set
     */
    public void setLineColor(Color lineColor) {
        Color oldValue = this.lineColor;
        this.lineColor = lineColor;

        firePropertyChange(PROPERTY_LINE_COLOR, oldValue, this.lineColor);
    }

    public void setChannelName(String channelName) {
        String oldValue = this.channelName;
        this.channelName = channelName;

        firePropertyChange(PROPERTY_CHANNEL_NAME, oldValue, this.channelName);
    }

    public String getChannelName() {
        return channelName;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof DmxChannel) {
            return (getDmxChannelId() == ((DmxChannel) obj).getDmxChannelId());
        }
        return false;
    }

    @Override
    public int hashCode() {
        return getDmxChannelId();
    }

    @Override
    public String toString() {
        String result = null;

        if (getDmxChannelId() != null) {
            result = "Channel " + getDmxChannelId();
        }
        else {
            result = "";
        }
        return result;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy