⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iconnoderenderer.java

📁 自动生成JAVA-Struts网站的程序
💻 JAVA
字号:
package com.sutternow.swingkar.tree;

/**
 * Created by IntelliJ IDEA.
 * User: payne
 * Date: May 12, 2003
 * Time: 4:51:09 PM
 * To change this template use Options | File Templates.
 */


import java.awt.*;
import java.util.HashMap;
import java.net.URL;
import java.net.MalformedURLException;
import javax.swing.*;
import javax.swing.tree.*;


/**
 * @version 1.0 01/12/99
 */
public class IconNodeRenderer extends DefaultTreeCellRenderer
{
     HashMap iconMap;

     public IconNodeRenderer()  {

          iconMap = new HashMap();
          iconMap.put("Beans", "bean.gif");
          iconMap.put("build", "build.gif");
          iconMap.put("database", "database.gif");
          iconMap.put("property", "project.gif");
          iconMap.put("security", "security.gif");
          iconMap.put("Global Values", "globalvalue.gif");
          iconMap.put("Global References", "globalref.gif");
          iconMap.put("Menus", "menu.gif");

          iconMap.put("query", "default.gif");
          iconMap.put("process", "default.gif");
          iconMap.put("security-constraint", "default.gif");
          iconMap.put("primary-key", "default.gif");
          iconMap.put("attribute", "default.gif");
          iconMap.put("menu", "default.gif");
          iconMap.put("global-value-ref", "default.gif");
          iconMap.put("global-reference", "default.gif");
          iconMap.put("bean", "default.gif");


    }


   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);
      // get the user object
      DefaultMutableTreeNode node  = (DefaultMutableTreeNode)value;

      Object s = node.getUserObject();

      if (s instanceof String) {

          URL imgURL = this.getClass().getResource(this.lookUpIconPath((String)s));
          if (imgURL != null) {
              ImageIcon imgIco= new ImageIcon(imgURL);
              this.setIcon(imgIco);
          }
      } else if(s instanceof DisplayNode) {
          DisplayNode dn = (DisplayNode)s;
          URL imgURL = this.getClass().getResource(this.lookUpIconPath(dn.getElement().getName()));
          if (imgURL != null) {
              ImageIcon imgIco= new ImageIcon(imgURL);
              this.setIcon(imgIco);
          }

      }  else {  System.out.println(s.getClass());  }
      return this;
   }

   private String lookUpIconPath (String name) {
       String iconName = (String)iconMap.get(name);
       if (iconName != null )
           return "/com/sutternow/swingkar/resources/" + iconName;
       else
           return "";
   }

};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -