Skip to content

Commit

Permalink
Merge pull request #162 from harley-ewu/Develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jsanders25 authored Dec 4, 2023
2 parents 1e00024 + 7c95877 commit df87203
Show file tree
Hide file tree
Showing 8 changed files with 432 additions and 380 deletions.
2 changes: 1 addition & 1 deletion UMLDiagram/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ tasks.register('runMain2', JavaExec) {

javafx {
version = "21.0.1"
modules = [ 'javafx.controls', 'javafx.fxml' ]
modules = [ 'javafx.controls', 'javafx.fxml' , 'javafx.swing']
}


Expand Down
106 changes: 85 additions & 21 deletions UMLDiagram/src/main/java/javaroo/cmd/UMLClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public static void addClassWithCoordinates(String name, double x, double y) {
if (!UMLDiagram.getClasses().containsKey(name)) {
UMLClass newClass = new UMLClass(name, x, y);
UMLDiagram.getClasses().put(name, newClass);
System.out.println("Class added: " + name);
//System.out.println("Class added: " + name);
} else {
System.out.println("Class '" + name + "' already exists.");
//System.out.println("Class '" + name + "' already exists.");
}
}

Expand Down Expand Up @@ -111,6 +111,22 @@ public void addField(String name, String type, String visibility)
}
}

public void addFieldGUI(String name, String type, String visibility)
{
//check for the empty string in paramters or if input contains only spaces
if(name.trim().isEmpty() || type.trim().isEmpty() || visibility.trim().isEmpty())
{
System.out.println("Invalid input");
return;
}

//check if field already exists
if(fieldExists(name) == null)
{
this.fields.add(new UMLFields(name, type, visibility));
}
}

//Method to remove a UMLFields object from the fields ArrayList with a name parameter
public void removeField(String name)
{
Expand All @@ -133,6 +149,20 @@ public void removeField(String name)
}
}

public void removeFieldGUI(String name) {
//check for the empty string in paramters or if input contains only spaces
if (name.trim().isEmpty()) {
return;
}

//check if field exists
if (fieldExists(name) != null) {
this.fields.remove(fieldExists(name));
}
}



// renameField method
public void renameField(String oldName, String newName) {
// statement to check if field exists
Expand All @@ -146,6 +176,15 @@ public void renameField(String oldName, String newName) {

}

public void renameFieldGUI(String oldName, String newName) {
// statement to check if field exists
if(fieldExists(oldName) == null || newName.trim().isEmpty()) {
return;
}
// if field exists, fields will be fetched and removed
fieldExists(oldName).setName(newName);
}

//Method to check if a UMLMethods object exists in the methods ArrayList
public UMLMethods methodExists(String name, ArrayList<String> parameters)
{
Expand Down Expand Up @@ -181,6 +220,22 @@ public void addMethod(String name, String returnType, ArrayList<String> paramete
}
}

public void addMethodGUI(String name, String returnType, ArrayList<String> parameters)
{
//check for the empty string in paramters or if input contains only spaces
if(name.trim().isEmpty() || returnType.trim().isEmpty() || parameters == null)
{
System.out.println("Invalid input");
return;
}

//check if method already exists
if(methodExists(name, parameters) == null)
{
this.methods.add(new UMLMethods(name, returnType, parameters));
}
}

//Method that takes an int as a parameter and removes the UMLMethods object at that index from the methods ArrayList
public void removeMethod(int index)
{
Expand All @@ -196,6 +251,7 @@ public void removeMethod(int index)
System.out.println("Method removed");
}


public void removeMethod(String methodName) {
// Find the index of the method with the given name
int index = -1;
Expand All @@ -217,6 +273,25 @@ public void removeMethod(String methodName) {
System.out.println("Method removed: " + methodName);
}

public void removeMethodGUI(String methodName) {
// Find the index of the method with the given name
int index = -1;
for (int i = 0; i < this.methods.size(); i++) {
if (this.methods.get(i).getName().equals(methodName)) {
index = i;
break;
}
}

// Check if the method was found
if (index == -1) {
return;
}

// Remove the method at the found index
this.methods.remove(index);
}


// rename method that will rename an UMLMethod from a class at a given index
public void renameMethod(int index, String newName) {
Expand All @@ -230,28 +305,17 @@ public void renameMethod(int index, String newName) {
System.out.println("Method renamed to: " + newName);
}

public void renameMethod(String oldName, String newName) {
// check if oldName or newName is null or empty
if (oldName == null || oldName.trim().isEmpty() || newName == null || newName.trim().isEmpty()) {
System.out.println("Invalid old name or empty new name");
public void renameMethodGUI(int index, String newName) {
// check if index is out of bounds or empty string
if (index < 0 || index >= this.methods.size() || newName.trim().isEmpty()) {
return;
}

// find the method with the old name
for (UMLMethods method : this.methods) {
if (method.getName().equals(oldName)) {
// rename method
method.setName(newName);
System.out.println("Method renamed from '" + oldName + "' to '" + newName + "'");
return;
}
}

// if method with old name is not found
System.out.println("Method named '" + oldName + "' not found");
// rename method at index
this.methods.get(index).setName(newName);
}



// method that lists all the methods in a class
public void listMethods() {
// check if methods is empty
Expand Down Expand Up @@ -315,8 +379,8 @@ public void setX(double x) {
this.x = x;
}

public void setY(double x) {
this.x = x;
public void setY(double y) {
this.y = y;
}

public void setMethods(ArrayList<UMLMethods> methods) {
Expand Down
41 changes: 38 additions & 3 deletions UMLDiagram/src/main/java/javaroo/cmd/UMLDiagram.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,28 @@ void listClassContents(String className) {
}
}

public UMLClass classExists(String name) {
return classes.get(name);
public UMLClass classExists(String name)
{
// check if name is null
if(name == null)
{
System.out.println("Sorry but we could not find a valid name for this class");
return null;
}

for(UMLClass c : classes.values())
{
if(c.getName().equals(name))
{
return c;
}
}
return null;
}

public void addClass(String name) {
if (classExists(name) != null) {
System.out.println("Sorry, but this class already exists");
//System.out.println("Sorry, but this class already exists");
return;
}

Expand All @@ -128,6 +143,26 @@ public void addClass(String name) {
executeCommand(addClassCommand);
}

//Method to remove a UMLClass object from the classes map via its name.
public void removeClass(String name)
{
//check if name is null
if(name == null)
{
System.out.println("Sorry but we could not find a valid name for this class");
return;
}
//Check if the class exists.
if(classExists(name) == null)
{
System.out.println("Sorry but this class does not exist");
return;
}
//Remove the UMLClass object from the classes map.
getClasses().remove(name);
System.out.println("Class deleted: " + name);
}

void addClassInternal(String name) {
String processedName = name.trim();

Expand Down
Loading

0 comments on commit df87203

Please sign in to comment.