gt:             x1 += w2 - getMinimizedRadius();
context: package no.hiof.skaalsveen.eskerud.olsen.prototype2.components;
  
  import android.graphics.Canvas;
  import android.graphics.Color;
  import android.graphics.Paint;
  import android.graphics.Paint.Align;
  import android.util.Log;
  
  import java.util.ArrayList;
  
  import no.hiof.skaalsveen.eskerud.olsen.prototype2.CustomDrawableView;
  
  public class RoomNode extends ChildEnabledGraphNode {
  
  	public static final String TAG = "RoomNode";
      private static final int LOW_ALPHA = 100;
      private static final int HIGH_ALPHA = 255;
      public static final float MAX_RADIUS = 50f;
  
      private static final double MOVE_FOCUSED_NODE_THRESHOLD = MAX_RADIUS;
      //does this do anything?
      //private final Paint ghostPaint;
      private final CustomDrawableView customDrawableView;
      //private int[] childrenTouchMap;
  
  	//public float fx, fy;
  	private Paint textPaint;
  	private float extra_margin = 20;
      private int minimizedRadius =40;
      private int requestLeft;
      //private float startX, startY;
      private float ghostX, ghostY;
      private float alternativeRadius = MAX_RADIUS;
      private int activeChildren2;
      //private DeviceNode hoverChild;
      //private int d1 = 0;
  
      private boolean ghost;
      private boolean isInteractable;
  
      @Override
      protected String getDebugInfo() {
          String debugInfo = super.getDebugInfo();
          debugInfo+= "\n isInteractable="+fromBoolean(isInteractable);
          debugInfo+= "\n interactionDisabled="+fromBoolean(interactionDisabled);
          debugInfo+= "\n activeChildren2="+activeChildren2;
  
          return debugInfo;
      }
  
      @Override
      protected void onFingerDown(float pressedPositionX, float pressedPositionY) {
  
      }
  
      public RoomNode(String name, Paint textPaint, CustomDrawableView customDrawableView) {
  		super(name, customDrawableView.getActivityEventListener(), customDrawableView.getDPI());
  
          this.customDrawableView = customDrawableView;
  		this.ox = 0;
  		this.oy = 0;
  
  		this.textPaint = textPaint;
  		textPaint.setAntiAlias(true);
  		textPaint.setColor(Color.BLACK);
  		textPaint.setTextAlign(Align.CENTER);
  
  		int textSize = 42;
  		int margin = 4;
  
  		do {
  
  			textPaint.setTextSize(textSize--);
  
  		} while (textPaint.measureText(name) > (getRadius() - margin) * 2);
  
      }
  
      @Override
      protected boolean outsideThreshold(double deltaPosition) {
          if(isChildrenVisible()){
              alpha = 0;
          }
          return super.outsideThreshold(deltaPosition);
      }
  
      @Override
  	public void draw(Canvas canvas) {
          float tx, ty;
  
          if(ghost){
              canvas.drawCircle(ghostX, ghostY, getRadius(), paint);
              tx = ghostX;
              ty = ghostY;
          }
          else{
              if(interactionDisabled){
                  if(!isInteractable){
                      paint.setColor(Color.BLACK);
                  }
                  else {
                      paint.setColor(Color.GRAY);
                  }
              }
  
              canvas.drawCircle(ox, oy, getRadius(), paint);
              tx = ox;
              ty = oy;
          }
  
          textPaint.setColor((minimized ? Color.BLUE : Color.RED));
  
  		canvas.drawText(name, tx, ty + 10.5f, textPaint);
  
          super.draw(canvas);
  
  	}
  
      /**
  	 * While coordinates are different from actual position, approach position.
  	 * 
  	 * */
  	@Override
  	public void update(long tpf) {
  
          //radius = getRadius();
  		super.update(tpf);
  
          activeChildren2 = 0;
          for (DeviceNode child : children) {
              activeChildren2 += (child.isMoving ? 1 : 0);
          }
  
  
  
  	}
  
  
  
      @Override
      public float getRadius() {
  
          int dpi = getDPI();
  
          if(isChildrenVisible()){
              return (alternativeRadius / STANDARD_DPI) * dpi;
          }
          else{
              return super.getRadius();
          }
  
      }
  
      @Override
      protected void onStartMove() {
          resetAlpha();
      }
  
      @Override
      public void setPlacement(float[] po) {
          if(po != null && po.length > 1) {
              moveTo(po[0], po[1]);
          }
      }
  
  	public void prepDelta() {
  		useTheForce = true;
  		socialfx = 0;
  		socialfy = 0;
  	}
  
  	public boolean trySet(float x, float y) {
          isInteractable = false;
  
  //        d1 = 0;
          if(activeChildren2 > 0 || interactionDisabled){
              isInteractable = false;
              return false;
  
          }
  
          saveCursor(x,y);
          double threshold = getMoveFocusedNodeThreshold();//getRadius() + extra_margin;
          if (getDistanceTo(x,y) < threshold || isMovable) {
  
              if(isMovable){
  
                  ghost = false;
                  alpha = HIGH_ALPHA;
  //                childrenVisible = false;
                  moveTo(x,y);
              }
              else if(isChildrenVisible()){
                  ghostX = x;
                  ghostY = y;
                  ghost = true;
  
                  float distance2 = (float) Math.sqrt(Math.pow(x - pressedPositionX, 2)
                          + Math.pow(y - pressedPositionY, 2));
                  alpha = (int)((255/ threshold) * (threshold - distance2));
  
                  //alternativeRadius = minimizedRadius + (int) ((MAX_RADIUS-minimizedRadius)/threshold * (threshold - distance2));
              } else if(!isMovable){
                  Log.e(TAG, "immovable object: "+this);
  
              }
  
              isInteractable = true;
  		}
  
  
  		return isInteractable;
  	}
  
      private double getMoveFocusedNodeThreshold() {
          return getRadius() + extra_margin;//MOVE_FOCUSED_NODE_THRESHOLD;
      }
  
  
      @Override
      protected void onFingerUp() {
  
          alternativeRadius = MAX_RADIUS;
          resetAlpha();
      }
  
  
  
      public void forceSet(float x, float y) { // used for moving nodes by hand & zooming
          setX(x);
          setY(y);
  	}
  
  	public int getFingersInsideRadius(float[] fingerPositionsX,
  			float[] fingerPositionsY) {
  
  		int fingers = 0;
  		for (int i = 0; i < fingerPositionsX.length; i++) {
  			if (Math.sqrt(Math.pow(fingerPositionsX[i] - ox, 2)
  					+ Math.pow(fingerPositionsY[i] - oy, 2)) < getRadius() + 20) {
  				fingers++;
  			}
  		}
  
  		return fingers;
  	}
  
  	public void applyCenterScreenForce(int width, int height) {
  
  	}
  
      @Override
      public String toString() {
  
          return "DeviceNode[" + name+ "]";
      }
  
  
  
      public void place(ArrayList<RoomNode> roomNodes, float width) {
  
          Log.d(TAG, this + " I will now try to place myself... ");
  
          float x1 = getX();
  
          while(isVerticallyInsideNode(roomNodes, x1)){
              float halfWidth = (width / 2);
              float wr = halfWidth - getMinimizedRadius();
              x1 = (float) (Math.random() * wr);
              x1 = subtractEdges(x1, halfWidth);
          }
          moveX(x1);
  
      }
  
      private float subtractEdges(float x1, float w2) {
          if(w2 < getX()){
  