示例#1
0
    @Override
    public Component getTreeCellRendererComponent(
        JTree tree,
        Object value,
        boolean selected,
        boolean expanded,
        boolean leaf,
        int row,
        boolean hasFocus) {

      super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);

      // If not a leaf, just return
      if (!leaf) return this;

      // If we don't find an ObjectType (likely we will) just return
      Object userObj = ((DefaultMutableTreeNode) value).getUserObject();
      if (!(userObj instanceof ObjectType)) return this;

      ObjectType type = (ObjectType) userObj;
      this.setText(type.getName());

      if (!RenderManager.isGood()) return this;

      if (type.getIconImage() == null) return this;

      icon.setImage(type.getIconImage());
      this.setIcon(icon);
      return this;
    }
示例#2
0
  private void updateTree() {

    // Create a tree that allows one selection at a time
    top.removeAllChildren();
    HashMap<String, DefaultMutableTreeNode> paletteNodes = new HashMap<>();
    for (ObjectType type : ObjectType.getAll()) {
      if (!type.isDragAndDrop()) continue;

      String pName = type.getPaletteName();
      DefaultMutableTreeNode palNode = paletteNodes.get(pName);
      if (palNode == null) {
        palNode = new DefaultMutableTreeNode(pName, true);
        paletteNodes.put(pName, palNode);
        top.add(palNode);
      }

      DefaultMutableTreeNode classNode = new DefaultMutableTreeNode(type, true);
      palNode.add(classNode);
    }
    treeModel.reload(top);
  }
示例#3
0
    /*
     * override getToolTipText to control what to display
     */
    @Override
    public String getToolTipText(MouseEvent e) {

      if (this.getPathForLocation(e.getX(), e.getY()) == null) {
        return null;
      }

      // Obtain the node under the mouse
      DefaultMutableTreeNode node =
          (DefaultMutableTreeNode)
              this.getPathForLocation(e.getX(), e.getY()).getLastPathComponent();
      if (node == null) {
        return null;
      }

      Object object = node.getUserObject();

      // It is a leaf node
      if (!(object instanceof ObjectType)) {
        return null;
      }
      ObjectType ot = (ObjectType) object;
      return GUIFrame.formatToolTip(ot.getName(), ot.getDescription());
    }
示例#4
0
 private static String unitToString(Class<? extends Unit> unit) {
   ObjectType type = ObjectType.getObjectTypeForClass(unit);
   if (type == null) return "Unknown Unit";
   return type.getName();
 }