Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) DrawingER diagram (Read 5999 times)
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
DrawingER diagram
Aug 31st, 2015 at 1:42pm
Print Post  
Hello,
I saw that touching on the screen it is possible to draw rectangle,
I would like to know if it is possible to draw rhombus too touching the screen and distinguish between the two shapes.
In alternative, I wrote a code in which I have a NodeListView where I can take the shapes and put them on the DiagramView but the problem is that in this way I can't modify the nodes. I would like to let the user click on a shape in the NodeListView and then open a dialog in which the user can insert the name of the node but it doesn't work, here is the code:

final String shapes[] =
                {
                        "Rectangle", "Ellipse", "Decision"
                };


       List<DiagramNode> nodes = new ArrayList<DiagramNode>();

        for (String shape : shapes)
        {
            final ShapeNode p = new ShapeNode(diagram);
            p.setShape(Shape.fromId(shape));
            Pen pen = new Pen();
            pen.setColor(Color.RED);
            p.setPen(pen);
            p.resizeToFitText(FitSize.KeepRatio);
            //p.setText("entity");

            final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity);
            alertDialogBuilder.setMessage(R.string.nameE);
            final EditText nameE = new EditText(activity);
            alertDialogBuilder.setPositiveButton(R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    //TODO mettere messaggio che bisogna mettere nome
                }
            });
            final ShapeNode finalNode = p;
            alertDialogBuilder.setNegativeButton(R.string.yes, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {

                    if (nameE.getText().toString().equals("")) {
                        return;
                    }
                    String sname = nameE.getText().toString();
                    //entityName.setText(sname);
                    //item.setName(sname);
                    //entityName.setText(item.getName());
                    //TODO settera il nome all'item
                    finalNode.setText(sname);
                    Pen pen = new Pen();
                    pen.setColor(Color.RED);
                    finalNode.setPen(pen);
                }
            });

            // create alert dialog
            AlertDialog alertDialog = alertDialogBuilder.create();
            alertDialog.setView(nameE);
            nameE.requestFocus();
            // show it
            alertDialog.show();

            diagram.setLinkText("Relation");
            nodes.add(p);


        }

        nodeListView.addNodes(nodes, shapes);
        diagramView = (DiagramView)findViewById(R.id.diag_view);
        nodeListView.setDiagramView(diagramView);
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: DrawingER diagram
Reply #1 - Aug 31st, 2015 at 1:57pm
Print Post  
You can change what kind of shapes are drawn interactively by setting Diagram.DefaultShape property:

Code
Select All
diagram.setDefaultShape(Shape.fromId("Decision")); 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: DrawingER diagram
Reply #2 - Aug 31st, 2015 at 2:26pm
Print Post  
Hi, thank you very much..
I've already tried that way but it doesn't work anyway, it drew only rectangles.
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: DrawingER diagram
Reply #3 - Aug 31st, 2015 at 2:53pm
Print Post  
Sorry, you are right, I tried again and know it works, maybe before I did something wrong.
Thank you very much!
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: DrawingER diagram
Reply #4 - Aug 31st, 2015 at 3:27pm
Print Post  
Sorry, I have another problem, in this way it draws rhombus too but it draws the rectangle only when I touched the screen for the first time then all the other times it draws rhombus while I want to draw both rhombus and rectangles any times depending from the user's will
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: DrawingER diagram
Reply #5 - Aug 31st, 2015 at 4:50pm
Print Post  
You could let the user select shapes from context menu or toolbar, whose commands call setDefaultShape(). If you need to determine the shape automatically based on path traced by user's finger, there's no built-in support for that, but you could probably implement it by examining the coordinates reported by touch events. An easy way to collect the touch points is to set DiagramView.Behavior to DrawLinks and Diagram.AllowUnconnectedLinks to true. Then in linkCreated event you will receive a DiagramLink instance whose ControlPoints property contains touch coordinates, and you could replace it with ShapeNode with appropriate shape.
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: DrawingER diagram
Reply #6 - Aug 31st, 2015 at 4:53pm
Print Post  
ok, thank you very much, i'll try...
I have another question, is it possible to give the user the possibility to rotate a ShapeNode?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: DrawingER diagram
Reply #7 - Aug 31st, 2015 at 5:04pm
Print Post  
It's possible by calling node.setEnabledHandles(AdjustmentHandles.All) and then dragging the rotation handle that appears. Multi-touch rotation gesture is not supported at this time.
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: DrawingER diagram
Reply #8 - Aug 31st, 2015 at 5:25pm
Print Post  
Ok, I tried and it works, thank you...
Sorry but know I have another doubt, is there a way to open a dialog every time the user creates a link? I mean can I add an event when the link is created?
Sorry if I ask you all those questions but I tried this library today for the first time and I have some problem in understanding it.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: DrawingER diagram
Reply #9 - Aug 31st, 2015 at 6:27pm
Print Post  
There is a linkCreated event defined in DiagramListener interface and DiagramAdapter class:

Code
Select All
diagram.addDiagramListener(new DiagramAdapter()
{
	@Override
	public void linkCreated(LinkEvent e)
	{
		DiagramLink link = e.getLink();
		// show dialog
	}
}); 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: DrawingER diagram
Reply #10 - Aug 31st, 2015 at 7:03pm
Print Post  
Thank you very much, it works Smiley
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint