/**
   * Update the layouts tree.
   *
   * @param current The name of the current layout or <CODE>null</CODE> if none.
   */
  public void updateLayouts(Path current) throws PipelineException {
    DefaultMutableTreeNode root = null;
    {
      root = new DefaultMutableTreeNode(new TreeData(), true);

      {
        Path path = new Path(PackageInfo.getSettingsPath(), "layouts");
        rebuildTreeModel(path, new Path("/"), root);
      }

      DefaultTreeModel model = (DefaultTreeModel) pTree.getModel();
      model.setRoot(root);

      {
        Enumeration e = root.depthFirstEnumeration();
        if (e != null) {
          while (e.hasMoreElements()) {
            DefaultMutableTreeNode tnode = (DefaultMutableTreeNode) e.nextElement();
            pTree.expandPath(new TreePath(tnode.getPath()));
          }
        }
      }
    }

    pTree.clearSelection();
    if (current != null) {
      TreePath tpath = null;
      DefaultMutableTreeNode tnode = root;
      for (String comp : current.getComponents()) {
        DefaultMutableTreeNode next = null;
        Enumeration e = tnode.children();
        if (e != null) {
          while (e.hasMoreElements()) {
            DefaultMutableTreeNode child = (DefaultMutableTreeNode) e.nextElement();
            TreeData data = (TreeData) child.getUserObject();
            if (data.toString().equals(comp)) {
              tpath = new TreePath(child.getPath());
              next = child;
              break;
            }
          }
        }

        if (next == null) break;

        tnode = next;
      }

      if (tpath != null) {
        pTree.setSelectionPath(tpath);
        pTree.makeVisible(tpath);
      }
    }
  }
 private DefaultMutableTreeNode findNodeForPackage(String qualifiedPackageName) {
   DefaultMutableTreeNode root = (DefaultMutableTreeNode) myModel.getRoot();
   Enumeration enumeration = root.depthFirstEnumeration();
   while (enumeration.hasMoreElements()) {
     Object o = enumeration.nextElement();
     if (o instanceof DefaultMutableTreeNode) {
       DefaultMutableTreeNode node = (DefaultMutableTreeNode) o;
       PsiPackage nodePackage = (PsiPackage) node.getUserObject();
       if (nodePackage != null) {
         if (Comparing.equal(nodePackage.getQualifiedName(), qualifiedPackageName)) return node;
       }
     }
   }
   return null;
 }
  private void doSaveAll() {
    ObjectOutputStream objectStream = getObjectOutputStream();

    if (objectStream != null) {
      try {
        System.out.println("Saving All " + generations.getLeafCount() + " Generations...");

        for (Enumeration e = generations.depthFirstEnumeration(); e.hasMoreElements(); ) {
          DefaultMutableTreeNode tmpNode = (DefaultMutableTreeNode) e.nextElement();

          if (tmpNode.isLeaf()) objectStream.writeObject(tmpNode.getUserObject());
        }

        objectStream.close();
        System.out.println("Save completed successfully.");
      } catch (IOException e) {
        System.err.println(e);
      }
    } else {
      System.out.println("Save All Files has been aborted!");
    }
  }
Exemple #4
0
  /**
   * Builds the JTree which represents the navigation menu and then returns it
   *
   * @return The navigation tree.
   */
  private JTree buildTree() {
    String name = Messages.message("menuBar.colopedia");
    DefaultMutableTreeNode root =
        new DefaultMutableTreeNode(new ColopediaTreeItem(null, null, name, null));

    FreeColClient fcc = getFreeColClient();
    new TerrainDetailPanel(fcc, this).addSubTrees(root);
    new ResourcesDetailPanel(fcc, this).addSubTrees(root);
    new GoodsDetailPanel(fcc, this).addSubTrees(root);
    new UnitDetailPanel(fcc, this).addSubTrees(root);
    new BuildingDetailPanel(fcc, this).addSubTrees(root);
    new FatherDetailPanel(fcc, this).addSubTrees(root);
    new NationDetailPanel(fcc, this).addSubTrees(root);
    new NationTypeDetailPanel(fcc, this).addSubTrees(root);
    new ConceptDetailPanel(fcc, this).addSubTrees(root);

    DefaultTreeModel treeModel = new DefaultTreeModel(root);
    tree =
        new JTree(treeModel) {
          @Override
          public Dimension getPreferredSize() {
            return new Dimension(200, super.getPreferredSize().height);
          }
        };
    tree.setRootVisible(false);
    tree.setCellRenderer(new ColopediaTreeCellRenderer());
    tree.setOpaque(false);
    tree.addTreeSelectionListener(this);

    listPanel.add(tree);
    Enumeration allNodes = root.depthFirstEnumeration();
    while (allNodes.hasMoreElements()) {
      DefaultMutableTreeNode node = (DefaultMutableTreeNode) allNodes.nextElement();
      ColopediaTreeItem item = (ColopediaTreeItem) node.getUserObject();
      nodeMap.put(item.getId(), node);
    }
    return tree;
  }