Exemple #1
0
 private void checkLogin() {
   // 对输入进行基本的合法非法判断
   String id = idTxt.getText();
   String passwd = String.valueOf(passwordTxt.getPassword());
   ResultMessage idResult = Utility.checkInputValid(id, 4, 14, false);
   ResultMessage passwdResult = Utility.checkInputValid(passwd, 5, 14, false);
   if (idResult != ResultMessage.SUCCESS) {
     MyOptionPane.showMessageDialog(null, "输入的用户名" + idResult.toFriendlyString() + "!");
     return;
   } else if (passwdResult != ResultMessage.SUCCESS) {
     MyOptionPane.showMessageDialog(null, "输入的密码" + passwdResult.toFriendlyString() + "!");
     return;
   }
   // 登录验证
   ResultMessage loginresult = loginController.login(usertype.getSelectedIndex(), id, passwd);
   if (loginresult == ResultMessage.SUCCESS) {
     new HomeUI(loginController);
     frame.dispose();
   } else {
     if (loginresult == ResultMessage.WRONG_ID) {
       MyOptionPane.showMessageDialog(null, "用户名错误!");
       idTxt.setText("");
       passwordTxt.setText("");
     } else if (loginresult == ResultMessage.WRONG_PASSWD) {
       MyOptionPane.showMessageDialog(null, "密码错误!");
       passwordTxt.setText("");
     } else {
       MyOptionPane.showMessageDialog(null, "服务器未开启!");
     }
   }
 }
    public void actionPerformed(ActionEvent e) {
      result = CANCEL_OPTION;

      String s = text.getText();
      String t = text2.getText();
      if (!(t.equals(""))) s += File.separator + t;
      File f = new File(s);
      if (f.isDirectory()) {
        if (f.list().length > 0) {
          MyOptionPane.showMessageDialog(driver.frame, "Folder not empty - cannot be deleted");

          return;
        }
      } else {
        if (driver.curDiag.diagramIsOpen(s)) {
          MyOptionPane.showMessageDialog(driver.frame, "File cannot be deleted while open");

          return;
        }
      }

      String u = f.isDirectory() ? "folder" : "file";

      if (JOptionPane.YES_OPTION
          == MyOptionPane.showConfirmDialog(
              frame,
              "Do you want to delete this " + u + ": " + f.getName() + "?",
              "File/folder delete",
              JOptionPane.YES_NO_OPTION)) {

        listHead = f.getParent();
        f.delete();
        // fullNodeName = listHead.getAbsolutePath();
        // showFileNames();
        text.setText(listHead);
        // panel.remove(listView);
        showList();
      }
      frame.repaint();
    }
  @SuppressWarnings("unchecked")
  LinkedList<String> buildListFromJSON(String fileName) {
    int level = 0;
    File f = new File(fileName);
    String fileString;
    LinkedList<String> ll = new LinkedList<String>();
    if (null == (fileString = driver.curDiag.readFile(f))) {
      MyOptionPane.showMessageDialog(driver.frame, "Unable to read file " + f.getName());
      return null;
    }
    Integer errNo = new Integer(0);
    BabelParser2 bp = new BabelParser2(fileString, errNo);
    String label = null;
    String operand = null;
    HashMap<String, Object> hm = new HashMap<String, Object>();
    // Stack<String> lStack = new Stack<String>();
    Stack<HashMap<String, Object>> hmStack = new Stack<HashMap<String, Object>>();

    // we will ignore the array structure for now...

    while (true) {
      if (!bp.tb('o')) break;
    }

    do {
      if (bp.tc('#', 'o')) { // assuming #-sign only in col.1
        while (true) {
          if (bp.tc('\r', 'o')) break;
          if (bp.tc('\n', 'o')) break;
          bp.tu('o');
        }
        continue;
      }

      if (bp.tc('[', 'o')) {
        level++;
        continue;
      }
      if (bp.tc('{', 'o')) {
        level++;
        if (label != null) {
          HashMap<String, Object> hm2 = new HashMap<String, Object>();
          hm.put(label, hm2);
          hmStack.push(hm);
          hm = hm2;
          label = null;
        }
        continue;
      }
      if (bp.tc(']', 'o')) {
        level--;
        continue;
      }
      if (bp.tc('}', 'o')) {
        level--;
        if (level > 0) hm = hmStack.pop();
        continue;
      }

      if (bp.tc(':', 'o')) {
        label = operand;
        continue;
      }
      if (bp.tc('"', 'o')) {
        while (true) {
          if (bp.tc('"', 'o')) break;
          if (bp.tc('\\', 'o')) {
            if (!(bp.tc('"'))) bp.w('\\');
            continue;
          }
          bp.tu();
        }
        operand = new String(bp.getOutStr());
        bp.eraseOutput();
        if (label != null) {
          hm.put(label, operand);
          label = null;
        }
        continue;
      }

      if (!(bp.tu('o'))) // tu only returns false at end of string
      break; // skip next character

    } while (level > 0);

    for (String k : hm.keySet()) {
      if (k.equals("noflo")) {
        HashMap<String, Object> m = (HashMap<String, Object>) hm.get(k);
        for (String k2 : m.keySet()) {
          if (k2.equals("graphs") && fCParms == driver.curDiag.fCPArr[DrawFBP.DIAGRAM]
              || k2.equals("components")
                  && (fCParms == driver.curDiag.fCPArr[DrawFBP.GENCODE]
                      || fCParms == driver.curDiag.fCPArr[DrawFBP.COMPONENT])) {
            HashMap<String, Object> m2 = (HashMap<String, Object>) m.get(k2);
            for (Object v : m2.values()) {
              ll.add((String) v);
            }
          }
        }
      }
    }

    if (ll.isEmpty()) {
      MyOptionPane.showMessageDialog(
          driver.frame, "No components or graphs in file: " + f.getName());
      // return null;
    }

    return ll;
  }
    public void actionPerformed(ActionEvent e) {

      if (selComp instanceof MyButton) {
        // ((MyButton) selComp).getAction().actionPerformed(new
        // ActionEvent(e, 0, ""));
        if (selComp == butOK) return;
        ((MyButton) selComp).doClick();
        return;
      }

      if (selComp == text) {
        String u = text.getText();
        File h = new File(u);
        if (!h.exists() || !h.isDirectory()) {
          MyOptionPane.showMessageDialog(
              driver.frame, "File " + u + " either doesn't exist or is not a directory");

          return;
        }
        listHead = u;
        // panel.remove(listView);
        text.setBackground(vLightBlue);
        showList();
        return;
      }
      if (selComp == text2) {
        // fullNodeName = text.getText() + File.separator
        // + text2.getText();
        // if (!saveAs)
        processOK();
      }

      if (!(selComp instanceof JList)) return;

      butNF.setEnabled(!inJarTree);
      butDel.setEnabled(!inJarTree);

      String s = "";

      int rowNo = list.getSelectedIndex();
      if (nodeNames.length == 0) return;
      if (rowNo == -1) return;
      s = nodeNames[rowNo];

      File f = null;

      if (
      /*s.startsWith("JavaFBP") &&*/ s.toLowerCase().endsWith(".jar")) {
        butNF.setEnabled(false);
        butDel.setEnabled(false);
        // if (filter instanceof DrawFBP.JarFileFilter)
        if (fCParms == driver.curDiag.fCPArr[DrawFBP.JARFILE]
            || fCParms == driver.curDiag.fCPArr[DrawFBP.JHALL]) {
          processOK();
          return;
        }

        // jarTree = buildJarFileTree(driver.javaFBPJarFile);
        jarTree = buildJarFileTree(s);
        inJarTree = true;
        butNF.setEnabled(!inJarTree);
        butDel.setEnabled(!inJarTree);
        currentNode = jarTree;
        text2.setText("");

        if (0 >= currentNode.getChildCount()) {
          MyOptionPane.showMessageDialog(driver.frame, "Error in jar file");
          return;
        }

        // listHead = driver.javaFBPJarFile + "!";
        listHead = s + "!";
        text.setText(listHead);
        // panel.remove(listView);
        showList();

      } else if (!inJarTree) {

        if (s.equals("")) f = new File(listHead);
        else {
          // int i = listHead.lastIndexOf("package.json");
          // if (i > -1)
          // listHead = listHead.substring(0, i - 1);
          f = new File(DrawFBP.makeAbsFileName(s, listHead));
        }

        if (!f.exists()) {

          if (!saveAs /* || selComp == text2 && !(text2.equals("")) */) processOK();
          else
            MyOptionPane.showMessageDialog(
                driver.frame, "File/folder does not exist: " + f.getAbsolutePath());
          return;
        }
        if (f.isDirectory() || f.getName().toLowerCase().endsWith("package.json")) {

          listHead = f.getAbsolutePath();
          // showFileNames();

          // panel.remove(listView);
          showList();

        } else
          // if (!saveAs)
          processOK();
      } else { // inJarTree

        currentNode = findChild(currentNode, s);
        if (currentNode == null) return;
        if (currentNode.getChildCount() > 0) listHead = listHead + File.separator + s;
        if (0 < currentNode.getChildCount()) {

          // panel.remove(listView);
          showList();

        } else
          // if (!saveAs)
          processOK();
      }

      // }
      dialog.repaint();
      frame.repaint();
    }