Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 230079

Summary: draw2d.Label alignment misleading
Product: [Tools] GEF Reporter: Christian M. Schweda <schweda>
Component: GEF-Legacy Draw2dAssignee: gef-inbox <gef-inbox>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: ahunter.eclipse, nyssen
Version: 3.3   
Target Milestone: ---   
Hardware: PC   
OS: Windows Vista   
Whiteboard:
Attachments:
Description Flags
Proposal for an adapted calculateLocations() Method none

Description Christian M. Schweda CLA 2008-05-03 15:19:58 EDT
Created attachment 98538 [details]
Proposal for an adapted calculateLocations() Method

Build ID: I20070621-1340

Steps To Reproduce:
When you use the labelAlignment property, you can (as it is realized as an int-bitarray) e.g. set the label to LEFT and TOP. Nevertheless, the label is not correctly aligned, in this particular case LEFT will be applied, ignoring TOP. 

Potential cause:
Maybe, I am missing a point how to use this method - if not, the implementation of org.eclipse.draw2d.Label#calculateLocations() might cause this behavior. Imho, the switch-block is not correct and should be replaced by respective if-statements.
Comment 1 Anthony Hunter CLA 2008-10-15 14:12:06 EDT
Hi Christian,

I need you to attach a patch so we can determine the changes made to the code. You attached the entire Label class.
Comment 2 Christian M. Schweda CLA 2008-10-16 02:11:39 EDT
Hi Anthony,

sorry for providing the entire class. Below, I provide a snippet of the old implementation and add the potential fix, I thought of:
<Old>
private void calculateLocations() {
//...
switch (labelAlignment) {
  case CENTER: 
    offset.scale(0.5f);
    break;
  case LEFT: 
    offset.scale(0.0f);
    break;
  case RIGHT: 
    offset.scale(1.0f); 
    break;
  case TOP: 
    offset.height = 0; 
    offset.scale(0.5f); 
    break;
  case BOTTOM: 
    offset.height = offset.height * 2; 
    offset.scale(0.5f); 
    break;
  default: 
    offset.scale(0.5f); 
    break;
}
//...
</Old>
This first switch block should be replaced by the two if-statements as below.
<New>
private void calculateLocations() {
//...
if ((this.labelAlignment & LEFT) != 0) {
  offset.width = 0;
} else if ((this.labelAlignment & CENTER) != 0) {
  offset.width /= 2;
}
if ((this.labelAlignment & TOP) != 0) {
  offset.height = 0;
} else if ((this.labelAlignment & MIDDLE) != 0) {
  offset.height /= 2;
}
//...
</New>
Hope, this comment is helpful - sorry again for not directly adding a patch - I am not that deep into the bugzilla thing.
Comment 3 Anthony Hunter CLA 2009-04-02 13:37:37 EDT
Hi Christian, I really need a patch contribution so we can add to the IP Log.

Did you need help with this?
Comment 4 Alexander Nyßen CLA 2011-09-30 16:43:32 EDT
According to its internal design and its documentation, Label is not intended to support boolean combinations of horizontal and vertical alignments, but allows only label alignments of LEFT, TOP, RIGHT, CENTER, or BOTTOM. Closing this thus as invalid. Please re-open a separate feature request if you need to have support for additional alignments.