Example #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, "服务器未开启!");
     }
   }
 }
Example #2
0
 private void checkQuit() {
   int result =
       MyOptionPane.showConfirmDialog(
           null, "确认退出?", "系统提示", MyOptionPane.YES_NO_OPTION, MyOptionPane.QUESTION_MESSAGE);
   if (result == MyOptionPane.YES_OPTION) {
     System.exit(0);
   }
 }
Example #3
0
    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();
    }
Example #4
0
    public void actionPerformed(ActionEvent e) {
      String fileName = (String) MyOptionPane.showInputDialog(frame, "Enter new folder name", null);

      if (fileName != null) {
        String s = listHead;
        // String t = s;
        s += File.separator + fileName;
        File f = new File(s);

        boolean b = f.mkdirs();
        if (!b) System.err.println("mkdirs did not succeed");
        // panel.remove(listView);
        // fullNodeName = s;
        // showFileNames();
        showList();
        // selComp = text2;

      }
      repaint();
    }
Example #5
0
  public void actionPerformed(ActionEvent e) {
    String s = e.getActionCommand();

    diag.jpm = null;

    if (s.equals("Edit Upstream Port Name")) {

      String ans =
          (String)
              MyOptionPane.showInputDialog(
                  driver.frame,
                  "Enter or change text",
                  "Edit upstream port name",
                  JOptionPane.PLAIN_MESSAGE,
                  null,
                  null,
                  upStreamPort);

      if (ans != null /* && ans.length() > 0 */) {
        Block b = diag.blocks.get(new Integer(fromId));
        // upStreamPort = ans;
        diag.changed = true;
        boolean found = false;
        for (Arrow a : diag.arrows.values()) {
          if (a.fromId == fromId
                  && a.upStreamPort != null
                  && a.upStreamPort.equals(ans)
                  && !(upStreamPort.equals(ans))
              || a.toId == fromId && a.downStreamPort != null && a.downStreamPort.equals(ans))
            found = true;
        }
        if (found) {
          MyOptionPane.showMessageDialog(driver.frame, "Duplicate port name: " + ans);
          // upStreamPort = "";
          // return;
        }
        upStreamPort = ans;

        if (b.type.equals(Block.Types.EXTPORT_IN_BLOCK) || b instanceof IIPBlock) {
          MyOptionPane.showMessageDialog(driver.frame, "Upstream port must be blank");
          upStreamPort = "";
        }
      }
      driver.frame.repaint();

    } else if (s.equals("Edit Downstream Port Name") && endsAtBlock) {
      String ans =
          (String)
              MyOptionPane.showInputDialog(
                  driver.frame,
                  "Enter or change text",
                  "Edit downstream port name",
                  JOptionPane.PLAIN_MESSAGE,
                  null,
                  null,
                  downStreamPort);

      if (ans != null /* && ans.length() > 0 */) {

        Block b = diag.blocks.get(new Integer(toId));

        diag.changed = true;
        boolean found = false;
        for (Arrow a : diag.arrows.values()) {
          if (a.fromId == toId && a.upStreamPort != null && a.upStreamPort.equals(ans)
              || a.toId == toId
                  && a.downStreamPort != null
                  && a.downStreamPort.equals(ans)
                  && !(downStreamPort.equals(ans))) found = true;
        }
        if (found) {
          MyOptionPane.showMessageDialog(driver.frame, "Duplicate port name: " + ans);
          // downStreamPort = "";
          // return;
        }

        downStreamPort = ans;

        if (b.type.equals(Block.Types.EXTPORT_OUT_BLOCK)) {
          MyOptionPane.showMessageDialog(driver.frame, "Downstream port must be blank");
          downStreamPort = "";
        }
      }
      driver.frame.repaint();

    } else if (s.equals("Set Capacity")) {

      String capString = null;
      if (capacity == 0) capString = "";
      else capString = Integer.toString(capacity);
      String ans =
          (String)
              MyOptionPane.showInputDialog(
                  driver.frame,
                  "Enter or change text",
                  "Set Capacity",
                  JOptionPane.PLAIN_MESSAGE,
                  null,
                  null,
                  capString);
      if ((ans != null) && (ans.length() > 0)) {
        capacity = Integer.parseInt(ans);
        if (capLegend == null) {
          diag.xa = 2; // get around fudge in DrawFBP
          diag.ya = 2; // get around fudge in DrawFBP
          capLegend = (LegendBlock) diag.driver.createBlock(Block.Types.LEGEND_BLOCK, false);

          int x = toX;
          int y = toY;
          if (bends != null) {
            Bend bd = bends.peek();
            x = bd.x;
            y = bd.y;
          }

          capLegend.cx = (fromX + x) / 2;
          capLegend.cy = (fromY + y) / 2 + 20;
          if (fromX == x) capLegend.cx -= 20;
        }
        capLegend.description = "(" + capacity + ")";
      }
      driver.frame.repaint();
      diag.changed = true;

    } else if (s.equals("Remove Capacity")) {
      capacity = 0;
      diag.delBlock(capLegend, false);
      capLegend = null;
      driver.frame.repaint();
      diag.changed = true;

    } else if (s.equals("Toggle Upstream Port Automatic / Normal")) {
      if (upStreamPort == null || !upStreamPort.equals("*")) upStreamPort = "*";
      else upStreamPort = null;
      driver.frame.repaint();
      diag.changed = true;

    } else if (s.equals("Toggle Downstream Port Automatic / Normal")) {
      if (downStreamPort == null || !downStreamPort.equals("*")) downStreamPort = "*";
      else downStreamPort = null;
      driver.frame.repaint();
      diag.changed = true;

    } else if (s.equals("Toggle DropOldest")) {
      dropOldest = !dropOldest;

    } else if (s.equals("Drag Tail")) {
      tailMarked = true;
      driver.arrowEndForDragging = this;

    } else if (s.equals("Drag Head")) {
      headMarked = true;
      driver.arrowEndForDragging = this;

    } else if (s.equals("Drag New or Existing Bend")) {
      createBend(driver.curx, driver.cury);

    } else if (s.equals("Add Extra Arrowhead")) {
      Point p = new Point(driver.curx, driver.cury);
      int fx = fromX;
      int fy = fromY;
      int tx, ty;
      if (bends != null) {
        for (Bend bend : bends) {
          tx = bend.x;
          ty = bend.y;
          if (pointInLine(p, fx, fy, tx, ty)) {
            extraArrowhead = new Arrowhead(fx, fy, driver.curx, driver.cury);
            return;
          }
          fx = tx;
          fy = ty;
        }
      }
      tx = toX;
      ty = toY;
      if (pointInLine(p, fx, fy, tx, ty))
        extraArrowhead = new Arrowhead(fx, fy, driver.curx, driver.cury);
      return;

    } else if (s.equals("Remove Extra Arrowhead")) {
      extraArrowhead = null;
      return;

    } else if (s.equals("Delete")) {

      if (JOptionPane.YES_OPTION
          == MyOptionPane.showConfirmDialog(
              driver.frame,
              "Do you want to delete this arrow?",
              "Delete arrow",
              JOptionPane.YES_NO_OPTION)) {
        diag.delArrow(this);

        diag.changed = true;
        diag.currentArrow = null;
      }

      driver.frame.repaint();
      diag.foundArrow = null;
    }
    // if (s.equals("Exit")) {
    //	diag.foundArrow = null;
    //	driver.frame.repaint();
    // }
  }
Example #6
0
  @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;
  }
Example #7
0
    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();
    }