Package org.sintef.umt.hutntree

Source Code of org.sintef.umt.hutntree.HutnTreeCellRenderer

//UML Model Transformation Tool (UMT)
//Copyright (C) 2003, 2004, 2005 SINTEF
//Authors:  jon.oldevik at sintef.no | roy.gronmo at sintef.no | tor.neple at sintef.no | fredrik.vraalsen at sintef.no
//Webpage: http://umt.sourceforge.net
//Deloped in the projects:  ACEGIS (EU project - IST-2002-37724),
// CAFE (EUREKA/ITEA - ip00004), FAMILIES (ITEA project ip02009)
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU Lesser General Public License
//as published by the Free Software Foundation; either version 2.1
//of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//Lesser General Public License for more details.
//
//You should have received a copy of the GNU Lesser General Public
//License along with this program; if not, write to the Free
//Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
//02111-1307 USA
package org.sintef.umt.hutntree;


import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTree;
import javax.swing.ToolTipManager;
import javax.swing.tree.DefaultMutableTreeNode;
import java.util.ResourceBundle;

import org.sintef.umt.umtmain.UMTMain;
import org.w3c.dom.Element;



public class HutnTreeCellRenderer implements javax.swing.tree.TreeCellRenderer
{
 
    protected HutnTreeView _owner = null;
   
  /**
   *  General icons
   *
   */

  String img_dir = org.sintef.umt.umtmain.UMTMain.img_dir;
  protected static ImageIcon packageimg = null;  
  protected static ImageIcon typepackageimg = null;
  protected static ImageIcon classimg = null;
  protected static ImageIcon typeimg = null
  protected static ImageIcon associationimg = null;
  protected static ImageIcon attributeimg = null;
  protected static ImageIcon operationimg = null;
  protected static ImageIcon parameterimg = null;
  protected static ImageIcon interfaceimg = null;
  protected static ImageIcon dependencyimg = null;
  protected static ImageIcon actionstateimg = null;
  protected static ImageIcon outtransitionimg = null;
  protected static ImageIcon intransitionimg = null;
  protected static ImageIcon objectflowimg = null;
  protected static ImageIcon activitygraphimg = null;
  protected static ImageIcon choiceimg = null
  protected static ImageIcon forkimg = null;
  protected static ImageIcon joinimg = null;
  protected static ImageIcon roleimg = null;
  protected static ImageIcon startstateimg = null;
  protected static ImageIcon endstateimg = null;
 
  /**
   *  Icons for technology marks
   *
   */
 
  final protected ImageIcon marked_packageimg = new ImageIcon(img_dir + "marked_package.gif")
  final protected ImageIcon defaultimg = new ImageIcon (img_dir + "default.gif");
 
  final protected Font small_font = new Font("SansSerif", Font.PLAIN, 9);
  final protected Font normal_font = new Font("SansSerif", Font.PLAIN, 10);
  final protected Font bold_normal = new Font("SansSerif", Font.BOLD, 10);
  private ResourceBundle resourceBundle = null;

 
  public HutnTreeCellRenderer (HutnTreeView owner) {
      super();     
      init ();
      _owner = owner;

  }
 
  private void init () {
      try {
          resourceBundle = ResourceBundle.getBundle("org.sintef.umt.hutntree.HutnTreeResources");
      } catch (Exception ex) {
          ex.printStackTrace();
      }     
      try {
      packageimg = new ImageIcon(img_dir + resourceBundle.getString("icon.package"))
      typepackageimg = new ImageIcon(img_dir + resourceBundle.getString("icon.types_package"));
      classimg = new ImageIcon(img_dir + resourceBundle.getString("icon.class"));
      typeimg = new ImageIcon(img_dir + resourceBundle.getString("icon.type"))
      associationimg = new ImageIcon(img_dir + resourceBundle.getString("icon.association"));
      attributeimg = new ImageIcon(img_dir + resourceBundle.getString("icon.attribute"));
      operationimg = new ImageIcon(img_dir + resourceBundle.getString("icon.operation"));
      parameterimg = new ImageIcon(img_dir + resourceBundle.getString("icon.parameter"));
      interfaceimg = new ImageIcon(img_dir + resourceBundle.getString("icon.interface"));
      dependencyimg = new ImageIcon(img_dir + resourceBundle.getString("icon.dependency"));
      actionstateimg = new ImageIcon(img_dir + resourceBundle.getString("icon.actionstate"));
      outtransitionimg = new ImageIcon(img_dir + resourceBundle.getString("icon.transition.out"));
      intransitionimg = new ImageIcon(img_dir + resourceBundle.getString("icon.transition.in"));
      objectflowimg = new ImageIcon(img_dir + resourceBundle.getString("icon.objectflow"));
      activitygraphimg = new ImageIcon(img_dir + resourceBundle.getString("icon.activitygraph"));
      choiceimg = new ImageIcon(img_dir + resourceBundle.getString("icon.activity.choice"))
      forkimg = new ImageIcon(img_dir + resourceBundle.getString("icon.activity.fork"));
      joinimg = new ImageIcon(img_dir + resourceBundle.getString("icon.activity.join"));
      roleimg = new ImageIcon(img_dir + resourceBundle.getString("icon.activity.role"));
      startstateimg = new ImageIcon(img_dir + resourceBundle.getString("icon.activity.initstate"));
      endstateimg = new ImageIcon(img_dir + resourceBundle.getString("icon.activity.endstate"))
      } catch (Exception ex) {
          System.out.println ("HutnTreeCellRenderer::init() - " + ex);
      }
  }
 
          public Component getTreeCellRendererComponent(JTree tree,
                Object value,
                boolean selected,
                boolean expanded,
                boolean leaf,
                int row,
                boolean hasFocus)
    {
      try{       
        JLabel l = new JLabel ();
        if (value == _owner.getModel().getRoot()) {
          String project_context = UMTMain.getProjectName();
          if (project_context != null && !project_context.equals("")){
            l.setText("Project: " + project_context);
          } else         
            l.setText("Model");                   
          return l;
        }
        Object userobj = ((DefaultMutableTreeNode)value).getUserObject ();
        l.setText(userobj.toString());       
        ToolTipManager ttmanager = ToolTipManager.sharedInstance ();
        ttmanager.registerComponent(l);
        if (userobj instanceof Element) {
          Element e = (Element) userobj;
          String nodename = e.getNodeName ();
          String name = e.getAttribute ("name");
          if (name == null) name = "";
          String id = e.getAttribute ("id");
          String stereotype = e.getAttribute ("stereoType");
          if (stereotype == null) stereotype = "";
          l.setToolTipText("<<" + stereotype + ">>" + name);
          l.setFont(normal_font);
          if (stereotype != null && !stereotype.equals(""))
            l.setText (" <<"+ stereotype+">> " + name);
          else
            l.setText (name);
         
          l.setToolTipText(l.getText());
         
          if (nodename.equalsIgnoreCase ("model")){
            l.setIcon (packageimg);
          }
          else if (nodename.equalsIgnoreCase ("package")){
//            String tech = e.getAttribute("technology");
            String transform = e.getAttribute ("transform");           
            if (transform.equalsIgnoreCase ("true")) {
/*              if (tech.equalsIgnoreCase("ejb")) {
                l.setIcon (marked_ejbimg);
              } else if (tech.equalsIgnoreCase("web service")){
                  l.setIcon (marked_greenpackageimg);
              } else if (tech.equalsIgnoreCase("servlet")) {
              } else
*/
              l.setIcon (marked_packageimg);             
            }
            else {
              /*
                 if (tech.equalsIgnoreCase("ejb")) {
                l.setIcon (ejbimg);
              } else if (tech.equalsIgnoreCase("web service")){
                  l.setIcon (greenpackageimg);
              } else if (tech.equalsIgnoreCase("servlet")) {
              } else
            */
                  l.setIcon (packageimg);           
              }
          }
          else if (nodename.equalsIgnoreCase ("class")){
            l.setToolTipText(l.getToolTipText() + " (" + id + ")");
              if (stereotype.equalsIgnoreCase("interface"))
              l.setIcon(interfaceimg);
            else if (stereotype.equalsIgnoreCase("datatype"))
              l.setIcon(typeimg);
              else {
              String superclass = e.getAttribute("superClass");
              l.setIcon (classimg);
              if (superclass != null && !superclass.equals(""))
                l.setToolTipText(l.getToolTipText() + " extends " + _owner.getNameForID(superclass) + "(" + superclass +")");
              }
          }
          else if (nodename.equalsIgnoreCase("datatype")) {
            l.setIcon(typeimg);
          }
          else if (nodename.equalsIgnoreCase ("attribute")){
            l.setIcon (attributeimg);
            String type = _owner.getNameForID (e.getAttribute ("type"));
            if (type != null)
              l.setText (l.getText() + " : " + type)
            else
              type = e.getAttribute("type");
            l.setToolTipText("<<attribute>>" + name + ":" + type);
          }
         
          else if (nodename.equalsIgnoreCase ("association")){
            String target = _owner.getNameForID(e.getAttribute ("targetClass"));
            String cardinality = e.getAttribute ("cardinality");
            l.setIcon (associationimg);           
            l.setText (l.getText () + " : " + target + " [" + cardinality + "]");
            l.setToolTipText("<<association>>" + name + ":" + target + "[" + cardinality + "]");
          }
          else if (nodename.equalsIgnoreCase ("operation")){
            String returntype = _owner.getNameForID (e.getAttribute ("returnType"));
            if (returntype == null || returntype.equals(""))
              returntype = "void";
            l.setText (l.getText() + " (): " + returntype);
            l.setIcon (operationimg);
            l.setToolTipText("<<operation>>" + name + "(...):" + returntype);
          }
          else if (nodename.equalsIgnoreCase ("parameter")){
            l.setIcon (parameterimg);
            String type = _owner.getNameForID(e.getAttribute ("type"));
            if (type != null)
              l.setText (l.getText () + ": " + type);
            else
              type = e.getAttribute("type");
            l.setToolTipText(name + ":" + type);
          } else if (nodename.equalsIgnoreCase ("uses")) {
            // l.setIcon (dependencyimg);
            String target = _owner.getNameForID(e.getAttribute ("target"));
            l.setFont(small_font);
            l.setIcon(intransitionimg);
            if (target != null)
              l.setText ("<<uses>>" + target);
            else
              l.setText("<<uses>>" + e.getAttribute("target"));
          } else if (nodename.equalsIgnoreCase ("taggedvalue")) {
            String tag = e.getAttribute("tag");
            String tagvalue = e.getAttribute("value");
            if (tag != null && value != null) {
              l.setText("<<tag>>" + tag + "=" + tagvalue);
              l.setToolTipText("<<TaggedValue>>" + tag + " = " + tagvalue);
            }
          } else if (nodename.equalsIgnoreCase("implements")) {
            l.setFont(small_font);
            String implname = _owner.getNameForID(id);
            l.setText("<<implements>>" + implname);
            l.setToolTipText("<<implements>>" + implname + " (" + id + ")");
          }
          /*
           * Activity Presentation
           */
          else if (nodename.equalsIgnoreCase("activity")) {
            l.setIcon(actionstateimg);
            String stype = e.getAttribute("stereoType"); if (stype == null) stype = "";
            stype = stype.equals("")?"":"<<"+stype+">>";
            l.setText(name);
            l.setToolTipText(stype +"activity " + e.getAttribute("name") + " id = " + e.getAttribute("id"));
          } else if (nodename.equalsIgnoreCase("incoming")) {
            l.setIcon(intransitionimg);
            l.setText("<<" + nodename + ">>" + e.getAttribute("source"));
            l.setToolTipText("incoming from source " + e.getAttribute("source") + " sourceId = " + e.getAttribute("sourceId"));
          } else if (nodename.equalsIgnoreCase("outgoing")) {
            l.setIcon(outtransitionimg);
            l.setText("<<" + nodename + ">>" + e.getAttribute("target") + " [guard:" + e.getAttribute("guard") + "]");
            l.setToolTipText("outgoing to target " + e.getAttribute("target") + " targetId = " + e.getAttribute("targetId"));           
          } else if (nodename.equalsIgnoreCase("objectflow")) {
            l.setIcon(objectflowimg);
            l.setText(name);
            l.setToolTipText("objectflow " + name + " id = " + e.getAttribute("id"));           
          } else if (nodename.equalsIgnoreCase("activitygraph") || nodename.equalsIgnoreCase("activitymodel")) {
            l.setIcon(activitygraphimg);
          } else if (nodename.equalsIgnoreCase("choice")) {
            l.setIcon(choiceimg);
            if (name.equals(""))
              l.setText("choice");
            else l.setText(e.getAttribute("name"));
          } else if (nodename.equalsIgnoreCase ("PseudoState")) {
            l.setText (name);
            String kind = e.getAttribute("kind");
            if (kind.equalsIgnoreCase("fork")) {
              l.setIcon(forkimg);
              l.setText(l.getText() + " (fork)");
            } else if (kind.equalsIgnoreCase("join")) {
              l.setIcon(joinimg);
              l.setText(l.getText() + " (join)");
            } else if (kind.equalsIgnoreCase("branch")) {
              l.setIcon(choiceimg);
              l.setText(l.getText() + " (branch)");
            } else if (kind.equalsIgnoreCase("initial")) {
              l.setIcon(startstateimg);
              l.setText(l.getText() + " (Start state)");
              l.setToolTipText("Start state " + e.getAttribute("id"));             
            } else if (kind.equalsIgnoreCase("final")) {
              l.setIcon(endstateimg);
              l.setText(l.getText () + " (End state)");
              l.setToolTipText("End state " + e.getAttribute("id"));                           
            }             
          } else if (nodename.equalsIgnoreCase("role") || nodename.equalsIgnoreCase("roles")) {
            l.setIcon(roleimg);
            if (nodename.equalsIgnoreCase("roles"))
              l.setText("Roles");
            else {
              l.setText(name);
              l.setToolTipText(name + " (" + e.getAttribute("id") + ")");
            }
          }
        }
        else if (userobj instanceof String && ((String)userobj).equalsIgnoreCase("datatypes"))
          l.setIcon(typepackageimg);
        else if (userobj instanceof String && ((String)userobj).equalsIgnoreCase("uses")) {
          l.setIcon(intransitionimg);
          l.setFont(small_font);
        }
        else if (userobj instanceof String)
          l.setIcon (defaultimg);
        else
          l.setIcon (defaultimg);
         
        if (selected){
          // l.setFont (new Font("SansSerif", Font.BOLD, 10));
          l.setForeground (Color.blue);
        }
        else{
          // l.setFont (new Font("SansSerif", Font.PLAIN, 10));
          l.setForeground(Color.black);
        }         
        return l;
      } catch (Exception ex){
          System.out.println (ex);
          ex.printStackTrace();
        return new JLabel ("....");
      }
        }
}
TOP

Related Classes of org.sintef.umt.hutntree.HutnTreeCellRenderer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.