/**
   * 主函数,整个程序的入口
   *
   * @param args
   */
  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(null);
    MainUI myUI = new MainUI(shell);
    myUI.open();

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }
Esempio n. 2
0
  private ProvidedObjectComboItem[] getComboItems(ConvertingPlugin plugin) {
    JInternalFrame[] frames = desktop.getAllFrames();
    ArrayList accepted = new ArrayList();
    comboItems = new ArrayList();

    for (int j = 0; j < frames.length; j++) {
      if (frames[j] instanceof Provider) {
        ProvidedObject[] po = ((Provider) frames[j]).getProvidedObjects();

        for (int i = 0; i < po.length; i++) {
          if (plugin.accepts(po[i])) {
            accepted.add(new ProvidedObjectComboItem(frames[j].getTitle(), po[i]));
            comboItems.add(po[i]);
          }
        }
      }
    }
    ProvidedObject[] po = MainUI.getInstance().getGlobalProvidedObjects();

    for (int i = 0; i < po.length; i++) {
      if (plugin.accepts(po[i])) {
        accepted.add(new ProvidedObjectComboItem("ProM Global Objects", po[i]));
        comboItems.add(po[i]);
      }
    }
    return (ProvidedObjectComboItem[]) accepted.toArray(new ProvidedObjectComboItem[0]);
  }
  private void jButton_new_printPreviewformed(ActionEvent evt) {

    if (mainUi == null) {
      mainUi = MainUI.getInstance(1);
    }
    if (jComboBox_deviceName.getSelectedIndex() > 0) {
      String deviceID = getDeviceID();

      deviceID = toFormedMAC(StringFilter(getDeviceID()));
      if (!chechMAC(deviceID)) {
        JOptionPane.showMessageDialog(getParent(), "MAC地址格式错误!", "错误", JOptionPane.WARNING_MESSAGE);
        return;
      }
      jTextField_DeviceID.setText(deviceID);

      String deviceSN = getDeviceSN().substring(0, 6) + StringFilter(deviceID);
      jTextField_DeviceSN.setText(deviceSN);
      String manageIP = getManageIP();
      productPowerLineQRCode(head, deviceID, deviceSN, manageIP);
      jButton_new_printPreviewActionPerformed(evt);
    } else {
      // mainUi.appendTextareaText(mainUi.jTextArea_status,"\n请选择设备");
      JOptionPane.showMessageDialog(getParent(), "请选择设备!", "错误", JOptionPane.WARNING_MESSAGE);
      return;
    }
  }
  // 从预览中点击打印按钮时执行此函数打印
  public void printBinaryPicture() {

    int formatIndex = jComboBox_deviceName.getSelectedIndex();
    int number = Integer.parseInt(getBinaryPrintNum());

    int index = jComboBox_deviceName.getSelectedIndex();
    String deviceName = getDeviceName();
    String deviceType = getDeviceModel();
    String deviceID = getDeviceID(); // MAC
    String manageIP = getManageIP();
    String deviceSN = getDeviceSN();
    // String deviceVresion = getDeviceVersion();
    String power = getPower();
    String officialWebsite = getOfficialWebsite();

    Book book = new Book();
    PageFormat pf = new MyPaperFormat(mainUi);

    // 生成二维码
    productPowerLineQRCode(head, deviceID, deviceSN, manageIP);

    printInfo printinfo = mainUi.new printInfo();

    printinfo.setdeviceID(deviceID);
    printinfo.setManageIP(manageIP);
    printinfo.setDeviceSN(deviceSN);

    printinfo.setdeviceName(deviceName);
    printinfo.setdeviceType(deviceType);
    // printinfo.setDeviceVresion(deviceVresion);
    printinfo.setPower(power);
    printinfo.setOfficialWebsite(officialWebsite);
    printinfo.setCompany(companyInit);
    printinfo.setPowerLineIndex(index);

    myPrint = new MyPrint(printinfo);
    book.append(myPrint, pf);
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPageable(book);
    try {
      if (true) {
        job.print();
        mainUi.appendTextareaText(mainUi.jTextArea_status, "\n执行打印");
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  private void jButton_new_printBinaryPerformed(ActionEvent evt) {
    if (mainUi == null) {
      mainUi = MainUI.getInstance(1);
    }
    if (jComboBox_deviceName.getSelectedIndex() > 0) {

      String deviceID = toFormedMAC(StringFilter(getDeviceID()));
      if (!chechMAC(deviceID)) {
        JOptionPane.showMessageDialog(getParent(), "MAC地址格式错误!", "错误", JOptionPane.WARNING_MESSAGE);
        return;
      }
      if (StringUtils.isEmpty(jTextField_PrintNum.getText())) {
        JOptionPane.showMessageDialog(getParent(), "请输入打印数量!", "错误", JOptionPane.WARNING_MESSAGE);
        return;
      }
      String deviceSN = getDeviceSN().substring(0, 6) + StringFilter(deviceID);
      jTextField_DeviceSN.setText(deviceSN);
      printNewBinaryPicture();
    } else {
      JOptionPane.showMessageDialog(getParent(), "请选择设备!", "错误", JOptionPane.WARNING_MESSAGE);
      return;
    }
  }
  public void productPowerLineQRCode(Head head, String deviceID, String deviceSN, String manageIP) {

    newQRCode = new QRCode();

    // 电力线二维码内容:MAC,S/N,IP
    str = head.ip + manageIP + "\n" + head.mac + deviceID + "\n" + head.sn + deviceSN;

    File filePath = new File("new_test_QR_CODE.png");
    String path = filePath.getAbsolutePath();
    int width, height;
    width = height = 120;
    newQRCode.encode(str, path, width, height);
    newQRCode.decode(filePath);

    Image barCodePic = null;
    try {
      barCodePic = ImageIO.read(filePath);
    } catch (IOException e) {
      e.printStackTrace();
    }

    mainUi.jLabel_binaryPic.setIcon(new ImageIcon(barCodePic));
    mainUi.appendTextareaText(mainUi.jTextArea_status, "\n二维码已生成: " + str);
  }
Esempio n. 7
0
  private void showConversion() {
    if (combo == null) {
      return;
    }
    JPanel mainPanel = new JPanel();
    if (algorithmList.getSelectedValue() == null) {
      JOptionPane.showMessageDialog(
          this,
          "Please select a conversion algorithm first.",
          "Conversion",
          JOptionPane.INFORMATION_MESSAGE);
      return;
    }

    final ConvertingPlugin algorithm =
        ((ConvertAlgorithm) algorithmList.getSelectedValue()).getPlugin();
    if ((combo.getSelectedIndex() < 0) || (combo.getSelectedIndex() >= combo.getItemCount())) {
      JOptionPane.showMessageDialog(
          this,
          "Please choose inputs for all items.",
          "Conversion",
          JOptionPane.INFORMATION_MESSAGE);
      return;
    }

    UISettings.getInstance().setLastUsedConversion(algorithm.getName());

    MainUI.getInstance()
        .addAction(
            algorithm,
            LogStateMachine.START,
            new Object[] {comboItems.get(combo.getSelectedIndex())});

    SwingWorker worker =
        new SwingWorker() {
          MiningResult result;
          StopWatch timer = new StopWatch();

          public Object construct() {
            Message.add("Start conversion.");
            timer.start();
            try {
              if (algorithm instanceof DoNotCreateNewInstance) {
                result =
                    algorithm.convert((ProvidedObject) comboItems.get(combo.getSelectedIndex()));
              } else {
                result =
                    ((ConvertingPlugin) algorithm.getClass().newInstance())
                        .convert((ProvidedObject) comboItems.get(combo.getSelectedIndex()));
              }
            } catch (IllegalAccessException ex) {
              Message.add(
                  "No new instantiation of "
                      + algorithm.getName()
                      + " could be made, using"
                      + " old instance instead",
                  Message.ERROR);
              result = algorithm.convert((ProvidedObject) comboItems.get(combo.getSelectedIndex()));
            } catch (InstantiationException ex) {
              Message.add(
                  "No new instantiation of "
                      + algorithm.getName()
                      + " could be made, using"
                      + " old instance instead",
                  Message.ERROR);
              result = algorithm.convert((ProvidedObject) comboItems.get(combo.getSelectedIndex()));
            }
            return result;
          }

          public void finished() {
            timer.stop();
            Message.add("Conversion duration: " + timer.formatDuration());
            MainUI.getInstance()
                .addAction(
                    algorithm,
                    LogStateMachine.COMPLETE,
                    (result instanceof Provider) ? ((Provider) result).getProvidedObjects() : null);

            getContentPane().removeAll();
            getContentPane().add(result.getVisualization(), BorderLayout.CENTER);
            getContentPane().validate();
            getContentPane().repaint();
          }
        };
    worker.start();
  }
 @Action(enabledProperty = "saveNeeded")
 public Task save() {
   return new SaveTask(MainUI.getApplication());
 }
  /**
   * 当选择设备后做一些初始化
   *
   * @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;
      }
    }
  }