Package com.mxgraph.view

Examples of com.mxgraph.view.mxGraph


  MuscleMonitor(MonitorController monitorc) {
    this.setTitle("Muscle Scheduling Monitor");
    this.monitorc = monitorc;

    map = new Hashtable<Long, Long>();
    graph = new mxGraph();
    parent = graph.getDefaultParent();

    JScrollPane scroller = new JScrollPane(new mxGraphComponent(graph))
    getContentPane().add(scroller);
    setSize(400, 300);
View Full Code Here


        };
    
       private mxGraphComponent getRolegraph(){
        
          LoggerManager.info(Constants.EDITOR_LOGGER, Messages.getString("PetriNet.Resources.DrawRoleGraph"));
           mxGraph graph;
           mxGraphComponent graphComponent;
          
            graph = new mxGraph();
            Object parentVertex = graph.getDefaultParent();
            graph.getModel().beginUpdate();
            //Colors
            String[] colors = {"00DB26" ,
                               "8DF200" ,
                               "F2B705" ,
                               "F29A2E" ,
                               "F37542" ,
                               "F25456" ,
                               "A73ADB" ,
                               "5549F2" ,
                               "40ADDB" ,
                               "04F9BE" ,
                               "938466" ,
                               "C6B38F" ,
                               "F99249" ,
                               "E26537" ,
                               "FC553D" ,
                               "E52C3B"};
            int alreadyPaintedFlag = 0;
           
            try {
              LogicalModel lm = new LogicalModel(objectsAssignedListModel,objectsUnassignedListModel,RolesTreeModel,RolesTopNode,GroupsTreeModel,GroupsTopNode,superRolesTreeModel,superGroupsTreeModel,superRolesTopNode, superGroupsTopNode);
            LayoutAlgorithm layoutAlgorithm = new LayoutAlgorithm();
            layoutAlgorithm.createLayout(lm);
            Set<Layout> RoleLayoutSet = layoutAlgorithm.RoleLayoutSet;
             
            //Assign color associations to the single Roles
            String[] RoleColorAssociation = new String[lm.allRoles.size()];
            int index = 0;
            Iterator<?> colorIt = lm.allRoles.iterator();
            while (colorIt.hasNext()) {
              Role currentRole = (Role) colorIt.next();
              RoleColorAssociation[index] = currentRole.name;
              index+=1;
            }
           
              Iterator<Layout> it = RoleLayoutSet.iterator();
             
              while (it.hasNext()) {
                Layout currentLayout = it.next();
               
                //Compound
                int dimensionX = 140;
                int dimensionY = 30;
               
                // Width== Number of Roles * dimensionX
                int compound_dimensionX = currentLayout.grid.length*dimensionX+20;
                int compoundDimensionY = 0;
               
                // maxRow= Longest Colum(with maximum of Rows)
                        int maxRow = 0;  
                       
                        // for each Role-Column -> do search the longest column, and remeber the Y
                        for (int i=0;i<currentLayout.grid.length;i++) {
                            if (currentLayout.grid[i] != null) {
                                for (int y=currentLayout.grid[i].length-1;y>=0;y--) {
                                    if (currentLayout.grid[i][y] != null) {
                                        if (y>maxRow) {
                                            maxRow = y;
                                        }
                                        break;
                                    }
                                }
                            }
                        }

                        // Search for the deepest Place
                Integer maxDepth[] = new Integer[currentLayout.grid.length];
                        Integer firstKill[] = new Integer[currentLayout.grid.length];
                Iterator<RoleLocator> deepBlue = currentLayout.Roles.iterator();
               
                while (deepBlue.hasNext()) {
                  RoleLocator currentRole = deepBlue.next();
                 
                  if(maxDepth[currentRole.column]==null){
                    maxDepth[currentRole.column]=1;
                  }else {
                    maxDepth[currentRole.column]++;
                  }
                }
               
                int deepestSubset = 0;
                for(int i=0;i<maxDepth.length;i++){
                 
                  if(maxDepth[i]>deepestSubset){
                    deepestSubset=maxDepth[i];
                  }
                }

                if(deepestSubset==1){
                 
                  // so finally -> compound_dim_Y = LongestColumn * dimensionY
                          compoundDimensionY = (maxRow+1)*dimensionY+60;
                 
                          // now draw compound                                                       x  y                 x-length              y-length
                  graph.insertVertex(parentVertex, null, currentLayout.name, 5, 5+alreadyPaintedFlag, compound_dimensionX + 40, compoundDimensionY, "rounded=1;strokeColor=black;fillColor=#CCCCCC;verticalAlign=top;fontStyle=1;fontColor=black" );
                 
                  // So now we build an Iterator to travel trough all Roles of the compound Role
                  //Roles
                  Iterator<RoleLocator>  subIt = currentLayout.Roles.iterator();
                  while (subIt.hasNext()) {
                    RoleLocator currentRole = subIt.next();
                   
                    //Find the related color
                    int colorRelation = 0;
                    for (int i=0; i<RoleColorAssociation.length;i++) {
                      if (RoleColorAssociation[i] == currentRole.name) {
                        colorRelation = i;
                        if (colorRelation>=colors.length) {
                          colorRelation = colorRelation - colors.length;
                        }
                        break;
                      }
                    }
                    graph.insertVertex(parentVertex, null, currentRole.name, 15+dimensionX*currentRole.column, 20+dimensionY*currentRole.ystart+alreadyPaintedFlag, dimensionX, dimensionY*(currentRole.yend-currentRole.ystart+1)+30, "rounded=1;strokeColor=black;fillColor="+colors[colorRelation]+";verticalAlign=top;fontStyle=1;fontColor=black"); //kursiv ;fontStyle=1;fontColor=black
                  }
                 
                  //Components
                  String containsString = new String();
                 
                  // for each column
                  for (int x1=0; x1<currentLayout.grid.length;x1++) {
                    // for each row/ Component
                    for (int y1=0;y1<currentLayout.grid[x1].length;y1++) {
                      int xMultiplicator = 0;
                      // is the object availible ?
                        if (currentLayout.grid[x1][y1] != null) {
                        if(containsString.contains(currentLayout.grid[x1][y1].name)){}
                          //do nothing -> cause it is already included
                        else if(!containsString.contains(currentLayout.grid[x1][y1].name)){
                          // Add current user
                          containsString = containsString +" "+ currentLayout.grid[x1][y1].name;
                          //for each column
                          for(int x2 = x1 + 1; x2 < currentLayout.grid.length; x2++){
                            // for each row
                            for(int y2 = 0; y2 < currentLayout.grid[x2].length; y2++){
                              // is the object availible ?
                              if(currentLayout.grid[x2][y2] != null){
                                if(currentLayout.grid[x1][y1].name == currentLayout.grid[x2][y2].name){
                                  if((x2 - x1) > xMultiplicator)
                                    // if the multiplicator has to be augmented by more than one column, it will not be done, cause in this case there ist a gap
                                    if((x2-x1)==(xMultiplicator+1)){
                                      xMultiplicator = x2 - x1;
                                    }else {
                                      containsString = containsString.replaceFirst(currentLayout.grid[x1][y1].name,"");
                                      xMultiplicator = 0;
                                    }
                                }
                              }
                            } 
                          }
                          if(xMultiplicator==0){
                            graph.insertVertex(parentVertex, null, currentLayout.grid[x1][y1].name, 20+x1*dimensionX, 45+y1*dimensionY+alreadyPaintedFlag, xMultiplicator * 5 + xMultiplicator * (dimensionX-10+ (dimensionX-10), dimensionY-4, "rounded=1;strokeColor=black;fillColor=white;opacity=65;fontStyle=1;fontColor=black");
                          }
                          if(xMultiplicator>0){
                            graph.insertVertex(parentVertex, null, currentLayout.grid[x1][y1].name, 20+x1*dimensionX, 45+y1*dimensionY+alreadyPaintedFlag, xMultiplicator * 5 + xMultiplicator * (dimensionX-10+ (dimensionX-5), dimensionY-4, "rounded=1;strokeColor=black;fillColor=white;opacity=65;fontStyle=1;fontColor=black");
                          }
                        }
                      }
                      }
                  }
                }else{
                          compoundDimensionY = (maxRow+1)*dimensionY+70;
                  graph.insertVertex(parentVertex, null, currentLayout.name, 5, 5+alreadyPaintedFlag, compound_dimensionX, compoundDimensionY, "rounded=1;strokeColor=black;fillColor=#CCCCCC;verticalAlign=top;fontStyle=1;fontColor=black" );
               
                  //Roles
                  Iterator<RoleLocator>  subIt = currentLayout.Roles.iterator();
                  while (subIt.hasNext()) {
                    RoleLocator currentRole = subIt.next();
                 
                    if(firstKill[currentRole.column]==null){
                      firstKill[currentRole.column]=0;
                    }else{
                      firstKill[currentRole.column]=1;
                    }
                   
                    //Find the related color
                    int colorRelation = 0;
                    for (int i=0; i<RoleColorAssociation.length;i++) {
                      if (RoleColorAssociation[i] == currentRole.name) {
                        colorRelation = i;
                        if (colorRelation>=colors.length) {
                          colorRelation = colorRelation - colors.length;
                        }
                        break;
                      }
                    }
                    graph.insertVertex(parentVertex, null, currentRole.name, 15+dimensionX*currentRole.column, 20+(dimensionY*currentRole.ystart*2)+alreadyPaintedFlag+(firstKill[currentRole.column]*20), dimensionX, dimensionY*(currentRole.yend-currentRole.ystart+1)-(firstKill[currentRole.column]*dimensionY)+44, "rounded=1;strokeColor=black;fillColor="+colors[colorRelation]+";verticalAlign=top;fontStyle=1;fontColor=black");
                  }
                 
                  //Components
                  String containsString = new String();
                  for (int x1=0; x1<currentLayout.grid.length;x1++) {
                    for (int y1=0;y1<currentLayout.grid[x1].length;y1++) {
                      int xMultiplicator = 0;
                        if (currentLayout.grid[x1][y1] != null) {
                        if(containsString.contains(currentLayout.grid[x1][y1].name)){}
                        else if(!containsString.contains(currentLayout.grid[x1][y1].name)){
                          containsString = containsString +" "+ currentLayout.grid[x1][y1].name;
                          for(int x2 = x1 + 1; x2 < currentLayout.grid.length; x2++){
                            for(int y2 = 0; y2 < currentLayout.grid[x2].length; y2++){
                              if(currentLayout.grid[x2][y2] != null){
                                if(currentLayout.grid[x1][y1].name == currentLayout.grid[x2][y2].name){
                                  if((x2 - x1) > xMultiplicator)
                                    if((x2-x1)==(xMultiplicator+1)){
                                      xMultiplicator = x2 - x1;
                                    }else {
                                      containsString = containsString.replaceFirst(currentLayout.grid[x1][y1].name,"");
                                      xMultiplicator = 0;
 
                                    }
                                }
                              }
                            } 
                          }
                          //                                                                                           x                 y                                x-length                                                                y-length
                          if(xMultiplicator==0){
                            graph.insertVertex(parentVertex, null, currentLayout.grid[x1][y1].name, 20+x1*dimensionX, 55+y1*dimensionY+alreadyPaintedFlag, xMultiplicator * 5 + xMultiplicator * (dimensionX-10+ (dimensionX-10), dimensionY-4, "rounded=1;strokeColor=black;fillColor=white;opacity=65;fontStyle=1;fontColor=black");
                          }
                          if(xMultiplicator>0){
                            graph.insertVertex(parentVertex, null, currentLayout.grid[x1][y1].name, 20+x1*dimensionX, 55+y1*dimensionY+alreadyPaintedFlag, xMultiplicator * 5 + xMultiplicator * (dimensionX-10+ (dimensionX-5), dimensionY-4, "rounded=1;strokeColor=black;fillColor=white;opacity=65;fontStyle=1;fontColor=black");
                          }
                        }
                      }
                      }
                  }
                }
                alreadyPaintedFlag = alreadyPaintedFlag + compoundDimensionY + 10;
              }
            } finally {
              graph.getModel().endUpdate();
            }
           
            if(alreadyPaintedFlag==0){
              graph.insertVertex(parentVertex, null,Messages.getString("PetriNet.Resources.NoRolesDefined"),10,10,150,30, "rounded=1;opacity=0;fontStyle=1;fontColor=black");           
            }
           
            // Create Listener, first parameter in constructor is the observed graph
            mxIEventListener mySelectListener = new selectListener(graph);
            // add Listener as CHANGE-Listener
            graph.getSelectionModel().addListener(mxEvent.CHANGE, mySelectListener);
            graphComponent = new mxGraphComponent(graph);

            temp_Role_graph = graph;
            temp_Role_graphComponent= graphComponent;

View Full Code Here

       return GroupPane;
     }
    
     private mxGraphComponent getGroupgraph(){
           LoggerManager.info(Constants.EDITOR_LOGGER, Messages.getString("PetriNet.Resources.DrawGroupGraph"));
           mxGraph graph;
           mxGraphComponent graphComponent;
           graph = new mxGraph();
            Object parentVertex = graph.getDefaultParent();
            graph.getModel().beginUpdate();
           
            //Colors
            String[] colors = {"00DB26" ,
                               "8DF200" ,
                               "F2B705" ,
                               "F29A2E" ,
                               "F37542" ,
                               "F25456" ,
                               "A73ADB" ,
                               "5549F2" ,
                               "40ADDB" ,
                               "04F9BE" ,
                               "938466" ,
                               "C6B38F" ,
                               "F99249" ,
                               "E26537" ,
                               "FC553D" ,
                               "E52C3B"};
            int alreadyPaintedFlag = 0;
            try {
              LogicalModel lm = new LogicalModel(objectsAssignedListModel,objectsUnassignedListModel,RolesTreeModel,RolesTopNode,GroupsTreeModel,GroupsTopNode,superRolesTreeModel,superGroupsTreeModel,superRolesTopNode, superGroupsTopNode);
            LayoutAlgorithm layoutAlgorithm = new LayoutAlgorithm();

            layoutAlgorithm.createLayout(lm);
            Set<Layout> GroupLayoutSet = layoutAlgorithm.GroupLayoutSet;
             
            //Assign color associations to the single Roles
            String[] RoleColorAssociation = new String[lm.allRoles.size()];
            int index = 0;
            Iterator<?> colorIt = lm.allGroups.iterator();
            while (colorIt.hasNext()) {
              Group currentGroup = (Group) colorIt.next();
              RoleColorAssociation[index] = currentGroup.name;
              index+=1;
            }
           
              Iterator<Layout> it = GroupLayoutSet.iterator();
             
              while (it.hasNext()) {
                Layout currentLayout = it.next();
               
                //Compound
                int dimensionX = 140;
                int dimensionY = 30;
                int compound_dimensionX = currentLayout.grid.length * dimensionX + 20;
                int compoundDimensionY = 0;
                int maxRow = 0;  
                  
                     for (int i=0;i<currentLayout.grid.length;i++) {
                         if (currentLayout.grid[i] != null) {
                             for (int y=currentLayout.grid[i].length-1; y>=0; y--) {
                                 if (currentLayout.grid[i][y] != null) {
                                     if (y>maxRow) {
                                         maxRow = y;
                                     }
                                     break;
                                 }
                             }
                         }
                      }
                       

                // Search for the deepest Place
               
                     Integer maxDepth[] = new Integer[currentLayout.grid.length];
                     Integer firstKill[] = new Integer[currentLayout.grid.length];
                 Iterator<GroupLocator> deepBlue = currentLayout.Groups.iterator();
               
                while (deepBlue.hasNext()) {
                  GroupLocator currentGroup = deepBlue.next();
                 
                  if(maxDepth[currentGroup.column]==null){
                    maxDepth[currentGroup.column]=1;
                  }else {
                    maxDepth[currentGroup.column]++;
                  }
                }
               
                int deepestSubset = 0;
                for(int i=0;i<maxDepth.length;i++){
                  if(maxDepth[i]>deepestSubset){
                    deepestSubset=maxDepth[i];
                  }
                }
               
                if(deepestSubset==1){
                  //dimensionY = 30;
                  compoundDimensionY = (maxRow+1) * dimensionY + 60;
                  graph.insertVertex(parentVertex, null, currentLayout.name, 5, 5+alreadyPaintedFlag, compound_dimensionX, compoundDimensionY, "rounded=1;strokeColor=black;fillColor=#CCCCCC;verticalAlign=top;fontStyle=1;fontColor=black" );

                  // So now we build an Iterator to travel trough all Roles of the compound Role
                  //Roles
                  Iterator<GroupLocator>  subIt = currentLayout.Groups.iterator();
                  while (subIt.hasNext()) {
                    GroupLocator currentGroup = subIt.next();
                   
                    //Find the related color
                    int colorRelation = 0;
                    for (int i=0; i<RoleColorAssociation.length;i++) {
                      if (RoleColorAssociation[i] == currentGroup.name) {
                        colorRelation = i;
                        if (colorRelation>=colors.length) {
                          colorRelation = colorRelation - colors.length;
                        }
                        break;
                      }
                    }
                    graph.insertVertex(parentVertex, null, currentGroup.name, 15+dimensionX*currentGroup.column, 20+dimensionY*currentGroup.ystart+alreadyPaintedFlag, dimensionX, dimensionY*(currentGroup.yend-currentGroup.ystart+1)+30, "rounded=1;strokeColor=black;fillColor="+colors[colorRelation]+";verticalAlign=top;fontStyle=1;fontColor=black");
                  }
                 
                  //Components
                  String containsString = new String();
                 
                  for (int x1=0; x1<currentLayout.grid.length;x1++) {
                    for (int y1=0;y1<currentLayout.grid[x1].length;y1++) {
                      int xMultiplicator = 0;
                        if (currentLayout.grid[x1][y1] != null) {
                        if(containsString.contains(currentLayout.grid[x1][y1].name)){
                        } else if(!containsString.contains(currentLayout.grid[x1][y1].name)){
                          containsString = containsString +" "+ currentLayout.grid[x1][y1].name;
                          for(int x2 = x1 + 1; x2 < currentLayout.grid.length; x2++){
                            for(int y2 = 0; y2 < currentLayout.grid[x2].length; y2++){
                              if(currentLayout.grid[x2][y2] != null){
                                if(currentLayout.grid[x1][y1].name == currentLayout.grid[x2][y2].name){
                                  if((x2 - x1) > xMultiplicator)
                                    if((x2-x1)==(xMultiplicator+1)){
                                      xMultiplicator = x2 - x1;
                                    }else {
                                      containsString = containsString.replaceFirst(currentLayout.grid[x1][y1].name,"");
                                      xMultiplicator = 0;
                                    }
                                }
                              }
                            } 
                          }
                          if(xMultiplicator==0){
                            graph.insertVertex(parentVertex, null, currentLayout.grid[x1][y1].name, 20+x1*dimensionX, 45+y1*dimensionY+alreadyPaintedFlag, xMultiplicator * 5 + xMultiplicator * (dimensionX-10+ (dimensionX-10), dimensionY-4, "rounded=1;strokeColor=black;fillColor=white;opacity=65;fontStyle=1;fontColor=black");
                          }
                          if(xMultiplicator>0){
                            graph.insertVertex(parentVertex, null, currentLayout.grid[x1][y1].name, 20+x1*dimensionX, 45+y1*dimensionY+alreadyPaintedFlag, xMultiplicator * 5 + xMultiplicator * (dimensionX-10+ (dimensionX-5), dimensionY-4, "rounded=1;strokeColor=black;fillColor=white;opacity=65;fontStyle=1;fontColor=black");
                          }
                        }
                      }
                      }
                  }
                }else{
                         compoundDimensionY = (maxRow+1)*dimensionY+70;
                  graph.insertVertex(parentVertex, null, currentLayout.name, 5, 5+alreadyPaintedFlag, compound_dimensionX, compoundDimensionY, "rounded=1;strokeColor=black;fillColor=#CCCCCC;verticalAlign=top;fontStyle=1;fontColor=black" );
               
                  //Roles
                  Iterator<GroupLocator>  subIt = currentLayout.Groups.iterator();
                  while (subIt.hasNext()) {
                    GroupLocator currentGroup = subIt.next();
                 
                    if(firstKill[currentGroup.column]==null){
                      firstKill[currentGroup.column]=0;
                    }else{
                      firstKill[currentGroup.column]=1;
                    }
                   
                    //Find the related color
                    int colorRelation = 0;
                    for (int i=0; i<RoleColorAssociation.length;i++) {
                      if (RoleColorAssociation[i] == currentGroup.name) {
                        colorRelation = i;
                        if (colorRelation>=colors.length) {
                          colorRelation = colorRelation - colors.length;
                        }
                        break;
                      }
                    }
                    graph.insertVertex(parentVertex, null, currentGroup.name, 15+dimensionX*currentGroup.column, 20+(dimensionY*currentGroup.ystart*2)+alreadyPaintedFlag+(firstKill[currentGroup.column]*20), dimensionX, dimensionY*(currentGroup.yend-currentGroup.ystart+1)-(firstKill[currentGroup.column]*dimensionY)+44, "rounded=1;strokeColor=black;fillColor="+colors[colorRelation]+";verticalAlign=top;fontStyle=1;fontColor=black");
                  }
                 
                  //Components
                  String containsString = new String();
                  for (int x1=0; x1<currentLayout.grid.length;x1++) {
                    for (int y1=0;y1<currentLayout.grid[x1].length;y1++) {
                      int xMultiplicator = 0;
                        if (currentLayout.grid[x1][y1] != null) {
                        if(containsString.contains(currentLayout.grid[x1][y1].name)){
                        } else if(!containsString.contains(currentLayout.grid[x1][y1].name)){
                          containsString = containsString +" "+ currentLayout.grid[x1][y1].name;
                          for(int x2 = x1 + 1; x2 < currentLayout.grid.length; x2++){
                            for(int y2 = 0; y2 < currentLayout.grid[x2].length; y2++){
                              if(currentLayout.grid[x2][y2] != null){
                                if(currentLayout.grid[x1][y1].name == currentLayout.grid[x2][y2].name){
                                  if((x2 - x1) > xMultiplicator)
                                    if((x2-x1)==(xMultiplicator+1)){
                                      xMultiplicator = x2 - x1;
                                    }else {
                                      containsString = containsString.replaceFirst(currentLayout.grid[x1][y1].name,"");
                                      xMultiplicator = 0;
                                    }
                                }
                              }
                            } 
                          }
                          if(xMultiplicator==0){
                            graph.insertVertex(parentVertex, null, currentLayout.grid[x1][y1].name, 20+x1*dimensionX, 55+y1*dimensionY+alreadyPaintedFlag, xMultiplicator * 5 + xMultiplicator * (dimensionX-10+ (dimensionX-10), dimensionY-4, "rounded=1;strokeColor=black;fillColor=white;opacity=65;fontStyle=1;fontColor=black");
                          }
                          if(xMultiplicator>0){
                            graph.insertVertex(parentVertex, null, currentLayout.grid[x1][y1].name, 20+x1*dimensionX, 55+y1*dimensionY+alreadyPaintedFlag, xMultiplicator * 5 + xMultiplicator * (dimensionX-10+ (dimensionX-5), dimensionY-4, "rounded=1;strokeColor=black;fillColor=white;opacity=65;fontStyle=1;fontColor=black");
                          }
                        }
                      }
                      }
                  }
                }
                alreadyPaintedFlag = alreadyPaintedFlag + compoundDimensionY + 10;
              }
            } finally {
                graph.getModel().endUpdate();
            }
           
            if(alreadyPaintedFlag==0){
              graph.insertVertex(parentVertex, null,Messages.getString("PetriNet.Resources.NoGroupsDefined"),10,10,150,30, "rounded=1;opacity=0;fontStyle=1;fontColor=black");
            }
           
            // Create Listener, first parameter in constructor is the observed graph
            mxIEventListener mySelectListener = new selectListener(graph);
            // add Listener as CHANGE-Listener
            graph.getSelectionModel().addListener(mxEvent.CHANGE, mySelectListener);
            graphComponent = new mxGraphComponent(graph);
 
            tempGroupGraph = graph;
            tempGroupGraphComponent= graphComponent;

View Full Code Here

    static final long serialVersionUID = 1L;

    public Visualisation() {
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        mxGraph graph = new mxGraph();
        Object parent = graph.getDefaultParent();
        Map<String, Object> defaultVertexStyle = graph.getStylesheet()
                .getDefaultVertexStyle();
        defaultVertexStyle.put(com.mxgraph.util.mxConstants.STYLE_SHAPE,
                com.mxgraph.util.mxConstants.SHAPE_ELLIPSE);
        graph.getStylesheet().setDefaultVertexStyle(defaultVertexStyle);

        graph.getModel().beginUpdate();
        try {
            Object v1 = graph.insertVertex(parent, null, null, 30, 30, 30, 30);
            Object v2 = graph.insertVertex(parent, null, null, 30, 130, 30, 30);
            Object v3 = graph.insertVertex(parent, null, null, 110, 30, 30, 30);
            graph.insertEdge(parent, null, null, v1, v2);
            graph.insertEdge(parent, null, null, v1, v1);
        } finally {
            graph.getModel().endUpdate();
        }

        mxGraphComponent graphComponent = new mxGraphComponent(graph);
        this.getContentPane().add(graphComponent);
        this.setSize(800, 600);
View Full Code Here

        this.setVisible(true);
    }

    public Visualisation(Network net) {
        this.network = net;
        mxGraph graph = new mxGraph();
        Map<String, Object> defaultVertexStyle = graph.getStylesheet()
                .getDefaultVertexStyle();
        defaultVertexStyle.put(com.mxgraph.util.mxConstants.STYLE_SHAPE,
                com.mxgraph.util.mxConstants.SHAPE_ELLIPSE);
        graph.getStylesheet().setDefaultVertexStyle(defaultVertexStyle);

        Collection<Neuron> neurons = this.network.getNeurons();
        Iterator<Neuron> it = neurons.iterator();
        HashSet<NeuronConnection> connections = this.network
                .getNeuronConnectionCollection();
        HashMap<Integer, HashMap<Integer, Neuron>> layers = new HashMap<Integer, HashMap<Integer, Neuron>>();
        while (it.hasNext()) {
            Neuron neuron = it.next();
            Integer layer = neuron.getOutputDistance();
            if (!layers.containsKey(layer)) {
                layers.put(layer, new HashMap<Integer, Neuron>());
            }
            layers.get(layer).put(neuron.getId(), neuron);
        }
        Iterator it2 = layers.values().iterator();
        Integer maxlayersize = 0;
        while (it2.hasNext()) {
            HashMap<Integer, Neuron> layer = (HashMap<Integer, Neuron>) it2
                    .next();
            if (layer.size() > maxlayersize)
                maxlayersize = layer.size();
        }
        Integer width = maxlayersize * (NODESIZE + HORIZSPACING);
        Integer height = layers.size() * (NODESIZE + HORIZSPACING);
        Iterator it3 = layers.values().iterator();
        HashMap<Integer, Object> vertices = new HashMap<Integer, Object>();

        Object parent = graph.getDefaultParent();
        graph.getModel().beginUpdate();
        try {
            for (int i = 0; i < layers.size(); i++) {
                HashMap<Integer, Neuron> layer = layers.get(i);
                Iterator<Neuron> it4 = layer.values().iterator();
                Integer k = 0;
                while (it4.hasNext()) {
                    Neuron current = it4.next();
                    // current.doClownSong("datdatdadadadatdatdada");
                    Object vertex = graph.insertVertex(parent, null, current
                            .getId(), ((++k) * (HORIZSPACING + NODESIZE)),
                            ((i + 1) * (VERTICSPACING + NODESIZE)), NODESIZE,
                            NODESIZE);
                    vertices.put(current.getId(), vertex);
                }
            }
            Iterator<NeuronConnection> it9 = connections.iterator();
            while (it9.hasNext()) {
                NeuronConnection current = it9.next();
                graph.insertEdge(parent, null, this.weightToString(current
                        .getWeight()), vertices
                        .get(current.getSource().getId()), vertices.get(current
                        .getTarget().getId()));
            }
        } finally {
            graph.getModel().endUpdate();
        }

        mxGraphComponent graphComponent = new mxGraphComponent(graph);
        this.getContentPane().add(graphComponent);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
View Full Code Here

  @SuppressWarnings("serial")
  public SchemaEditorMenuBar(final BasicGraphEditor editor)
  {
    final mxGraphComponent graphComponent = editor.getGraphComponent();
    final mxGraph graph = graphComponent.getGraph();
    JMenu menu = null;
    JMenu submenu = null;

    // Creates the file menu
    menu = add(new JMenu(mxResources.get("file")));
View Full Code Here

   * @param g
   *            The graphics to paint the ruler to.
   */
  public void paintComponent(Graphics g)
  {
    mxGraph graph = graphComponent.getGraph();
    Rectangle clip = g.getClipBounds();
    updateIncrementAndUnits();

    // Fills clipping area with background.
    if (activelength > 0 && inactiveBackground != null)
    {
      g.setColor(inactiveBackground);
    }
    else
    {
      g.setColor(getBackground());
    }

    g.fillRect(clip.x, clip.y, clip.width, clip.height);

    // Draws the active region.
    g.setColor(getBackground());
    Point2D p = new Point2D.Double(activeoffset, activelength);

    if (orientation == ORIENTATION_HORIZONTAL)
    {
      g.fillRect((int) p.getX(), clip.y, (int) p.getY(), clip.height);
    }
    else
    {
      g.fillRect(clip.x, (int) p.getX(), clip.width, (int) p.getY());
    }

    double left = clip.getX();
    double top = clip.getY();
    double right = left + clip.getWidth();
    double bottom = top + clip.getHeight();

    // Fetches some global display state information
    mxPoint trans = graph.getView().getTranslate();
    double scale = graph.getView().getScale();
    double tx = trans.getX() * scale;
    double ty = trans.getY() * scale;

    // Sets the distance of the grid lines in pixels
    double stepping = increment;
View Full Code Here

      {
        String font = fontCombo.getSelectedItem().toString();

        if (font != null && !font.equals("-"))
        {
          mxGraph graph = editor.getGraphComponent().getGraph();
          graph.setCellStyles(mxConstants.STYLE_FONTFAMILY, font);
        }
      }
    });

    final JComboBox sizeCombo = new JComboBox(new Object[] { "6pt", "8pt",
        "9pt", "10pt", "12pt", "14pt", "18pt", "24pt", "30pt", "36pt",
        "48pt", "60pt" });
    sizeCombo.setEditable(true);
    sizeCombo.setMinimumSize(new Dimension(65, 0));
    sizeCombo.setPreferredSize(new Dimension(65, 0));
    sizeCombo.setMaximumSize(new Dimension(65, 100));
    add(sizeCombo);

    sizeCombo.addActionListener(new ActionListener()
    {
      /**
       *
       */
      public void actionPerformed(ActionEvent e)
      {
        mxGraph graph = editor.getGraphComponent().getGraph();
        graph.setCellStyles(mxConstants.STYLE_FONTSIZE, sizeCombo
            .getSelectedItem().toString().replace("pt", ""));
      }
    });

    addSeparator();
View Full Code Here

  {
    boolean source = isSource(index);

    if (source || isTarget(index))
    {
      mxGraph graph = graphComponent.getGraph();
      Object terminal = graph.getModel().getTerminal(state.getCell(),
          source);

      if (terminal == null
          && !graphComponent.getGraph().isTerminalPointMovable(
              state.getCell(), source))
View Full Code Here

   * @param gridEnabled
   * @return Returns the scaled, translated and grid-aligned point.
   */
  protected mxPoint convertPoint(mxPoint point, boolean gridEnabled)
  {
    mxGraph graph = graphComponent.getGraph();
    double scale = graph.getView().getScale();
    mxPoint trans = graph.getView().getTranslate();
    double x = point.getX() / scale - trans.getX();
    double y = point.getY() / scale - trans.getY();

    if (gridEnabled)
    {
      x = graph.snap(x);
      y = graph.snap(y);
    }

    point.setX(x - state.getOrigin().getX());
    point.setY(y - state.getOrigin().getY());

View Full Code Here

TOP

Related Classes of com.mxgraph.view.mxGraph

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.