Skip to main content
aboutsummaryrefslogblamecommitdiffstats
blob: 4a479943e2917776b1ca6360acf04eeddd592ea5 (plain) (tree)
1
2
3
4
5
6
7
8
9
10





                                                                                            

                                                                                                                                       

                          









                                                                           





                                                                
                                               
                                            
                                             

                                              
                                                





                                                                                                      












                                                                                                       

                                                                                            
                                                                                                                                                      







                                                                                  
                                                                                                                                                      







                                                                                       
<%@ 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.getImportManager().getImportedName((String) dispatcher.getFQNSwitch().doSwitch(gmfLayout));

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