コード例 #1
0
ファイル: ProbaTree.java プロジェクト: student2ua/myTaning
  private void createPainToTree2(
      final DefaultTreeModel treeModel, DefaultMutableTreeNode root, Collection paintCollection) {
    ArrayList a = (ArrayList) paintCollection;
    DefaultMutableTreeNode parent = root;
    System.out.println("a = " + a.size());
    Iterator i = a.iterator();
    // Person lastPerson = null;
    while (i.hasNext()) {
      Person p = (Person) i.next();

      Object[] pathTree = {
        root, p.getFio().getLastName(), p.getFio().getMidllName(), p.getFio().getFirstName()
      };
      // int poz=Arrays.binarySearch(pathTree, parent.getUserObject());
      List l = Arrays.asList(pathTree);
      int poz = l.lastIndexOf(parent.getUserObject());
      while (poz > -1) { // bvtyf yt cjdgflf.n
        while (pathTree.length > poz) {
          DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(pathTree[poz + 1]);
          treeModel.insertNodeInto(newNode, parent, parent.getChildCount());
          parent = newNode;
          poz = Arrays.binarySearch(pathTree, parent.getUserObject());
        }
      }
      //   TreePath path = new TreePath(pathTree);
      //  TreeNode[] pa = parent.getPath();
      // Object[] o = parent.getUserObjectPath();
      // if (p.getFio().getFirstName() != (o[o.length - 1])) {

      //
      //                treeModel.insertNodeInto(
      //                        new DefaultMutableTreeNode(
      //                                path.getLastPathComponent()),
      //                        parent, parent.getChildCount());
      //   lastPerson = p;
      // }
    }
  }
コード例 #2
0
ファイル: ProbaTree.java プロジェクト: student2ua/myTaning
 private int comparePerson(Person p, Person person) {
   System.out.println("p = " + p);
   System.out.println("person = " + person);
   if (p.getFio().getLastName().equalsIgnoreCase(person.getFio().getLastName())) {
     if (p.getFio().getMidllName().equalsIgnoreCase(person.getFio().getMidllName())) {
       if (!p.getFio().getFirstName().equalsIgnoreCase(person.getFio().getFirstName())) {
         return 2; // имена не совпали
       }
     } else return 1; // отчества не совпали
   } else return 0; // ‘амилии не совпали
   return 0;
 }
コード例 #3
0
ファイル: ProbaTree.java プロジェクト: student2ua/myTaning
 private int comparePersonAsString(Person p, Person person) {
   String sP1 =
       p.getFio().getLastName()
           + " "
           + p.getFio().getMidllName()
           + " "
           + p.getFio().getFirstName();
   String sP2 =
       person.getFio().getLastName()
           + " "
           + person.getFio().getMidllName()
           + " "
           + person.getFio().getFirstName();
   Collator collator = Collator.getInstance(new Locale("Ru"));
   return collator.compare(sP1, sP2);
 }
コード例 #4
0
ファイル: ProbaTree.java プロジェクト: student2ua/myTaning
  private void createPainToTree(
      final DefaultTreeModel treeModel, DefaultMutableTreeNode root, Collection c) {
    ArrayList a = (ArrayList) c;
    System.out.println("a = " + a.size());
    Iterator i = a.iterator();
    DefaultMutableTreeNode lastN = new DefaultMutableTreeNode("");
    DefaultMutableTreeNode midlN = new DefaultMutableTreeNode("");
    DefaultMutableTreeNode fistN = new DefaultMutableTreeNode("");
    while (i.hasNext()) {
      Person p = (Person) i.next();
      if (p.getFio().getLastName().equals((String) lastN.getUserObject())) { // совпала фамили¤
        if (p.getFio().getMidllName().equals((String) midlN.getUserObject())) {
          if (p.getFio().getFirstName().equals((String) fistN.getUserObject())) {
            //    treeModel.insertNodeInto(fistN,midlN,0);
          } else {
            fistN = new DefaultMutableTreeNode(p.getFio().getFirstName());
            treeModel.insertNodeInto(fistN, midlN, midlN.getChildCount());
          }
        } else {
          midlN = new DefaultMutableTreeNode(p.getFio().getMidllName());
          fistN = new DefaultMutableTreeNode(p.getFio().getFirstName());
          treeModel.insertNodeInto(midlN, lastN, lastN.getChildCount());
          treeModel.insertNodeInto(fistN, midlN, midlN.getChildCount());
        }
      } else {
        lastN = new DefaultMutableTreeNode(p.getFio().getLastName());
        midlN = new DefaultMutableTreeNode(p.getFio().getMidllName());
        fistN = new DefaultMutableTreeNode(p.getFio().getFirstName());
        treeModel.insertNodeInto(lastN, root, root.getChildCount());
        treeModel.insertNodeInto(midlN, lastN, lastN.getChildCount());
        treeModel.insertNodeInto(fistN, midlN, midlN.getChildCount());
      }

      TreePath path = new TreePath(treeModel.getPathToRoot(fistN));
      System.out.println("path = " + path);
    }
  }