⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connector.java

📁 JStock是一个免费股市软件
💻 JAVA
字号:
/*
 * Connector.java
 *
 * Created on May 9, 2007, 11:07 PM
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Copyright (C) 2007 Cheok YanCheng <yccheok@yahoo.com>
 */

package org.yccheok.jstock.analysis;

/**
 *
 * @author yccheok
 */
public class Connector implements org.jhotdraw.xml.DOMStorable {
    
    /* For serialization purpose. */
    public Connector() {
        this.operator = null;
        this.value = null;
        this.listeners = new java.util.ArrayList<ConnectorValueChangeListener>();        
    }
    
    /** Creates a new instance of Connector */
    public Connector(Operator operator) {
        this.operator = operator;
        this.value = null;
        this.listeners = new java.util.ArrayList<ConnectorValueChangeListener>();
    }
    
    public Object getValue() {
        return value;
    }
    
    public void setValue(Object value) {
        Object oldValue = this.value;
        this.value = value;
        
        // Special case when the value is null.
        if(oldValue == null) {
            if(value != null) {
                ConnectorEvent event = new ConnectorEvent(this);

                for(ConnectorValueChangeListener listerner : listeners)
                    listerner.connectorValueChange(event);                
            }
            
            return;
        }
        
        if(oldValue.equals(value) == false)
        {
            ConnectorEvent event = new ConnectorEvent(this);
            
            for(ConnectorValueChangeListener listerner : listeners)
                listerner.connectorValueChange(event);
        }
    }
    
    public Operator getOperator() {
        return operator;
    }

    public void addConnectorValueChangeListener(ConnectorValueChangeListener connectorValueChangeLister) {
        if(listeners.contains(connectorValueChangeLister))
            return;
        
        listeners.add(connectorValueChangeLister);
    }
    
    public void removeConnectorValueChangeListener(ConnectorValueChangeListener connectorValueChangeLister) {
        listeners.remove(connectorValueChangeLister);
    }
    
    public void write(org.jhotdraw.xml.DOMOutput out) throws java.io.IOException {
        out.openElement("operator");
        out.writeObject(operator);
        out.closeElement();
        
        out.openElement("value");
        out.writeObject(value);
        out.closeElement();
        
        out.openElement("listeners");
        for(ConnectorValueChangeListener listener : listeners) {
            out.writeObject(listener);
        }
        out.closeElement();
    }

    public void read(org.jhotdraw.xml.DOMInput in) throws java.io.IOException {
        in.openElement("operator");
        operator = (Operator)in.readObject();
        in.closeElement();
        
        in.openElement("value");
        value = (Object)in.readObject();
        in.closeElement();  
        
        in.openElement("listeners");
        listeners.clear();        
        final int size = in.getElementCount();
        for(int i = 0; i < size; i++)
            listeners.add((ConnectorValueChangeListener)in.readObject(i));
        in.closeElement();
    }
    
    private Operator operator;
    private Object value;
    private java.util.List<ConnectorValueChangeListener> listeners;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -