if (in instanceof EPICSVarLink) {
if (in instanceof EPICSVarOutLink) {
public static void drawKneeLine(Graphics g, OutLink out, InLink in, boolean firstHorizontal) {	ViewState view = ViewState.getInstance();	double scale = view.getScale();	int x1 = (int)(scale*out.getOutX()-view.getRx());	int y1 = (int)(scale*out.getOutY()-view.getRy());		int x2 = x1;	int y2 = y1;	if (in!=null)	{		// EPICSVarLink is double sided, take the best side		if (in instanceof EPICSVarLink) {			int lx = in.getLeftX();			int rx = in.getRightX();			if (out.getOutX() > (lx+rx)/2)				x2 = (int)(scale*rx-view.getRx());			else				x2 = (int)(scale*lx-view.getRx());		}		else			x2 = (int)(scale*in.getInX()-view.getRx());				y2 = (int)(scale*in.getInY()-view.getRy());	}	// 	// !!! temporary "solution"	//	// inivsible mode	if (out.getMode() == OutLink.INVISIBLE_MODE)	{		int s = (int)(scale*Constants.INVISIBLE_CROSS_SIZE);			if (firstHorizontal) {			g.drawLine(x1-s, y1, x1+s, y1);			g.drawLine(x1, y1-s, x1, y1+s);			g.drawLine(x2, y2-s, x2, y2+s);			g.drawLine(x2-s, y2, x2+s, y2);		}		else {			g.drawLine(x1, y1-s, x1, y1+s);			g.drawLine(x1-s, y1, x1+s, y1);			g.drawLine(x2-s, y2, x2+s, y2);			g.drawLine(x2, y2-s, x2, y2+s);		}						Linkable descPoint = out;					int r = (int)(LARGE_RECT*view.getScale());		int dx = tailLenOfR*r;					String label = null;		validateFont(view);		if (font!=null) {			g.setFont(font);			Linkable target = null;			//else if (descPoint instanceof OutLink && !(descPoint instanceof EPICSVarOutLink))			{				target = EPICSLinkOut.getEndPoint(descPoint);				// any special threatment ??				if (target instanceof Descriptable)					label = ((Descriptable)target).getDescription();			}							if (label!=null) {				/*if (isRight) dx = 3*r; 				else*/ dx = -(fontMetrics.stringWidth(label)+2*r);				g.drawString(label, x1+dx, y1+dy);			}		}				label = null;		descPoint = in;					r = (int)(LARGE_RECT*view.getScale());		dx = tailLenOfR*r;					if (font!=null) {			g.setFont(font);			Linkable target = null;				//if (descPoint instanceof InLink)			{				target = EPICSLinkOut.getStartPoint(descPoint);				// any special threatment ??				if (target instanceof Descriptable)					label = ((Descriptable)target).getDescription();			}							if (label!=null) {				/*if (isRight) dx = 3*r; 				else*/ dx = -(fontMetrics.stringWidth(label)+2*r);				g.drawString(label, x2+dx, y2+dy);			}		}						return;	}	// only test here	else if (out.getMode() == OutLink.EXTERNAL_OUTPUT_MODE)	{		// horizontal				int s = (int)(scale*Constants.LINK_STUB_SIZE/2.0);		//		if (x2<x1) s = -s;		if (!firstHorizontal) s = -s;		// draw tail		g.drawLine(x1, y1, x1+s, y1);		x1+=s;			// drawing -->		g.drawLine(x1, y1-s, x1, y1+s);		g.drawLine(x1, y1-s, x1+s, y1-s);		g.drawLine(x1, y1+s, x1+s, y1+s);		g.drawLine(x1+s, y1-s, x1+2*s, y1);		g.drawLine(x1+s, y1+s, x1+2*s, y1);		Linkable descPoint = out;					int r = (int)(LARGE_RECT*view.getScale());		int dx = tailLenOfR*r;					String label = null;		validateFont(view);		if (font!=null) {			g.setFont(font);			Linkable target = null;			//else if (descPoint instanceof OutLink && !(descPoint instanceof EPICSVarOutLink))			{				target = EPICSLinkOut.getStartPoint(descPoint);				// any special threatment ??				if (target instanceof Field)					label = ((Field)target).getFieldData().getValue();			}							if (label!=null) {				/*if (isRight) dx = 3*r; 				else*/ 				if (!firstHorizontal) dx = -fontMetrics.stringWidth(label)+3*s;				g.drawString(label, x1+dx, y1+dy);			}		}		return;	}	else if (out.getMode() == OutLink.EXTERNAL_INPUT_MODE)	{		// horizontal				int s = (int)(scale*Constants.LINK_STUB_SIZE/2.0);		//		if (x2<x1) s = -s;		if (!firstHorizontal) s = -s;				// draw tail		g.drawLine(x1, y1, x1+s, y1);		x1+=s;			// drawing -->		g.drawLine(x1, y1-s, x1, y1+s);		g.drawLine(x1, y1-s, x1+2*s, y1-s);		g.drawLine(x1, y1+s, x1+2*s, y1+s);		g.drawLine(x1+2*s, y1-s, x1+s, y1);		g.drawLine(x1+2*s, y1+s, x1+s, y1);		Linkable descPoint = out;					int r = (int)(LARGE_RECT*view.getScale());		int dx = tailLenOfR*r;					String label = null;		validateFont(view);		if (font!=null) {			g.setFont(font);			Linkable target = null;			//else if (descPoint instanceof OutLink && !(descPoint instanceof EPICSVarOutLink))			{				target = EPICSLinkOut.getStartPoint(descPoint);				// any special threatment ??				if (target instanceof Field)					label = ((Field)target).getFieldData().getValue();			}							if (label!=null) {				/*if (isRight) dx = 3*r; 				else*/ 				if (!firstHorizontal) dx = -fontMetrics.stringWidth(label)+3*s;				g.drawString(label, x1+dx, y1+dy);			}		}		return;	}/*	else if (out.getMode() == ?)	{		// horizontal				int s = (int)(scale*Constants.LINK_STUB_SIZE/2.0);				if (x2<x1) s = -s;				g.drawLine(x1, y1-s, x1, y1+s);		g.drawLine(x1, y1-s, x1+2*s, y1-s);		g.drawLine(x1, y1+s, x1+2*s, y1+s);		g.drawLine(x1+s, y1-s, x1+s, y1);		g.drawLine(x1+s, y1+s, x1+s, y1);		return;	}*/		int dotSize = view.getDotSize();	int dotSize2 = 2*dotSize;		if (Settings.getInstance().isWireCrossingAvoidiance())		// smart connectors	{		int vx = firstHorizontal ? x2 : x1;				if (out instanceof EPICSLink) {			if (((EPICSLink)out).isRight()) {				int rx=(int)(out.getRightX()*scale)  - view.getRx();				if (vx<rx) vx = rx;			} else {				int lx=(int)(out.getLeftX()*scale)  - view.getRx();				if (vx>lx) vx = lx;			}		}				if (in instanceof EPICSLink) {			if (((EPICSLink)in).isRight()) {				int rx=(int)(in.getRightX()*scale)  - view.getRx();				if (vx<rx) vx = rx;			} else {				int lx=(int)(in.getLeftX()*scale)  - view.getRx();				if (vx>lx) vx = lx;			}		}				/*if (in instanceof Field) {			int n = ((Field)in).getVerticalPosition();			int f = (int)(Constants.LINK_SLOT_WIDTH * n * scale);					if (in.isRight()) vx += f; else vx -= f;		}	*/				if (in!=null) {			g.drawLine(x1,y1,vx,y1);  // --->			g.drawLine(vx,y1,vx,y2); //      |			g.drawLine(vx,y2,x2,y2); //      <-----			if (in instanceof MultiInLink && ((MultiInLink)in).getLinkCount() > 1)			{				g.fillOval(vx-dotSize, y1-dotSize, dotSize2, dotSize2);				g.fillOval(vx-dotSize, y2-dotSize, dotSize2, dotSize2);			}			// tails to be drawn to cover distance -?[ (where ? is)			final double rlsw = Constants.LINK_SLOT_WIDTH*scale;			//line for out			if (out instanceof Field) {				if (out.isRight())					g.drawLine(x1,y1,x1-(int)(((Field)out).getVerticalPosition()*rlsw),y1);				else 					g.drawLine(x1,y1,x1+(int)(((Field)out).getVerticalPosition()*rlsw),y1);			}						//line for int			if (in instanceof Field) {				if (in.isRight()) 					g.drawLine(x2,y2,x2-(int)(((Field)in).getVerticalPosition()*rlsw),y2);				else 					g.drawLine(x2,y2,x2+(int)(((Field)in).getVerticalPosition()*rlsw),y2);			}		}	}	else	{	    if (in!=null) {			if (firstHorizontal) {					g.drawLine(x1, y1, x2, y1);				g.drawLine(x2, y1, x2, y2);				if (in instanceof MultiInLink && ((MultiInLink)in).getLinkCount() > 1)				{					g.fillOval(x2-dotSize, y1-dotSize, dotSize2, dotSize2);					g.fillOval(x2-dotSize, y2-dotSize, dotSize2, dotSize2);				}			}			else {				g.drawLine(x1, y1, x1, y2);				g.drawLine(x1, y2, x2, y2);				if (in instanceof MultiInLink && ((MultiInLink)in).getLinkCount() > 1)				{					g.fillOval(x1-dotSize, y2-dotSize, dotSize2, dotSize2);					g.fillOval(x2-dotSize, y2-dotSize, dotSize2, dotSize2);				}			}	    }	}}