Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor project to be more OO and add code similarity detection results #4

Merged
merged 6 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
268 changes: 191 additions & 77 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,31 @@

# UML Editor

- [Software Requirements](#software-requirements)
- [Maven Dependencies](#maven-dependencies)
- [Features](#features)
- [GUI Layout and Buttons](#gui-layout-and-buttons)
- [Functions](#functions)
- [Extra Features](#extra-features)
- [Program Flow Overview](#program-flow-overview)
- [Usage](#usage)
- [Build](#build)
- [Run](#run)
- [Class Diagram](#class-diagram)
- [Future Work](#future-work)
- [Project File Structure](#project-file-structure)
- [References](#references)
- [Documentations](#documentations)
- [Related Projects](#related-projects)
- [UML Editor](#uml-editor)
- [Software Requirements](#software-requirements)
- [Maven Dependencies](#maven-dependencies)
- [Features](#features)
- [GUI Layout and Buttons](#gui-layout-and-buttons)
- [Functions](#functions)
- [Extra Features](#extra-features)
- [Usage](#usage)
- [Build](#build)
- [Run](#run)
- [Class Diagram](#class-diagram)
- [Future Work](#future-work)
- [Project File Structure](#project-file-structure)
- [Program Flow Overview](#program-flow-overview)
- [Use Case Sequence Diagram](#use-case-sequence-diagram)
- [A. Creating a UML Object](#a-creating-a-uml-object)
- [B. Creating a UML Connection Line](#b-creating-a-uml-connection-line)
- [C. Select/Unselect a Single Object](#c-selectunselect-a-single-object)
- [D.1 Group Objects](#d1-group-objects)
- [D.2 Ungroup Objects](#d2-ungroup-objects)
- [E. Move Objects](#e-move-objects)
- [F. Change Object Name](#f-change-object-name)
- [References](#references)
- [Documentations](#documentations)
- [Related Projects](#related-projects)

## Software Requirements

Expand Down Expand Up @@ -85,60 +94,7 @@

- [ ] Delete UMLObject

## Program Flow Overview

> [!CAUTION]
> This part will be updated soon.

1. Click Tool Button
2. Mode
1. Create UMLObject
1. Create UMLConnectionLine
2. Create UMLBasicObject
2. Select
1. If selection is UMLObjects
1. can Move (UMLConnectionLine movement are not supported yet.)
2. If selection is UMLBasicObject
1. can change it’s ObjectName
3. If selection is an Area including several UMLObjects
1. can Group
4. If selection is an UMLGroup
1. can UnGroup
3. Canvas Repaint

```mermaid
graph TD
A[Initialize UML Editor] --> B{Button Clicked}
B -->|Select| C[Set Select Mode]
B -->|Association| D[Set Association Mode]
B -->|Generalization| E[Set Generalization Mode]
B -->|Composition| F[Set Composition Mode]
B -->|Class| G[Set Class Creation Mode]
B -->|Use Case| H[Set Use Case Creation Mode]
C --> I{Mouse Event on Canvas}
D --> I
E --> I
F --> I
G --> I
H --> I
I -->|Left Click on Object| J[Select/Unselect Object]
I -->|Left Click on Canvas| K[Unselect All Objects]
I -->|Left Press on Object| L[Start Line Creation]
I -->|Mouse Drag| M[Update Line Endpoint]
I -->|Left Release on Object| N[Create Connection Line]
I -->|Left Press on Object| O[Start Object Movement]
I -->|Mouse Drag| P[Move Object]
I -->|Left Release| Q[Update Object Position]
J --> R{Edit Menu}
K --> R
R -->|Group Selected| S[Merge Selected Objects]
R -->|Ungroup Selected| T[Decompose Composite Object]
R -->|Change Object Name| U[Open Name Change Window]
U -->|OK with New Name| V[Update Object Name]
U -->|Cancel| W[Close Window]
V --> W
W --> I
```

## Usage

Expand All @@ -156,16 +112,11 @@ mvn clean package
java -jar target/uml-editor-1.0-jar-with-dependencies.jar
```

## Class Diagram
## Class Diagram with Dependency

> [!TIP]
> Generated by [UML class diagrams](https://www.jetbrains.com/help/idea/class-diagram.html)

Class Diagram

![Class Diagram](./assets/class-diagram.png)

Class Diagram with Dependency

![Class Diagram with Dependency](./assets/class-diagram-with-dependency.png)

Expand Down Expand Up @@ -229,6 +180,169 @@ Class Diagram with Dependency
...
```

## Program Flow Overview

1. Click Tool Button
2. Mode
1. Create UMLObject
1. Create UMLConnectionLine
2. Create UMLBasicObject
2. Select
1. If selection is UMLObjects
1. can Move (UMLConnectionLine movement are not supported yet.)
2. If selection is UMLBasicObject
1. can change it’s ObjectName
3. If selection is an Area including several UMLObjects
1. can Group
4. If selection is an UMLGroup
1. can UnGroup
3. Canvas Repaint

```mermaid
graph TD
A[Initialize UML Editor] --> B{Button Clicked}
B -->|Select| C[Set Select Mode]
B -->|Association| D[Set Association Mode]
B -->|Generalization| E[Set Generalization Mode]
B -->|Composition| F[Set Composition Mode]
B -->|Class| G[Set Class Creation Mode]
B -->|Use Case| H[Set Use Case Creation Mode]
C --> I{Mouse Event on Canvas}
D --> I
E --> I
F --> I
G --> I
H --> I
I -->|Left Click on Object| J[Select/Unselect Object]
I -->|Left Click on Canvas| K[Unselect All Objects]
I -->|Left Press on Object| L[Start Line Creation]
I -->|Mouse Drag| M[Update Line Endpoint]
I -->|Left Release on Object| N[Create Connection Line]
I -->|Left Press on Object| O[Start Object Movement]
I -->|Mouse Drag| P[Move Object]
I -->|Left Release| Q[Update Object Position]
J --> R{Edit Menu}
K --> R
R -->|Group Selected| S[Merge Selected Objects]
R -->|Ungroup Selected| T[Decompose Composite Object]
R -->|Change Object Name| U[Open Name Change Window]
U -->|OK with New Name| V[Update Object Name]
U -->|Cancel| W[Close Window]
V --> W
W --> I
```

## Use Case Sequence Diagram

### A. Creating a UML Object

```mermaid
sequenceDiagram
participant User
participant Button
participant Canvas
User->>Button: Click button
Button-->>User: Change button color to black
User->>Canvas: Move cursor to (x,y) and press left mouse button
Canvas-->>Canvas: Draw a blank object at (x,y)
User->>Canvas: Repeat creating same object
alt User press another button
User->>Button: Click another button
Button-->>User: Change to the mode of clicked button
end
```

### B. Creating a UML Connection Line

```mermaid
sequenceDiagram
participant User
participant Object1
participant Object2
participant Canvas
User->>Object1: Press left mouse button within boundary
User->>Canvas: Drag mouse
User->>Object2: Release mouse button within boundary
Canvas-->>Canvas: Create connection line between Object1 and Object2
Canvas-->>Canvas: Draw arrow at Object2 based on line type
alt Press point not on object
User->>Canvas: Press, drag and release not on any object
Canvas-->>Canvas: Do nothing
else Release point not on object
User->>Canvas: Release mouse not on any object
Canvas-->>Canvas: Do not create connection line
end
```

### C. Select/Unselect a Single Object

```mermaid
sequenceDiagram
participant User
participant Object
participant Canvas
User->>Object: Click on object
Object-->>Canvas: Deselect any other selected objects
Object-->>Object: Display 4 connection ports
alt Click on empty area
User->>Canvas: Click on coordinates without object
Canvas-->>Canvas: Deselect any selected objects
end
```

### D.1 Group Objects

```mermaid
sequenceDiagram
participant User
participant EditMenu
participant SelectedObjects
User->>EditMenu: Select "Group" option
EditMenu->>SelectedObjects: Merge into one composite object
```

### D.2 Ungroup Objects

```mermaid
sequenceDiagram
participant User
participant EditMenu
participant CompositeObject
User->>EditMenu: Select "Ungroup" option
EditMenu->>CompositeObject: Decompose one layer
```


### E. Move Objects

```mermaid
sequenceDiagram
participant User
participant Object
participant Canvas
User->>Object: Press left mouse button
User->>Canvas: Drag mouse to (x,y)
User->>Canvas: Release mouse button
Canvas->>Object: Move object to (x,y)
Canvas-->>Canvas: Redraw connected lines
```

### F. Change Object Name

```mermaid
sequenceDiagram
participant User
participant EditMenu
participant Object
participant NameWindow
User->>Object: Select object
User->>EditMenu: Select "Change Object Name"
EditMenu-->>NameWindow: Open window with text area and OK/Cancel
User->>NameWindow: Enter new name, press OK
NameWindow-->>Object: Change object name
NameWindow-->>NameWindow: Close window
```

## References

### Documentations
Expand All @@ -241,8 +355,8 @@ Class Diagram with Dependency

### Related Projects

> [!CAUTION]
> Code similarity will be checked and updated. Expecting to use [MOSS](https://theory.stanford.edu/~aiken/moss/)
> [!TIP]
> Code similarity is checked by using [MOSS](https://theory.stanford.edu/~aiken/moss/). Result: http://moss.stanford.edu/results/1/9411843636512/

- [haVincy/UML-Editor](https://github.com/haVincy/UML-Editor)
- [MU-PING/UML-editor](https://github.com/MU-PING/UML-editor)
Expand Down
Binary file modified assets/class-diagram-with-dependency.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/class-diagram.png
Binary file not shown.
Binary file added assets/usecase-a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/usecase-b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/usecase-c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/usecase-d-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/usecase-d-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/usecase-e.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/usecase-f.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion src/main/java/com/xxrjun/components/uml/UMLObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public abstract class UMLObject{
/**
* The Uml ports.
*/
protected UMLPort[] umlPorts;
private boolean isGroupSelected = false;
private boolean isNameChangeable = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private enum PortPosition {
*/
RIGHT}

private final Map<UMLConnectionLine, UMLConnectionLine.EndPointType> connectionLines = new HashMap<>();
private final Map<UMLConnectionLine, UMLConnectionLine.EndPointTypes> connectionLines = new HashMap<>();

/**
* Instantiates a new Uml basic object.
Expand Down Expand Up @@ -102,17 +102,17 @@ public UMLPort findNearestPort(Point point) {
* Update connection line.
*/
public void updateConnectionLine() {
for (Map.Entry<UMLConnectionLine, UMLConnectionLine.EndPointType> entry : connectionLines.entrySet()) {
for (Map.Entry<UMLConnectionLine, UMLConnectionLine.EndPointTypes> entry : connectionLines.entrySet()) {
// if source => calculate source Nearest port => set source port
// if destination => calculate destination Nearest port => set destination port
UMLConnectionLine connectionLine = entry.getKey();
UMLConnectionLine.EndPointType endPointType = entry.getValue();
UMLConnectionLine.EndPointTypes endPointType = entry.getValue();


// TODO: BUG: UMLBasicObject and UMLConnectionLine overlapping still exists after updating to nearest port
if (endPointType == UMLConnectionLine.EndPointType.SOURCE) {
if (endPointType == UMLConnectionLine.EndPointTypes.SOURCE) {
connectionLine.setSourcePort(findNearestPort(new Point(connectionLine.getX1(), connectionLine.getY1())));
} else if (endPointType == UMLConnectionLine.EndPointType.DESTINATION) {
} else if (endPointType == UMLConnectionLine.EndPointTypes.DESTINATION) {
connectionLine.setDestinationPort(findNearestPort(new Point(connectionLine.getX2(), connectionLine.getY2())));
}
// reset the location of the connection line
Expand All @@ -136,7 +136,7 @@ public void updateLocation(int deltaX, int deltaY) {
* @param connectionLine the connection line
* @param endPointType the end point type
*/
public void addConnectionLine(UMLConnectionLine connectionLine, UMLConnectionLine.EndPointType endPointType) {
public void addConnectionLine(UMLConnectionLine connectionLine, UMLConnectionLine.EndPointTypes endPointType) {
connectionLines.put(connectionLine, endPointType);
}

Expand Down
Loading