예제 #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
    /*
     * 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());
    }
예제 #3
0
 private static String unitToString(Class<? extends Unit> unit) {
   ObjectType type = ObjectType.getObjectTypeForClass(unit);
   if (type == null) return "Unknown Unit";
   return type.getName();
 }