R4SlotPanel.java :  » App » learnandroid » com » lgnortel » r4 » r4equipment » shelf » Android Open Source

Android Open Source » App » learnandroid 
learnandroid » com » lgnortel » r4 » r4equipment » shelf » R4SlotPanel.java
package com.lgnortel.r4.r4equipment.shelf;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.util.logging.Logger;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

import com.lgnortel.lib.logger.LoggerUtil;
import com.lgnortel.platform.db.DBDataDesc;
import com.lgnortel.platform.db.DBR4NiuSfpIF;
import com.lgnortel.platform.db.DBSlotUnitIF;

/**
 * Copyright (c) 2008 LG-Nortel, Inc. All Rights Reserved.
 *
 * CONFIDENTIALITY AND LIMITED USE: This software, including any software of <br>
 * third parties embodied herein, contains code, information, data and concepts <br>
 * which are confidential and/or proprietary to LG-Nortel and such third <br>
 * parties. This software is licensed for use solely in accordance with the <br>
 * terms and conditions of the applicable license agreement with LG-Nortel or <br>
 * its authorized distributor, and not for any other use or purpose. No <br>
 * redistribution of this software by any party is permitted. <br>
 *
 * Title: SlotPanel.java<br>
 * Description: This class draws the slot in shelf view.<br>
 * Copyright: Copyright(c) 2009 LG-NORTEL ALL Rights Reserved<br>
 * Company: LG-Nortel<br>
 *
 * @author Tran Thu Phuong
 * @version 0.1
 * @created 2009. 1. 21.
 * @modified 2009. 1. 21.
 * @product EFA R4.0 EMS
 * @sw_block client block
 */
class R4SlotPanel extends JPanel {

  /**
   *
   */
  private static final long serialVersionUID = -8549046461083741604L;

  // Log4J
  Logger logger = LoggerUtil.getInstance().getLogger(this.getClass().getName());

  ImageIcon R4_mcIcon_nr = new ImageIcon(getClass().getClassLoader().getResource("image/r4_mc_normal.gif"));
  ImageIcon R4_swIcon_nr = new ImageIcon(getClass().getClassLoader().getResource("image/r4_sw_normal.gif"));
  ImageIcon R4_piIcon_100M_nr = new ImageIcon(getClass().getClassLoader().getResource("image/r4_pi100_normal.gif"));
  ImageIcon R4_piIcon_hp100M_nr = new ImageIcon(getClass().getClassLoader().getResource("image/r4_pihp100_normal.gif"));
  ImageIcon R4_piIcon_1G_nr = new ImageIcon(getClass().getClassLoader().getResource("image/r4_pi1g_normal.gif"));
  ImageIcon R4_ciIcon_nr = new ImageIcon(getClass().getClassLoader().getResource("image/r4_cei_normal.gif"));
  ImageIcon R4_eiIcon_nr = new ImageIcon(getClass().getClassLoader().getResource("image/r4_ei_normal.gif"));


  // red, green, yellow
  ImageIcon R4_mcIcon_cr = new ImageIcon(getClass().getClassLoader().getResource("image/r4_mc_critical.gif"));
  ImageIcon R4_mcIcon_mj = new ImageIcon(getClass().getClassLoader().getResource("image/r4_mc_major.gif"));
  ImageIcon R4_mcIcon_mn = new ImageIcon(getClass().getClassLoader().getResource("image/r4_mc_minor.gif"));

  ImageIcon R4_swIcon_cr = new ImageIcon(getClass().getClassLoader().getResource("image/r4_sw_critical.gif"));
  ImageIcon R4_swIcon_mj = new ImageIcon(getClass().getClassLoader().getResource("image/r4_sw_major.gif"));
  ImageIcon R4_swIcon_mn = new ImageIcon(getClass().getClassLoader().getResource("image/r4_sw_minor.gif"));

  ImageIcon R4_piIcon_100M_cr = new ImageIcon(getClass().getClassLoader().getResource("image/r4_pi100_critical.gif"));
  ImageIcon R4_piIcon_100M_mj = new ImageIcon(getClass().getClassLoader().getResource("image/r4_pi100_major.gif"));
  ImageIcon R4_piIcon_100M_mn = new ImageIcon(getClass().getClassLoader().getResource("image/r4_pi100_minor.gif"));
  
  ImageIcon R4_piIcon_hp100M_cr = new ImageIcon(getClass().getClassLoader().getResource("image/r4_pihp100_critical.gif"));
  ImageIcon R4_piIcon_hp100M_mj = new ImageIcon(getClass().getClassLoader().getResource("image/r4_pihp100_major.gif"));
  ImageIcon R4_piIcon_hp100M_mn = new ImageIcon(getClass().getClassLoader().getResource("image/r4_pihp100_minor.gif"));

  ImageIcon R4_piIcon_1G_cr = new ImageIcon(getClass().getClassLoader().getResource("image/r4_pi1g_critical.gif"));
  ImageIcon R4_piIcon_1G_mj = new ImageIcon(getClass().getClassLoader().getResource("image/r4_pi1g_major.gif"));
  ImageIcon R4_piIcon_1G_mn = new ImageIcon(getClass().getClassLoader().getResource("image/r4_pi1g_minor.gif"));

  ImageIcon R4_ciIcon_cr = new ImageIcon(getClass().getClassLoader().getResource("image/r4_cei_critical.gif"));
  ImageIcon R4_ciIcon_mj = new ImageIcon(getClass().getClassLoader().getResource("image/r4_cei_major.gif"));
  ImageIcon R4_ciIcon_mn = new ImageIcon(getClass().getClassLoader().getResource("image/r4_cei_minor.gif"));
  
  ImageIcon R4_eiIcon_cr = new ImageIcon(getClass().getClassLoader().getResource("image/r4_ei_critical.gif"));
  ImageIcon R4_eiIcon_mj = new ImageIcon(getClass().getClassLoader().getResource("image/r4_ei_major.gif"));
  ImageIcon R4_eiIcon_mn = new ImageIcon(getClass().getClassLoader().getResource("image/r4_ei_minor.gif"));

  // blank, out, deact
  ImageIcon R4_mcIcon_blank = new ImageIcon(getClass().getClassLoader().getResource("image/r4_mc_blank.gif"));
  ImageIcon R4_swIcon_blank = new ImageIcon(getClass().getClassLoader().getResource("image/r4_sw_blank.gif"));
  ImageIcon R4_piIcon_blank = new ImageIcon(getClass().getClassLoader().getResource("image/r4_pi1g_blank.gif"));
  
  ImageIcon R4_swIcon_out = new ImageIcon(getClass().getClassLoader().getResource("image/r4_sw_out.gif"));
  ImageIcon R4_mcIcon_out = new ImageIcon(getClass().getClassLoader().getResource("image/r4_mc_out.gif"));
  ImageIcon R4_piIcon_out = new ImageIcon(getClass().getClassLoader().getResource("image/r4_pi1g_out.gif"));
  
  ImageIcon R4_mcIcon_deact = new ImageIcon(getClass().getClassLoader().getResource("image/r4_mc_deact.gif"));
  ImageIcon R4_swIcon_deact = new ImageIcon(getClass().getClassLoader().getResource("image/r4_sw_deact.gif"));
  ImageIcon R4_piIcon_deact_100M = new ImageIcon(getClass().getClassLoader().getResource("image/r4_pi100_deact.gif"));
  ImageIcon R4_piIcon_deact_hp100M = new ImageIcon(getClass().getClassLoader().getResource("image/r4_pihp100_deact.gif"));
  ImageIcon R4_piIcon_deact_1G = new ImageIcon(getClass().getClassLoader().getResource("image/r4_pi1g_deact.gif"));
  ImageIcon R4_ciIcon_deact = new ImageIcon(getClass().getClassLoader().getResource("image/r4_cei_deact.gif"));
  ImageIcon R4_eiIcon_deact = new ImageIcon(getClass().getClassLoader().getResource("image/r4_ei_deact.gif"));

  // led
  ImageIcon ledIcon_gray = new ImageIcon(getClass().getClassLoader().getResource("image/led_1_deact.gif"));
  ImageIcon ledIcon_green = new ImageIcon(getClass().getClassLoader().getResource("image/led_1_normal.gif"));
  ImageIcon ledIcon_cr = new ImageIcon(getClass().getClassLoader().getResource("image/led_1_critical.gif"));
  ImageIcon ledIcon_mj = new ImageIcon(getClass().getClassLoader().getResource("image/led_1_major.gif"));
  ImageIcon ledIcon_mn = new ImageIcon(getClass().getClassLoader().getResource("image/led_1_minor.gif"));

  ImageIcon ledOntnormal = new ImageIcon(getClass().getClassLoader().getResource("image/led_2_normal.gif"));
  ImageIcon ledOntdown = new ImageIcon(getClass().getClassLoader().getResource("image/led_2_critical.gif"));
  ImageIcon ledOntdeact = new ImageIcon(getClass().getClassLoader().getResource("image/led_2_deact.gif"));
  ImageIcon ledCheck = new ImageIcon(getClass().getClassLoader().getResource("image/led_check.gif"));

  ImageIcon sfp_port_normal = new ImageIcon(getClass().getClassLoader().getResource("image/insert_pin_normal.gif"));
  ImageIcon sfp_port_deact = new ImageIcon(getClass().getClassLoader().getResource("image/insert_pin_deact.gif"));
  ImageIcon sfp_port_alarm = new ImageIcon(getClass().getClassLoader().getResource("image/insert_pin_critical.gif"));
  ImageIcon sfp_port_remove = new ImageIcon(getClass().getClassLoader().getResource("image/insert_pin_remove.gif"));
  ImageIcon sfp_port_remove_deact = new ImageIcon(getClass().getClassLoader().getResource("image/insert_pin_remove_deact.gif"));

  ImageIcon sfp_s_port_normal = new ImageIcon(getClass().getClassLoader().getResource("image/sw_small_led_normal.gif"));
  ImageIcon sfp_s_port_alarm = new ImageIcon(getClass().getClassLoader().getResource("image/sw_small_led_critical.gif"));
  ImageIcon sfp_s_port_deact = new ImageIcon(getClass().getClassLoader().getResource("image/sw_small_led_deact.gif"));

  private DBSlotUnitIF slotInfo;
  private DBR4NiuSfpIF[] niuSfp;
  private boolean blank = true;
  private int crCnt = 0;
  private int mjCnt = 0;
  private int mnCnt = 0;
  private int[] piuPort_100M;
  private int[] piuPort_1G;
  private int piuLine;
  private int cesLine;
  private int nodeId = 0;
  private int shelfId = DBDataDesc.SHELF_OLT1;
  private int selectedOntId = DBDataDesc.NON_SELECTED;
  private int selectedSecondOntId = DBDataDesc.NON_SELECTED;

  private Image imgBack = null;
  private Graphics gback = null;

  /**
   * Constructor.
   *
   * @param _nodeId
   *            nodeId
   * @param _shelfId
   *            shelfId
   * @param slotId
   *            slotId
   * @param blank
   *            blank or not state.
   */
  public R4SlotPanel(int _nodeId, int _shelfId, int slotId, boolean blank) {
    super();
    this.nodeId = _nodeId;
    this.shelfId = _shelfId;
    slotInfo = new DBSlotUnitIF();
    this.slotInfo.slotId = slotId;
    this.blank = blank;
    piuPort_100M = new int[32];
    piuPort_1G = new int[32];
    logger.fine("nodeId: " + nodeId + ", shelfId: " + shelfId + ", blank: " + this.blank);

    setSize();
  }

  /**
   * Set the nodeId and shelfId parameter.
   *
   * @param _nodeId
   *            nodeId
   * @param _shelfId
   *            shelfId
   */
  public void setNodeId(int _nodeId, int _shelfId) {
    this.nodeId = _nodeId;
    this.shelfId = _shelfId;
  }

  /**
   * Set the size of specific slot unit in MC, SI, and SW.
   */
  public void setSize() {
    if (slotInfo.slotId == DBDataDesc.R4_SLOT_MC) {
      this.setPreferredSize(new Dimension(51, 500));
      this.setMaximumSize(new Dimension(51, 500));
      this.setMinimumSize(new Dimension(51, 500));
    } else if (slotInfo.slotId == DBDataDesc.R4_SLOT_SWA || slotInfo.slotId == DBDataDesc.R4_SLOT_SWB ) {
      this.setPreferredSize(new Dimension(88, 500));
      this.setMaximumSize(new Dimension(88, 500));
      this.setMinimumSize(new Dimension(88, 500));
    } else {
      this.setPreferredSize(new Dimension(73, 500));
      this.setMaximumSize(new Dimension(73, 500));
      this.setMinimumSize(new Dimension(73, 500));
    }
  }

  /**
   * Set CR alarm count.
   *
   * @param crCnt
   *            CR alarm count
   */
  public void setCrCnt(int crCnt) {
    this.crCnt = crCnt;
  }

  /**
   * Clear all port in PI unit for normal state.
   */
  public void clrSiPort() {
    piuLine = DBDataDesc.R4_PIUPORT_NORMAL;
    cesLine = DBDataDesc.R4_PIUPORT_NORMAL;

    for (int i = 0; i < piuPort_100M.length; i++) {
      piuPort_100M[i] = DBDataDesc.R4_PIUPORT_DEACT;
    }

    for (int j = 0; j < piuPort_1G.length; j++) {
      piuPort_1G[j] = DBDataDesc.R4_PIUPORT_DEACT;
    }
  }

  /**
   * Clear all NI unit.
   */
  public void clrNiuPort() {

    if (niuSfp == null)
      return;
    if (niuSfp.length != DBDataDesc.MAX_NIU_PORT)
      return;

    for (int i = 0; i < DBDataDesc.MAX_NIU_PORT; i++) {
      niuSfp[i].setAlarmInfo(DBDataDesc.ALM_NORMAL);
    }
  }

  /**
   * Set alarm state of specific port in PI unit.
   *
   * @param port
   *            port number in PI unit
   */
  public void setAlarmPiuPort(int port) {
    if(slotInfo.unitId == DBDataDesc.R4_UNIT_PI_100M || slotInfo.unitId == DBDataDesc.R4_UNIT_PI_HP){
      piuPort_100M[port] = DBDataDesc.R4_PIUPORT_ALARM;
    } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_PI_1G) {
      piuPort_1G[port] = DBDataDesc.R4_PIUPORT_ALARM;
    }
  }

  /**
   * Set alarm state of specific PI unit.
   */
  public void setAlarmPiuLine() {
    piuLine = DBDataDesc.R4_PIUPORT_ALARM;
  }
  
  /**
   * Set alarm state of specific PI unit.
   */
  public void setAlarmCesLine() {
    cesLine = DBDataDesc.R4_PIUPORT_ALARM;
  }

  /**
   * Set deact state of specific port in PI unit.
   *
   * @param port
   *            port number in PI unit
   */
  public void setDeactStatePiuPort(int port) {
    if(slotInfo.unitId == DBDataDesc.R4_UNIT_PI_100M || slotInfo.unitId == DBDataDesc.R4_UNIT_PI_HP){
      piuPort_100M[port] = DBDataDesc.R4_PIUPORT_DEACT;
    } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_PI_1G){
      piuPort_1G[port] = DBDataDesc.R4_PIUPORT_DEACT;
    }
  }

  public void setActStatePiuPort(int port){
    if(slotInfo.unitId == DBDataDesc.R4_UNIT_PI_100M || slotInfo.unitId == DBDataDesc.R4_UNIT_PI_HP){
      piuPort_100M[port] = DBDataDesc.R4_PIUPORT_NORMAL;
    } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_PI_1G){
      piuPort_1G[port] = DBDataDesc.R4_PIUPORT_NORMAL;
    }
  }

  /**
   * Set the count of `major alarm.
   *
   * @param mjCnt
   *            count of major alarm.
   */
  public void setMjCnt(int mjCnt) {
    this.mjCnt = mjCnt;
  }

  /**
   * Set the count of minor alarm.
   *
   * @param mnCnt
   *            count of minor alarm.
   */
  public void setMnCnt(int mnCnt) {
    this.mnCnt = mnCnt;
  }

  /**
   * Set slot unit information from database.
   *
   * @param slotInfo
   *            slot unit information in database.
   */
  public void setSlotInfo(DBSlotUnitIF slotInfo) {
    this.slotInfo = slotInfo;
  }

  /**
   * Set the slotId.
   *
   * @param slotId
   *            slotId
   */
  public void setSlotId(int slotId) {
    this.slotInfo.slotId = slotId;
  }

  /**
   * Set the unitId.
   *
   * @param unitId
   *            unitId
   */
  public void setUnitId(int unitId) {
    this.slotInfo.unitId = unitId;
  }

  /**
   * Return the slot unit information in database.
   *
   * @return DBSlotUnitIF slotInfo
   */
  public DBSlotUnitIF getSlotInfo() {
    return slotInfo;
  }

  /**
   * Return the slotId of slot unit information from database.
   *
   * @return slotInfo.slotId
   */
  public int getSlotId() {
    return slotInfo.slotId;
  }

  /**
   * Return the unitId of slot unit information from database.
   *
   * @return slotInfo.unitId
   */
  public int getUnitId() {
    return slotInfo.unitId;
  }

  /**
   * Return the slot state of slot unit information from database.
   *
   * @return slotInfo.slotState
   */
  public int getSlotState() {
    return slotInfo.slotState;
  }

  /**
   * Draw the specific slot unit.
   */
  public void paintComponent(Graphics g2) {

    int width = getWidth();
    int height = getHeight();

    if (imgBack == null) {
      imgBack = createImage(width, height);
      gback = imgBack.getGraphics();
    }


    if (slotInfo.slotId == DBDataDesc.R4_SLOT_MC) {
      // BLK
      if (slotInfo.unitId == DBDataDesc.R4_UNIT_BLK || slotInfo.unitId == DBDataDesc.R4_UNIT_INIT) {
        gback.drawImage(R4_mcIcon_blank.getImage(), 0, 0, this);
      }
      // INSERT
      else {
        // DEACT
        if (slotInfo.slotState == DBDataDesc.R4_SLOT_DEACT) {
          gback.drawImage(R4_mcIcon_deact.getImage(), 0, 0, this);
        }
        // ACT
        else {
          // OUT
          if (slotInfo.slotState == DBDataDesc.R4_SLOT_OUT) {
            gback.drawImage(R4_mcIcon_out.getImage(), 0, 0, this);
          }
          // ALARM
          else {
            if (slotInfo.alarmInfo == DBDataDesc.ALM_NORMAL) {
              gback.drawImage(R4_mcIcon_nr.getImage(), 0, 0, this);
            } else if (slotInfo.alarmInfo == DBDataDesc.ALM_MN) {
              gback.drawImage(R4_mcIcon_mn.getImage(), 0, 0, this);
            } else if (slotInfo.alarmInfo == DBDataDesc.ALM_MJ) {
              gback.drawImage(R4_mcIcon_mj.getImage(), 0, 0, this);
            } else if (slotInfo.alarmInfo == DBDataDesc.ALM_CR) {
              gback.drawImage(R4_mcIcon_cr.getImage(), 0, 0, this);
            } else {
              gback.drawImage(R4_mcIcon_nr.getImage(), 0, 0, this);
            }

            showAcoLed(gback);
          }
        }
      }
    }  else if (slotInfo.slotId == DBDataDesc.R4_SLOT_SWA || slotInfo.slotId == DBDataDesc.R4_SLOT_SWB) {
      // BLK
      if (slotInfo.unitId == DBDataDesc.R4_UNIT_BLK || slotInfo.unitId == DBDataDesc.R4_UNIT_INIT) {
        gback.drawImage(R4_swIcon_blank.getImage(), 0, 0, this);
      }
      // INSERT
      else {
        // DEACT
        if (slotInfo.slotState == DBDataDesc.R4_SLOT_DEACT) {
          gback.drawImage(R4_swIcon_deact.getImage(), 0, 0, this);
        }
        // ACT
        else {
          // OUT
          if (slotInfo.slotState == DBDataDesc.R4_SLOT_OUT) {
            gback.drawImage(R4_swIcon_out.getImage(), 0, 0, this);
          }
          // ALARM
          else {
            if (slotInfo.alarmInfo == DBDataDesc.ALM_NORMAL) {
              gback.drawImage(R4_swIcon_nr.getImage(), 0, 0, this);
            } else if (slotInfo.alarmInfo == DBDataDesc.ALM_MN) {
              gback.drawImage(R4_swIcon_mn.getImage(), 0, 0, this);
            } else if (slotInfo.alarmInfo == DBDataDesc.ALM_MJ) {
              gback.drawImage(R4_swIcon_mj.getImage(), 0, 0, this);
            } else if (slotInfo.alarmInfo == DBDataDesc.ALM_CR) {
              gback.drawImage(R4_swIcon_cr.getImage(), 0, 0, this);
            } else {
              gback.drawImage(R4_swIcon_nr.getImage(), 0, 0, this);
            }
            showNiuSfpPort(gback);
          }
        }
      }
    } else {
      // BLK
      if (slotInfo.unitId == DBDataDesc.R4_UNIT_BLK || slotInfo.unitId == DBDataDesc.R4_UNIT_INIT) {
        gback.drawImage(R4_piIcon_blank.getImage(), 0, 0, this);
      }
      // INSERT
      else {
        // DEACT
        if (slotInfo.slotState == DBDataDesc.R4_SLOT_DEACT) {
          if (slotInfo.unitId == DBDataDesc.R4_UNIT_PI_100M) {
            gback.drawImage(R4_piIcon_deact_100M.getImage(), 0, 0, this);
          } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_PI_HP) {
            gback.drawImage(R4_piIcon_deact_hp100M.getImage(), 0, 0, this);
          } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_PI_1G) {
            gback.drawImage(R4_piIcon_deact_1G.getImage(), 0, 0, this);
          } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_EI) {
            gback.drawImage(R4_eiIcon_deact.getImage(), 0, 0, this);
          } else {
            gback.drawImage(R4_ciIcon_deact.getImage(), 0, 0, this);
          }
        }
        // ACT
        else {
          // OUT
          if (slotInfo.slotState == DBDataDesc.R4_SLOT_OUT) {
            gback.drawImage(R4_piIcon_out.getImage(), 0, 0, this);
          }
          // ALARM
          else {
            if (slotInfo.alarmInfo == DBDataDesc.ALM_NORMAL) {
              if (slotInfo.unitId == DBDataDesc.R4_UNIT_PI_100M) {
                gback.drawImage(R4_piIcon_100M_nr.getImage(), 0, 0, this);
              } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_PI_HP) {
                gback.drawImage(R4_piIcon_hp100M_nr.getImage(), 0, 0, this);
              } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_PI_1G) {
                gback.drawImage(R4_piIcon_1G_nr.getImage(), 0, 0, this);
              } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_EI) {
                gback.drawImage(R4_eiIcon_nr.getImage(), 0, 0, this);
              }else {
                gback.drawImage(R4_ciIcon_nr.getImage(), 0, 0, this);
              }
            } else if (slotInfo.alarmInfo == DBDataDesc.ALM_MN) {
              if (slotInfo.unitId == DBDataDesc.R4_UNIT_PI_100M) {
                gback.drawImage(R4_piIcon_100M_mn.getImage(), 0, 0, this);
              } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_PI_HP) {
                gback.drawImage(R4_piIcon_hp100M_mn.getImage(), 0, 0, this);
              } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_PI_1G){
                gback.drawImage(R4_piIcon_1G_mn.getImage(), 0, 0, this);
              } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_EI){
                gback.drawImage(R4_eiIcon_mn.getImage(), 0, 0, this);
              } else {
                gback.drawImage(R4_ciIcon_mn.getImage(), 0, 0, this);
              }
            } else if (slotInfo.alarmInfo == DBDataDesc.ALM_MJ) {
              if (slotInfo.unitId == DBDataDesc.R4_UNIT_PI_100M) {
                gback.drawImage(R4_piIcon_100M_mj.getImage(), 0, 0, this);
              } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_PI_HP) {
                gback.drawImage(R4_piIcon_hp100M_mj.getImage(), 0, 0, this);
              } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_PI_1G) {
                gback.drawImage(R4_piIcon_1G_mj.getImage(), 0, 0, this);
              } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_EI) {
                gback.drawImage(R4_eiIcon_mj.getImage(), 0, 0, this);
              } else {
                gback.drawImage(R4_ciIcon_mj.getImage(), 0, 0, this);
              }
            } else if (slotInfo.alarmInfo == DBDataDesc.ALM_CR) {
              if (slotInfo.unitId == DBDataDesc.R4_UNIT_PI_100M) {
                gback.drawImage(R4_piIcon_100M_cr.getImage(), 0, 0, this);
              } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_PI_HP) {
                gback.drawImage(R4_piIcon_hp100M_cr.getImage(), 0, 0, this);
              } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_PI_1G){
                gback.drawImage(R4_piIcon_1G_cr.getImage(), 0, 0, this);
              } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_EI){
                gback.drawImage(R4_eiIcon_cr.getImage(), 0, 0, this);
              } else {
                gback.drawImage(R4_ciIcon_cr.getImage(), 0, 0, this);
              }
            } else {
              if (slotInfo.unitId == DBDataDesc.R4_UNIT_PI_100M) {
                gback.drawImage(R4_piIcon_100M_nr.getImage(), 0, 0, this);
              } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_PI_HP) {
                gback.drawImage(R4_piIcon_hp100M_nr.getImage(), 0, 0, this);
              } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_PI_1G) {
                gback.drawImage(R4_piIcon_1G_nr.getImage(), 0, 0, this);
              } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_EI) {
                gback.drawImage(R4_eiIcon_nr.getImage(), 0, 0, this);
              } else {
                gback.drawImage(R4_ciIcon_nr.getImage(), 0, 0, this);
              }
            }
          }
        }
      }
    }

    if (slotInfo.slotState != DBDataDesc.R4_SLOT_OUT && 
        slotInfo.slotState != DBDataDesc.R4_SLOT_BLK && 
        slotInfo.slotState != DBDataDesc.R4_SLOT_DEACT) {
      showWork(gback);
      showFail(gback);
      showAlarm(gback);
      showPiuPort(gback);
      showSiLine(gback);
      showESpringPort(gback);
    }

    g2.drawImage(imgBack, 0, 0, this);
  } // paintComponent end

  /**
   * Draw the working state of the unit.
   *
   * @param g
   *            Graphics component
   */
  public void showWork(Graphics g) {
    if (slotInfo.unitId == DBDataDesc.R4_UNIT_MC || slotInfo.unitId == DBDataDesc.R4_UNIT_SW ||
        slotInfo.unitId == DBDataDesc.R4_UNIT_PI_100M || slotInfo.unitId == DBDataDesc.R4_UNIT_PI_HP ||
        slotInfo.unitId == DBDataDesc.R4_UNIT_PI_1G) {
      if (slotInfo.slotState == DBDataDesc.R4_SLOT_DEACT) {
        ledIcon_gray.paintIcon(this, g, 10, 77);
      } else {
        if (slotInfo.workingFlag == DBDataDesc.STANDBY) {
          ledIcon_gray.paintIcon(this, g, 10, 77);
        } else if (slotInfo.workingFlag == DBDataDesc.WORKING) {
          ledIcon_green.paintIcon(this, g, 10, 77);
        }
      }
    } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_CI) {
      if (slotInfo.slotState == DBDataDesc.R4_SLOT_DEACT) {
        ledIcon_gray.paintIcon(this, g, 7, 77);
      } else {
        if (slotInfo.workingFlag == DBDataDesc.STANDBY) {
          ledIcon_gray.paintIcon(this, g, 7, 77);
        } else if (slotInfo.workingFlag == DBDataDesc.WORKING) {
          ledIcon_green.paintIcon(this, g, 7, 77);
        }
      }
    } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_EI) {
      if (slotInfo.slotState == DBDataDesc.R4_SLOT_DEACT) {
        ledIcon_gray.paintIcon(this, g, 10, 72);
      } else {
        if (slotInfo.workingFlag == DBDataDesc.STANDBY) {
          ledIcon_gray.paintIcon(this, g, 10, 72);
        } else if (slotInfo.workingFlag == DBDataDesc.WORKING) {
          ledIcon_green.paintIcon(this, g, 10, 72);
        }
      }
    }
  }

  /**
   * Draw the fail state of the unit.
   *
   * @param g
   *            Graphics component
   */
  public void showFail(Graphics g) {
    if (slotInfo.unitId == DBDataDesc.R4_UNIT_MC || slotInfo.unitId == DBDataDesc.R4_UNIT_SW || 
        slotInfo.unitId == DBDataDesc.R4_UNIT_PI_100M || slotInfo.unitId == DBDataDesc.R4_UNIT_PI_HP ||
        slotInfo.unitId == DBDataDesc.R4_UNIT_PI_1G) {

      if (slotInfo.slotState == DBDataDesc.R4_SLOT_FAULT || slotInfo.slotState == DBDataDesc.R4_SLOT_MISMATCH) {
        ledIcon_cr.paintIcon(this, g, 10, 90);
      } else {
        ledIcon_gray.paintIcon(this, g, 10, 90);
      }
    } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_CI) {
      if (slotInfo.slotState == DBDataDesc.R4_SLOT_FAULT || slotInfo.slotState == DBDataDesc.R4_SLOT_MISMATCH) {
        ledIcon_cr.paintIcon(this, g, 7, 90);
      } else {
        ledIcon_gray.paintIcon(this, g, 7, 90);
      }
    } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_EI) {
      if (slotInfo.slotState == DBDataDesc.R4_SLOT_FAULT || slotInfo.slotState == DBDataDesc.R4_SLOT_MISMATCH) {
        ledIcon_cr.paintIcon(this, g, 10, 84);
      } else {
        ledIcon_gray.paintIcon(this, g, 10, 84);
      }
    }
  }

  /**
   * Draw the ports of the PI unit.
   *
   * @param g
   *            Graphics component
   */
  public void showPiuPort(Graphics g) {

    if (slotInfo.unitId == DBDataDesc.R4_UNIT_PI_100M || slotInfo.unitId == DBDataDesc.R4_UNIT_PI_HP) {

      for (int i = 0; i < piuPort_100M.length; i++) {

        int rest = i % 2;
        int share = i / 2;

        int xLocation = 17 + rest * 11;
        int yLocation = 169 + share * 11;

        switch(piuPort_100M[i]) {
        case DBDataDesc.R4_PIUPORT_ALARM:
          ledOntdown.paintIcon(this, g, xLocation, yLocation);
          break;
        case DBDataDesc.R4_PIUPORT_DEACT:
          ledOntdeact.paintIcon(this, g, xLocation, yLocation);
          break;
        default:
          ledOntnormal.paintIcon(this, g, xLocation, yLocation);
        break;
        }
      }
    } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_PI_1G) {

      for (int i = 0; i < piuPort_1G.length; i++) {

        int rest = i % 2;
        int share = i / 2;

        int xLocation = 17 + rest * 11;
        int yLocation = 169 + share * 11;

        switch(piuPort_1G[i]) {
        case DBDataDesc.R4_PIUPORT_ALARM:
          ledOntdown.paintIcon(this, g, xLocation, yLocation);
          break;
        case DBDataDesc.R4_PIUPORT_DEACT:
          ledOntdeact.paintIcon(this, g, xLocation, yLocation);
          break;
        default:
          ledOntnormal.paintIcon(this, g, xLocation, yLocation);
        break;
        }
      }
    }
  }
  
  
  /**
   * Draw the ports of the PI unit.
   *
   * @param g
   *            Graphics component
   */
  public void showPiuPortInPonLinkFailure(Graphics g) {

    if (slotInfo.unitId == DBDataDesc.R4_UNIT_PI_100M || slotInfo.unitId == DBDataDesc.R4_UNIT_PI_HP) {

      for (int i = 0; i < piuPort_100M.length; i++) {

        int rest = i % 2;
        int share = i / 2;

        int xLocation = 17 + rest * 11;
        int yLocation = 169 + share * 11;

        ledOntdeact.paintIcon(this, g, xLocation, yLocation);
      }
    } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_PI_1G) {

      for (int i = 0; i < piuPort_1G.length; i++) {

        int rest = i % 2;
        int share = i / 2;

        int xLocation = 17 + rest * 11;
        int yLocation = 169 + share * 11;

        ledOntdeact.paintIcon(this, g, xLocation, yLocation);
      }
    }
  }


  /**
   * Draw the ports of the PI unit.
   *
   * @param gback
   *            Graphics component
   */
  public void showESpringPort(Graphics g) {

    if( (slotInfo.unitId != DBDataDesc.R4_UNIT_PI_100M)  && 
      (slotInfo.unitId != DBDataDesc.R4_UNIT_PI_HP)  &&
      (slotInfo.unitId != DBDataDesc.R4_UNIT_PI_1G) )  return;

    if(selectedOntId != DBDataDesc.NON_SELECTED) {

      int rest = (selectedOntId - DBDataDesc.PORT_ONT1) % 2;
      int share = (selectedOntId - DBDataDesc.PORT_ONT1) / 2;

      int xLocation = 17 + rest * 11;
      int yLocation = 169 + share * 11;

      ledCheck.paintIcon(this, g, xLocation, yLocation);

    }

    if(selectedSecondOntId != DBDataDesc.NON_SELECTED) {

      int rest = (selectedSecondOntId - DBDataDesc.PORT_ONT1) % 2;
      int share = (selectedSecondOntId - DBDataDesc.PORT_ONT1) / 2;

      int xLocation = 17 + rest * 11;
      int yLocation = 169 + share * 11;

      ledCheck.paintIcon(this, g, xLocation, yLocation);

    }
  }


  /**
   * Draw the ports of the PI unit.
   *
   * @param gback
   *            Graphics component
   */
  public void setSelectedOntId(int ontonuId) {
    selectedOntId = ontonuId;
  }

  public void setSelectedSecondOntId(int ontonuId) {
    selectedSecondOntId = ontonuId;
  }


  /**
   * Draw the line of PI unit.
   *
   * @param g
   *            Graphics component
   */
  public void showSiLine(Graphics g) {
    if (slotInfo.unitId == DBDataDesc.R4_UNIT_PI_100M || 
      slotInfo.unitId == DBDataDesc.R4_UNIT_PI_HP ||
      slotInfo.unitId == DBDataDesc.R4_UNIT_PI_1G) {
      if (piuLine == DBDataDesc.R4_PIUPORT_ALARM) {
        ledIcon_cr.paintIcon(this, g, 10, 118);
        showPiuPortInPonLinkFailure(g);
      } else {
        ledIcon_green.paintIcon(this, g, 10, 131);
      }
    } else if (slotInfo.unitId == DBDataDesc.R4_UNIT_CI) {
      if (cesLine == DBDataDesc.R4_PIUPORT_ALARM) {
        ledIcon_cr.paintIcon(this, g, 48, 126);
      } 
    }
  }

  /**
   * Set NI unit information from database.
   *
   * @param niuSfp
   *            DBR4NiuSfpIF
   */
  public void setNiuSfp(DBR4NiuSfpIF[] niuSfp) {
    this.niuSfp = niuSfp;
  }

  /**
   * Set the alarm info of NIU SFP.
   *
   * @param portId
   */
  public void setAlarmNiuSfp(int portId) {

    if (niuSfp == null)
      return;

    if (niuSfp.length != DBDataDesc.MAX_NIU_PORT)
      return;
    if ((portId > 0) && (portId <= DBDataDesc.MAX_NIU_PORT)) {
      niuSfp[portId - 1].setAlarmInfo(DBDataDesc.ALM_CR);
    }
  }

  /**
   * Draw the ports of NIU SFP.
   *
   * @param g
   *            Graphics component
   */
  public void showNiuSfpPort(Graphics g) {

    if (slotInfo.unitId == DBDataDesc.R4_UNIT_SW) {

      if (niuSfp != null && niuSfp.length != DBDataDesc.MAX_NIU_PORT)
        return;

      for (int i = 0; i < DBDataDesc.MAX_NIU_PORT; i++) {

        int yIndex = i;
        yIndex = yIndex % 8;

        int xLocation = 11;
        int yLocation = 158 + (yIndex * 33);

        int xSmallLed = 0;
        int ySmallLed = 0;

        switch (yIndex) {
        case 0:
          xSmallLed = 11;
          ySmallLed = 111;
          break;
        case 1:
          xSmallLed = 16;
          ySmallLed = 111;
          break;
        case 2:
          xSmallLed = 21;
          ySmallLed = 111;
          break;
        case 3:
          xSmallLed = 26;
          ySmallLed = 111;
          break;
        case 4:
          xSmallLed = 11;
          ySmallLed = 123;
          break;
        case 5:
          xSmallLed = 16;
          ySmallLed = 123;
          break;
        case 6:
          xSmallLed = 21;
          ySmallLed = 123;
          break;
        case 7:
          xSmallLed = 26;
          ySmallLed = 123;
          break;
        }

        int portStatus = DBDataDesc.SFP_ACT;

        if (niuSfp == null){
          sfp_s_port_deact.paintIcon(this, g, xSmallLed, ySmallLed);
          continue;
        }

        if (niuSfp[i] == null)
          return;

        if (niuSfp[i].portStatus == DBDataDesc.ACT) {
          if (niuSfp[i].opticInsert == DBDataDesc.OPTIC_INSERT) {
            portStatus = DBDataDesc.SFP_ACT;
          } else {
            portStatus = DBDataDesc.SFP_REMOVE;
          }
        } else {
          if (niuSfp[i].opticInsert == DBDataDesc.OPTIC_INSERT) {
            portStatus = DBDataDesc.SFP_DEACT;
          } else {
            portStatus = DBDataDesc.SFP_REMOVE_DEACT;
          }
        }

        switch (portStatus) {
        case DBDataDesc.SFP_ACT:
          sfp_port_normal.paintIcon(this, g, xLocation, yLocation);
          sfp_s_port_normal.paintIcon(this, g, xSmallLed, ySmallLed);
          break;
        case DBDataDesc.SFP_DEACT:
          sfp_port_deact.paintIcon(this, g, xLocation, yLocation);
          sfp_s_port_deact.paintIcon(this, g, xSmallLed, ySmallLed);
          break;
        case DBDataDesc.SFP_REMOVE:
          sfp_port_remove.paintIcon(this, g, xLocation, yLocation);
          sfp_s_port_deact.paintIcon(this, g, xSmallLed, ySmallLed);
          break;
        case DBDataDesc.SFP_REMOVE_DEACT:
          sfp_port_remove_deact.paintIcon(this, g, xLocation, yLocation);
          sfp_s_port_deact.paintIcon(this, g, xSmallLed, ySmallLed);
          break;
        default:
          sfp_port_normal.paintIcon(this, g, xLocation, yLocation);
          sfp_s_port_normal.paintIcon(this, g, xSmallLed, ySmallLed);
          break;
        }

        if (niuSfp[i].alarmInfo == DBDataDesc.ALM_CR) {
          if(portStatus == DBDataDesc.SFP_ACT) {
            sfp_port_alarm.paintIcon(this, g, xLocation, yLocation);
            sfp_s_port_alarm.paintIcon(this, g, xSmallLed, ySmallLed);
          }
        }
      }
    }
  }

  /**
   * Draw the ACO LED.
   *
   * @param g
   *            Graphics component
   */
  public void showAcoLed(Graphics g) {

    // location is changed from 190 to 235
    // always LED off
    int xLocation = 10;
    int yLocation = 235;

    ledIcon_gray.paintIcon(this, g, xLocation, yLocation);
  }

  /**
   * Draw the alarm LED and alarm history of MC unit.
   *
   * @param g
   *            Graphics component
   */
  public void showAlarm(Graphics g) {
    if (slotInfo.unitId == DBDataDesc.R4_UNIT_MC) {
      if (crCnt == 0) {
        ledIcon_gray.paintIcon(this, g, 10, 118);
      } else {
        ledIcon_cr.paintIcon(this, g, 10, 118);
      }

      if (mjCnt == 0) {
        ledIcon_gray.paintIcon(this, g, 10, 131);
      } else {
        ledIcon_mj.paintIcon(this, g, 10, 131);
      }

      if (mnCnt == 0) {
        ledIcon_gray.paintIcon(this, g, 10, 144);
      } else {
        ledIcon_mn.paintIcon(this, g, 10, 144);
      }

      //
      //  always off..
      //  alarm history LED.. location is changed from 235 --> 190..
      //
      ledIcon_gray.paintIcon(this, g, 10, 190);
    }
  }

  }
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.