diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DependencyCellEditor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DependencyCellEditor.java index 205b5a7..889b232 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DependencyCellEditor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DependencyCellEditor.java @@ -20,7 +20,7 @@ if (editingCell != null) stopEditing(true); DependencyModelingStage ddmStage = (DependencyModelingStage) stage; - // セルがnull、または頂点以外なら編集しない + // Do not edit if the cell is null or not a vertex if (cellObj == null || !(cellObj instanceof mxCell)) return; mxCell cell = (mxCell) cellObj; @@ -29,7 +29,7 @@ MouseEvent mouseEvent = (MouseEvent) eventObj; - //Right-Click + // Right-click if (SwingUtilities.isRightMouseButton(mouseEvent)) { if (cell.isEdge()) { showEdgeContextMenu(cell, mouseEvent); @@ -39,7 +39,7 @@ return; } - // Left-Click + // Left-click if (ddmStage.getCurState() == DependencyModelingStageStatus.IDLE && isInterfaceNode(cell) && mouseEvent.getClickCount() == 2) { @@ -49,7 +49,7 @@ } /** - * セルがインターフェースノード(ひし形)かどうかを判定 + * Determines whether the given cell is an interface node (rhombus shape) */ private boolean isInterfaceNode(mxCell cell) { if (cell == null || !cell.isVertex()) return false; @@ -58,43 +58,43 @@ } /** - * エッジがインターフェースノードに接続されているかどうかを判定 + * Checks whether the edge is connected to an interface node */ private boolean isConnectedToInterface(mxCell edgeCell) { if (edgeCell == null || !edgeCell.isEdge()) return false; - + mxCell source = (mxCell) edgeCell.getSource(); mxCell target = (mxCell) edgeCell.getTarget(); - + return isInterfaceNode(source) || isInterfaceNode(target); } /** - * エッジ右クリック時のコンテキストメニューを表示 + * Displays the context menu when right-clicking on an edge */ private void showEdgeContextMenu(mxCell edgeCell, MouseEvent mouseEvent) { - // インターフェースノードに接続されているエッジの場合は何もしない + // Do nothing if the edge is connected to an interface node if (isConnectedToInterface(edgeCell)) { return; } - + JPopupMenu popup = new JPopupMenu(); - JMenuItem reverseItem = new JMenuItem("依存関係の逆転を適用"); - + JMenuItem reverseItem = new JMenuItem("Apply Dependency Inversion"); + reverseItem.addActionListener(e -> { applyDependencyInversion(edgeCell); }); - + popup.add(reverseItem); popup.show(graphComponent, mouseEvent.getX(), mouseEvent.getY()); } /** - * インターフェースノード右クリック時のコンテキストメニューを表示 + * Displays the context menu when right-clicking on an interface node */ private void showInterfaceContextMenu(mxCell interfaceCell, MouseEvent mouseEvent) { JPopupMenu popup = new JPopupMenu(); - JMenuItem deleteItem = new JMenuItem("Interfaceを削除"); + JMenuItem deleteItem = new JMenuItem("Delete Interface"); deleteItem.addActionListener(e -> { removeInterface(interfaceCell); @@ -105,32 +105,32 @@ } /** - * インターフェースノードを削除し、元のエッジに戻す + * Deletes the interface node and restores the original edge */ private void removeInterface(mxCell interfaceCell) { DependencyModelingStage ddmStage = (DependencyModelingStage) stage; - // DEPENDENCY_LAYERを取得 + // Get the DEPENDENCY_LAYER mxCell root = (mxCell) graphComponent.getGraph().getDefaultParent(); mxCell layerCell = (mxCell) root.getChildAt(ddmStage.DEPENDENCY_LAYER); - // インターフェースノードに接続されているエッジを取得 + // Get edges connected to the interface node int edgeCount = interfaceCell.getEdgeCount(); if (edgeCount != 2) { - // 正確に2つのエッジがない場合は処理しない + // If not exactly two edges, do nothing return; } mxCell edge1 = (mxCell) interfaceCell.getEdgeAt(0); mxCell edge2 = (mxCell) interfaceCell.getEdgeAt(1); - // source -> interface と target -> interface のエッジを識別 + // Identify source -> interface and target -> interface edges mxCell sourceCell = null; mxCell targetCell = null; String edgeStyle = null; Object edgeValue = null; - // edge1とedge2から元のsourceとtargetを特定 + // Determine the original source and target from edge1 and edge2 if (edge1.getTarget() == interfaceCell) { // edge1: source -> interface sourceCell = (mxCell) edge1.getSource(); @@ -148,7 +148,7 @@ edgeStyle = edge2.getStyle(); edgeValue = edge2.getValue(); } else { - // edge2: target -> interface (逆向き) + // edge2: target -> interface (reverse direction) targetCell = (mxCell) edge2.getSource(); } } else if (edge2.getSource() == interfaceCell) { @@ -164,16 +164,18 @@ graphComponent.getGraph().getModel().beginUpdate(); try { - // インターフェースノードとそのエッジを削除 + // Remove the interface node and its edges graphComponent.getGraph().getModel().remove(edge1); graphComponent.getGraph().getModel().remove(edge2); graphComponent.getGraph().getModel().remove(interfaceCell); - // 元のエッジを復元 (source -> target) - // dashedスタイルを削除 + // Restore the original edge (source -> target) + // Remove the dashed style String restoredStyle = edgeStyle; if (restoredStyle != null && restoredStyle.contains("dashed=true")) { - restoredStyle = restoredStyle.replace(";dashed=true", "").replace("dashed=true;", "").replace("dashed=true", ""); + restoredStyle = restoredStyle.replace(";dashed=true", "") + .replace("dashed=true;", "") + .replace("dashed=true", ""); } graphComponent.getGraph().insertEdge( @@ -205,7 +207,7 @@ mxCell root = (mxCell) graphComponent.getGraph().getDefaultParent(); mxCell layerCell = (mxCell) root.getChildAt(ddmStage.DEPENDENCY_LAYER); - // エッジの中点を計算 + // Calculate the midpoint of the edge mxGeometry sourceGeo = source.getGeometry(); mxGeometry targetGeo = target.getGeometry(); @@ -214,10 +216,10 @@ graphComponent.getGraph().getModel().beginUpdate(); try { - // 元のエッジを削除 + // Remove the original edge graphComponent.getGraph().getModel().remove(edgeCell); - // インターフェースノード(ひし形)をDEPENDENCY_LAYERに挿入 + // Insert the interface node (rhombus) into the DEPENDENCY_LAYER mxCell interfaceNode = (mxCell) graphComponent.getGraph().insertVertex( layerCell, null, @@ -229,15 +231,15 @@ "shape=rhombus;fillColor=#BBFFBB;perimeter=rhombusPerimeter;resizable=0;" ); - // 元のエッジのスタイルを取得 + // Get the original edge's style and value String edgeStyle = edgeCell.getStyle(); Object edgeValue = edgeCell.getValue(); - // source -> interface のエッジを作成 (元のスタイルを維持) + // Create edge from source -> interface (keep original style) graphComponent.getGraph().insertEdge(layerCell, null, edgeValue, source, interfaceNode, edgeStyle); - // target -> interface のエッジを作成 (逆向き・点線) - // 元のスタイルに dashed=true を追加 + // Create edge from target -> interface (reverse direction, dashed) + // Add "dashed=true" to the style String reversedStyle = edgeStyle; if (reversedStyle != null && !reversedStyle.contains("dashed")) { reversedStyle = reversedStyle + ";dashed=true"; @@ -254,17 +256,17 @@ } public void editInterfaceName(mxCell cell, EventObject eventObj){ - // 現在のラベルを取得 + // Get the current label String currentName = (cell.getValue() != null) ? cell.getValue().toString() : ""; - // 入力ダイアログを表示 + // Show input dialog String newName = JOptionPane.showInputDialog( null, - "Edit Interface Name:", + "Edit Interface Name:", currentName ); - // OKが押されて、入力が空でなければラベルを更新 + // If OK is pressed and input is not empty, update the label if (newName != null && !newName.trim().isEmpty()) { graphComponent.getGraph().getModel().beginUpdate(); try {