Package edu.uci.ics.jung.graph

Examples of edu.uci.ics.jung.graph.Vertex


    public LayeredIcon getIcon_Vertex(Vertex v) {
        return (LayeredIcon)iconMap.get(v);
    }
   
    public LayeredIcon getIcon_Vertex(String hostname) {
        Vertex v = getVertex(hostname);
        return getIcon_Vertex(v);
    }
View Full Code Here


    }
   
    public void adjustVerticesPhysicalLevel() {
        Set vertices = _myGraph.getVertices();
        int maxLvls = 0;
        Vertex v = null;
        for (Object o: vertices) {
            if (o instanceof Vertex) {
                v = (Vertex)o;
                Integer lvl = new Integer(getLevelAcordingToParents(v));
                v.setUserDatum("level", lvl, UserData.REMOVE);
                if (lvl.intValue() > maxLvls) {
                    maxLvls = lvl.intValue();
                }
            }
        } // for
View Full Code Here

    private int getLevelAcordingToParents_Aux(Vertex v, int lvl) {
        if (v == null) {
            return lvl;
        }
        LinkedList pars = (LinkedList)v.getUserDatum("parents");
        Vertex aux = null;
        if (pars != null) {
            aux = (Vertex)pars.getFirst();
        }
        return getLevelAcordingToParents_Aux(aux, lvl + 1);
    }
View Full Code Here

     */
    public String getGraphXML(String name, String key) {
        StringBuffer sb = new StringBuffer();
        Set vertices = _myGraph.getVertices();
        Set edges = _myGraph.getEdges();
        Vertex v = null;
        Edge e = null;
        Coordinates coord = null;
        Boolean hidden = null;
        Object tmp = null;
       
        sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n");
        sb.append("<mapdefinition>\n");
        // The config
        sb.append("<config>\n");
        sb.append("<view>" + name + "</view>\n");
        double scale = getVV(key).getLayoutTransformer().getScale();
        double ltranslateX = getVV(key).getLayoutTransformer().getTranslateX();
        double ltranslateY = getVV(key).getLayoutTransformer().getTranslateY();
        double vtranslateX = getVV(key).getViewTransformer().getTranslateX();
        double vtranslateY = getVV(key).getViewTransformer().getTranslateY();
        if (scale == 1.0)  {
            scale = getVV(key).getViewTransformer().getScale();
        }
        sb.append("<layouttranslatex>" + ltranslateX + "</layouttranslatex>\n");
        sb.append("<layouttranslatey>" + ltranslateY + "</layouttranslatey>\n");
        sb.append("<viewtranslatex>" + vtranslateX + "</viewtranslatex>\n");
        sb.append("<viewtranslatey>" + vtranslateY + "</viewtranslatey>\n");
        sb.append("<scale>" + scale + "</scale>\n");
        String title = getBackgroundTitle(key);
        if (title != null && title.length() > 0)  {
            sb.append("<backgroundtitle>" + title + "</backgroundtitle>\n");
        }
        String bgImage = getBackground(key);
        if (bgImage != null && bgImage.length() > 0)
            sb.append("<backgroundimage>"+ bgImage +"</backgroundimage>\n");
        sb.append("</config>\n");
        // The hosts
        if (!vertices.isEmpty()) {
            sb.append("<hosts>\n");
            for (Object o: vertices) {
                if (o != null && o instanceof Vertex) {
                    v = (Vertex)o;
                    coord = getLayout(key).getCoordinates(v);
                    hidden = (Boolean)v.getUserDatum(userdatumkey+key);
                    sb.append("<host");
                    if (hidden != null && hidden.booleanValue()) {
                        sb.append(" hidden=\"true\"");
                    } if (isLocked(v, key)) {
                        sb.append(" locked=\"true\"");
                    }
                    sb.append(">\n");
                    sb.append("<name>" + getLabel(v) + "</name>\n");
                    sb.append("<coords>" + coord.getX() + "," + coord.getY() + "</coords>\n");
                    tmp = v.getUserDatum("labelLocation");
                    if (tmp != null && tmp instanceof Location) {
                        sb.append("<label_location>" + ((Location)tmp).toString() + "</label_location>\n");
                        tmp = null;
                    }
                    sb.append("</host>\n");
View Full Code Here

   
    public void alignSelectedVertices(String key, Location loc) {
        PickedState pickedstate = getVV(key).getPickedState();
        Set vertices = pickedstate.getPickedVertices();
        Layout l = getVV(key).getGraphLayout();
        Vertex v = null;
        if (!vertices.isEmpty()) {
            Iterator it = vertices.iterator();
            v = (Vertex)it.next();
            Point2D p = l.getLocation(v);
           
View Full Code Here

    public void addServiceExtInfo(ServiceExtInfo serviceExtInfo) {
        setVertex_ServiceExtInfo(serviceExtInfo.getHostName(), serviceExtInfo);
    }
   
    public ServiceExtInfo getServiceExtInfo(String hostname, String dsc) {
        Vertex v = getVertex(hostname);
        Object sx = v.getUserDatum("servicesextinfo");
        ServiceExtInfo sei = null;
        if (sx instanceof Map) {
            Map <String, ServiceExtInfo> ssei = (Map <String, ServiceExtInfo>)sx;
            sei = ssei.get(dsc);
        }
View Full Code Here

     * Sets the service's status in host identified by host to <code>status</code>
     *@param host The host whose service status <code>status</code> is to be set
     *@param status The service's status to set
     */
    public void setVertex_ServiceExtInfo(String host, ServiceExtInfo extinfo) {
        Vertex v = getVertex(host);
        if (v != null) {
            Map <String, ServiceExtInfo>services = (Map<String,ServiceExtInfo>)v.getUserDatum("servicesextinfo");
            if (services == null) {
                v.addUserDatum("servicesextinfo", new HashMap<String, ServiceExtInfo>(), UserData.REMOVE);
                services = (Map<String,ServiceExtInfo>)v.getUserDatum("servicesextinfo");
            }
            services.put(extinfo.getServiceDescription(), extinfo);
        }
    }
View Full Code Here

            angles[xi] = 0;
        }
       
       
        double lvl = 0;
        Vertex v = null;
        for (Object o: vertices) {
           if (o instanceof Vertex) {
               v = (Vertex)o;
                junk = v.getUserDatum("level");
                if (junk instanceof Integer) {
                    lvl = (double)((Integer)junk).intValue();
                }
               angles[(int)lvl-((int)lvl > 0?1:0)]++; // total por nivel      
           }
        }
       
       
        int i = 0;
        int nivelVisitado = 1;
        int cuantos = 1;
       
        while (nivelVisitado <= level_num) {
            i = 0;
        for (Object o: vertices) {
            if (o instanceof Vertex) {
               
                v = (Vertex)o;
                if (isLocked(v))
                    continue;
                Coordinates coord = getCoordinates(v);
               
                junk = v.getUserDatum("level");
                if (junk instanceof Integer) {
                    lvl = (double)((Integer)junk).intValue();
                }
                if (lvl != nivelVisitado)
                    continue;
               
                double my_lvl_radius = radius / nivelVisitado;
                //double my_lvl_radius = radius * angles[(int)lvl-((int)lvl > 0?1:0)];
               
                double angle = (2 * Math.PI * i++) / angles[(int)lvl-((int)lvl > 0?1:0)];
               
                double cosX = Math.cos(angle);
                double sinY = Math.sin(angle);
                double xradius = (my_lvl_radius + (width/3 * (lvl / level_num)));
                double yradius = (my_lvl_radius + (width/3 * (lvl / level_num)));

    
     if (coord.getX() == 0d || coord.getY() == 0d)  {
         System.out.println("Oops... alguna coordenada es 0");
     }

     // test
                LinkedList parents = (LinkedList)v.getUserDatum("parents");
                Vertex parent = null;
                if (parents != null) {
                 parent = (Vertex)parents.getFirst();
                 if (parent != null) {
                     Coordinates pcoords = getCoordinates(parent);
                     if (pcoords.getX() == 0 || pcoords.getY() == 0) {
View Full Code Here

        int []angles = new int[(int)level_num];
        for (int xi = 0; xi < angles.length; xi++) {
            angles[xi] = 0;
        }

        Vertex v = null;
        double lvl = 0;
        int i = 0;
        int nivelVisitado = 1;
        int cuantos = 1;
       
        while (nivelVisitado < level_num) {
            i = 0;
        for (Object o: vertices) {
            if (o instanceof Vertex) {
                cuantos++;
                v = (Vertex)o;
                if (isLocked(v))
                    continue;
                Coordinates coord = getCoordinates(v);
               
                junk = v.getUserDatum("level");
                if (junk instanceof Integer) {
                    lvl = (double)((Integer)junk).intValue();
                }
                if (lvl != nivelVisitado)
                    continue;
                // calcular el angulo segun la cantidad de Vertices
                // en este nivel vCant
                // level_num cantidad de niveles
                //double angle = (2 * Math.PI * angles[(int)lvl-((int)lvl > 0?1:0)]++) / angles[(int)lvl-((int)lvl > 0?1:0)];
                //double angle = (2 * Math.PI * angles[(int)lvl-((int)lvl > 0?1:0)]++) / (vertices.size() / level_num);
// funca                double angle = (Math.PI * angles[(int)lvl-((int)lvl > 0?1:0)]++) / (double)(vertices.size() / level_num) ;
                // calcular el x,y segun la cantidad de niveles
//                coord.setX(Math.cos(angle) * (width / 2) + (radius * (lvl / level_num)));
//                coord.setY(Math.sin(angle) * (height / 2)  + (radius * (lvl / level_num)));
//coord.setX(Math.cos(angle) * radius + width / 2);
//coord.setY(Math.sin(angle) * radius + height / 2);
    
               

double angle = (2 * Math.PI * i++) / vCant;

               
                double cosX = Math.cos(angle);
                double sinY = Math.sin(angle);
                double xradius = (radius + (width * (lvl / level_num)));
                double yradius = (radius + (width * (lvl / level_num)));

     coord.setX(cosX * xradius + (width / 2));
     coord.setY(sinY * yradius + (height / 2));
    
     if (coord.getX() == 0d || coord.getY() == 0d)  {
         System.out.println("Oops... alguna coordenada es 0");
     }


     // test
                LinkedList parents = (LinkedList)v.getUserDatum("parents");
                Vertex parent = null;
                if (parents != null) {
                 parent = (Vertex)parents.getFirst();
                 if (parent != null) {
                     Coordinates pcoords = getCoordinates(parent);
                     if (pcoords.getX() == 0 || pcoords.getY() == 0) {
View Full Code Here

        return tempServiceExtInfo;
    }
   
   
    private void takeObjectsAction(LinkedList l) {
        Vertex v = null;
        LinkedList <ServiceExtInfo> svcextinfolist;
        for (Object n: l) {
            if (n instanceof HostExtInfo) {
                _graphManager.addHostExtInfo((HostExtInfo)n);
            } else if (n instanceof ServiceExtInfo) {
                // As ServiceExtInfo are stored in the vertex but the
                // hosts are not created yet, store the info in a temporary HashMap
                // that will be used later when hosts are already processed
                 svcextinfolist = getExtInfoMap().get(((ServiceExtInfo)n).getHostName());
                 if (svcextinfolist == null) {
                     svcextinfolist = new LinkedList<ServiceExtInfo>();
                     getExtInfoMap().put(((ServiceExtInfo)n).getHostName(),svcextinfolist);
                 }
                 svcextinfolist.add((ServiceExtInfo)n);
            } else if (n instanceof Host) {
                try {
                    if (_graphManager.getType() == GraphTypes.Directed)
                        v = _graphManager.addVertex(new DirectedSparseVertex(), ((Host)n).getName());
                    else if (_graphManager.getType() == GraphTypes.UnDirected) {
                        v = _graphManager.addVertex(new UndirectedSparseVertex(), ((Host)n).getName());
                    }
                    v.setUserDatum("host", (Host)n, UserData.CLONE);
                } catch (UniqueLabelException ule) {}
            } else if (n instanceof ErrorMapper) {
                ErrorMapper err = (ErrorMapper)n;
                if (_statusErrorsTypeDisplayed[err.getType()] == 0) {
                    MapperEvent me = new MapperEvent(this);
                    me.setMapperType(MapperActionType.DisplayError);
                    me.setParams(err);
                    fireMapperActionRequested(me);
                    _statusErrorsTypeDisplayed[err.getType()] = 1;
                }
            } else if (n instanceof ObjectHostGroup) {
                _graphManager.addHostGroup((ObjectHostGroup)n);
            }
        }
        String[] verts;
        int i = 0;
        v = null;
        for (Object n: l) {
            if (n instanceof Host) {
                verts = ((Host)n).getParentsString().split(",");
                LinkedList <Object>lparents = new LinkedList<Object>();
                v = _graphManager.getVertex(((Host)n).getName());
                // get temporary list of svcextinfo for this host.
                svcextinfolist = getExtInfoMap().get(((Host)n).getName());
                if (svcextinfolist != null) {
                    for (ServiceExtInfo sei : svcextinfolist) {
                        _graphManager.addServiceExtInfo(sei);
                    }
                    svcextinfolist.clear(); // clear the list of svcextinfo's
                    getExtInfoMap().remove(((Host)n).getName()); // remove the host referece in the list
                }
                for (i = 0; i < verts.length; i++) {
                    try {
                        _graphManager.addEdge(verts[i].trim(), ((Host)n).getName());
                    } catch (GraphException ge) {
                        MapperEvent me = new MapperEvent(this);
                        me.setMapperType(MapperActionType.DisplayError);
                        ErrorMapper em = new ErrorMapper(ge.getMessage());
                        me.setParams(em);
                        fireMapperActionRequested(me);
                    }
                    lparents.add(_graphManager.getVertex(verts[i].trim()));
                }
                if (v != null)
                    v.addUserDatum("parents", lparents, UserData.REMOVE);
            }
        }
        _graphManager.adjustVerticesPhysicalLevel();
    }
View Full Code Here

TOP

Related Classes of edu.uci.ics.jung.graph.Vertex

Copyright © 2018 www.massapicom. 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.