/**
   * 当选择设备后做一些初始化
   *
   * @param evt
   */
  private void jComboBox_new_chooseDeviceItemStateChanged(ItemEvent evt) {
    if (mainUi == null) {
      mainUi = MainUI.getInstance(1);
    }
    if (evt.getStateChange() == ItemEvent.SELECTED) {
      mainUi.appendTextareaText(mainUi.jTextArea_status, '\n' + "选择设备:" + (String) evt.getItem());
      String item = (String) jComboBox_deviceName.getSelectedItem();
      Map manageip = LabelsUtil.readFileForMap("manageIP.txt");
      switch (item) {
        case "电力线适配器":
          jLabel_UserName.setVisible(false);
          jTextField_UserName.setVisible(false);
          jLabel_Password.setVisible(false);
          jTextField_Password.setVisible(false);

          Map map = LabelsUtil.readFileForMap("PowerLineDevice.txt");
          Map mapStyle = LabelsUtil.readFileForMap("deviceStyle.txt");
          String style = (String) map.get(jComboBox_deviceName.getSelectedItem());
          String styleCode = (String) mapStyle.get(style);
          String manageiIP = (String) manageip.get(style);

          jComboBox_deviceModel.setSelectedItem(style);
          jComboBox_deviceVersion.setSelectedIndex(0);
          jComboBox_deviceVersion.setEnabled(false);
          jComboBox_Power.setSelectedIndex(4);

          String mac = jTextField_DeviceID.getText();
          jTextField_DeviceSN.setText(styleCode + StringFilter(mac));
          jTextField_ManageIP.setText(manageiIP);

          head = new Head(); // 设置head
          head.ip = "IP:";
          head.mac = "MAC:";
          head.sn = "S/N:";
          break;
        case "电力线无线路由器":
          jLabel_UserName.setVisible(true);
          jTextField_UserName.setVisible(true);
          jLabel_Password.setVisible(true);
          jTextField_Password.setVisible(true);
          Map map2 = LabelsUtil.readFileForMap("PowerLineDevice.txt");
          Map mapStyle2 = LabelsUtil.readFileForMap("deviceStyle.txt");
          String style2 = (String) map2.get(jComboBox_deviceName.getSelectedItem());
          String styleCode2 = (String) mapStyle2.get(style2);
          String manageiIP2 = (String) manageip.get(style2);

          jComboBox_deviceModel.setSelectedItem(style2);
          jComboBox_deviceVersion.setSelectedIndex(0);
          jComboBox_deviceVersion.setEnabled(false);
          jComboBox_Power.setSelectedIndex(5);

          String mac2 = jTextField_DeviceID.getText();
          jTextField_DeviceSN.setText(styleCode2 + StringFilter(mac2));
          jTextField_ManageIP.setText(manageiIP2);

          head = new Head(); // 设置head
          head.ip = "IP:";
          head.mac = "PLC MAC:";
          head.sn = "S/N:";
          break;
        default:
          jLabel_UserName.setVisible(false);
          jTextField_UserName.setVisible(false);
          jLabel_Password.setVisible(false);
          jTextField_Password.setVisible(false);
          jComboBox_deviceModel.setSelectedIndex(0);
          jComboBox_deviceVersion.setEnabled(true);
          jComboBox_deviceVersion.setSelectedIndex(0);
          jComboBox_Power.setSelectedIndex(0);
          break;
      }
    }
  }
  public PowerLineAdapterPanel() {
    super();
    this.setBounds(10, 10, 300, 546);
    this.setLayout(null);
    this.setBackground(new java.awt.Color(236, 233, 216));
    this.setBorder(
        BorderFactory.createTitledBorder(
            null, "电力线适配器二维码项目", TitledBorder.LEADING, TitledBorder.DEFAULT_POSITION));

    ArrayList<String> list = LabelsUtil.readFile("companys.txt");
    companyInit = list.get(0);
    { // 选择设备
      jLabel_deviceName = new JLabel();
      jLabel_deviceName.setBounds(12, 30, 90, 18);
      jLabel_deviceName.setText("选择设备:");
      this.add(jLabel_deviceName);

      jComboBox_deviceName = new JComboBox();
      this.add(jComboBox_deviceName);
      jComboBox_deviceName.setBounds(120, 26, 180, 25);
      Map map = LabelsUtil.readFileForMap("PowerLineDevice.txt");
      Set set = map.keySet();
      Iterator t = set.iterator();
      jComboBox_deviceName.addItem("选择设备");
      while (t.hasNext()) {
        Object k = t.next();
        jComboBox_deviceName.addItem(k);
      }
      jComboBox_deviceName.addItemListener(
          new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent evt) {
              jComboBox_new_chooseDeviceItemStateChanged(evt);
            }
          });
    }
    { // 用户名
      jLabel_UserName = new JLabel("用户名:");
      this.add(jLabel_UserName);
      jLabel_UserName.setBounds(320, 25, 60, 18);
      jLabel_UserName.setVisible(false);

      jTextField_UserName = new JTextField();
      this.add(jTextField_UserName);
      jTextField_UserName.setBounds(370, 25, 90, 25);
      jTextField_UserName.setText("root");
      jTextField_UserName.setVisible(false);

      // 密码
      jLabel_Password = new JLabel("密码:");
      this.add(jLabel_Password);
      jLabel_Password.setBounds(320, 70, 60, 18);
      jLabel_Password.setVisible(false);

      jTextField_Password = new JTextField();
      this.add(jTextField_Password);
      jTextField_Password.setBounds(370, 70, 90, 25);
      jTextField_Password.setText("admin");
      jTextField_Password.setVisible(false);
    }
    {
      jLabel_deviceModel = new JLabel();
      this.add(jLabel_deviceModel);
      jLabel_deviceModel.setText("设备型号:");
      jLabel_deviceModel.setBounds(12, 70, 90, 18);

      jComboBox_deviceModel = new JComboBox();
      this.add(jComboBox_deviceModel);
      jComboBox_deviceModel.setBounds(120, 66, 180, 25);

      // String str[] = {"请选择","ES-A61500"};
      Map map = LabelsUtil.readFileForMap("deviceStyle.txt");
      Set set = map.keySet();
      Iterator t = set.iterator();
      jComboBox_deviceModel.addItem("");
      while (t.hasNext()) {
        Object k = t.next();
        jComboBox_deviceModel.addItem(k);
      }
      jComboBox_deviceModel.addItemListener(
          new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent evt) {
              jComboBox_chooseDeviceStyleChanged(evt);
            }
          });
    }
    { // 版本
      jLabel_deviceVersion = new JLabel();
      this.add(jLabel_deviceVersion);
      jLabel_deviceVersion.setText("	版本:");
      jLabel_deviceVersion.setBounds(12, 110, 90, 18);

      jComboBox_deviceVersion = new JComboBox();
      this.add(jComboBox_deviceVersion);
      jComboBox_deviceVersion.setBounds(120, 106, 180, 25);
      ArrayList<String> version = LabelsUtil.readFile("deviceVersion.txt");
      jComboBox_deviceVersion.addItem("");
      for (String t : version) {
        jComboBox_deviceVersion.addItem(t);
      }
    }
    { // MAC地址
      jLabel_DeviceID = new JLabel();
      this.add(jLabel_DeviceID);
      jLabel_DeviceID.setText("MAC地址:");
      jLabel_DeviceID.setBounds(12, 150, 90, 18);

      String deviceID = LabelsUtil.readLastLine("mac.txt");
      jTextField_DeviceID = new JTextField();
      this.add(jTextField_DeviceID);
      jTextField_DeviceID.setBounds(120, 146, 180, 25);
      jTextField_DeviceID.setText(deviceID);
      jTextField_DeviceID.setEditable(false);
    }
    { // S/N码
      jLabel_DeviceSN = new JLabel();
      this.add(jLabel_DeviceSN);
      jLabel_DeviceSN.setText("S/N:");
      jLabel_DeviceSN.setBounds(12, 190, 90, 18);

      jTextField_DeviceSN = new JTextField();
      this.add(jTextField_DeviceSN);
      jTextField_DeviceSN.setBounds(120, 186, 180, 25);
      jTextField_DeviceSN.setEditable(false);
    }
    { // 电源
      jLabel_Power = new JLabel();
      this.add(jLabel_Power);
      jLabel_Power.setText("电源:");
      jLabel_Power.setBounds(12, 230, 90, 18);

      jComboBox_Power = new JComboBox();
      this.add(jComboBox_Power);
      jComboBox_Power.setBounds(120, 226, 180, 25);

      ArrayList<String> voltages = LabelsUtil.readFile("voltages.txt");
      jComboBox_Power.addItem("");
      for (String t : voltages) {
        jComboBox_Power.addItem(t);
      }
    }

    { // 官方网址
      jLabel_OfficialWebsite = new JLabel();
      this.add(jLabel_OfficialWebsite);
      jLabel_OfficialWebsite.setText("官方网址:");
      jLabel_OfficialWebsite.setBounds(12, 310, 90, 18);

      jTextField_OfficialWebsite = new JTextField();
      this.add(jTextField_OfficialWebsite);
      jTextField_OfficialWebsite.setBounds(120, 306, 180, 25);
      ArrayList<String> officalurl = LabelsUtil.readFile("officalWebSite.txt");
      if (officalurl == null) {
        jTextField_OfficialWebsite.setText("www.eastsoft.com.cn");
      } else {
        jTextField_OfficialWebsite.setText(officalurl.get(0));
      }
    }
    { // 管理IP
      jLabel_ManageIP = new JLabel();
      this.add(jLabel_ManageIP);
      jLabel_ManageIP.setText("管理IP:");
      jLabel_ManageIP.setBounds(12, 270, 90, 18);
      jLabel_ManageIP.setHorizontalTextPosition(JLabel.RIGHT);

      jTextField_ManageIP = new JTextField();
      this.add(jTextField_ManageIP);
      jTextField_ManageIP.setBounds(120, 266, 180, 25);
      jTextField_ManageIP.setEditable(false);
      /*ArrayList<String> manageip = LabelsUtil.readFile("manageIP.txt");
      if(manageip==null){
      	jTextField_ManageIP.setText("192.168.1.1");
      }else{
      	jTextField_ManageIP.setText(manageip.get(0));
      }*/
    }
    { // 打印标签数量
      jLabel_PrintNum = new JLabel();
      this.add(jLabel_PrintNum);
      jLabel_PrintNum.setText("打印标签数量:");
      jLabel_PrintNum.setBounds(12, 350, 90, 18);

      jTextField_PrintNum = new JTextField();
      this.add(jTextField_PrintNum);
      jTextField_PrintNum.setBounds(120, 346, 180, 25);
      jTextField_PrintNum.setText("1");
    }
    {
      jCheckBox_Edit = new JCheckBox("编辑:MAC、S/N、管理IP");
      this.add(jCheckBox_Edit);
      jCheckBox_Edit.setBounds(120, 386, 180, 25);
      // jTextField_ManageIP
      jCheckBox_Edit.addItemListener(
          new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent evt) {
              JCheckBox box = (JCheckBox) evt.getItemSelectable();
              if (box.isSelected()) {
                jTextField_ManageIP.setEditable(true);
                jTextField_DeviceID.setEditable(true);
                jTextField_DeviceSN.setEditable(true);
              } else {
                jTextField_ManageIP.setEditable(false);
                jTextField_DeviceID.setEditable(false);
                jTextField_DeviceSN.setEditable(false);
              }
            }
          });
    }
    {
      jButton_printPreview_p = new JButton();
      this.add(jButton_printPreview_p);
      jButton_printPreview_p.setText("打印预览");
      jButton_printPreview_p.setBounds(40, 460, 100, 50);
      jButton_printPreview_p.addActionListener(
          new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
              jButton_new_printPreviewformed(evt);
            }
          });
    }
    {
      jButton_repeatPrint_p = new JButton();
      this.add(jButton_repeatPrint_p);
      jButton_repeatPrint_p.setBounds(160, 460, 100, 50);
      jButton_repeatPrint_p.setText("打印");
      jButton_repeatPrint_p.addActionListener(
          new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
              jButton_new_printBinaryPerformed(evt);
            }
          });
    }
  }
 /**
  * jComboBox_chooseDeviceStyleChanged当改变设备型号时重新设置SN码
  *
  * @param evt
  */
 private void jComboBox_chooseDeviceStyleChanged(ItemEvent evt) {
   Map mapStyle = LabelsUtil.readFileForMap("deviceStyle.txt");
   String styleCode = (String) mapStyle.get(jComboBox_deviceModel.getSelectedItem());
   String mac = jTextField_DeviceID.getText();
   jTextField_DeviceSN.setText(styleCode + StringFilter(mac));
 }