Draw specific shapes of elements, displayed in a diagram

General discussions about code engineering

Moderator: Moderators

Draw specific shapes of elements, displayed in a diagram

Postby Zellax » Mon Jun 11, 2012 3:10 am

The sample plug-in SymbolRendering shows that we can provide a new renderer.
Like this, I have written a new renderer, named mClassRenderer. My goal is to draw a diamond shape instead of original rectangle shape of Class.
My English is so-so, maybe the following picture can make clear.

The following picture is a normal class, its shape is a rectangle.
Image

The following picture is my class, its shape is a diamond.
Image
Its name is Hello2, and it has one attribute named q. This is its specification.
Image
Image

But why its name and attribute has not displayed in the diagram?

The following code is my work in class RendererProvider.
Code: Select all
public class RendererProvider implements PresentationElementRendererProvider
{
   private DependencyRenderer mDependencyRenderer;
   private MyClassRenderer mClassRenderer;
   private PackageRenderer mPackageRenderer;
   private SlotRenderer mSlotRenderer;
   
   public RendererProvider()
   {
      mDependencyRenderer = new DependencyRenderer();
                ...
               mClassRenderer = new MyClassRenderer();
   }

   public PresentationElementRenderer getRenderer(PresentationElement presentationElement)
   {
      if (presentationElement instanceof DependencyView)
      {
         return mDependencyRenderer;
      }
   
      if (presentationElement instanceof ClassView)
      {
                       return mClassRenderer;
      }
           ...

      return null;
   }

}


The following is the code of class MyClassRenderer.
Code: Select all
public class MyClassRenderer extends ShapeRenderer {
   public void draw(Graphics g, PresentationElement presentationElement) {
      Rectangle r = presentationElement.getBounds();
      int x0 = r.x;
      int y0 = r.y;
      int xStep = r.width / 3;
      int yStep = r.height / 4;
      int xPoints[] = { x0, x0 + r.width / 2, x0 + r.width, x0 + r.width / 2 };
      int yPoints[] = { y0 + r.height / 2, y0, y0 + r.height / 2, y0 + r.height };
                g.drawPolygon(xPoints, yPoints, 4);
   }

}


Could you help me?? :cry: :cry:

Thanks.
Jing XU
Zellax
Forum Newbie
Forum Newbie
 
Posts: 4
Posts Rating:0
Joined: Thu Jun 07, 2012 2:46 am

Re: Draw specific shapes of elements, displayed in a diagram

Postby mindaugas.genutis » Mon Jun 18, 2012 6:16 am

Dear Jing XU,

With ShapeRenderer you may decorate the symbol or completely change it. It is not easy to remove parts of old drawing and reuse some of them.
Here would be a not so perfect workaround:

In the draw() method do your drawing and later invoke drawing of symbol's inner elements, for example:

Code: Select all
((ClassView)presentationElement).getHeaderView().getNameLabel().draw(g);


Yours Sincerely,

-- Mindaugas Genutis
User avatar
mindaugas.genutis
Customer Support
Customer Support
 
Posts: 510
Posts Rating:37
Joined: Thu Feb 04, 2010 1:57 am
Location: Kaunas

Re: Draw specific shapes of elements, displayed in a diagram

Postby Zellax » Mon Jun 18, 2012 6:30 am

mindaugas.genutis wrote:Dear Jing XU,

With ShapeRenderer you may decorate the symbol or completely change it. It is not easy to remove parts of old drawing and reuse some of them.
Here would be a not so perfect workaround:

In the draw() method do your drawing and later invoke drawing of symbol's inner elements, for example:

Code: Select all
((ClassView)presentationElement).getHeaderView().getNameLabel().draw(g);


Yours Sincerely,

-- Mindaugas Genutis


Thank you for your reply.
Zellax
Forum Newbie
Forum Newbie
 
Posts: 4
Posts Rating:0
Joined: Thu Jun 07, 2012 2:46 am


Return to Code engineering

Who is online

Users browsing this forum: No registered users and 0 guests

cron