View Javadoc

1   /*
2    * This file is a part of CAST project.
3    * (c) Copyright 2007, AGH University of Science & Technology
4    * https://caribou.iisg.agh.edu.pl/trac/cast
5    *
6    * Licensed under the Eclipse Public License, Version 1.0 (the "License").
7    * You may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    * http://www.eclipse.org/legal/epl-v10.html
10   */
11  /*
12   * File: LayoutEntityAdapter.java
13   * Created: 2009-04-15
14   * Author: koperek, kupisz, kpietak
15   * $Id: LayoutEntityAdapter.java 3324 2009-09-09 13:59:04Z tmilos $
16   */
17  package pl.edu.agh.cast.zestalgorithms.core;
18  
19  import org.eclipse.zest.layouts.LayoutEntity;
20  import org.eclipse.zest.layouts.constraints.LayoutConstraint;
21  
22  
23  import pl.edu.agh.cast.schema.model.presentation.ISchemaNode;
24  import pl.edu.agh.cast.schema.model.visual.IVisualSchemaNode;
25  
26  /**
27   * Adapts interface of {@link ISchemaNode} to a {@link LayoutEntity}.
28   * 
29   * @author AGH CAST Team
30   */
31  public class LayoutEntityAdapter implements LayoutEntity {
32  
33  	private static final long serialVersionUID = 388599899387325632L;
34  
35  	/**
36  	 * Can be used to hold additional information about the layout or any other data.
37  	 */
38  	private Object layoutInformation;
39  
40  	/**
41  	 * Node from CASTs schema presentation model that is being adapted to ZESTs {@link LayoutEntity}
42  	 */
43  	private ISchemaNode node;
44  
45  	/**
46  	 * Constructs new adapter for given node
47  	 * 
48  	 * @param node
49  	 *            Node which is going to be adapted to ZEST model
50  	 */
51  	public LayoutEntityAdapter(ISchemaNode node) {
52  		this.node = node;
53  	}
54  
55  	@Override
56  	public double getHeightInLayout() {
57  		return ((IVisualSchemaNode)node.getVisualElement()).getHeight();
58  	}
59  
60  	@Override
61  	public double getWidthInLayout() {
62  		return ((IVisualSchemaNode)node.getVisualElement()).getWidth();
63  	}
64  
65  	@Override
66  	public double getXInLayout() {
67  		return ((IVisualSchemaNode)node.getVisualElement()).getXCoordinate();
68  	}
69  
70  	@Override
71  	public double getYInLayout() {
72  		return ((IVisualSchemaNode)node.getVisualElement()).getYCoordinate();
73  	}
74  
75  	@Override
76  	public Object getLayoutInformation() {
77  		return layoutInformation;
78  	}
79  
80  	@Override
81  	public void populateLayoutConstraint(LayoutConstraint arg0) {
82  		// here we should invoke smth like:
83  		// graph.invokeConstraintAdapters(this, constraint);
84  	}
85  
86  	@Override
87  	public void setLayoutInformation(Object layoutInformation) {
88  		this.layoutInformation = layoutInformation;
89  
90  	}
91  
92  	/**
93  	 * Sets new position of the node<br>
94  	 * <b>Warning!</b> coordinates will be casted to int
95  	 */
96  	@Override
97  	public void setLocationInLayout(double x, double y) {
98  		((IVisualSchemaNode)node.getVisualElement()).setXCoordinate((int)x);
99  		((IVisualSchemaNode)node.getVisualElement()).setYCoordinate((int)y);
100 	}
101 
102 	/**
103 	 * Sets new position of the node<br>
104 	 * <b>Warning!</b> coordinates will be casted to int
105 	 */
106 	@Override
107 	public void setSizeInLayout(double x, double y) {
108 		((IVisualSchemaNode)node.getVisualElement()).setWidth((int)x);
109 		((IVisualSchemaNode)node.getVisualElement()).setHeight((int)y);
110 	}
111 
112 	@Override
113 	public int compareTo(Object arg) {
114 		int _result = 0;
115 
116 		if (arg instanceof ISchemaNode) {
117 			_result = this.node.getId().compareTo(((ISchemaNode)arg).getId());
118 		}
119 
120 		return _result;
121 	}
122 
123 	/**
124 	 * @return the node that is being adapted
125 	 */
126 	public Object getGraphData() {
127 		return node;
128 	}
129 
130 	/**
131 	 * Required by {@link LayoutEntity}. Does nothing.
132 	 */
133 	public void setGraphData(Object arg0) {
134 		// does nothing
135 	}
136 
137 }