Javaでフローチャートを作成する

この記事では、Java でフローチャートを作成する方法について説明します。これには、Java でフローチャート メーカー を開発するためのステップバイステップのアルゴリズムと実行可能なコード スニペットが含まれています。さらに、スキーマ、シェイプの数、接続、その他のプロパティを操作して、要件に応じて flowchart を作成することでプロセスを強化できます。

Javaでフローチャートを作成する手順

  1. フローチャートを作成するための Aspose.Diagram API をインストールして環境を準備します
  2. フローチャートのスキーマを開発する
  3. Diagram クラスのオブジェクトを作成し、シェイプを挿入するためのマスター シェイプをロードします
  4. フローチャートのレイアウトを設定し、save Save メソッドを使用して生成されたフローチャートをエクスポートします

これらの手順は、Java でフローチャート ジェネレーターを開発するプロセスを示しています。まず、さまざまな役割、指定、その他のプロパティを設定するためのスキーマを作成します。その後、レイアウトを設定して出力フローチャートを保存する前に、マスター シェイプを使用して長方形やコネクタなどのさまざまなシェイプを追加します。

Java でフローチャート ジェネレーターを作成するコード

import com.aspose.diagram.*;
public class Main
{
public static void main(String[] args) throws Exception // Create flowchart in Java
{
// Set the licenses
new License().setLicense("License.lic");
// Create a new diagram
int pageNumber = 0;
String MasterRectangle = "Process", decisionMaster = "Decision", connectorMaster = "Dynamic connector";
com.aspose.diagram.Diagram diagram = new com.aspose.diagram.Diagram("XANFLOWCHARTNEW.vss");
double widthparam = 1, heightparam = 1, pinX = 4, pinY = 10;
long process1 = diagram.addShape(pinX, pinY, widthparam, heightparam, MasterRectangle, 0);
Shape processShape1 = diagram.getPages().getPage(pageNumber).getShapes().getShape(process1);
processShape1.getText().getValue().add(new Txt("PROCESS"));
processShape1.setName("PROCESS");
processShape1.getXForm().getLocPinX().getUfe().setF("Width*0.5");
processShape1.getXForm().getLocPinY().getUfe().setF("Height*0.5");
pinY = pinY - 2;
long decision1 = diagram.addShape(pinX, pinY, widthparam, heightparam, decisionMaster, 0);
Shape decisionShape1 = diagram.getPages().getPage(pageNumber).getShapes().getShape(decision1);
decisionShape1.getText().getValue().add(new Txt("DECISION"));
decisionShape1.setName("DECISION");
decisionShape1.getXForm().getLocPinX().getUfe().setF("Width*0.5");
decisionShape1.getXForm().getLocPinY().getUfe().setF("Height*0.5");
pinY = pinY - 2;
long process2 = diagram.addShape(pinX, pinY, widthparam, heightparam, MasterRectangle, 0);
Shape processShape2 = diagram.getPages().getPage(pageNumber).getShapes().getShape(process2);
processShape2.getText().getValue().add(new Txt("PROCESS"));
processShape2.setName("PROCESS");
processShape2.getXForm().getLocPinX().getUfe().setF("Width*0.5");
processShape2.getXForm().getLocPinY().getUfe().setF("Height*0.5");
pinY = pinY - 2;
long process3 = diagram.addShape(pinX, pinY, widthparam, heightparam, MasterRectangle, 0);
Shape processShape3 = diagram.getPages().getPage(pageNumber).getShapes().getShape(process3);
processShape3.getText().getValue().add(new Txt("PROCESS"));
processShape3.setName("PROCESS");
processShape3.getXForm().getLocPinX().getUfe().setF("Width*0.5");
processShape3.getXForm().getLocPinY().getUfe().setF("Height*0.5");
pinY = pinY - 2;
long process4 = diagram.addShape(pinX, pinY, widthparam, heightparam, MasterRectangle, 0);
Shape processShape4 = diagram.getPages().getPage(pageNumber).getShapes().getShape(process4);
processShape4.getText().getValue().add(new Txt("PROCESS"));
processShape4.setName("PROCESS");
processShape4.getXForm().getLocPinX().getUfe().setF("Width*0.5");
processShape4.getXForm().getLocPinY().getUfe().setF("Height*0.5");
long connecterId = diagram.addShape(new Shape(), connectorMaster, 0);
diagram.getPages().getPage(pageNumber).connectShapesViaConnector(process1, ConnectionPointPlace.BOTTOM,
decision1, ConnectionPointPlace.TOP, connecterId);
long connecterId1 = diagram.addShape(new Shape(), connectorMaster, 0);
diagram.getPages().getPage(pageNumber).connectShapesViaConnector(decision1, ConnectionPointPlace.BOTTOM,
process2, ConnectionPointPlace.TOP, connecterId1);
long connecterId2 = diagram.addShape(new Shape(), connectorMaster, 0);
diagram.getPages().getPage(pageNumber).connectShapesViaConnector(process2, ConnectionPointPlace.BOTTOM,
process3, ConnectionPointPlace.TOP, connecterId2);
long connecterId3 = diagram.addShape(new Shape(), connectorMaster, 0);
diagram.getPages().getPage(pageNumber).connectShapesViaConnector(process3, ConnectionPointPlace.BOTTOM,
process4, ConnectionPointPlace.TOP, connecterId3);
long connecterId4 = diagram.addShape(new Shape(), connectorMaster, 0);
diagram.getPages().getPage(pageNumber).connectShapesViaConnector(decision1, ConnectionPointPlace.RIGHT,
process4, ConnectionPointPlace.TOP, connecterId4);
// Set automatic layout options
com.aspose.diagram.LayoutOptions layoutOptions = new com.aspose.diagram.LayoutOptions();
layoutOptions.setLayoutStyle(com.aspose.diagram.LayoutStyle.FLOW_CHART);
layoutOptions.setDirection(com.aspose.diagram.LayoutDirection.BOTTOM_TO_TOP); diagram.layout(layoutOptions);
com.aspose.diagram.DiagramSaveOptions options = new com.aspose.diagram.DiagramSaveOptions(com.aspose.diagram.SaveFileFormat.VSDX);
diagram.save( "flowchart.vsdx", options);
System.out.println("Done");
}
}

このコード スニペットは、Java でフローチャートを描画するための基本バージョンです。 Diagram クラスは、いくつかのマスター シェイプを読み込み、レイアウトを指定し、出力フローチャートをエクスポートするために使用されます。ただし、一部のカスタム クラスは、さまざまなコネクタやさまざまな形状を作成するためにも使用され、要件に合わせてさらに即興で作成できます。

このチュートリアルでは、Java でフローチャート ビルダー を作成するための情報をまとめました。さらに、画像を Visio 図に変換する必要がある場合は、Java で画像を Visio に変換する方法 の記事にアクセスしてください。

 日本語