Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f6de3b9b1526c6d5300cc6bf029ed81107cf62ac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="InitFlowLayoutGenerator"
	imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.graphdef.codegen.*"%>
<%
GraphDefDispatcher.LayoutArgs argsBundle = (GraphDefDispatcher.LayoutArgs) argument;
final FlowLayout gmfLayout = (FlowLayout) argsBundle.getLayout();
final String layouterVarName = argsBundle.getManagerVariableName();
final GraphDefDispatcher dispatcher = argsBundle.getDispatcher();
final String layouterClassName = dispatcher.getFQNSwitch().get(gmfLayout, dispatcher.getImportManager());

class AlignmentConverter {
	private final String myBegin;
	private final String myCenter;
	private final String myEnd;
	
	public AlignmentConverter(String begin, String center, String end){
		myBegin = begin;
		myCenter = center;
		myEnd = end;
	}
	
	public String convert(Alignment alignment){
		if (alignment == null){
			alignment = Alignment.BEGINNING_LITERAL;
		}
		switch (alignment.getValue()){
			case Alignment.BEGINNING : 
				return myBegin;
			case Alignment.END :
				return myEnd;
			case Alignment.FILL:
			case Alignment.CENTER:
				return myCenter;
			default:
				throw new IllegalArgumentException("Unknown alignment: " + alignment);
		}
	}
}

class AlignmentFacade {
	public String convert(FlowLayout layout, Alignment alignment){
		return getConverter(layout).convert(alignment);
	}
	
	private AlignmentConverter getConverter(FlowLayout layout){
		return layout.isForceSingleLine() ? 
			new AlignmentConverter("ALIGN_TOPLEFT", "ALIGN_CENTER", "ALIGN_BOTTOMRIGHT") : 
			new AlignmentConverter("ALIGN_LEFTTOP", "ALIGN_CENTER", "ALIGN_RIGHTBOTTOM");
	}
}

final AlignmentFacade alignmentFacade = new AlignmentFacade();
%>
		<%=layouterVarName%>.setStretchMinorAxis(<%=gmfLayout.isMatchMinorSize()%>);
		<%=layouterVarName%>.setMinorAlignment(<%=layouterClassName%>.<%=alignmentFacade.convert(gmfLayout, gmfLayout.getMinorAlignment())%>);
<%
if (gmfLayout.isForceSingleLine()){
%>		
		<%=layouterVarName%>.setSpacing(<%=gmfLayout.getMajorSpacing()%>);
		<%=layouterVarName%>.setVertical(<%=gmfLayout.isVertical()%>);
<%
} else {
%>
		<%=layouterVarName%>.setMajorAlignment(<%=layouterClassName%>.<%=alignmentFacade.convert(gmfLayout, gmfLayout.getMajorAlignment())%>);
		<%=layouterVarName%>.setMajorSpacing(<%=gmfLayout.getMajorSpacing()%>);
		<%=layouterVarName%>.setMinorSpacing(<%=gmfLayout.getMinorSpacing()%>);
		<%=layouterVarName%>.setHorizontal(<%=!gmfLayout.isVertical()%>);
<%
} 
%>


Back to the top