Ejemplo n.º 1
0
  /**
   * Recursively rebuild the tree nodes.
   *
   * @param root The full abstract path to the root saved layout directory.
   * @param local The current directory relative to root (null if none).
   * @param tnode The current parent tree node.
   */
  private void rebuildTreeModel(Path root, Path local, DefaultMutableTreeNode tnode) {
    TreeSet<Path> subdirs = new TreeSet<Path>();
    TreeSet<String> layouts = new TreeSet<String>();
    {
      Path current = new Path(root, local);
      File files[] = current.toFile().listFiles();
      if (files != null) {
        int wk;
        for (wk = 0; wk < files.length; wk++) {
          String name = files[wk].getName();
          if (files[wk].isDirectory()) subdirs.add(new Path(local, name));
          else if (files[wk].isFile()) layouts.add(name);
        }
      }
    }

    for (Path subdir : subdirs) {
      TreeData data = new TreeData(subdir);
      DefaultMutableTreeNode child = new DefaultMutableTreeNode(data, true);
      tnode.add(child);

      rebuildTreeModel(root, subdir, child);
    }

    for (String lname : layouts) {
      TreeData data = new TreeData(new Path(local, lname), lname);
      DefaultMutableTreeNode child = new DefaultMutableTreeNode(data, false);
      tnode.add(child);
    }
  }
Ejemplo n.º 2
0
  public MsnTreeTest() {
    String[] tab = {"hello", "test", "blabla"};

    container = getContentPane();
    container.setLayout(null);

    eleve = new DefaultMutableTreeNode("MSN");

    worker = new DefaultMutableTreeNode("Worker");
    prof = new DefaultMutableTreeNode("Profs");

    for (int i = 0; i < tab.length; i++) {
      worker.add(new DefaultMutableTreeNode(tab[i]));
      prof.add(new DefaultMutableTreeNode(tab[i]));
    }
    //        worker.add(new DefaultMutableTreeNode("hello world2"));

    eleve.add(worker);
    eleve.add(prof);

    tree = new JTree(eleve);

    scroll = new JScrollPane(tree);
    scroll.setBounds(10, 10, 100, 100);

    container.add(scroll);

    setSize(300, 300);
    setLocation(200, 200);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);

    //        worker.add(n);

  }
 private static void replaceChildren(
     final DefaultMutableTreeNode node, final Collection<? extends ElementNode> arrayList) {
   node.removeAllChildren();
   for (ElementNode child : arrayList) {
     node.add(child);
   }
 }
Ejemplo n.º 4
0
  /**
   * Adds nodes to the specified parent node recurrsively.
   *
   * @param parent_node the parent node.
   * @param list the list of child node names.
   */
  protected void addNode(DefaultMutableTreeNode parent_node, Vector list) {
    SortableArray array = null;

    if (mode == DATE_ORIENTED && parent_node.getLevel() <= 2) {
      array = new Array(list.size());

      for (int i = 0; i < list.size(); i++)
        ((Array) array).set(i, Integer.parseInt((String) list.elementAt(i)));
    } else {
      array = new StringArray(list.size());

      for (int i = 0; i < list.size(); i++)
        ((StringArray) array).set(i, (String) list.elementAt(i));
    }

    ArrayIndex index = array.sortAscendant();

    for (int i = 0; i < array.getArraySize(); i++) {
      String name = (String) list.elementAt(index.get(i));

      // Converts 1...12 to January...December.
      if (mode == DATE_ORIENTED && parent_node.getLevel() == 1) {
        int month = Integer.parseInt(name);
        name = JulianDay.getFullSpellMonthString(month);
      }

      DefaultMutableTreeNode node = new DefaultMutableTreeNode(name);
      parent_node.add(node);
    }
  }
Ejemplo n.º 5
0
  private TreeModel buildModel(Object[] resolvers) {
    TreeModel fullModel = null;
    DefaultMutableTreeNode top = new DefaultMutableTreeNode(Tr.t("root"));

    try {
      cpos = null;
      for (Object resolver : resolvers) {
        if (resolver instanceof ColorPository) {
          cpos = (ColorPository) resolver;
          GraphCellRenderer graphCellRenderer = new GraphCellRenderer(cpos);
          colors.setCellRenderer(graphCellRenderer);
          break;
        }
      }
      Collection<ColorPository.ClassRecord> classes = cpos.getClasses();
      String[] classNames = new String[classes.size()];
      Iterator<ColorPository.ClassRecord> it = classes.iterator();
      int count = 0;
      while (it.hasNext()) {
        classNames[count] = it.next().name;
        count++;
      }
      Arrays.sort(classNames);

      for (String className : classNames) {
        ColorPository.ColorRecord[] colors = cpos.enumerateColors(className);
        String[] colorNames = new String[colors.length];
        for (int a = 0; a < colorNames.length; a++) {
          colorNames[a] = colors[a].name;
        }
        Arrays.sort(colorNames);

        DefaultMutableTreeNode tn = new DefaultMutableTreeNode(className);
        top.add(tn);
        for (String colorName : colorNames) {
          tn.add(new DefaultMutableTreeNode(colorName));
        }
      }

      fullModel = new DefaultTreeModel(top);
    } catch (Exception e) {
      fullModel = new DefaultTreeModel(new DefaultMutableTreeNode(Tr.t("root.failed")));
      // e.printStackTrace();
    }
    return fullModel;
  }
 public ElementNodeImpl(
     @Nullable DefaultMutableTreeNode parent, MemberChooserObject delegate, Ref<Integer> order) {
   myOrder = order.get();
   order.set(myOrder + 1);
   myDelegate = delegate;
   if (parent != null) {
     parent.add(this);
   }
 }
Ejemplo n.º 7
0
 private MutableTreeNode populateNest(Nest n) throws SQLException {
   DefaultMutableTreeNode tree = new DefaultMutableTreeNode(n);
   // tree.add(populateAttributes(n));
   Statement stmt = db.statement();
   for (Visit v : n.loadVisits(stmt)) {
     tree.add(populateVisit(v));
   }
   stmt.close();
   return tree;
 }
Ejemplo n.º 8
0
 private MutableTreeNode populateCavity(Cavity c) throws SQLException {
   DefaultMutableTreeNode tree = new DefaultMutableTreeNode(c);
   // tree.add(populateAttributes(c));
   Statement stmt = db.statement();
   for (Nest n : c.loadNests(stmt)) {
     tree.add(populateNest(n));
   }
   stmt.close();
   return tree;
 }
Ejemplo n.º 9
0
 private MutableTreeNode populateTree(Tree t) throws SQLException {
   DefaultMutableTreeNode tree = new DefaultMutableTreeNode(t);
   // tree.add(populateAttributes(t));
   Statement stmt = db.statement();
   for (Cavity c : t.loadCavities(stmt)) {
     tree.add(populateCavity(c));
   }
   stmt.close();
   return tree;
 }
Ejemplo n.º 10
0
 private MutableTreeNode populatePlot(Plot p) throws SQLException {
   DefaultMutableTreeNode tree = new DefaultMutableTreeNode(p);
   // tree.add(populateAttributes(p));
   Statement stmt = db.statement();
   for (Tree t : p.loadTrees(stmt)) {
     tree.add(populateTree(t));
   }
   stmt.close();
   return tree;
 }
  private static TreeNode groupAndSortArchetypes(Set<MavenArchetype> archetypes) {
    List<MavenArchetype> list = new ArrayList<MavenArchetype>(archetypes);

    Collections.sort(
        list,
        new Comparator<MavenArchetype>() {
          public int compare(MavenArchetype o1, MavenArchetype o2) {
            String key1 = o1.groupId + ":" + o1.artifactId;
            String key2 = o2.groupId + ":" + o2.artifactId;

            int result = key1.compareToIgnoreCase(key2);
            if (result != 0) return result;

            return o2.version.compareToIgnoreCase(o1.version);
          }
        });

    Map<String, List<MavenArchetype>> map = new TreeMap<String, List<MavenArchetype>>();

    for (MavenArchetype each : list) {
      String key = each.groupId + ":" + each.artifactId;
      List<MavenArchetype> versions = map.get(key);
      if (versions == null) {
        versions = new ArrayList<MavenArchetype>();
        map.put(key, versions);
      }
      versions.add(each);
    }

    DefaultMutableTreeNode result = new DefaultMutableTreeNode("root", true);
    for (List<MavenArchetype> each : map.values()) {
      MavenArchetype eachArchetype = each.get(0);
      DefaultMutableTreeNode node = new DefaultMutableTreeNode(eachArchetype, true);
      for (MavenArchetype eachVersion : each) {
        DefaultMutableTreeNode versionNode = new DefaultMutableTreeNode(eachVersion, false);
        node.add(versionNode);
      }
      result.add(node);
    }

    return result;
  }
Ejemplo n.º 12
0
  protected void restoreTree() {
    Pair<ElementNode, List<ElementNode>> selection = storeSelection();

    DefaultMutableTreeNode root = getRootNode();
    if (!myShowClasses || myContainerNodes.isEmpty()) {
      List<ParentNode> otherObjects = new ArrayList<ParentNode>();
      Enumeration<ParentNode> children = getRootNodeChildren();
      ParentNode newRoot =
          new ParentNode(
              null, new MemberChooserObjectBase(getAllContainersNodeName()), new Ref<Integer>(0));
      while (children.hasMoreElements()) {
        final ParentNode nextElement = children.nextElement();
        if (nextElement instanceof ContainerNode) {
          final ContainerNode containerNode = (ContainerNode) nextElement;
          Enumeration<MemberNode> memberNodes = containerNode.children();
          List<MemberNode> memberNodesList = new ArrayList<MemberNode>();
          while (memberNodes.hasMoreElements()) {
            memberNodesList.add(memberNodes.nextElement());
          }
          for (MemberNode memberNode : memberNodesList) {
            newRoot.add(memberNode);
          }
        } else {
          otherObjects.add(nextElement);
        }
      }
      replaceChildren(root, otherObjects);
      sortNode(newRoot, myComparator);
      if (newRoot.children().hasMoreElements()) root.add(newRoot);
    } else {
      Enumeration<ParentNode> children = getRootNodeChildren();
      while (children.hasMoreElements()) {
        ParentNode allClassesNode = children.nextElement();
        Enumeration<MemberNode> memberNodes = allClassesNode.children();
        ArrayList<MemberNode> arrayList = new ArrayList<MemberNode>();
        while (memberNodes.hasMoreElements()) {
          arrayList.add(memberNodes.nextElement());
        }
        Collections.sort(arrayList, myComparator);
        for (MemberNode memberNode : arrayList) {
          myNodeToParentMap.get(memberNode).add(memberNode);
        }
      }
      replaceChildren(root, myContainerNodes);
    }
    myTreeModel.nodeStructureChanged(root);

    defaultExpandTree();

    restoreSelection(selection);
  }
 public void fillOptions(@NotNull ColorAndFontOptions options) {
   DefaultMutableTreeNode root = new DefaultMutableTreeNode();
   for (EditorSchemeAttributeDescriptor description : getOrderedDescriptors(options)) {
     if (!description.getGroup().equals(myCategoryName)) continue;
     List<String> path = extractPath(description);
     if (path != null && path.size() > 1) {
       MyTreeNode groupNode = ensureGroup(root, path, 0);
       groupNode.add(new MyTreeNode(description, path.get(path.size() - 1)));
     } else {
       root.add(new MyTreeNode(description));
     }
   }
   myTreeModel.setRoot(root);
 }
 private static MyTreeNode ensureGroup(
     @NotNull DefaultMutableTreeNode root, @NotNull List<String> path, int index) {
   String groupName = path.get(index++);
   for (int i = 0; i < root.getChildCount(); i++) {
     TreeNode child = root.getChildAt(i);
     if (child instanceof MyTreeNode && groupName.equals(child.toString())) {
       return index < path.size() - 1
           ? ensureGroup((MyTreeNode) child, path, index)
           : (MyTreeNode) child;
     }
   }
   MyTreeNode groupNode = new MyTreeNode(groupName);
   root.add(groupNode);
   return index < path.size() - 1 ? ensureGroup(groupNode, path, index) : groupNode;
 }
Ejemplo n.º 15
0
  private MutableTreeNode populateAttributes(CavityDBObject obj) {
    DefaultMutableTreeNode tree = new DefaultMutableTreeNode("attrs");
    Class cls = obj.getClass();
    for (Field f : cls.getFields()) {
      int mod = f.getModifiers();
      if (Modifier.isPublic(mod) && !Modifier.isStatic(mod)) {
        String fieldName = f.getName();
        try {
          Object value = f.get(obj);
          tree.add(
              new DefaultMutableTreeNode(String.format("%s=%s", fieldName, String.valueOf(value))));

        } catch (IllegalAccessException e) {
          // do nothing.
        }
      }
    }
    return tree;
  }
  // Public Methods
  public void appendNextTreeGeneration(Vector generation) {
    DefaultMutableTreeNode nextGeneration = generationNodeBuilder(generation);

    generations.add(nextGeneration);

    // If Generations contains leaf nodes (generated objects)
    // Enabled Save All Menu Item
    if (generations.getLeafCount() > 0) miSaveAll.setEnabled(true);
    else miSaveAll.setEnabled(false);

    // Update JTree View

    // affected nodes needing updating
    int[] nodeRangeToUpdate = {generations.getIndex(nextGeneration)};
    ((DefaultTreeModel) tree.getModel()).nodesWereInserted(generations, nodeRangeToUpdate);

    // Expand Parent after first child node is displayed
    if (generationNumber == 1) tree.expandRow(0);

    ++generationNumber;
  }
Ejemplo n.º 17
0
  /** Sets the value for the given node at the given column to the given value. */
  public void setValueAt(Object value, Object node, int col) {
    DefaultMutableTreeNode tree_node = (DefaultMutableTreeNode) node;
    Object node_value = tree_node.getUserObject();

    switch (col) {
        // Name (not supported)
      case 0:
        break;
        // Value
      case 1:
        DefaultMutableTreeNode parent_node = (DefaultMutableTreeNode) tree_node.getParent();

        // First child of root is always the element name
        if (parent_node == getRoot() && parent_node.getIndex((TreeNode) node) == 0) {
          ConfigElement elt = (ConfigElement) parent_node.getUserObject();
          elt.setName((String) value);
          tree_node.setUserObject(value);
        } else if (node_value instanceof PropertyDefinition) {
          // Hey, we're editing a property definition. If it's type is not a
          // configuration element, we're probably editing a summary list of
          // the valuesof the children.
          if (((PropertyDefinition) node_value).getType() != ConfigElement.class) {
            ConfigElement elt = (ConfigElement) parent_node.getUserObject();
            PropertyDefinition prop_def = (PropertyDefinition) node_value;
            StringTokenizer tokenizer = new StringTokenizer((String) value, ", ");
            int idx = 0;
            while (tokenizer.hasMoreTokens()) {
              String token = tokenizer.nextToken();

              // Make sure we don't overrun the property values
              if ((idx >= prop_def.getPropertyValueDefinitionCount()) && (!prop_def.isVariable())) {
                break;
              }

              // Convert the value to the appropriate type
              Object new_value = null;
              Class type = prop_def.getType();
              if (type == Boolean.class) {
                new_value = new Boolean(token);
              } else if (type == Integer.class) {
                new_value = new Integer(token);
              } else if (type == Float.class) {
                new_value = new Float(token);
              } else if (type == String.class) {
                new_value = new String(token);
              } else if (type == ConfigElementPointer.class) {
                new_value = new ConfigElementPointer(token);
              }

              setProperty(new_value, elt, prop_def.getToken(), idx);

              // Get the node for the current property value and update it
              if (idx < tree_node.getChildCount()) {
                DefaultMutableTreeNode child_node =
                    (DefaultMutableTreeNode) tree_node.getChildAt(idx);
                child_node.setUserObject(new_value);
              } else {
                // Insert the new property
                DefaultMutableTreeNode new_node = new DefaultMutableTreeNode(new_value);
                tree_node.add(new_node);
                fireTreeNodesInserted(
                    this,
                    new Object[] {getPathToRoot(tree_node)},
                    new int[] {tree_node.getIndex(new_node)},
                    new Object[] {new_node});
              }
              ++idx;
            }
          }
        } else {
          // Parent is a ConfigElement ... must be a single-valued property
          if (parent_node.getUserObject() instanceof ConfigElement) {
            ConfigElement elt = (ConfigElement) parent_node.getUserObject();
            int desc_idx = parent_node.getIndex(tree_node);

            // If the parent is the root, take into account the extra name
            // and type nodes
            if (parent_node == getRoot()) {
              desc_idx -= 2;
            }
            PropertyDefinition prop_def =
                (PropertyDefinition) elt.getDefinition().getPropertyDefinitions().get(desc_idx);
            setProperty(value, elt, prop_def.getToken(), 0);
            tree_node.setUserObject(value);
          } else {
            // Parent must be a PropertyDefinition
            PropertyDefinition prop_def = (PropertyDefinition) parent_node.getUserObject();
            int value_idx = parent_node.getIndex(tree_node);
            DefaultMutableTreeNode elt_node = (DefaultMutableTreeNode) parent_node.getParent();
            ConfigElement elt = (ConfigElement) elt_node.getUserObject();
            setProperty(value, elt, prop_def.getToken(), value_idx);
            tree_node.setUserObject(value);
          }
        }
        fireTreeNodesChanged(
            this,
            new Object[] {getPathToRoot(parent_node)},
            new int[] {parent_node.getIndex(tree_node)},
            new Object[] {tree_node});
        break;
      default:
        throw new IllegalArgumentException("Invalid column: " + col);
    }
  }
  protected TreeTable createOptionsTree(CodeStyleSettings settings) {
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
    Map<String, DefaultMutableTreeNode> groupsMap = new THashMap<String, DefaultMutableTreeNode>();

    List<Option> sorted = sortOptions(ContainerUtil.concat(myOptions, myCustomOptions));
    for (Option each : sorted) {
      if (!(myCustomOptions.contains(each)
          || myAllowedOptions.contains(each.field.getName())
          || myShowAllStandardOptions)) continue;

      String group = each.groupName;
      MyTreeNode newNode = new MyTreeNode(each, each.title, settings);

      DefaultMutableTreeNode groupNode = groupsMap.get(group);
      if (groupNode != null) {
        groupNode.add(newNode);
      } else {
        String groupName;

        if (group == null) {
          groupName = each.title;
          groupNode = newNode;
        } else {
          groupName = group;
          groupNode = new DefaultMutableTreeNode(groupName);
          groupNode.add(newNode);
        }
        groupsMap.put(groupName, groupNode);
        rootNode.add(groupNode);
      }
    }

    ListTreeTableModel model = new ListTreeTableModel(rootNode, COLUMNS);
    TreeTable treeTable =
        new TreeTable(model) {
          @Override
          public TreeTableCellRenderer createTableRenderer(TreeTableModel treeTableModel) {
            TreeTableCellRenderer tableRenderer = super.createTableRenderer(treeTableModel);
            UIUtil.setLineStyleAngled(tableRenderer);
            tableRenderer.setRootVisible(false);
            tableRenderer.setShowsRootHandles(true);

            return tableRenderer;
          }

          @Override
          public TableCellRenderer getCellRenderer(int row, int column) {
            TreePath treePath = getTree().getPathForRow(row);
            if (treePath == null) return super.getCellRenderer(row, column);

            Object node = treePath.getLastPathComponent();

            @SuppressWarnings("unchecked")
            TableCellRenderer renderer = COLUMNS[column].getRenderer(node);
            return renderer == null ? super.getCellRenderer(row, column) : renderer;
          }

          @Override
          public TableCellEditor getCellEditor(int row, int column) {
            TreePath treePath = getTree().getPathForRow(row);
            if (treePath == null) return super.getCellEditor(row, column);

            Object node = treePath.getLastPathComponent();
            @SuppressWarnings("unchecked")
            TableCellEditor editor = COLUMNS[column].getEditor(node);
            return editor == null ? super.getCellEditor(row, column) : editor;
          }
        };
    new TreeTableSpeedSearch(treeTable).setComparator(new SpeedSearchComparator(false));

    treeTable.setRootVisible(false);

    final JTree tree = treeTable.getTree();
    tree.setCellRenderer(myTitleRenderer);
    tree.setShowsRootHandles(true);
    // myTreeTable.setRowHeight(new JComboBox(new String[]{"Sample
    // Text"}).getPreferredSize().height);
    treeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    treeTable.setTableHeader(null);

    expandTree(tree);

    treeTable.getColumnModel().getSelectionModel().setAnchorSelectionIndex(1);
    treeTable.getColumnModel().getSelectionModel().setLeadSelectionIndex(1);

    int maxWidth = tree.getPreferredScrollableViewportSize().width + 10;
    final TableColumn titleColumn = treeTable.getColumnModel().getColumn(0);
    titleColumn.setPreferredWidth(maxWidth);
    titleColumn.setMinWidth(maxWidth);
    titleColumn.setMaxWidth(maxWidth);
    titleColumn.setResizable(false);

    // final TableColumn levelColumn = treeTable.getColumnModel().getColumn(1);
    // TODO[max]: better preffered size...
    // TODO[kb]: Did I fixed it by making the last column floating?
    // levelColumn.setPreferredWidth(valueSize.width);
    // levelColumn.setMaxWidth(valueSize.width);
    // levelColumn.setMinWidth(valueSize.width);
    // levelColumn.setResizable(false);

    final Dimension valueSize =
        new JLabel(ApplicationBundle.message("option.table.sizing.text")).getPreferredSize();
    treeTable.setPreferredScrollableViewportSize(
        new Dimension(maxWidth + valueSize.width + 10, 20));

    return treeTable;
  }
Ejemplo n.º 19
0
 private void populate() throws SQLException {
   Collection<Plot> plots = db.select(Plot.class).values();
   for (Plot p : plots) {
     top.add(populatePlot(p));
   }
 }
  /**
   * Constructs a X509 certificate panel.
   *
   * @param certificates <tt>X509Certificate</tt> objects
   */
  public X509CertificatePanel(Certificate[] certificates) {
    setLayout(new BorderLayout(5, 5));

    // Certificate chain list
    TransparentPanel topPanel = new TransparentPanel(new BorderLayout());
    topPanel.add(
        new JLabel(
            "<html><body><b>"
                + R.getI18NString("service.gui.CERT_INFO_CHAIN")
                + "</b></body></html>"),
        BorderLayout.NORTH);

    DefaultMutableTreeNode top = new DefaultMutableTreeNode();
    DefaultMutableTreeNode previous = top;
    for (int i = certificates.length - 1; i >= 0; i--) {
      Certificate cert = certificates[i];
      DefaultMutableTreeNode next = new DefaultMutableTreeNode(cert);
      previous.add(next);
      previous = next;
    }
    JTree tree = new JTree(top);
    tree.setBorder(new BevelBorder(BevelBorder.LOWERED));
    tree.setRootVisible(false);
    tree.setExpandsSelectedPaths(true);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setCellRenderer(
        new DefaultTreeCellRenderer() {

          @Override
          public Component getTreeCellRendererComponent(
              JTree tree,
              Object value,
              boolean sel,
              boolean expanded,
              boolean leaf,
              int row,
              boolean hasFocus) {
            JLabel component =
                (JLabel)
                    super.getTreeCellRendererComponent(
                        tree, value, sel, expanded, leaf, row, hasFocus);
            if (value instanceof DefaultMutableTreeNode) {
              Object o = ((DefaultMutableTreeNode) value).getUserObject();
              if (o instanceof X509Certificate) {
                component.setText(getSimplifiedName((X509Certificate) o));
              } else {
                // We don't know how to represent this certificate type,
                // let's use the first 20 characters
                String text = o.toString();
                if (text.length() > 20) {
                  text = text.substring(0, 20);
                }
                component.setText(text);
              }
            }
            return component;
          }
        });
    tree.getSelectionModel()
        .addTreeSelectionListener(
            new TreeSelectionListener() {

              @Override
              public void valueChanged(TreeSelectionEvent e) {
                valueChangedPerformed(e);
              }
            });
    tree.setSelectionPath(
        new TreePath((((DefaultTreeModel) tree.getModel()).getPathToRoot(previous))));
    topPanel.add(tree, BorderLayout.CENTER);

    add(topPanel, BorderLayout.NORTH);

    // Certificate details pane
    Caret caret = infoTextPane.getCaret();
    if (caret instanceof DefaultCaret) {
      ((DefaultCaret) caret).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
    }

    /*
     * Make JEditorPane respect our default font because we will be using it
     * to just display text.
     */
    infoTextPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);

    infoTextPane.setOpaque(false);
    infoTextPane.setEditable(false);
    infoTextPane.setContentType("text/html");
    infoTextPane.setText(toString(certificates[0]));

    final JScrollPane certScroll = new JScrollPane(infoTextPane);
    certScroll.setPreferredSize(new Dimension(300, 500));
    add(certScroll, BorderLayout.CENTER);
  }
Ejemplo n.º 21
0
  /**
   * Helper function to display a Swing window with a tree representation of the specified list of
   * joins. See {@link #orderJoins}, which may want to call this when the analyze flag is true.
   *
   * @param js the join plan to visualize
   * @param pc the PlanCache accumulated whild building the optimal plan
   * @param stats table statistics for base tables
   * @param selectivities the selectivities of the filters over each of the tables (where tables are
   *     indentified by their alias or name if no alias is given)
   */
  private void printJoins(
      Vector<LogicalJoinNode> js,
      PlanCache pc,
      HashMap<String, TableStats> stats,
      HashMap<String, Double> selectivities) {

    JFrame f = new JFrame("Join Plan for " + p.getQuery());

    // Set the default close operation for the window,
    // or else the program won't exit when clicking close button
    f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    f.setVisible(true);

    f.setSize(300, 500);

    HashMap<String, DefaultMutableTreeNode> m = new HashMap<String, DefaultMutableTreeNode>();

    // int numTabs = 0;

    // int k;
    DefaultMutableTreeNode root = null, treetop = null;
    HashSet<LogicalJoinNode> pathSoFar = new HashSet<LogicalJoinNode>();
    boolean neither;

    System.out.println(js);
    for (LogicalJoinNode j : js) {
      pathSoFar.add(j);
      System.out.println("PATH SO FAR = " + pathSoFar);

      String table1Name = Database.getCatalog().getTableName(this.p.getTableId(j.t1Alias));
      String table2Name = Database.getCatalog().getTableName(this.p.getTableId(j.t2Alias));

      // Double c = pc.getCost(pathSoFar);
      neither = true;

      root =
          new DefaultMutableTreeNode(
              "Join "
                  + j
                  + " (Cost ="
                  + pc.getCost(pathSoFar)
                  + ", card = "
                  + pc.getCard(pathSoFar)
                  + ")");
      DefaultMutableTreeNode n = m.get(j.t1Alias);
      if (n == null) { // never seen this table before
        n =
            new DefaultMutableTreeNode(
                j.t1Alias
                    + " (Cost = "
                    + stats.get(table1Name).estimateScanCost()
                    + ", card = "
                    + stats.get(table1Name).estimateTableCardinality(selectivities.get(j.t1Alias))
                    + ")");
        root.add(n);
      } else {
        // make left child root n
        root.add(n);
        neither = false;
      }
      m.put(j.t1Alias, root);

      n = m.get(j.t2Alias);
      if (n == null) { // never seen this table before

        n =
            new DefaultMutableTreeNode(
                j.t2Alias == null
                    ? "Subplan"
                    : (j.t2Alias
                        + " (Cost = "
                        + stats.get(table2Name).estimateScanCost()
                        + ", card = "
                        + stats
                            .get(table2Name)
                            .estimateTableCardinality(selectivities.get(j.t2Alias))
                        + ")"));
        root.add(n);
      } else {
        // make right child root n
        root.add(n);
        neither = false;
      }
      m.put(j.t2Alias, root);

      // unless this table doesn't join with other tables,
      // all tables are accessed from root
      if (!neither) {
        for (String key : m.keySet()) {
          m.put(key, root);
        }
      }

      treetop = root;
    }

    JTree tree = new JTree(treetop);
    JScrollPane treeView = new JScrollPane(tree);

    tree.setShowsRootHandles(true);

    // Set the icon for leaf nodes.
    ImageIcon leafIcon = new ImageIcon("join.jpg");
    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
    renderer.setOpenIcon(leafIcon);
    renderer.setClosedIcon(leafIcon);

    tree.setCellRenderer(renderer);

    f.setSize(300, 500);

    f.add(treeView);
    for (int i = 0; i < tree.getRowCount(); i++) {
      tree.expandRow(i);
    }

    if (js.size() == 0) {
      f.add(new JLabel("No joins in plan."));
    }

    f.pack();
  }
  public MetalworksInBox() {
    super("In Box", true, true, true, true);

    DefaultMutableTreeNode unread;
    DefaultMutableTreeNode personal;
    DefaultMutableTreeNode business;
    DefaultMutableTreeNode spam;

    DefaultMutableTreeNode top = new DefaultMutableTreeNode("Mail Boxes");

    top.add(unread = new DefaultMutableTreeNode("Unread Mail"));
    top.add(personal = new DefaultMutableTreeNode("Personal"));
    top.add(business = new DefaultMutableTreeNode("Business"));
    top.add(spam = new DefaultMutableTreeNode("Spam"));

    unread.add(new DefaultMutableTreeNode("Buy Stuff Now"));
    unread.add(new DefaultMutableTreeNode("Read Me Now"));
    unread.add(new DefaultMutableTreeNode("Hot Offer"));
    unread.add(new DefaultMutableTreeNode("Re: Re: Thank You"));
    unread.add(new DefaultMutableTreeNode("Fwd: Good Joke"));

    personal.add(new DefaultMutableTreeNode("Hi"));
    personal.add(new DefaultMutableTreeNode("Good to hear from you"));
    personal.add(new DefaultMutableTreeNode("Re: Thank You"));

    business.add(new DefaultMutableTreeNode("Thanks for your order"));
    business.add(new DefaultMutableTreeNode("Price Quote"));
    business.add(new DefaultMutableTreeNode("Here is the invoice"));
    business.add(new DefaultMutableTreeNode("Project Metal: delivered on time"));
    business.add(new DefaultMutableTreeNode("Your salary raise approved"));

    spam.add(new DefaultMutableTreeNode("Buy Now"));
    spam.add(new DefaultMutableTreeNode("Make $$$ Now"));
    spam.add(new DefaultMutableTreeNode("HOT HOT HOT"));
    spam.add(new DefaultMutableTreeNode("Buy Now"));
    spam.add(new DefaultMutableTreeNode("Don't Miss This"));
    spam.add(new DefaultMutableTreeNode("Opportunity in Precious Metals"));
    spam.add(new DefaultMutableTreeNode("Buy Now"));
    spam.add(new DefaultMutableTreeNode("Last Chance"));
    spam.add(new DefaultMutableTreeNode("Buy Now"));
    spam.add(new DefaultMutableTreeNode("Make $$$ Now"));
    spam.add(new DefaultMutableTreeNode("To Hot To Handle"));
    spam.add(new DefaultMutableTreeNode("I'm waiting for your call"));

    JTree tree = new JTree(top);
    JScrollPane treeScroller = new JScrollPane(tree);
    treeScroller.setBackground(tree.getBackground());
    setContentPane(treeScroller);
    setSize(325, 200);
    setLocation(75, 75);
  }