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

📄 jgpdmarqueehandler.java

📁 用JGraph编的软件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:

      // Create Ports
      int u = GraphConstants.PERMILLE;
      Object port;

      // Floating Center Port
      port =
          gmp.createCell(
          model,
          GraphModelProvider.CELL_PORT_DEFAULT,
          "Center",
          null);
      gmp.addPort(cell, port);
      //port = new DefaultPort("Center");
      //cell.add(port);
      toInsert.add(port);

      // Top Left
      //port = new DefaultPort("Topleft");
      //cell.add(port);
      map = GraphConstants.createMap();
      GraphConstants.setOffset(
          map,
          new Point( (int) (u / 4), (int) (u / 4)));
      port =
          gmp.createCell(
          model,
          GraphModelProvider.CELL_PORT_DEFAULT,
          "Topleft",
          map);
      gmp.addPort(cell, port);
      viewMap.put(port, map);
      toInsert.add(port);

      // Top Center
      // port = new DefaultPort("Topcenter");
      //cell.add(port);
      map = GraphConstants.createMap();
      GraphConstants.setOffset(map, new Point( (int) (u / 2), 0));
      port =
          gmp.createCell(
          model,
          GraphModelProvider.CELL_PORT_DEFAULT,
          "Topcenter",
          map);
      gmp.addPort(cell, port);
      viewMap.put(port, map);
      toInsert.add(port);

      // Top Right
      // port = new DefaultPort("Topright");
      // cell.add(port);
      map = GraphConstants.createMap();
      GraphConstants.setOffset(
          map,
          new Point( (int) (u * 3 / 4), (int) (u / 4)));
      port =
          gmp.createCell(
          model,
          GraphModelProvider.CELL_PORT_DEFAULT,
          "Topright",
          map);
      gmp.addPort(cell, port);
      viewMap.put(port, map);
      toInsert.add(port);

      // Top Center
      //port = new DefaultPort("Middleleft");
      //cell.add(port);
      map = GraphConstants.createMap();
      GraphConstants.setOffset(map, new Point(0, (int) (u / 2)));
      port =
          gmp.createCell(
          model,
          GraphModelProvider.CELL_PORT_DEFAULT,
          "Middleleft",
          map);
      gmp.addPort(cell, port);
      viewMap.put(port, map);
      toInsert.add(port);

      // Middle Right
      //port = new DefaultPort("Middleright");
      //cell.add(port);
      map = GraphConstants.createMap();
      GraphConstants.setOffset(map, new Point(u, (int) (u / 2)));
      port =
          gmp.createCell(
          model,
          GraphModelProvider.CELL_PORT_DEFAULT,
          "Middleright",
          map);
      gmp.addPort(cell, port);
      viewMap.put(port, map);
      toInsert.add(port);

      // Bottom Left
      //port = new DefaultPort("Bottomleft");
      //cell.add(port);
      map = GraphConstants.createMap();
      GraphConstants.setOffset(
          map,
          new Point( (int) (u / 4), (int) (u * 3 / 4)));
      port =
          gmp.createCell(
          model,
          GraphModelProvider.CELL_PORT_DEFAULT,
          "Bottomleft",
          map);
      gmp.addPort(cell, port);
      viewMap.put(port, map);
      toInsert.add(port);

      // Bottom Center
      //port = new DefaultPort("Bottomcenter");
      //cell.add(port);
      map = GraphConstants.createMap();
      GraphConstants.setOffset(map, new Point( (int) (u / 2), u));
      port =
          gmp.createCell(
          model,
          GraphModelProvider.CELL_PORT_DEFAULT,
          "Bottomcenter",
          map);
      gmp.addPort(cell, port);
      viewMap.put(port, map);
      toInsert.add(port);

      // Bottom Right
      //port = new DefaultPort("Bottomright");
      //cell.add(port);
      map = GraphConstants.createMap();
      GraphConstants.setOffset(
          map,
          new Point( (int) (u * 3 / 4), (int) (u * 3 / 4)));
      port =
          gmp.createCell(
          model,
          GraphModelProvider.CELL_PORT_DEFAULT,
          "Bottomright",
          map);
      gmp.addPort(cell, port);
      viewMap.put(port, map);
      toInsert.add(port);

      graphpad.getCurrentGraph().getModel().insert(
          toInsert.toArray(),
          viewMap,
          null,
          null,
          null);

}




  public void addInter(Rectangle bounds) {
    int defaultWidth = InterView.defaultWidth;
    int defaultHeight = InterView.defaultHeight;
    Color backgroundColour = Color.white;

    ModelExportInterface exportModel = graphpad.getExportModel();
    Object userObject = exportModel.createInter();

    commonAddCircle(bounds,
                    backgroundColour,
                    defaultHeight,
                    defaultWidth,
                    userObject,
                    GraphModelProvider.CELL_VERTEX_INTER);
  }

  public void addStart(Rectangle bounds) {
    int defaultWidth = StartView.defaultWidth;
    int defaultHeight = StartView.defaultHeight;
    Color backgroundColour = Color.green;

    ModelExportInterface exportModel = graphpad.getExportModel();
    Object userObject = exportModel.createStart();

    commonAddCircle(bounds,
                    backgroundColour,
                    defaultHeight,
                    defaultWidth,
                    userObject,
                    GraphModelProvider.CELL_VERTEX_START);
  }

  public void addPool(Rectangle bounds) {
    int defaultWidth = PoolView.default_width;
    int defaultHeight = PoolView.default_height;
    Color backgroundColour = Color.LIGHT_GRAY;

    ModelExportInterface exportModel = graphpad.getExportModel();
    Object userObject = exportModel.createPool();

    commonAddCircle(bounds,
                       backgroundColour,
                       defaultHeight,
                       defaultWidth,
                       userObject,
                       GraphModelProvider.CELL_VERTEX_POOL);
  }

  //添加数据对象
  public void addDataObj(Rectangle bounds) {
   int defaultWidth = DataObjView.default_width;
   int defaultHeight = DataObjView.default_height;
   Color backgroundColour = Color.YELLOW;

   ModelExportInterface exportModel = graphpad.getExportModel();
   Object userObject = exportModel.createDataObj();

   commonAddCircle(bounds,
                      backgroundColour,
                      defaultHeight,
                      defaultWidth,
                      userObject,
                      GraphModelProvider.CELL_VERTEX_DATAOBJ);
 }
 //添加文字注解
 public void addTextAnnotation(Rectangle bounds) {
  int defaultWidth = TextAnnotationView.default_width;
  int defaultHeight = TextAnnotationView.default_height;
  Color backgroundColour = Color.WHITE;

  ModelExportInterface exportModel = graphpad.getExportModel();
  Object userObject = exportModel.createTextAnnotation();

  commonAddCircle(bounds,
                     backgroundColour,
                     defaultHeight,
                     defaultWidth,
                     userObject,
                     GraphModelProvider.CELL_VERTEX_TEXTANNOTATION);
}
   //添加子任务
   public void addSubProcess(Rectangle bounds) {
     int defaultWidth = SubProcessView.default_width;
     int defaultHeight = SubProcessView.default_height;
     Color backgroundColour = Color.CYAN;

     ModelExportInterface exportModel = graphpad.getExportModel();
     Object userObject = exportModel.createSubProcess();

     commonAddCircle(bounds,
                        backgroundColour,
                        defaultHeight,
                        defaultWidth,
                        userObject,
                        GraphModelProvider.CELL_VERTEX_SUBPROCESS);
   }


  public void addLane(Rectangle bounds) {
   int defaultWidth = LaneView.default_width;
   int defaultHeight = LaneView.default_height;
   Color backgroundColour = Color.LIGHT_GRAY;

   ModelExportInterface exportModel = graphpad.getExportModel();
   Object userObject = exportModel.createLane();

   commonAddCircle(bounds,
                      backgroundColour,
                      defaultHeight,
                      defaultWidth,
                      userObject,
                      GraphModelProvider.CELL_VERTEX_LANE);
 }


  public void addEnd(Rectangle bounds) {
    int defaultWidth = EndView.defaultWidth;
    int defaultHeight = EndView.defaultHeight;
    Color backgroundColour = Color.red;

    ModelExportInterface exportModel = graphpad.getExportModel();
    Object userObject = exportModel.createEnd();

    commonAddCircle(bounds,
                    backgroundColour,
                    defaultHeight,
                    defaultWidth,
                    userObject,
                    GraphModelProvider.CELL_VERTEX_END);
  }

  public void commonAddCircle(Rectangle bounds,
                              Color backgroundColour,
                              int defaultHeight,
                              int defaultWidth,
                              Object userObject,
                              int nodeType) {
    Map viewMap = new Hashtable();
    Map map;
    GraphModelProvider gmp = graphpad.getCurrentGraphModelProvider();
    GraphModel model = graphpad.getCurrentGraph().getModel();

    // If bounds is smaller than the default activity
    // ensure the default dimensions are used.
    int width = bounds.width;
    int height = bounds.height;

    if (bounds.getWidth() < defaultWidth) {
      width = defaultWidth;
    }
    if (bounds.getHeight() < defaultHeight) {
      height = defaultHeight;
    }

    bounds.setSize(width, height);

    map = GraphConstants.createMap();
    GraphConstants.setBounds(map, bounds);
    GraphConstants.setOpaque(map, true);
    GraphConstants.setBackground(map, backgroundColour);
    GraphConstants.setBorderColor(map, Color.black);
    String fontName = Translator.getString("FontName");
    try {
      int fontSize = Integer.parseInt(Translator.getString("FontSize"));
      int fontStyle = Integer.parseInt(Translator.getString("FontStyle"));
      GraphConstants.setFont(
          map,
          new Font(fontName, fontStyle, fontSize));
    }
    catch (Exception e) {
      // handle error
    }
    List toInsert = new LinkedList();

    Object cell =
        gmp.createCell(
        model,
        nodeType,
        userObject,
        map);

    viewMap.put(cell, map);
    toInsert.add(cell);

    // Create Ports
    int u = GraphConstants.PERMILLE;
    Object port;

    // Floating Center Port
    port =
        gmp.createCell(
        model,
        GraphModelProvider.CELL_PORT_DEFAULT,
        "Center",
        null);
    gmp.addPort(cell, port);
    //port = new DefaultPort("Center");
    //cell.add(port);
    toInsert.add(port);

    graphpad.getCurrentGraph().getModel().insert(
        toInsert.toArray(),
        viewMap,
        null,
        null,
        null);

  }

  public void addSplit(Rectangle bounds) {
    int defaultWidth = EndView.defaultWidth;
    int defaultHeight = EndView.defaultHeight;
    Color backgroundColour = Color.red;

    ModelExportInterface exportModel = graphpad.getExportModel();
    Object userObject = exportModel.createFork();

    commonAddRectangle(bounds,
                       backgroundColour,
                       defaultHeight,
                       defaultWidth,
                       userObject,
                       GraphModelProvider.CELL_VERTEX_SPLIT);
  }

  public void addJoin(Rectangle bounds) {
    int defaultWidth = EndView.defaultWidth;
    int defaultHeight = EndView.defaultHeight;
    Color backgroundColour = Color.red;

    ModelExportInterface exportModel = graphpad.getExportModel();
    Object userObject = exportModel.createJoin();

    commonAddRectangle(bounds,
                       backgroundColour,
                       defaultHeight,
                       defaultWidth,
                       userObject,
                       GraphModelProvider.CELL_VERTEX_JOIN);
  }

  public void commonAddRectangle(Rectangle bounds,
                                 Color backgroundColour,
                                 int defaultHeight,
                                 int defaultWidth,
                                 Object userObject,
                                 int nodeType) {
    Map viewMap = new Hashtable();
    Map map;
    GraphModelProvider gmp = graphpad.getCurrentGraphModelProvider();
    GraphModel model = graphpad.getCurrentGraph().getModel();

    // If bounds is smaller than the default activity
    // ensure the default dimensions are used.
    int width = bounds.width;
    int height = bounds.height;

    if (bounds.getWidth() < defaultWidth) {
      width = defaultWidth;
    }
    if (bounds.getHeight() < defaultHeight) {
      height = defaultHeight;
    }

    bounds.setSize(width, height);

    map = GraphConstants.createMap();
    GraphConstants.setBounds(map, bounds);
    // FIXME, when an image isn't provided use this colour
//		GraphConstants.setOpaque(map, true);
//		GraphConstants.setBackground(map, backgroundColour);
//		GraphConstants.setBorderColor(map, Color.black);
    String fontName = Translator.getString("FontName");
    try {
      int fontSize = Integer.parseInt(Translator.getString("FontSize"));
      int fontStyle = Integer.parseInt(Translator.getString("FontStyle"));
      GraphConstants.setFont(
          map,
          new Font(fontName, fontStyle, fontSize));
    }
    catch (Exception e) {
      // handle error
    }
    List toInsert = new LinkedList();

    Object cell =
        gmp.createCell(
        model,
        nodeType,
        userObject,
        map);

    viewMap.put(cell, map);
    toInsert.add(cell);

    // Create Ports
    int u = GraphConstants.PERMILLE;
    Object port;

    // Floating Center Port
    port =
        gmp.createCell(
        model,
        GraphModelProvider.CELL_PORT_DEFAULT,
        "Center",
        null);
    gmp.addPort(cell, port);
    //port = new DefaultPort("Center");
    //cell.add(port);
    toInsert.add(port);

    graphpad.getCurrentGraph().getModel().insert(
        toInsert.toArray(),
        viewMap,
        null,
        null,
        null);

  }
}

⌨️ 快捷键说明

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