How to draw any shape i like

General discussions about code engineering

Moderator: Moderators

How to draw any shape i like

Postby Zellax » Thu Jun 07, 2012 3:30 am

Magicdraw OpenAPI UserGuide says a presentation element is a textual or graphical presentation of one or more model elements.
And 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 drawing a diamond instead of original rectangle 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: How to draw any shape i like

Postby saulius_p » Fri Jun 15, 2012 1:25 am

Dear Jing XU,

Thank you for your questions. We are locking this topic as duplicated. Lets continue discussion at:
draw-specific-shapes-of-elements-displayed-in-a-diagram-t2285.html
Best regards,
Saulius Pavalkis
User avatar
saulius_p
No Magic
No Magic
 
Posts: 259
Posts Rating:8
Joined: Fri Dec 04, 2009 5:37 am
Full name: Saulius Pavalkis


Return to Code engineering

Who is online

Users browsing this forum: No registered users and 0 guests

cron