prmr / JetUML

A desktop application for fast UML diagramming.
GNU General Public License v3.0
622 stars 121 forks source link

Add copy-and-paste feature #12

Closed prmr closed 9 years ago

JoelChev commented 9 years ago

@prmr I have been looking at this problem a bit and I think I may need to implement a means of converting a SelectionList to a Graph. Do you think this will be necessary, or would there be an easier way to copy and paste the contents of a GraphPanel? I'm trying to work from the copy+paste feature of Violet 0.23 right now as a template, but their method is based on a Graph being the object created on a mouse-drag selection, not GraphElements being added to a SelectionList. Any tips or pointers would be appreciated.

prmr commented 9 years ago

There's only one graph per panel, so you would want to go through the selection list and add the elements in the selection to the existing graph (and remove them from the original one in the case of cut). They are cloneable so that part should not be too hard. However, the more interesting bit here is to carefully specify the behavior of cut and paste. For instance, if should only work for nodes, but copying multiple nodes should include the edges between them, etc.

prmr commented 9 years ago

Actually the cut part should just work because GraphPanel.removeSelected() does the right thing. However, implementing the pasting behavior will require a more systematic study. Don't base yourself on the 0.21 behavior because it's highly unsatisfactory. For example, if you cut an edge and paste it, a node appears!

prmr commented 9 years ago

Final comment for now: why not start a wiki page with the specification of the Copy-and-Paste Behavior?

JoelChev commented 9 years ago

@prmr I just wrote a wiki page describing the behaviour as I see it. If you think I am missing anything or if you want anything else added, please feel free to edit it. I will think about this problem some more, but I think some major redesign work may be necessary for the pasting part of the operation (I don't believe copying will be too difficult to implement).

prmr commented 9 years ago

I'm not sure we need a big redesign. IMO inheriting Clipboard from Graph as in 0.23 is overkill for our needs. I've just committed some code to branch 0012 that sketches a solution. Look at class Clipboard and methods cut, copy, and paste in EditorFrame. Implementing these, and the required services in GraphPanel, should get you closer to something quite workable.

JoelChev commented 9 years ago

@prmr I've made some progress on the copy, paste and cut features. I'm able to successfully copy/cut and paste nodes on simple diagrams (Class and Object diagrams) without children nodes. I'm going to add in the children node support (for sequence diagrams) later. The only issue I'm running into however, is that I don't think Edges are being selected/added into the SelectionList on mouse drags when in "Select Mode" (they are properly added if you CTRL-Click on them and nodes in "Select Mode" however). Is this the intended design of SelectionList when selecting with Mouse drags?

The next step I hope to do is to get edges to be properly copied/cut and pasted. I have not implemented functionality for pasting or working with these yet as I wanted to make sure I could get Nodes working first. Once I have this in place, I will get children node support in place and then this feature should be ready for testing.

On a side note, I saw your Clipboard class template and unfortunately I had already started implementing my own Clipbard class design. While mine is a little different than yours, I plan on refactoring my code as I currently have a lot of the copy/cut and paste logic in the EditorFrame class which I think would be better put in the Clipboard class. Thank you for all the help with this issue, I will keep you updated with my progress.

JoelChev commented 9 years ago

@prmr I have now got copy+paste working on all diagram types, except for sequence type diagrams. For whatever reason, when I try to copy and paste those types of diagrams, I get really buggy behavior (I don't know why). I think there is something going on with the setting of children/parent nodes that I'm not seeing, but I will keep trying a few more things to get it working. I'm going to try to get a working version of cut going, then I will commit what I have so far.

prmr commented 9 years ago

Good to know, I'll look at the code for this diagram.

JoelChev commented 9 years ago

Alright, I just committed what I have been able to do with cutting, copying and pasting. @prmr There are still bugs with pasting onto Sequence Diagrams, but everything else seems to be behaving normally. @EJBQ, I have not implemented any functionality for "undoing" or "redoing" a cut, copy or paste action. You will have to figure out a way to implement this, but I am totally open to you modifying my design in any way if you need to for your part of Milestone 2. If anything I have done is unclear, please let me know and I will try to explain what I did here.

I had to modify a few other things in JetUML too, including how edges are selected (now if you drag over an edge in "Select-Mode" with the "Click-Down-Lasso" and both its endpoints have been selected, it is automatically selected). I also updated how children Arraylists are handled in the AbstractNode class during the clone method(before it was giving me IndexOutOfBounds errors when I tried to clone the children of nodes). Anyways, if either of you can please check out my commit and make sure it works properly, I would appreciate it. Thanks!

prmr commented 9 years ago

I've noticed some problems with object diagrams, now even unrelated to cut-and-paste. For example, if you have two object nodes linked by an edge and delete one of the nodes, the edge remains. When copying multiple times the same clipboard object, things get really messed up.

JoelChev commented 9 years ago

@prmr Yeah, I will look into the object diagram problem a bit. Another bug I found involved Note Nodes on Class Diagrams. Steps to reproduce:

  1. Create a Note Node in a Class Diagram
  2. Add a Note Connector with the start end being the Note Node and the End Node being either white space or another Node
  3. Notice that the edge either ends in white space or does not connect to the End Node desired.

Interestingly, if you try to start a Note Edge in a non-Note Node, it behaves properly. I'm not sure what is going on her either, but I can try to look into it as well.

JoelChev commented 9 years ago

@prmr I think I may have remedied the Object Diagram bugs you listed above, but I'm not sure if other bugs still remain with Object Diagrams and their edges. Please let me know if you see anything in the latest commit and I will look at it more. Sequence Diagrams are still quite buggy.

JoelChev commented 9 years ago

Alright, I have refactored the code so that the logic is now in the Clipboard class itself. I am still noticing some buggy behavior with Object and Sequence diagrams (I will have to look more into this), but for now, the basic logic is in place and the code is in the class where it belongs. If you guys notice any other mistakes or errors, please let me know. Thanks!

prmr commented 9 years ago

Parent-Child Relation in Sequence Diagrams

(this comment is also relevant to @EJBQ 's work) It seems a lot of the friction you are experiencing comes from the fact that in sequence diagrams the parent-child relation is defined to map to the parent-child node in the corresponding call graph. This is not actually what we really need for a diagram editor. Instead, in all diagrams the parent-child node relation should be defined as "child node is semantically a component of the parent) (e.g., field nodes in the object diagram). I started a wiki page to document the parent-child relations

JoelChev commented 9 years ago

@prmr @EJBQ I forgot to tag my recent commits with a #12 (my bad, I will do this again from now on). In my recent two commits, I have fixed two major bugs:

  1. The duplication/buggy behavior of Field Nodes that lay inside ObjectNodes when they are cloned. Now the copying/cutting and pasting behaves as it should for this diagram.
  2. The weird bug that prevented diagrams from being translated if an edge was in the SelectionList. I had to modify the SelectionList class to make this work properly, essentially, it needed a getLastNode() method not a getLastSelected() method (as an Edge can be the last element in the SelectionList). Take a look at my additions to the GraphPanel and SelectionList classes if this seems confusing.

Anyways, I encourage you guys to check out my latest commit to this branch and play around with it and make sure both issues have been fixed. I will be working on fixing the Sequence Diagram bugs between now and our next meeting. Thanks!

JoelChev commented 9 years ago

I have taken a look into the Sequence Diagram issue a bit, and it is still giving me issues. I think we need to decide as a group if we want to redesign this or not. As you mentioned @prmr, CallNodes can have CallNode children (which to me seems like an odd way to organize things). I would much rather see CallNodes by default be children of ImplicitParameterNodes (unless they are created by a self-call). I don't know what you guys think about this, but I am open to discussing this at our next meeting in further detail.

EJBQ commented 9 years ago

While testing I found a new issue with pasting and the undo system, as well as an issue with double pasting. I'm delaying the release by a day while I fix this.

EJBQ commented 9 years ago

The undoing issue is solved, just waiting on @JoelChev to look at double pasting.

JoelChev commented 9 years ago

@EJBQ @prmr I believe I have solved the double pasting bug, but it involved me modifying the addNode() method of the Graph class. If either of you can please check out #13's latest commit and play around with double pasting nodes with edges (so copy/cut nodes with edges between them, then paste them two or more times in a row), I would appreciate it. Thanks!