//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.systemfamily;
import javax.swing.tree.TreeCellRenderer;
import java.awt.Component;
import java.awt.Font;
import java.awt.Color;
import java.util.ResourceBundle;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.ToolTipManager;
import javax.swing.tree.DefaultMutableTreeNode;
import org.sintef.umt.hutntree.HutnTreeCellRenderer;
import org.sintef.umt.umtmain.UMTMain;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
public class SystemFamilyTreeCellRenderer extends HutnTreeCellRenderer implements TreeCellRenderer
{
String pfimg_dir = UMTMain.family_img_dir;
public static ImageIcon familyRoot = null;
public static ImageIcon familyPackage = null;
public static ImageIcon productsPackage = null;
public static ImageIcon dependencyConflicts = null;
public static ImageIcon dependencyRequires = null;
public static ImageIcon familiesClass = null;
public static ImageIcon variationPoint = null;
public static ImageIcon variationPointChecked = null;
public static ImageIcon categoryClass = null;
public static ResourceBundle fresourceBundle = null;
public SystemFamilyTreeCellRenderer (SystemFamilyTreeView owner) {
super(owner);
init ();
}
public static ResourceBundle getResourceBundle () {
return fresourceBundle;
}
private void init () {
try {
fresourceBundle = ResourceBundle.getBundle("org.sintef.umt.systemfamily.SystemFamilyTreeResources");
} catch (Exception ex) {
ex.printStackTrace();
}
try {
familyRoot = new ImageIcon (pfimg_dir + fresourceBundle.getString("family.root"));
familyPackage = new ImageIcon (pfimg_dir + fresourceBundle.getString("family.package"));
productsPackage = new ImageIcon (pfimg_dir + fresourceBundle.getString("family.products.package"));
dependencyConflicts = new ImageIcon (pfimg_dir + fresourceBundle.getString("family.conflicts"));
dependencyRequires= new ImageIcon (pfimg_dir + fresourceBundle.getString("family.requires"));
familiesClass = new ImageIcon (pfimg_dir + fresourceBundle.getString("family.class"));
variationPoint = new ImageIcon (pfimg_dir + fresourceBundle.getString("family.variationPoint"));
variationPointChecked = new ImageIcon (pfimg_dir + fresourceBundle.getString("family.variationPointChecked"));
categoryClass = new ImageIcon (pfimg_dir + fresourceBundle.getString("family.category"));
} catch (Exception ex) {
ex.printStackTrace();
}
}
/**
* Checks if a stereotype is market as being optional
* @param stereotype
* @return
*/
protected boolean isOptionalVP (String stereotype) {
boolean isOptional = false;
isOptional = (stereotype != null) &&
(stereotype.equalsIgnoreCase("vp") ||
stereotype.equalsIgnoreCase("variationpoint") ||
stereotype.equalsIgnoreCase("optional"));
return isOptional;
}
/**
*
* @param stereotype
* @return
*/
protected boolean isRequiredVP (String stereotype) {
return (stereotype!=null) && (stereotype.equalsIgnoreCase("requires"));
}
/**
* @param stereotype
* @return
*/
protected boolean isConflictsVP (String stereotype) {
return (stereotype!=null) && (stereotype.equalsIgnoreCase("conflicts"));
}
/**
* @param stereotype
* @return
*/
protected boolean isPropertyVP (String stereotype) {
return (stereotype!=null) && (stereotype.equalsIgnoreCase("property"));
}
/**
* @param stereotype
* @return
*/
protected boolean isRangeVP (String stereotype) {
return (stereotype!=null) && (stereotype.equalsIgnoreCase("range"));
}
public Component getTreeCellRendererComponent(JTree tree,
Object value,
boolean selected,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus)
{
JLabel l = (JLabel) super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
try{
//
//
//
if (value == _owner.getModel().getRoot()) {
String project_context = UMTMain.getProjectName();
l.setText("ProductLine");
l.setIcon(familyRoot);
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;
Node parent = e.getParentNode();
String nodename = e.getNodeName ();
String name = e.getAttribute ("name");
if (name == null) name = "";
String id = e.getAttribute ("id");
String stereotype = e.getAttribute ("stereoType");
String vpvalue = e.getAttribute(VariabilityManager.VARIABILITY_INDICATOR);
ImageIcon variationIcon = null;
if (vpvalue != null && !vpvalue.equals(""))
variationIcon = variationPointChecked;
else
variationIcon = variationPoint;
if (nodename.equalsIgnoreCase ("package")){
if (stereotype != null && (stereotype.equalsIgnoreCase("SystemFamily") || stereotype.equalsIgnoreCase("ProductLine"))) {
l.setIcon(familyPackage);
}
if (parent != null && parent.getNodeName().equalsIgnoreCase("model")) {
l.setIcon(familyRoot);
}
} else if (nodename.equalsIgnoreCase ("class")){
if (stereotype.equalsIgnoreCase("SystemFamily") || stereotype.equalsIgnoreCase("ProductLine")) {
/*
* Check for SystemFamily Stereotypes
*/
l.setIcon(familiesClass);
l.setText(name);
} else if (stereotype.equalsIgnoreCase("category")){
l.setIcon(categoryClass);
}
else {
}
}
else if (nodename.equalsIgnoreCase("datatype")) {
l.setIcon(typeimg);
}
else if (nodename.equalsIgnoreCase ("attribute")){
/*
* Check for SystemFamily Stereotypes
*/
String initialValue = e.getAttribute("initialValue");
if (isOptionalVP(stereotype)) {
l.setToolTipText("Optional Variation Point");
l.setIcon(variationIcon);
} else if (isPropertyVP(stereotype)) {
l.setToolTipText("Property Variation Point");
l.setIcon(variationIcon);
} else if (isRangeVP(stereotype)) {
l.setToolTipText("Range Variation Point");
l.setIcon(variationIcon);
}
if (initialValue != null && !initialValue.equals(""))
l.setToolTipText(l.getToolTipText() + " = " + initialValue);
}
else if (nodename.equalsIgnoreCase ("association")){
/*
* Check for SystemFamily Stereotypes
*/
if (isOptionalVP(stereotype)) {
l.setToolTipText("Optional Variation Point");
l.setIcon(variationIcon);
} else if (this.isRequiredVP(stereotype)) {
l.setToolTipText("Requires Variation Point");
l.setIcon(variationIcon);
} else if (this.isConflictsVP(stereotype)) {
l.setToolTipText("Conflicts Variation Point");
l.setIcon(variationIcon);
}
}
else if (nodename.equalsIgnoreCase ("operation")){
/*
* Check for SystemFamily Stereotypes
*/
if (this.isOptionalVP(stereotype)) {
l.setToolTipText("Optional Variation Point");
l.setIcon(variationIcon);
}
}
else if (nodename.equalsIgnoreCase ("parameter")){
} else if (nodename.equalsIgnoreCase ("uses")) {
} else if (nodename.equalsIgnoreCase ("taggedvalue")) {
} else if (nodename.equalsIgnoreCase("implements")) {
}
}
else if (userobj instanceof String && ((String)userobj).equalsIgnoreCase("ProductLineModel")){
l.setIcon(SystemFamilyTreeCellRenderer.familyRoot);
}
else if (userobj instanceof String && ((String)userobj).equalsIgnoreCase("Products")){
l.setIcon(SystemFamilyTreeCellRenderer.productsPackage);
}
} catch (Exception ex){
System.out.println (ex);
ex.printStackTrace();
return new JLabel ("....");
}
return l;
}
}