package am.userInterface.canvas2.nodes;

import java.awt.Graphics;

import am.userInterface.canvas2.graphical.GraphicalData;
import am.userInterface.canvas2.graphical.MappingData;
import am.userInterface.canvas2.graphical.MappingData.MappingType;
import am.userInterface.canvas2.utility.Canvas2Edge;
import am.userInterface.canvas2.utility.Canvas2Vertex;

public class LegacyMapping extends Canvas2Edge {
	
	public LegacyMapping(Canvas2Vertex orig, Canvas2Vertex dest, GraphicalData o, int matcherID, String label ) {
		super(orig, dest, o);
		
		GraphicalData source = orig.getObject();
		GraphicalData target = dest.getObject();
		
		int sourceX = source.x + source.width;
		int sourceY = source.y + (source.height / 2);
		
		int targetX = target.x + LegacyNode.circlePadding;
		int targetY = target.y + (target.height / 2); 
		
		int width = targetX - sourceX;
		int height = targetY - sourceY;
		
		MappingType mappingType = MappingType.NOT_SET; 
		if( source.type == GraphicalData.NodeType.CLASS_NODE || source.type == GraphicalData.NodeType.CLASSES_ROOT ) {
			mappingType = MappingType.ALIGNING_CLASSES;
		} else if( source.type == GraphicalData.NodeType.PROPERTY_NODE || source.type == GraphicalData.NodeType.PROPERTIES_ROOT ) {
			mappingType = MappingType.ALIGNING_PROPERTIES;
		}
		
		MappingData data = new MappingData( sourceX, sourceY, width, height, source.layout, 
											source.r, target.r, source.ontologyID, target.ontologyID, matcherID, mappingType );
		data.setLabel(label);
		
		setObject( data );
		
		
	}
	
	@Override
	public void draw(Graphics g ) {
		g.setColor( ((MappingData)d).color );
		g.drawLine(d.x , d.y, d.x+d.width, d.y+d.height);
		if( ((MappingData)d).label != null )
			g.drawString( ((MappingData)d).label, d.x+d.width/2, d.y+d.height/2);
	}

}

@@ -59,16 +59,102 @@
 raphics;
+%0Aimport java.awt.Rectangle;%0Aimport java.awt.geom.Line2D;%0Aimport java.awt.geom.Point2D;
 %0A%0Aimport
@@ -483,16 +483,72 @@
 s2Edge %7B
+%0A%0A%09Line2D.Double line; // the line formed by the mapping
 %0A%09%0A%09publ
@@ -1668,264 +1668,1382 @@
 %09%0A%09%09
-%0A%09%7D%0A%09%0A%09@Override%0A%09public void draw(Graphics g ) %7B%0A%09%09g.setColor( ((MappingData)d).color );%0A%09%09g.drawLine(d.x , d.y, d.x+d.width, d.y+d.height);%0A%09%09if( ((MappingData)d).label != null )%0A%09%09%09g.drawString( ((MappingData)d).label, d.x+d.width/2, d.y+d.height/2);%0A%09%7D
+Point2D.Double startPoint = new Point2D.Double(d.x, d.y);%0A%09%09Point2D.Double endPoint =   new Point2D.Double(d.x+d.width, d.y+d.height);%0A%09%09%0A%09%09line = new Line2D.Double( startPoint, endPoint );%0A%09%09%0A%09%7D%0A%09%0A%09// Used when the line endpoints have changed.%0A%09@Override%0A%09public void updateBounds( int x, int y, int width, int height ) %7B %0A%09%09super.updateBounds(x, y, width, height);%0A%09%09%0A%09%09// recreate the line%0A%09%09Point2D.Double startPoint = new Point2D.Double(d.x, d.y);%0A%09%09Point2D.Double endPoint =   new Point2D.Double(d.x+d.width, d.y+d.height);%0A%09%09%0A%09%09line = new Line2D.Double( startPoint, endPoint );%0A%09%7D;%0A%09%0A%09@Override%0A%09public void draw(Graphics g ) %7B%0A%09%09g.setColor( ((MappingData)d).color );%0A%09%09g.drawLine(d.x , d.y, d.x+d.width, d.y+d.height);%0A%09%09if( ((MappingData)d).label != null )%0A%09%09%09g.drawString( ((MappingData)d).label, d.x+d.width/2, d.y+d.height/2);%0A%09%7D%0A%09%0A%09@Override%0A%09public boolean isVisible(Rectangle bounds) %7B%0A%09%09//if( graph != null ) %7B if( !graph.visible ) return false; %7D  // if the graph isn't visible, any of its elements aren't visible either%0A%09%09if( d == null ) return false; // no GraphicalData -%3E no visibility%0A%09%09%0A%09%09if( !d.visible ) return false;  // if our node was set to be invisible, so no need to check bounds%0A%09%09%0A%09%09if( bounds.getBounds2D().intersectsLine(line) ) return true; // if the line formed by the mapping intersects the viewport rectangle%0A%09%09%0A%09%09return false;%0A%09%09%0A%09%7D%0A%09
 %0A%0A%7D%0A

Solve visibility issues.