Control labels

For a while I have tried to have labels not sit on top of other labels
or nodes with no luck. Whatever I place in value to attempt to
reposition the label does nothing. I have the following in my
positionMidLabel
method.

if (lab instanceof FlowLabel)
{
FlowLabel label = (FlowLabel)lab;
Rectangle labelRectangle = label.getBoundingRect();
Point off = label.getOffset();
Point midpt = label.getMidLabelConnectionPoint(null);

JGoDocument doc = view.getDoc();
JGoListPosition pos = doc.getFirstObjectPos();
while(pos != null)
{
    JGoObject obj = doc.getObjectAtPos(pos);
    pos = doc.getNextObjectPosAtTop(pos);
    if(obj instanceof WorkflowStateNode ||  obj instanceof FlowLabel)
    {
        Rectangle compareRect = obj.getBoundingRect();
        boolean thisLabel = false;
        if(obj instanceof FlowLabel)
        {
            FlowLabel flowLabel  = (FlowLabel)obj;
            if(flowLabel == this.getMidLabel())
                thisLabel = true;
        }    

        if(!thisLabel && labelRectangle.intersects(compareRect))
        {
       
int position = obtainPosition(compareRect,

labelRectangle);
if(position == Rectangle.OUT_TOP)
{
if (midpt != null)
{

        int value =

new Double(((compareRect.getY() + compareRect.getHeight()) -
compareRect.getY()) * 2).intValue();

lab.setSpotLocationOffset(Center, midpt.x , midpt.y + value, off.x,
off.y);
}
}
else if(position == Rectangle.OUT_BOTTOM)
{

}
else if(position == Rectangle.OUT_LEFT)
{

}
else if(position == Rectangle.OUT_RIGHT)
{

}
}
else
{

}
}
}
}
else
{
super.positionMidLabel(lab, ax, ay, bx, by);
}

Just wondering if i’m calling the method setSpotLocationOffset
correctly I. I know that the intersects returns true whenever there is
a collision between a label and a node or other label. However it only
displaces one label and leaves all the other ones as is i.e. sitting on
top of other labels or nodes. Any ideas?

walter any ideas on this. sorry but i really need to solve this

Thank you

I don’t have any comments about where you try to move the label.
Regarding not having all of the labels be moved–are you sure your code is being called for all of the labels? You might need to invoke JGoLink.positionLabels() explicitly on each of the links, if you have been creating all of the links programmatically.

Thank for your reply walter. Im testing it in the processor example
that is provided with jgo in the flowlink class. I have the following
this you can see exactly what I have. Thanks again

protected void positionMidLabel(JGoObject lab, int ax, int ay, int bx, int by)
{
if (lab instanceof FlowLabel)
{
FlowLabel label = (FlowLabel)lab;
Rectangle labelRectangle = label.getBoundingRect();
Point off = label.getOffset();
Point midpt = label.getMidLabelConnectionPoint(null);

        //doc is passed to the constructor which comes from line
        //266  of

ProcessDocument FlowLink ll = new FlowLink(from,
//to, this);
JGoListPosition pos = doc.getFirstObjectPos();
while(pos != null)
{
JGoObject obj = doc.getObjectAtPos(pos);
pos = doc.getNextObjectPosAtTop(pos);

if(obj instanceof MultiPortNode ||  obj

instanceof FlowLabel)
{

    Rectangle compareRect =

obj.getBoundingRect();

    boolean thisLabel = false;
       
       
    if(obj instanceof FlowLabel)
       
       
    {
       
       
        FlowLabel

flowLabel = (FlowLabel)obj;

        if(flowLabel

== this.getMidLabel())

thisLabel = true;
       
       
    }    
       
       
    
       
       
    if(!thisLabel &&

labelRectangle.intersects(compareRect))

    {

System.out.println("LAB IS " + label.getText());

        int position =

obtainPosition(compareRect, labelRectangle);

        if(position ==

Rectangle.OUT_TOP)

        {
       
       
       
if (midpt != null) 
       
       
       
{
       
       
       
    int value = new

Double(((compareRect.getY() + compareRect.getHeight()) -
compareRect.getY()) * 2).intValue();

    lab.setSpotLocationOffset(Center,

midpt.x , midpt.y, off.x - value, off.y);

}
       
       
        }
       
       
        else

if(position == Rectangle.OUT_BOTTOM)

        {
       
       
       
if (midpt != null) 
       
       
       
{
       
       
       
    int value = new

Double(((compareRect.getY() + compareRect.getHeight()) -
compareRect.getY()) * 2).intValue();

    lab.setSpotLocationOffset(Center,

midpt.x , midpt.y , off.x + value, off.y);

}
       
       
        }
       
       
        else

if(position == Rectangle.OUT_LEFT)

        {
       
       
       
if (midpt != null) 
       
       
       
{
       
       
       
    int value = new

Double(((compareRect.getY() + compareRect.getHeight()) -
compareRect.getY()) * 2).intValue();

    lab.setSpotLocationOffset(Center,

midpt.x , midpt.y , off.x, off.y - value);

}
       
       
        }
       
       
        else

if(position == Rectangle.OUT_RIGHT)

        {
       
       
       
if (midpt != null) 
       
       
       
{
       
       
       
    int value = new

Double(((compareRect.getY() + compareRect.getHeight()) -
compareRect.getY()) * 2).intValue();

    lab.setSpotLocationOffset(Center,

midpt.x , midpt.y , off.x, off.y + value);

}
       
       
        }
       
       
    }
       
       
    else 
       
       
    {
       
       
       
lab.setSpotLocationOffset(Center, midpt.x, midpt.y,

off.x, off.y);

    }
       
       
    
            }    
        }
    } 
    else 
    {
        super.positionMidLabel(lab, ax, ay, bx, by);
    }

}

private int obtainPosition(Rectangle rectangle, Rectangle currentRect)
{
double x = currentRect.getX();
double y = currentRect.getY();

        int code = rectangle.outcode(x, y);
        if(code == 0)
       
code = rectangle.outcode(x + currentRect.getWidth(),

y);
if(code == 2)
{
return 2;
}
//bottom
else if(code == 8)
{
return 8;
}
//right
else if(code == 4 || code == 6 || code == 12)
{
return 4;
}
//left
else if(code == 1 || code == 3 || code == 9)
{

int secondCode = rectangle.outcode(x +

currentRect.getWidth(), y);
if(code == 9 && secondCode == 8)
{
return 8;
}
else if(code == 3 && secondCode == 2)
{
return 2;
}
else
return 1;
}
return 1;
}

Do you want to call setOffset, to remember the offset? Why are you using offset at all?

Initially I tried changing the x-coordinate or the
y-coordinate of the setSpotLocationOffset method however that seemed to
produce the same result. Im not sure what I need to call or change.
What do you think?

I don’t think you need to consider the offsets at all. Every call to positionLabels will cause all this searching to occur, which will give you a new location for the label. So you can just set its Location. Who cares about the offset?

ok i have tried now simply calling label.setLocation however I still
get the same result. The first label that is dropped is moved but any
additional label always remains in the same location.

Are you sure your code is being called for all of the labels? You might need to invoke JGoLink.positionLabels() explicitly on each of the links, if you have been creating all of the links programmatically.