All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ingenias.editor.ProjectTreeRenderer Maven / Gradle / Ivy

There is a newer version: 1.0.9
Show newest version

/** 
 * Copyright (C) 2010  Jorge J. Gomez-Sanz
 * 
 * 
 * This file is part of the INGENME tool. INGENME is an open source meta-editor
 * which produces customized editors for user-defined modeling languages
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation version 3 of the License
 *
 * 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 General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see 
 **/
 
package ingenias.editor;

import java.awt.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.util.Map;
import java.util.Hashtable;

import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
import java.awt.event.*;
import java.net.URL;
import java.util.Map;
import java.util.Hashtable;
import java.util.ArrayList;
import javax.swing.event.UndoableEditEvent;
import org.jgraph.JGraph;
import org.jgraph.graph.*;
import org.jgraph.event.*;
import java.util.Vector;
import org.jgraph.JGraph;
import org.jgraph.graph.*;
import org.jgraph.event.*;
import org.jgraph.plaf.basic.*;
import ingenias.editor.entities.*;

public class ProjectTreeRenderer extends javax.swing.tree.DefaultTreeCellRenderer{
// Meta-models icons

static ImageIcon modeloNRGraph=new ImageIcon(ImageLoader.getImage("images/mdiagram.png"));


// Object icons
 
 static ImageIcon NRNodeIcon=new ImageIcon(ImageLoader.getImage("images/mnode.png"));
	

	static ImageIcon ConventionalFolderIcon=new ImageIcon(ImageLoader.getImage("images/folder.png"));

	static ImageIcon RootFolderIcon=new ImageIcon(ImageLoader.getImage("images/world.png"));


  public ProjectTreeRenderer() {

  super();

  }


    public Component getTreeCellRendererComponent(
                        JTree tree,
                        Object value,
                        boolean sel,
                        boolean expanded,
                        boolean leaf,
                        int row,
                        boolean hasFocus) {

       		super.getTreeCellRendererComponent(
				tree, value, sel,
				expanded, leaf, row,
				hasFocus);
		ImageIcon img=this.selectIcon(value);
		if (row==0)
			img=RootFolderIcon;

		if (img!=null) {
			setIcon(img);
			return this;
		} else
			return super.getTreeCellRendererComponent(tree,value,sel,expanded,leaf,row,hasFocus);
    }



  public static ImageIcon selectIcon(Object value) {
        DefaultMutableTreeNode node =
            (DefaultMutableTreeNode)value;
        return selectIconByUserObject(node.getUserObject());
    }

    public static String getIconNameByUserObject(Object userObject) {
	if (userObject.getClass().equals(String.class))
			return "images/folder.png";


	
        if (userObject.getClass().equals(NRNode.class))
          return "images/mnode.png";
	


        if (userObject.getClass().equals(ingenias.editor.models.NRGraphModelJGraph.class))
            return "images/mdiagram.png";

        return null;
    }

    public static ImageIcon selectIconByUserObject(Object userObject) {
   
	if (userObject.getClass().equals(String.class))
			return ConventionalFolderIcon;


	
        if (userObject.getClass().equals(NRNode.class))
          return NRNodeIcon;
	


        if (userObject.getClass().equals(ingenias.editor.models.NRGraphModelJGraph.class))
            return modeloNRGraph;

        return null;
      }

}






© 2015 - 2024 Weber Informatics LLC | Privacy Policy