Skip to content

Commit

Permalink
Merge pull request #31 from HazemE1/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
EricSimonsson authored Mar 18, 2022
2 parents 0ea701b + a845188 commit bb91d11
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 14 deletions.
2 changes: 1 addition & 1 deletion preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<project_directory>C:\Users\manso\Desktop</project_directory>
<window_maximized>false</window_maximized>
<window_width>1417</window_width>
<window_height>720</window_height>
<window_height>562</window_height>
</preferences>
138 changes: 128 additions & 10 deletions src/main/java/com/team34/controller/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.team34.model.chapter.Chapter;
import com.team34.model.Project;
import com.team34.model.Project;
import com.team34.model.chapter.ChapterListObject;
import com.team34.model.event.EventListObject;
import com.team34.view.MainView;
import com.team34.view.dialogs.*;
Expand Down Expand Up @@ -78,6 +79,9 @@ public MainController(MainView view, Project model) {
/**
* Registers events {@link MainController#evtButtonAction} and
* {@link MainController#evtContextMenuAction} on the view
*
* update
* @author Alexander Olsson
*/
private void registerEventsOnView() {
view.registerButtonEvents(evtButtonAction);
Expand All @@ -88,14 +92,20 @@ private void registerEventsOnView() {
view.registerDragEventDragComplete(evtDragComplete);
view.registerMouseEvents(evtMouseCharacterList);
view.registerMouseEventsList(mouseEventEventHandler);
view.registerMouseChapterList(mouseEventChapterHandler);
//view.registerMouseChapterList(mouseEventChapterHandler);
view.registerCharacterChartEvents(
new EventCharacterRectReleased(),
new EventChartClick(),
new EventAssociationLabelReleased()

);
view.registerChapterPressEvent(new EventChapterPressed());

view.registerChapterPressEvent(
new EventChapterPressed()
//new ChapterListMouseEvent()
);


}

/**
Expand All @@ -116,6 +126,13 @@ private void createNewEvent() {
return;
}

else if (view.getEditEventDialog().getEventName().equals("")) {
view.showDialog("The event must have a name, a new event was not created.");
return;
}



if(model.chapterManager.getChapters() != null && view.getEditEventDialog().getChapterList() != null){
long newEventUID = model.eventManager.newEvent(
view.getEditEventDialog().getEventName(),
Expand Down Expand Up @@ -182,6 +199,11 @@ private void createNewChapter() {
view.showDialog("A chapter with that name already exists, chapter was not created!");
return;
}
else if (view.getEditChapterDialog().getChapterName().equals("")) {
view.showDialog("The chapter must have a name, a new chapter was not created.");
return;
}

model.chapterManager.newChapter(
view.getEditChapterDialog().getChapterName(),
view.getEditChapterDialog().getChapterDescription(),
Expand All @@ -204,14 +226,57 @@ private void editChapter(long uid) {
view.showDialog("A chapter with that name already exists, chapter was not created!");
return;
}
String chapterNew = view.getEditChapterDialog().getChapterName();
boolean success = model.chapterManager.editChapter(uid,
view.getEditChapterDialog().getChapterName(),
view.getEditChapterDialog().getChapterDescription()
);
changeEventChapter(chapterNew, chapterData[0].toString());
//model.eventManager.
}
refreshTitleBar();
}

/**
*
* @param newChapter
* @param oldChapter
*
* @Author
* Alexander Olsson
*/

private void changeEventChapter(String newChapter, String oldChapter) {
if(model.eventManager.getEvents() != null) {


System.out.println(oldChapter + ", " + newChapter);
Object[][] data = model.eventManager.getEvents();
Object[][] dataChapter = model.chapterManager.getChapters();
long chapterUID = 0;
String color = null;

for (int i = 0; i < model.eventManager.getEvents().length; i++) {
if (dataChapter[i][1].toString().equals(newChapter)) {
System.out.println("Hello");
chapterUID = (long) dataChapter[i][0];
color = dataChapter[i][2].toString();
}

}
for (int i = 0; i < model.eventManager.getEvents().length; i++) {
System.out.println(data[i][4].toString());
if (data[i][4].toString().equals(oldChapter)) {
System.out.println("Hello2");
model.eventManager.editEvent((long) data[i][0], data[i][1].toString(), data[i][2].toString(), new ChapterListObject(newChapter, chapterUID, color));
//model.chapterManager.getChapter();
//model.eventManager.getEvent().getChapterListObject().getUid(chapter)
refreshViewChapters();
}
}
}
}

/**
* Instructs the view to update the view of events with the current state of the model.
*/
Expand Down Expand Up @@ -414,6 +479,10 @@ private void createNewCharacter(double x, double y) {
view.showDialog("A character with that name already exists, a character has not been created");
return;
}
else if (view.getEditCharacterPanel().getCharacterName().equals("")) {
view.showDialog("The character must have a name, a new character was not created.");
return;
}

long newCharacterUID = model.characterManager.newCharacter(
view.getEditCharacterPanel().getCharacterName(),
Expand Down Expand Up @@ -448,14 +517,45 @@ private void createNewCharacter(double x, double y) {
private void editCharacter(long uid) {
Object[] characterData = model.characterManager.getCharacterData(uid);


if (view.getEditCharacterPanel().showEditCharacter((String) characterData[0], (String) characterData[1])
== EditCharacterDialog.WindowResult.OK
) {
if (model.characterManager.getCharacter(view.getEditCharacterPanel().getCharacterName()) != null) {
view.showDialog("A Character with that name already exists, a character has not been created");
return;


if (model.characterManager.getCharacter(view.getEditCharacterPanel().getCharacterName()) == null) {
if (characterData[0] != view.getEditCharacterPanel().getCharacterName()) {
model.characterManager.editCharacter(uid,
view.getEditCharacterPanel().getCharacterName(),
view.getEditCharacterPanel().getCharacterAge(),
view.getEditCharacterPanel().getCharacterDescription(),
view.getEditCharacterPanel().getCharacterEvent()
);
} else {
view.showDialog("A character with that name already exists, the character has not been edited");
return;
}
}



/*
if (model.characterManager.getCharacter(view.getEditCharacterPanel().getCharacterName()) == null) {
if (characterData[0] != view.getEditCharacterPanel().getCharacterName()) {
model.characterManager.editCharacter(uid,
view.getEditCharacterPanel().getCharacterName(),
view.getEditCharacterPanel().getCharacterAge(),
view.getEditCharacterPanel().getCharacterDescription(),
view.getEditCharacterPanel().getCharacterEvent()
);
}else {
view.showDialog("A character with that name already exists, the character has not been edited");
return;
}
}
*/

if (view.getEditCharacterPanel().getCharacterAge() == -1) {
WarningDialog.displayWarning("Character's age needs to be a positive digit", "Invalid age");
} else {
Expand Down Expand Up @@ -812,6 +912,9 @@ public void handle(WindowEvent e) {

/**
* This event is fired from the user clicking items in the menu bar.
*
* Update
* @Author Alexander Olsson
*/
private class EventMenuBarAction implements EventHandler<ActionEvent> {
@Override
Expand All @@ -825,6 +928,7 @@ public void handle(ActionEvent e) {
model.clearProject();
refreshViewEvents();
refreshCharacterList();
refreshViewChapters();
}
refreshTitleBar();
break;
Expand Down Expand Up @@ -866,15 +970,29 @@ public void handle(ActionEvent e) {
private class EventChapterPressed implements EventHandler<MouseEvent> {
@Override
public void handle(MouseEvent e) {
if (e.getButton() != MouseButton.PRIMARY)
if (e.getButton() != MouseButton.PRIMARY) {
return;
}

if (view.getLeftChapterPane().getList().getSelectionModel().getSelectedItem() == null)
if (view.getLeftChapterPane().getList().getSelectionModel().getSelectedItem() == null){
return;

Chapter c = model.chapterManager.getChapter(view.getLeftChapterPane().getList().getSelectionModel().getSelectedItem().getUid());
}


if (e.getButton() == MouseButton.PRIMARY && e.getClickCount() == 2
&& view.chapterListItemSelected()) {
showChapters(view.getSelectedChapterUID());
return;
}


model.chapterManager.getChapter(view.getSelectedChapterUID());

Chapter c = model.chapterManager.getChapter(view.getLeftChapterPane().getList().getSelectionModel().getSelectedItem().getUid());
System.out.println(c);
view.updateCharacterList(model.characterManager.getCharacterList(), model.characterManager.getAssociationData(), c);

view.updateCharacterList(model.characterManager.getCharacterList(), model.characterManager.getAssociationData(), c);

}
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/team34/model/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -944,10 +944,14 @@ public void saveProject() throws IOException, XMLStreamException {
/**
* Discards all data currently loaded. Does not overwrite or erase any file.
* This only affects the data currently loaded in the application.
*
* Update
* @Author Alexander Olsson
*/
public void clearProject() {
eventManager.clear();
characterManager.clear();
chapterManager.clear();
UIDManager.clear();
currProjectName = "";
currProjectFile = null;
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/com/team34/model/chapter/ChapterManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,26 @@ public long newChapter(String name, String description, String color) {
return uid;
}

/**
*
*
* @param uid
* @param name
* @param description
* @return
*
* Update
* @Autor
* Alexander Olsson
*/

public boolean editChapter(long uid, String name, String description) {
if (chapters.containsKey(uid)) {
chapters.replace(uid, new Chapter(name, description, "#F28220"));
Chapter chapter = getChapter(uid);
chapter.setName(name);
chapter.setColor("#F28220");
chapter.setDescription(description);
chapters.replace(uid, chapter);
hasChanged = true;
return true;
}
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/com/team34/model/event/EventManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,32 @@ public boolean editEvent(long uid, String name, String description, ChapterListO
return false;
}

public void editEventChapterListObject(long uid){
if(events.containsKey(uid)){
events.get(uid).setChapterListObject(null);
}
}



/**
* Removes the event associated with the given UID.
* Also removes the UID from each order list, and the UIDManager.
* This will set {@link EventManager#hasChanged} to true, as data has been changed.
*
* @param uid the UID of the event to remove
*
* Update
* @Author Alexander Olsson
*/
public void removeEvent(long uid) {
Event event = events.get(uid);
chapterManager.getChapter(event.getChapterListObject().getUid()).getEvents().remove(event);
if(chapterManager.getChapters() != null){
if(chapterManager.getChapters().equals(events.get(uid).getChapterListObject())){
chapterManager.getChapter(event.getChapterListObject().getUid()).getEvents().remove(event);
}
}

events.remove(uid);
UIDManager.removeUID(uid);
for (LinkedList<Long> e : eventOrderLists)
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/team34/view/MainView.java
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,6 @@ public EventListObject returns() {
*/
public void updateCharacterList(ArrayList<Object[]> characters, Object[][] associations, Chapter c) {
rightPane.updateListView(characters);

characterChart.updateCharacters(characters, associations, c);
}

Expand Down Expand Up @@ -602,10 +601,13 @@ public void registerCharacterChartEvents(EventHandler<MouseEvent> evtCharacterRe
characterChart.registerEvents(evtCharacterReleased, evtMouseClicked, evtLabelReleased);
}

/*
public void registerChapterEvents(EventHandler<MouseEvent> evtChapterClicked) {
leftChapterPane.addMouseClickEventHandler(evtChapterClicked);
}
*/

public Object[] getChartCharacterData(long uid) {
return characterChart.getChartCharacterData(uid);
}
Expand Down Expand Up @@ -643,7 +645,10 @@ public ShowCharacterDialog getShowCharacterDialog() {
}

public void registerChapterPressEvent(EventHandler<MouseEvent> eventChapterPressed) {


leftChapterPane.addMouseClickEventHandler(eventChapterPressed);
//leftChapterPane.registerMouseEvents(listEventHandler);
}

public ChapterList getLeftChapterPane() {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/team34/view/chapter/ChapterList.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,12 @@ public long getChapterUID() {

public void addMouseClickEventHandler(EventHandler<MouseEvent> e) {
list.setOnMouseClicked(e);
//list.setOnMouseClicked(listEventHandler);

}



public ListView<ChapterListObject> getList() {
return list;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ public void updateCharacters(ArrayList<Object[]> characters, Object[][] _associa
public void updateCharacters(ArrayList<Object[]> characters, Object[][] _associations, Chapter c) {
clear();


for (Event e : c.getEvents()) {
System.out.println(e.getName());
if (e != null) {
Expand Down

0 comments on commit bb91d11

Please sign in to comment.