关闭

端口配置

475人阅读 评论(0) 收藏 举报
package com.zg.component.ui.vlanchannel;

import javax.swing.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import com.zg.ems.client.util.*;

public class PortChannelConfigDlg
    
extends JDialog implements ActionListener {

  
public final static int Only_Port_Type = 1//只显示端口
  public final static int Port_Channel_Type = 2//端口,通道都显示
  
  
public final static int Binding = 1;
  
public final static int Unbinding = 2;
  
public final static int BindingDefault = 0;

  
private BorderLayout borderLayout1 = new BorderLayout();
  
private BorderLayout borderLayout2 = new BorderLayout();
  
private BorderLayout borderLayout3 = new BorderLayout();
  
private BorderLayout borderLayout4 = new BorderLayout();
  
private BorderLayout borderLayout5 = new BorderLayout();
  
private BorderLayout borderLayout6 = new BorderLayout();
  
private GridBagLayout gridBagLayout1 = new GridBagLayout();
  
private GridBagLayout gridBagLayout2 = new GridBagLayout();

  
private JPanel toppanel = new JPanel();
  
private JPanel leftpanel = new JPanel();
  
private JPanel rightpanel = new JPanel();
  
private JPanel footpanel = new JPanel();
  
private JPanel centerpanel = new JPanel();

  
private JLabel jLabel1 = new JLabel();
  
private JLabel jLabel2 = new JLabel();
  
private JLabel jLabel3 = new JLabel();
  
private JLabel titleLabel = new JLabel();

  
private JPanel cardpanel = new JPanel();
  
private JPanel portpanel = new JPanel();
  
private JPanel chosedpanel = new JPanel();
  
private JPanel footPanel = new JPanel();
  
private JPanel buttonPanel = new JPanel();
  
private JPanel jPanel3 = new JPanel();
  
private JPanel jPanel4 = new JPanel(new FlowLayout(FlowLayout.LEFT));
  
private JPanel channelPanel = new JPanel();

  
private JScrollPane cardScrollPane = new JScrollPane();
  
private JScrollPane portScrollPane = new JScrollPane();
  
private JScrollPane choosedScrollPane = new JScrollPane();

  
private JButton addButton = new JButton();
  
private JButton delButton = new JButton();
  
private JButton clearAllButton = new JButton();
  
private JButton allChoiceButton = new JButton();
  
private JButton orderButton = new JButton();
  
private JButton clearResultButton = new JButton();
  
private JButton okButton = new JButton();
  
private JButton cancleButton = new JButton();

  
private JCheckBox[] portcheckboxs = new JCheckBox[32];
  
private JCheckBox[][] chanlecheckboxs = new JCheckBox[32][8];
  JList choosedList 
= new JList();
  
private static JList cardlist;
  
private DefaultListModel choosedList_model = new DefaultListModel();

  
private int[] hasCardIndex; //在线的板卡号,从1开始,主控盘为17或18号盘
  private int portType; //取两个值Only_Port_Type和Port_Channel_Type
  private int currentCard = 1//当前正在配置的板卡
  private HashMap portState = new HashMap(18);//端口状态

  
private String portList;//PortList字符串,十六进制
  private static PortChannelConfigDlg vlanPortChannelDlg = null;

  
private HashMap portlistMap;//PortList对应的名称及其PortList对
  private String portlistName;//PortList对应的名称
  private int bindingType = 0//1:绑定,2:解绑定,0:普通

  
/**
   * 单例
   
*/

  
public static PortChannelConfigDlg getInstance(Window owner,
                                                 
int[] hasCardIndex,
                                                 
int portType,
                                                 String portlistName) 
{
    
if (vlanPortChannelDlg != null{
      vlanPortChannelDlg.portlistName 
= portlistName;
      vlanPortChannelDlg.hasCardIndex 
= hasCardIndex;
      vlanPortChannelDlg.portType 
= portType;
      vlanPortChannelDlg.initCardPanel();
      vlanPortChannelDlg.initPortState();
      
if (vlanPortChannelDlg.cardlist != null{
        vlanPortChannelDlg.cardlist.setSelectedIndex(
0);
      }

      vlanPortChannelDlg.choosedList_model.clear();
      vlanPortChannelDlg.choosedList.setModel(vlanPortChannelDlg.
                                              choosedList_model);
    }

    
else {
      
if (owner instanceof Frame) {
        vlanPortChannelDlg 
= new PortChannelConfigDlg( (Frame) owner,
            hasCardIndex,
            portType, portlistName);
      }

      
else if (owner instanceof Dialog) {
        vlanPortChannelDlg 
= new PortChannelConfigDlg( (Dialog) owner,
            hasCardIndex,
            portType, portlistName);
      }

    }

    
return vlanPortChannelDlg;
  }


  
public void setPortlistMap(HashMap portlistMap) {
    
this.portlistMap = portlistMap;
  }


  
private PortChannelConfigDlg(Frame owner, int[] hasCardIndex,
                               
int portType, String portlistName) {
    
super(owner, true);
    initPortState();
    
this.portlistName = portlistName;
    
this.portType = portType;
    
this.hasCardIndex = hasCardIndex;
    
try {
      jbInit();
    }

    
catch (Exception ex) {
      ex.printStackTrace();
    }

  }


  
private PortChannelConfigDlg(Dialog owner, int[] hasCardIndex,
                               
int portType, String portlistName) {
    
super(owner, true);
    initPortState();
    
this.portlistName = portlistName;
    
this.portType = portType;
    
this.hasCardIndex = hasCardIndex;
    
try {
      jbInit();
    }

    
catch (Exception ex) {
      ex.printStackTrace();
    }

  }


  
public void showDlg() {
    
if (this.portType == Port_Channel_Type) {
      
this.setSize(new Dimension(900600));
    }

    
else {
      
this.setSize(new Dimension(700500));
    }

    DlgUtils.setCenter(
this);
    
this.setVisible(true);
  }


  
public void fresh() {
    
if (portList == null{
      StringBuffer buffer 
= new StringBuffer();
      
for (int k = 0; k < 1154; k++{
        buffer.append(
"0");
      }

      portList 
= buffer.toString();
    }

    
if (portList.equals("")) {
      StringBuffer buffer 
= new StringBuffer();
      
for (int k = 0; k < 1154; k++{
        buffer.append(
"0");
      }

      portList 
= buffer.toString();
    }

    String binarystr 
= PortListData.hexToBinary(portList);
    setPortState(binarystr);
    freshPortstate();
    initSelectedList();
  }


  
public void setDlgTitle(String title) {
    vlanPortChannelDlg.setTitle(title);
    titleLabel.setText(title);
  }


  
private void initPortState() {
    
int[][] card = new int[32][8];
    
for (int i = 0; i < 18; i++{
      portState.put(
new Integer(i + 1), card);
    }

  }


  
private void setPortState(String binaryPortStateString) {
    
if (binaryPortStateString == null{
      
return;
    }

    portState.clear();
    
for (int i = 0; i < 18; i++{
      
int[][] cardstate = new int[32][8];
      String card 
= binaryPortStateString.substring(i * 32 * 8,
          i 
* 32 * 8 + 32 * 8);
      
for (int j = 0; j < 32; j++{
        
int portindex = j;
        
for (int k = 0; k < 8; k++{
          
int channalindex = k;
          
char port = card.charAt(portindex * 8 + channalindex);
          
if (port == '1'{
            cardstate[portindex][channalindex] 
= 1;
          }

          
else {
            cardstate[portindex][channalindex] 
= 0;
          }

        }

      }

      portState.put(
new Integer(i + 1), cardstate);
    }

  }


  
private void jbInit() throws Exception {
    setTitle(
"端口设置");
    
this.getContentPane().setLayout(borderLayout6);
    choosedList.setModel(choosedList_model);
    toppanel.setPreferredSize(
new Dimension(1030));
    centerpanel.setLayout(borderLayout1);
    jLabel1.setText(
"选择板卡号:");
    cardpanel.setBorder(BorderFactory.createEtchedBorder());
    cardpanel.setPreferredSize(
new Dimension(100100));
    cardpanel.setLayout(borderLayout3);
    jLabel2.setText(
"选择端口号:");
    chosedpanel.setPreferredSize(
new Dimension(200100));
    chosedpanel.setLayout(borderLayout4);
    jLabel3.setText(
"已选端口号:");
    titleLabel.setText(
"端口设置");
    portpanel.setLayout(borderLayout2);
    jPanel3.setLayout(borderLayout5);
    buttonPanel.setMinimumSize(
new Dimension(5040));
    buttonPanel.setLayout(gridBagLayout1);
    addButton.setHorizontalTextPosition(SwingConstants.CENTER);
    addButton.setText(
">>");
    addButton.setActionCommand(
"add");
    addButton.addActionListener(
this);
    footPanel.setPreferredSize(
new Dimension(20035));
    delButton.setText(
"<<");
    delButton.setActionCommand(
"del");
    delButton.addActionListener(
this);
    clearAllButton.setText(
"全不选");
    clearAllButton.setActionCommand(
"clearall");
    clearAllButton.addActionListener(
this);
    allChoiceButton.setText(
"全选");
    allChoiceButton.setActionCommand(
"allchoice");
    allChoiceButton.addActionListener(
this);
    portpanel.setBorder(BorderFactory.createEtchedBorder());
    jPanel3.setBorder(BorderFactory.createEtchedBorder());
    orderButton.setText(
"排序");
    orderButton.setActionCommand(
"order");
    orderButton.addActionListener(
this);
    clearResultButton.setText(
"清空");
    clearResultButton.setActionCommand(
"clearresult");
    clearResultButton.addActionListener(
this);
    jPanel4.setPreferredSize(
new Dimension(13535));
    footpanel.setPreferredSize(
new Dimension(1040));
    okButton.setText(
"确定");
    okButton.setActionCommand(
"ok");
    okButton.addActionListener(
this);
    cancleButton.setText(
"取消");
    cancleButton.setActionCommand(
"cancle");
    cancleButton.addActionListener(
this);
    channelPanel.setLayout(gridBagLayout2);
    toppanel.add(titleLabel);
    centerpanel.add(cardpanel, java.awt.BorderLayout.WEST);
    centerpanel.add(portpanel, java.awt.BorderLayout.CENTER);
    centerpanel.add(chosedpanel, java.awt.BorderLayout.EAST);
    footpanel.add(okButton);
    footpanel.add(cancleButton);
    portpanel.add(portScrollPane, java.awt.BorderLayout.CENTER);
    portScrollPane.getViewport().add(channelPanel);

    
if (hasCardIndex != null{
      
if (hasCardIndex.length > 0{
        initPortChannelPanel(
32, portType,
                             (
int[][]) portState.get(new Integer(hasCardIndex[0])));
        initCardPanel();
      }

    }

    cardScrollPane.getViewport().add(cardlist);
    chosedpanel.add(buttonPanel, java.awt.BorderLayout.WEST);
    jPanel3.add(choosedScrollPane, java.awt.BorderLayout.CENTER);
    choosedScrollPane.getViewport().add(choosedList);
    chosedpanel.add(jPanel3, java.awt.BorderLayout.CENTER);
    jPanel4.add(allChoiceButton);
    jPanel4.add(clearAllButton);
    buttonPanel.add(delButton, 
new GridBagConstraints(01110.00.0
        , GridBagConstraints.CENTER,
        GridBagConstraints.NONE,
        
new Insets(0000), 03));
    buttonPanel.add(addButton, 
new GridBagConstraints(00110.00.0
        , GridBagConstraints.CENTER,
        GridBagConstraints.NONE,
        
new Insets(70410), 03));
    cardpanel.add(cardScrollPane, java.awt.BorderLayout.CENTER);
    cardpanel.add(jLabel1, java.awt.BorderLayout.NORTH);
    portpanel.add(jLabel2, java.awt.BorderLayout.NORTH);
    portpanel.add(jPanel4, java.awt.BorderLayout.SOUTH);
    jPanel3.add(jLabel3, java.awt.BorderLayout.NORTH);
    jPanel3.add(footPanel, java.awt.BorderLayout.SOUTH);
    footPanel.add(clearResultButton);
    footPanel.add(orderButton);
    
this.getContentPane().add(footpanel, java.awt.BorderLayout.SOUTH);
    
this.getContentPane().add(toppanel, java.awt.BorderLayout.NORTH);
    
this.getContentPane().add(centerpanel, java.awt.BorderLayout.CENTER);
    
this.getContentPane().add(rightpanel, java.awt.BorderLayout.EAST);
    
this.getContentPane().add(leftpanel, java.awt.BorderLayout.WEST);
  }


  
/**
   * 初始化端口和通道
   * 
@param portnum int 端口数
   * 
@param portType int 样式:只有端口或既有端口又有通道
   * 
@param cardstate int[][] 32×8的数组,标示端口,通道状态
   
*/

  
private void initPortChannelPanel(int portnum, int portType,
                                    
int[][] cardstate) {
    
if (cardstate == null{
      cardstate 
= new int[32][8];
    }

    
if (portType == Only_Port_Type) {
      initPortPanel(portnum, cardstate);
    }

    
else if (portType == Port_Channel_Type) {
      initChannelPanel(portnum, cardstate);
    }

  }


  
/**
   * 初始化端口
   * 
@param portnum int
   * 
@param cardstate int[][]
   
*/

  
private void initPortPanel(int portnum, int[][] cardstate) {
    
int rowindex = 0;
    
for (int i = 0; i < portnum; i++{
      JCheckBox jCheckBox 
= new JCheckBox();
      
int port = i + 1;
      jCheckBox.setText(
" 端口" + port);
      portcheckboxs[i] 
= jCheckBox;
      portcheckboxs[i].addActionListener(
new PortCheckBoxAction(this, i));
      channelPanel.add(jCheckBox,
                       
new GridBagConstraints(i % 4, i / 4110.00.0
                                              , GridBagConstraints.CENTER,
                                              GridBagConstraints.BOTH,
                                              
new Insets(5000), 00));
      rowindex
++;
    }

  }


  
/**
   * 初始化通道
   * 
@param portnum int
   * 
@param cardstate int[][]
   
*/

  
private void initChannelPanel(int portnum, int[][] cardstate) {
    
int rowindex = 0;
    
for (int i = 0; i < portnum; i++{
      JCheckBox jCheckBox 
= new JCheckBox();
      
int port = i + 1;
      jCheckBox.setText(
" 端口" + port);
      portcheckboxs[i] 
= jCheckBox;
      portcheckboxs[i].addActionListener(
new PortCheckBoxAction(this, i));
      channelPanel.add(jCheckBox,
                       
new GridBagConstraints(0, rowindex, 110.00.0
                                              , GridBagConstraints.CENTER,
                                              GridBagConstraints.BOTH,
                                              
new Insets(5000), 00));
      rowindex
++;
      
for (int j = 0; j < 8; j++{
        JCheckBox jCheckBox1 
= new JCheckBox();
        
if (cardstate[i][j] == 1{
          jCheckBox1.setSelected(
true);
        }

        chanlecheckboxs[i][j] 
= jCheckBox1;
        
int chanle = j + 1;
        jCheckBox1.setText(
"通道" + chanle);
        
int empty = (j == 0? 20 : 5;
        channelPanel.add(jCheckBox1,
                         
new GridBagConstraints(j, rowindex, 110.00.0
                                                , GridBagConstraints.CENTER,
                                                GridBagConstraints.BOTH,
                                                
new Insets(2, empty, 00), 0,
                                                
0));
      }

      rowindex
++;
    }

  }


  
/**
   * 初始化板卡
   
*/

  
private void initCardPanel() {
    
if (hasCardIndex == null{
      
return;
    }

    Vector cardindex 
= new Vector();
    
for (int i = 0; i < hasCardIndex.length; i++{
      cardindex.add(
"板卡" + hasCardIndex[i]);
    }

    cardlist 
= new JList(cardindex);
    cardlist.addListSelectionListener(
new CardListSelectListener(this));
    cardlist.setSelectedIndex(
0);
    currentCard 
= hasCardIndex[0];
  }


  
/**
   *  初始化已配置的端口通道列表
   
*/

  
private void initSelectedList() {
    
for (int i = 0; i < 16; i++{
      
int cardindex = i + 1;
      
int[][] card = (int[][]) portState.get(new Integer(cardindex));
      
for (int j = 0; j < 32; j++{
        
int portindex = j + 1;
        String anote 
= "";
        
if (portType == Only_Port_Type) {
          
if (card[j][0== 1{
            anote 
= "板卡" + cardindex + "--端口" + portindex;
            choosedList_model.addElement(anote);
          }

        }

        
else if (portType == Port_Channel_Type) {
          
for (int k = 0; k < 8; k++{
            
int channelindex = k + 1;
            anote 
= "板卡" + cardindex + "--端口" + portindex + "--通道" +
                channelindex;
            choosedList_model.addElement(anote);
          }

        }

      }

    }

    
for (int i = 16; i < 18; i++{
      
int cardindex = i + 1;
      
int[][] card = (int[][]) portState.get(new Integer(i));
      
for (int j = 0; j < 4; j++{
        
int portindex = j + 1;
        String anote 
= "";
        
if (portType == Only_Port_Type) {
          
if (card[j][0== 1{
            anote 
= "板卡" + cardindex + "--端口" + portindex;
            choosedList_model.addElement(anote);
          }

        }

        
else if (portType == Port_Channel_Type) {
          
for (int k = 0; k < 8; k++{
            
int channelindex = k + 1;
            anote 
= "板卡" + cardindex + "--端口" + portindex + "--通道" +
                channelindex;
            choosedList_model.addElement(anote);
          }

        }

      }

    }

    choosedList.setModel(choosedList_model);
  }


  
public void actionPerformed(ActionEvent e) {
    String command 
= e.getActionCommand();
    
if (command.equals("add")) {
      
if (hasCardIndex.length <= 0{
        
return;
      }

      
int[] choosedcardsIndices = cardlist.getSelectedIndices();
      
int[] choosedcards = null;
      
if (choosedcardsIndices != null{
        choosedcards 
= new int[choosedcardsIndices.length];
        
for (int i = 0; i < choosedcardsIndices.length; i++{
          choosedcards[i] 
= hasCardIndex[choosedcardsIndices[i]];
        }

      }

      
for (int j = 0; j < 32; j++{
        
if (portType == Port_Channel_Type) {
          
for (int i = 0; i < 8; i++{
            
if (chanlecheckboxs[j][i].isSelected()) {
              String anote 
= "";
              
if (choosedcards != null{
                
for (int p = 0; p < choosedcards.length; p++{
                  
int card = choosedcards[p];
                  
int port = j + 1;
                  
if ( (card == 17 || card == 18&& port > 4{
                    
continue;
                  }

                  
int chanle = i + 1;
                  anote 
= "板卡" + card + "--端口" + port + "--通道" + chanle;
                  
if (!choosedList_model.contains(anote)) {
                    choosedList_model.addElement(anote);
                  }

                }

              }

            }

          }

        }

        
else if (portType == Only_Port_Type) {
          
if (portcheckboxs[j] != null{
            
if (portcheckboxs[j].isSelected()) {
              String anote 
= "";
              
if (choosedcards != null{
                
for (int p = 0; p < choosedcards.length; p++{
                  
int card = choosedcards[p];
                  
int port = j + 1;
                  
if ( (card == 17 || card == 18&& port > 4{
                    
continue;
                  }

                  anote 
= "板卡" + card + "--端口" + port;
                  
if (!choosedList_model.contains(anote)) {
                    choosedList_model.addElement(anote);
                  }

                }

              }

            }

          }

        }

        choosedList.setModel(choosedList_model);
      }

    }


    
if (command.equals("del")) {
      
int[] dels = choosedList.getSelectedIndices();
      
for (int i = 0; i < dels.length; i++{
        choosedList_model.remove(dels[i]);
      }

      choosedList.setModel(choosedList_model);
    }


    
if (command.equals("allchoice")) {
      
if (hasCardIndex.length <= 0{
        
return;
      }

      
int portnum = 0;
      
if (hasCardIndex[cardlist.getSelectedIndex()] == 17 ||
          hasCardIndex[cardlist.getSelectedIndex()] 
== 18{
        portnum 
= 4;
      }

      
else {
        portnum 
= 32;
      }

      
for (int j = 0; j < portnum; j++{
        
if (portType == Port_Channel_Type) {
          
for (int i = 0; i < 8; i++{
            chanlecheckboxs[j][i].setSelected(
true);
          }

        }

        portcheckboxs[j].setSelected(
true);
      }

    }


    
if (command.equals("clearall")) {
      
if (hasCardIndex.length <= 0{
        
return;
      }

      setAllSelectFasle();
    }


    
if (command.equals("clearresult")) {
      choosedList_model.clear();
      choosedList.setModel(choosedList_model);
    }

    
if (command.equals("order")) {
      orderSelectResult();
    }

    
if (command.equals("ok")) {
      
if (hasCardIndex.length <= 0{
        
return;
      }

      portlistCalculator();
      
this.dispose();
    }

    
if (command.equals("cancle")) {
      
this.dispose();
    }

  }


  
private void portlistCalculator() throws NumberFormatException {
    
int cardNum = 18;
    
int portNum = 32;
    
int cannelNum = 8;
//    int[] totalStatus = new int[ (cardNum - 2) * portNum * cannelNum + 2 * 4 * cannelNum];
    int[] totalStatus = new int[cardNum * portNum * cannelNum];
    ListModel modle 
= choosedList.getModel();
    
for (int i = 0; i < modle.getSize(); i++{
      String str 
= (String) modle.getElementAt(i);
      
if (portType == Port_Channel_Type) {
        cardNum 
= Integer.parseInt(
            str.substring(str.indexOf(
"板卡"+ 2, str.indexOf("--")));
        portNum 
= Integer.parseInt(
            str.substring(str.indexOf(
"端口"+ 2, str.lastIndexOf("--")));
        cannelNum 
= Integer.parseInt(
            str.substring(str.indexOf(
"通道"+ 2, str.length()));
      }

      
else if (portType == Only_Port_Type) {
        cardNum 
= Integer.parseInt(
            str.substring(str.indexOf(
"板卡"+ 2, str.indexOf("--")));
        portNum 
= Integer.parseInt(
            str.substring(str.indexOf(
"端口"+ 2, str.length()));
      }

      totalStatus[ (cardNum 
- 1* 32 * 8 + (portNum - 1* 8 +
          (cannelNum 
- 1)] = 1;
    }

    String newStatus 
= "";
    
for (int i = 0; i < 18 * 32 * 2; i++{
      String tem 
= PortListData.getData(totalStatus, i * 4);
      newStatus 
= newStatus + tem;
    }

    newStatus 
= newStatus + "00";
    System.out.println(newStatus.trim());
    
for (int i = 0; i < totalStatus.length; i++{
      totalStatus[i] 
= 0;
    }

    portList 
= newStatus;
    
if (portlistMap != null{
      portlistMap.remove(portlistName);
      portlistMap.put(portlistName, portList);
    }

//    Object[] key = map.keySet().toArray();
//    for(int i=0;i<map.size();i++){
//      String akey = (String)key[i];
//      String value = (String)map.get(akey);
//      System.out.println("key:"+akey+",value:"+value);
//    }
  }


  
private void orderSelectResult() {
    String str1, str2;
    
for (int j = 0; j < choosedList_model.size(); j++{
      
for (int i = 1; i < choosedList_model.size(); i++{
        str1 
= (String) choosedList_model.get(i - 1);
        str2 
= (String) choosedList_model.get(i);
        
if (str1.compareTo(str2) > 0{
          choosedList_model.set(i 
- 1, str2);
          choosedList_model.set(i, str1);
        }

      }

    }

    choosedList.setModel(choosedList_model);
  }


  
private void setAllSelectFasle() {
    
int portnum = 0;
    
if (hasCardIndex[cardlist.getSelectedIndex()] == 17 ||
        hasCardIndex[cardlist.getSelectedIndex()] 
== 18{
      portnum 
= 4;
    }

    
else {
      portnum 
= 32;
    }

    
for (int j = 0; j < portnum; j++{
      
if (portType == Port_Channel_Type) {
        
for (int i = 0; i < 8; i++{
          chanlecheckboxs[j][i].setSelected(
false);
        }

      }

      portcheckboxs[j].setSelected(
false);
    }

  }


  
/**
   * 端口checkbox的监听器,当选中时,系统将其下的通道都选上,当取消时,系统将其下的通道都取消
   
*/

  
class PortCheckBoxAction
      
implements ActionListener {
    PortChannelConfigDlg dlg;
    
int index;

    
/**
     * PortCheckBoxAction
     
*/

    
public PortCheckBoxAction(PortChannelConfigDlg dlg, int index) {
      
this.dlg = dlg;
      
this.index = index;
    }


    
public void actionPerformed(ActionEvent e) {
      
boolean isSelected = portcheckboxs[index].isSelected();
      
if (portType == Port_Channel_Type) {
        
for (int i = 0; i < 8; i++{
          chanlecheckboxs[index][i].setSelected(isSelected);
        }

      }

    }

  }


  
/**
   *板卡列表的监听器
   
*/

  
class CardListSelectListener
      
implements ListSelectionListener {
    PortChannelConfigDlg dlg;
    
public CardListSelectListener(PortChannelConfigDlg dlg) {
      
this.dlg = dlg;
    }


    
public CardListSelectListener() {
    }


    
public void valueChanged(ListSelectionEvent e) {
      channelPanel.removeAll();
      JList list 
= (JList) e.getSource();
//      if (hasCardIndex[cardlist.getSelectedIndex()] == 17 ||
//          hasCardIndex[cardlist.getSelectedIndex()] == 18) {
      if (hasCardIndex[list.getSelectedIndex()] == 17 ||
          hasCardIndex[list.getSelectedIndex()] 
== 18{
        initPortChannelPanel(
4, portType,
                             (
int[][]) portState.get(new Integer(cardlist.
            getSelectedIndex())));
      }

      
else {
        initPortChannelPanel(
32, portType,
                             (
int[][]) portState.get(new
            Integer(cardlist.getSelectedIndex())));
      }

      freshPortstate();
      channelPanel.updateUI();
      currentCard 
= hasCardIndex[cardlist.getSelectedIndex()];
    }

  }


  
private void freshPortstate() {
    
if (cardlist == null{
      
return;
    }

    
int cardindex = hasCardIndex[cardlist.getSelectedIndex()];
    
int portnum = 32;
    
if (cardindex == 17 || cardindex == 18{
      portnum 
= 4;
    }

    
int[][] cardstate = (int[][]) portState.get(new Integer(cardindex));
    
if (cardstate == null{
      
return;
    }

    
if (portType == Port_Channel_Type) {
      
for (int i = 0; i < portnum; i++{
        
for (int j = 0; j < 8; j++{
          
if (cardstate[i][j] == 1{
            chanlecheckboxs[i][j].setSelected(
true);
          }

          
else {
            chanlecheckboxs[i][j].setSelected(
false);
          }

        }

      }

    }

    
else {
      
for (int i = 0; i < portnum; i++{
        
if (cardstate[i][0== 1{
          portcheckboxs[i].setSelected(
true);
        }

        
else {
          portcheckboxs[i].setSelected(
false);
        }

      }

    }

  }


  
public String getPortList() {
    
return portList;
  }


  
public void setPortList(String portList) {
    
this.portList = portList;
  }


  
/////////////////////////////////////////////////////////////////////////////////////////
  public static void main(String[] agr) {
    
int[] hasCardIndex = new int[] {
        
12,345,6,7,8,9,10,11,12,13,14,15,16,1718}
;
    PortChannelConfigDlg dlg 
= PortChannelConfigDlg.getInstance(new JDialog(),
        hasCardIndex, 
1null);

    String s 
=  "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000FFFF0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
    dlg.setPortList(s);
    dlg.fresh();

    dlg.showDlg();
  }

  
/////////////////////////////////////////////////////////////////////////////////////////

}


package com.zg.component.ui.vlanchannel;

public class PortListData {
//  private String hexPortList = "";
//  private String binaryPortList = "";

//  public PortListData(String hexPortList) {
//    this.hexPortList = hexPortList;
//    binaryPortList = hexToBinary(hexPortList);
//  }

  
private PortListData() {
  }


  
public static String getData(int[] totalStatus, int postion) {
    String str 
= "g";
    
int[] temData = {
        totalStatus[postion], totalStatus[postion 
+ 1],
        totalStatus[postion 
+ 2], totalStatus[postion + 3]}
;
    
int tem = temData[0* 8 + temData[1* 4 + temData[2* 2 + temData[3];
    
if (tem < 10{
      str 
= String.valueOf(tem);
    }

    
else {
      
switch (tem) {
        
case 10:
          str 
= "a";
          
break;
        
case 11:
          str 
= "b";
          
break;
        
case 12:
          str 
= "c";
          
break;
        
case 13:
          str 
= "d";
          
break;
        
case 14:
          str 
= "e";
          
break;
        
case 15:
          str 
= "f";
          
break;
      }

    }

    
return str;
  }


  
public static String hexToBinary(String hexString) {
    StringBuffer buffer 
= new StringBuffer();
    
for (int i = 0; i < hexString.length(); i++{
      
char num = hexString.charAt(i);
      
int p = hexToInt(num);
      String str 
= Integer.toBinaryString(p);
      
if (str.length() < 4{
        
int zeronum = 4 - str.length();
        StringBuffer zero 
= new StringBuffer();
        
for (int j = 0; j < zeronum; j++{
          zero.append(
"0");
        }

        str 
= zero.toString() + str;
      }

      buffer.append(str);
    }

    
return buffer.toString();
  }


  
private static int hexToInt(char achar) {
    
int num = 0;
    String str 
= "0123456789";
    
if (str.contains(String.valueOf(achar))) {
      num 
= Integer.parseInt(String.valueOf(achar));
    }

    
else if (achar == 'a'||achar == 'A'{
      num 
= 10;
    }

    
else if (achar == 'b'||achar == 'B'{
      num 
= 11;
    }

    
else if (achar == 'c'||achar == 'C'{
      num 
= 12;
    }

    
else if (achar == 'd'||achar == 'D'{
      num 
= 13;
    }

    
else if (achar == 'e'||achar == 'E'{
      num 
= 14;
    }

    
else if (achar == 'f'||achar == 'F'{
      num 
= 15;
    }

    
return num;
  }


}


 
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:94349次
    • 积分:1306
    • 等级:
    • 排名:千里之外
    • 原创:33篇
    • 转载:11篇
    • 译文:0篇
    • 评论:21条
    文章分类
    最新评论