Newer
Older
AlgebraicDataflowArchitectureModel / AlgebraicDataflowArchitectureModel / src / application / actions / ChangeCallOrderAction.java
k-fujii on 12 Mar 2 KB コメントを追記.
package application.actions;

import java.awt.event.ActionEvent;

import javax.swing.JOptionPane;

import com.mxgraph.model.mxCell;
import com.mxgraph.swing.mxGraphComponent;

import models.controlFlowModel.CallEdgeAttribute;

/*************************************************************
 *
 */
public class ChangeCallOrderAction extends AbstractPopupAction {
	
	/*************************************************************
	/*************************************************************
	 *  [ *constructor ]
	/*************************************************************
	 */
	public ChangeCallOrderAction(final mxGraphComponent graphComponent ,final mxCell cell) {
		super(/*propName*/"changeCallOrder", cell, graphComponent);
	}

	/*************************************************************
	/*************************************************************
	 *  [ *public ]
	/*************************************************************
	 * 
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		super.actionPerformed(e);
		if(targetCell == null) return;
		changeCallOrderOfCallEdge(targetCell);
	}
	
	/*************************************************************
	/*************************************************************
	 * [ *private ]
	/*************************************************************
	 * コントロールフローの呼び出し順を変更する
	 * @param cellObj 選択されたエッジ(コントロールフロー)のセル
	 */
	private void changeCallOrderOfCallEdge(Object cellObj) {		
		String input = "";
		int inputOrder = 0;

		CallEdgeAttribute callEdgeAttr = (CallEdgeAttribute)graphComponent.getGraph().getModel().getValue(cellObj);	
		if (callEdgeAttr == null) return;

		input = JOptionPane.showInputDialog("Call order");
		if ( input == null) return;

		if ( !isNumeric(input) ) {
			JOptionPane.showMessageDialog(graphComponent, "Input value must type of number.");
			return;
		}

		inputOrder = Integer.parseInt(input);

		final int endOfOrderOfSrc = callEdgeAttr.getSourceObjectNode().getOutdegree();
		if (inputOrder <= 0	|| endOfOrderOfSrc < inputOrder) {
			JOptionPane.showMessageDialog(graphComponent, "Input order must be between 1 and " + endOfOrderOfSrc + ".");
			return;
		}

		int curOrder = callEdgeAttr.getSourceObjectNode().getOutEdgeCallOrder(callEdgeAttr.getCallEdge());
		callEdgeAttr.getSourceObjectNode().sortOutEdgesByCallOrder(curOrder,  inputOrder);					

		graphComponent.refresh();
	}

	/*************************************************************
	 * フォームに入力された文字列が数値か判定
	 * @param str フォームに入力された文字列
	 */
	private boolean isNumeric(final String str) {
		if (str == null) return false;
		return str.matches("[0-9.]+");
	}
}