Horizontal line cell

Hello MPS team,

I would like to draw a seperating horizontal line in the editor. I have already managed to draw a fixed size (in pixels) horizontal line (using a java swing component).

Now I'd like to get the current editor total width in pixels to adapt its size automatically

Can I get that information from the editor context, or is there any better alternatives ?

Thanks and best regards,

Etienne
2 comments
Hi Etienne,

months ago, I found an implementation for a Horizonal-Line Cell provider that increases the line length with increasing reference cell width. I don'r remember where I found it. ;) But here is it:

public class HorizontalLineCellProvider extends AbstractCellProvider { 
  private SNode myNode; 
   
  public HorizontalLineCellProvider(node<> node) { 
    this.myNode = node; 
  } 
  @Override 
  public EditorCell createEditorCell(EditorContext p0) { 
    EditorCell_Basic result = new EditorCell_Basic(p0, HorizontalLineCellProvider.this.myNode) { 
      @Override 
      public void paintContent(Graphics g, ParentSettings parentSettings) { 
        if (this.isSelectionPaintedOnAncestor(parentSettings).isSelectionPainted()) { 
          g.setColor(Color.WHITE); 
        } else { 
          g.setColor(Color.BLACK); 
        } 
        int x = this.getParent().getX(); 
        int width = this.getParent().getWidth(); 
        this.setWidth(width); 
        this.setX(x); 
        g.fillRect(x, this.getY() + 1, width, 1); 
      } 
      @Override 
      public int getAscent() { 
        return this.getPrevLeaf().getHeight() / 4; 
      } 
      @Override 
      public void relayoutImpl() { 
        this.myWidth = 20; 
        this.myHeight = 3; 
      } 
    }; 
    return result; 
  } 
   
}

prettyPrint();
I hope that helps!

Regards,
LaAck
1

Please sign in to leave a comment.