Skip to content

Commit

Permalink
POC - adjust text box position in relation to iconic image
Browse files Browse the repository at this point in the history
- This is not so good if the image is big
  • Loading branch information
Phillipus committed Jan 17, 2024
1 parent cfeb54f commit d370525
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,59 @@ protected int getTextControlMarginHeight() {
return 4;
}

/**
* @return The tex control area taking into account user icon
*/
public Rectangle getTextControlBoundsWithIconImageOffset() {
Rectangle rectWithImageOffset = getBounds().getCopy();

if(getIconicDelegate() == null || getIconicDelegate().getImage() == null || !(getDiagramModelObject() instanceof IIconic)) {
return rectWithImageOffset;
}

IIconic dmo = (IIconic)getDiagramModelObject();
org.eclipse.swt.graphics.Rectangle imageBounds = getIconicDelegate().getImage().getBounds();

// Add 1 pixel for some space
imageBounds.width++;

int imagePosition = dmo.getImagePosition();
//int textAlignment = dmo.getTextAlignment();
int textPosition = ((ITextPosition)dmo).getTextPosition();

if(textPosition == ITextPosition.TEXT_POSITION_TOP) {
if(imagePosition == IIconic.ICON_POSITION_TOP_RIGHT) {
rectWithImageOffset.width -= imageBounds.width;
}
if(imagePosition == IIconic.ICON_POSITION_TOP_LEFT) {
rectWithImageOffset.x += imageBounds.width;
rectWithImageOffset.width -= imageBounds.width;
}
}

if(textPosition == ITextPosition.TEXT_POSITION_CENTRE) {
if(imagePosition == IIconic.ICON_POSITION_MIDDLE_RIGHT) {
rectWithImageOffset.width -= imageBounds.width;
}
if(imagePosition == IIconic.ICON_POSITION_MIDDLE_LEFT) {
rectWithImageOffset.x += imageBounds.width;
rectWithImageOffset.width -= imageBounds.width;
}
}

if(textPosition == ITextPosition.TEXT_POSITION_BOTTOM) {
if(imagePosition == IIconic.ICON_POSITION_BOTTOM_RIGHT) {
rectWithImageOffset.width -= imageBounds.width;
}
if(imagePosition == IIconic.ICON_POSITION_BOTTOM_LEFT) {
rectWithImageOffset.x += imageBounds.width;
rectWithImageOffset.width -= imageBounds.width;
}
}

return rectWithImageOffset;
}

/**
* Calculate the Text Control Bounds or null if none.
*/
Expand All @@ -295,20 +348,19 @@ protected Rectangle calculateTextControlBounds() {
}
}

// We will adjust for any internal icons...
Rectangle rect = getTextControlBoundsWithIconImageOffset();

// If there is no icon offset or the icon is not visible we don't need to do any offsets
if(getIconOffset() == 0 || !isIconVisible()) {
return null;
return rect;
}

// Adjust for icon offset and left/right margins
int iconOffset = getIconOffset() - getTextControlMarginWidth();

Rectangle rect = getBounds().getCopy();
// Adjust for icon offset and left/right margins

// Text position is Top
if(((ITextPosition)getDiagramModelObject()).getTextPosition() == ITextPosition.TEXT_POSITION_TOP) {
if(rect.equals(getBounds()) && ((ITextPosition)getDiagramModelObject()).getTextPosition() == ITextPosition.TEXT_POSITION_TOP) {
int iconOffset = getIconOffset() - getTextControlMarginWidth();

int textAlignment = getDiagramModelObject().getTextAlignment();

if(textAlignment == ITextAlignment.TEXT_ALIGNMENT_CENTER) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import org.eclipse.swt.graphics.Path;
import org.eclipse.swt.graphics.Pattern;

import com.archimatetool.editor.diagram.figures.AbstractDiagramModelObjectFigure;
import com.archimatetool.editor.diagram.figures.AbstractFigureDelegate;
import com.archimatetool.editor.diagram.figures.AbstractTextControlContainerFigure;
import com.archimatetool.editor.ui.ColorFactory;
import com.archimatetool.model.ITextAlignment;
import com.archimatetool.model.ITextPosition;
Expand All @@ -26,7 +26,7 @@ public class BoxFigureDelegate extends AbstractFigureDelegate {

private static final int EDGE_SIZE = 14;

public BoxFigureDelegate(AbstractDiagramModelObjectFigure owner) {
public BoxFigureDelegate(AbstractTextControlContainerFigure owner) {
super(owner);
}

Expand Down Expand Up @@ -99,7 +99,7 @@ public void drawFigure(Graphics graphics) {

@Override
public Rectangle calculateTextControlBounds() {
Rectangle rect = getBounds();
Rectangle rect = ((AbstractTextControlContainerFigure)getOwner()).getTextControlBoundsWithIconImageOffset();

int textPosition = ((ITextPosition)getOwner().getDiagramModelObject()).getTextPosition();
int textAlignment = getOwner().getDiagramModelObject().getTextAlignment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void drawFigure(Graphics graphics) {
public Rectangle calculateTextControlBounds() {
int textPosition = ((ITextPosition)getDiagramModelObject()).getTextPosition();
if(textPosition == ITextPosition.TEXT_POSITION_BOTTOM) {
Rectangle bounds = getBounds();
Rectangle bounds = getTextControlBoundsWithIconImageOffset();
bounds.y -= TOP_MARGIN - getTextControlMarginHeight();
return bounds;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void drawFigure(Graphics graphics) {

@Override
public Rectangle calculateTextControlBounds() {
Rectangle bounds = getBounds();
Rectangle bounds = getTextControlBoundsWithIconImageOffset();

int textPosition = ((ITextPosition)getDiagramModelObject()).getTextPosition();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void drawFigure(Graphics graphics) {

@Override
public Rectangle calculateTextControlBounds() {
Rectangle bounds = getBounds();
Rectangle bounds = getTextControlBoundsWithIconImageOffset();

int textPosition = ((ITextPosition)getDiagramModelObject()).getTextPosition();

Expand Down

0 comments on commit d370525

Please sign in to comment.