⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graphmanager.java

📁 jawe的最新版本,基于Java的图形化工作流编辑器。图形化工作流编辑器 。使用JAVA语言开发
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            Rectangle2D rpar = getBounds(par, propertyMap);//HM, JGraph3.4.1            Rectangle2D ract = getBounds(a, propertyMap);//HM, JGraph3.4.1            int yOff = ract.getBounds().y - rpar.getBounds().y;//HM,                                                               // JGraph3.4.1            int xOff = ract.getBounds().x - rpar.getBounds().x;//HM,                                                               // JGraph3.4.1            return new Point(xOff, yOff);         }      }      return new Point(0, 0);   }   public Point getOffset(Point actPoint) {      if (actPoint != null) {         GraphParticipantInterface par = findParentActivityParticipantForLocation(actPoint, null, null);//         System.err.println("Handling relative offset for point "+actPoint+", found par="+par);         if (par != null) {            Rectangle2D rpar = getBounds(par, new HashMap());//HM, JGraph3.4.1            int yOff = actPoint.y - rpar.getBounds().y;//HM, JGraph3.4.1            int xOff = actPoint.x - rpar.getBounds().x;//HM, JGraph3.4.1//            System.err.println("               ..........par  bounds "+rpar+", offset="+new Point(xOff,yOff));            return new Point(xOff, yOff);         }      }      return new Point(0, 0);   }   public Point getRealPosition(GraphActivityInterface a, GraphParticipantInterface gpar) {      if (a != null) {         if (gpar != null) {            CellView view = getView(gpar);            Rectangle2D rpar = view.getBounds();            Point aoffset=a.getOffset();            int y = aoffset.y + rpar.getBounds().y;            int x = aoffset.x + rpar.getBounds().x;//            System.out.println("NP1="+new Point(x,y));//            //            if (y>rpar.getHeight()) y=(int)rpar.getHeight()-defActivityHeight-5;//            if (x>rpar.getWidth()) x=(int)rpar.getWidth()-defActivityWidth-10;            Point p=new Point(x,y);//            System.out.println("NP2="+p);            return p;         }      }      return new Point(0, 0);   }   /**    * Inserts new activities into model, changes positions and sizes of    * participants due to a insertion of new activities or due to a moving of    * activities. Also, finds and changes parent's of inserted/changed-position    * activities. This method is called when inserting new activities, when    * pasting activities, and when moving activities. All changes to the model    * and to the view are at first made virtually (to the parentMap and to the    * propertyMap) and when all is done, method insertAndEdit of PEGraphModel    * class is called to actually make changes. The updateCollection parameter    * is used when some objects are inserted into model, to update collection of    * XML elements.    *     * @param arrangeParticipants    *           TODO    */   protected void updateModelAndArrangeParticipants(Object[] insert, Map propertyMap, ParentMap parentMap, Map viewMap,         String actionName, ConnectionSet cs, boolean arrangeParticipants) {      if (propertyMap == null && viewMap == null)         return;      if (propertyMap == null) {         propertyMap = new HashMap(viewMap);      }      if (parentMap == null) {         parentMap = new JaWEParentMap();      }      if (arrangeParticipants) {         arrangeParticipants(propertyMap, parentMap);      } else {         arrangeParticipantRelationsOnly(propertyMap, parentMap);      }      // extracting viewMap elements out of propertyMap (if any), applying      // change to viewMap element bounds (this must be done, because user      // could press mouse when inserting or pasting activities at the      // forbiden position so position of activity is changed during      // updateActivityParent method) and applying change to model and view      //        if (viewMap != null) { Iterator it = viewMap.keySet().iterator(); while//        (it.hasNext()) { Object cell=it.next(); //        // removing entry for cell that is contained within viewMap //        Map mapP=(Map)propertyMap.remove(cell); //        //  apply position changes to corresponding viewMap element //        Map  mapV=(Map)viewMap.get(cell); //        if (!(cell instanceof Port)) { //           Rectangle2D r=GraphConstants.getBounds(mapP); //           GraphConstants.setBounds(mapV,r); //           } //        } //        }             if (insert != null && ((JaWEParentMap) parentMap).entryCount() != insert.length) {         //return; //HM: enable Transition-copy/paste      }      // makes all changes (if there was any) - to model and to view      //graphModel().insertAndEdit(insert,null,propertyMap,parentMap,viewMap,actionName);      graphModel().insertAndEdit(insert, propertyMap, cs, parentMap, null, actionName);            Dimension prefSize = null;      if (!creatingGraph) {         try {            prefSize = getGraphsPreferredSize();         } catch (Exception ex) {         }      }      if (!creatingGraph && prefSize != null) {         try {            graph.setPreferredSize(prefSize);         } catch (Exception ex) {         }      }   }   /**    * Arranges participants according to the given property and parent maps.    */   protected void arrangeParticipants(Map propertyMap, ParentMap parentMap) {      Set parsToArrange = new HashSet();      // going through given propertyMap keys, and if key is      // activity->updating it's parent if needed.      // WARNING: must extract keys and put it in a array because      //          propertyMap changes -> ConcurrentModificationException      //          can happend      Object[] cellsToManage = propertyMap.keySet().toArray();      for (int i = 0; i < cellsToManage.length; i++) {         Object cell = cellsToManage[i];         if (cell instanceof GraphActivityInterface) {            Set oldAndNewParentPar = updateActivityParent((GraphActivityInterface) cell, propertyMap, parentMap);            parsToArrange.addAll(oldAndNewParentPar);         }      }      if (isGraphRotated()) {         arrangeParticipantsHorizontally(parsToArrange.toArray(), propertyMap, parentMap);         resizeAllParticipantsVertically(propertyMap, parentMap);      } else {         // arrange participants vertically         arrangeParticipantsVertically(parsToArrange.toArray(), propertyMap, parentMap);         resizeAllParticipantsHorizontally(propertyMap, parentMap);      }   }   protected void arrangeParticipantRelationsOnly(Map propertyMap, ParentMap parentMap) {      Set parsToArrange = new HashSet();      // going through given propertyMap keys, and if key is      // activity->updating it's parent if needed.      // WARNING: must extract keys and put it in a array because      //          propertyMap changes -> ConcurrentModificationException      //          can happend      Object[] cellsToManage = propertyMap.keySet().toArray();      for (int i = 0; i < cellsToManage.length; i++) {         Object cell = cellsToManage[i];         if (cell instanceof GraphActivityInterface) {            Set oldAndNewParentPar = updateActivityParent((GraphActivityInterface) cell, propertyMap, parentMap);            parsToArrange.addAll(oldAndNewParentPar);         }      }   }   /**    * Determines old and new participant for activity, adjusts activities    * position if needed and properly changes parent of activity (adds entry    * into the parentMap).    */   protected Set updateActivityParent(GraphActivityInterface ac, Map propertyMap, ParentMap parentMap) {      // must return old and new participant to the caller method      Set oldAndNewPar = new HashSet();      // old and new parent participant of given activity      GraphParticipantInterface oldPar = (GraphParticipantInterface) ac.getParent();      // adds oldPar to the set to be returned      if (oldPar != null) {         oldAndNewPar.add(oldPar);      }      GraphParticipantInterface newPar = null;      // taking position elements of Activity      // taking bounding rectangle      Rectangle2D acRect = getBounds(ac, propertyMap);//HM, JGraph3.4.1      // taking upper-left corner, this will be reference for moving activitys      Point acUpperLeft = acRect.getBounds().getLocation();//HM, JGraph3.4.1      Point newAcUpperLeft = new Point(acUpperLeft);      newPar = findParentActivityParticipantForLocation(newAcUpperLeft, propertyMap, parentMap);//      System.out.println("Old par for activity "+ac+" is "+oldPar+", and new par is "+newPar);      // if previous method changed location of upper-left point,      // move activity to new location      if (!newAcUpperLeft.equals(acUpperLeft)) {         Rectangle r = new Rectangle(acRect.getBounds());//HM, JGraph3.4.1         r.setLocation(newAcUpperLeft);         changeBounds(ac, propertyMap, r);      }      if (newPar != null) {         // adds newPar to the set to be returned         oldAndNewPar.add(newPar);         // VERY IMPORTANT IS TO CHANGE THE PARENT         // changing the parent participant of Activity cell if it has changed         // position         if (!newPar.equals(oldPar)) {            parentMap.addEntry(ac, newPar);         }      }      return oldAndNewPar;   }   public GraphParticipantInterface findParentForLocation(Point loc) {      GraphParticipantInterface newPar = null;      // if user put activity cell somewhere outside visible area, move it back      if (loc.y <= 0) {         loc.y = 1;      }      if (loc.x <= 0) {         loc.x = 1;      }      // determining the container for new position      if (isGraphRotated()) {         newPar = getLeafParticipantForXPos(loc.x, null, null);      } else {         newPar = getLeafParticipantForYPos(loc.y, null, null);      }            return newPar;   }      /**    * Finds new participant for activity after it's position changes. WARNING:    * this method changes it's argument loc if not appropriate.    */   public GraphParticipantInterface findParentActivityParticipantForLocation(Point loc, Map propertyMap,         ParentMap parentMap) {      GraphParticipantInterface newPar = null;      // if user put activity cell somewhere outside visible area, move it back      if (loc.y <= 0) {         loc.y = 1;      }      if (loc.x <= 0) {         loc.x = 1;      }      // determining the container for new position      if (isGraphRotated()) {         newPar = getLeafParticipantForXPos(loc.x, propertyMap, parentMap);         // if new container isn't found -> activity is placed under all         // participants         // so it's new participant will be the leaf participant with the         // highest y-coord         if (newPar == null) {            newPar = getLeafParticipantForXPos(getNewRootParXPos(propertyMap, null) - 10, propertyMap, parentMap);         }         if (newPar != null) {            // Adjust activities x-pos if needed            Rectangle2D newParRect = getBounds(newPar, propertyMap);//HM,            // JGraph3.4.1            // if x-position is not OK, set appropriate position            if (newParRect.getY() + defParNameWidth >= loc.y) {               loc.y = (int) (newParRect.getY() + defParNameWidth + 1);            }         }         // it is activity that belongs to an block activity         else {            // if x-position is not OK, set appropriate position            if (verticalOffset >= loc.y) {               loc.y = horizontalOffset;            }         }      } else {         newPar = getLeafParticipantForYPos(loc.y, propertyMap, parentMap);         // if new container isn't found -> activity is placed under all         // participants         // so it's new participant will be the leaf participant with the         // highest y-coord         if (newPar == null) {            newPar = getLeafParticipantForYPos(getNewRootParYPos(propertyMap, null) - 10, propertyMap, parentMap);         }         if (newPar != null) {            // Adjust activities x-pos if needed            Rectangle2D newParRect = getBounds(newPar, propertyMap);//HM,            // JGraph3.4.1            // if x-position is not OK, set appropriate position            if (newParRect.getX() + defParNameWidth >= loc.x) {               loc.x = (int) newParRect.getX() + defParNameWidth + 1;            }         }         // it is activity that belongs to an block activity         else {            // if x-position is not OK, set appropriate position            if (horizontalOffset >= loc.x) {               loc.x = horizontalOffset;            }         }      }      return newPar;   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -