Skip to content

Commit

Permalink
Finished every UI element and added every algorithm to the app.
Browse files Browse the repository at this point in the history
  • Loading branch information
AramZahedi committed Jul 18, 2019
1 parent 2aa5815 commit 7a76179
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 47 deletions.
38 changes: 38 additions & 0 deletions Graph/src/elements/MenuManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public class MenuManager {
private ParallelTransition hideFailIcon;
private TranslateTransition hideRuntimeMenu;
private TranslateTransition showRuntimeMenu;
private ParallelTransition shrinkRuntimeMenu;
private ParallelTransition expandRuntimeMenu;
private TranslateTransition hideAntColonyMenu;
private TranslateTransition showAntColonyMenu;
private ParallelTransition hideExpandingProblemsMenu;
Expand Down Expand Up @@ -422,6 +424,24 @@ public void setLoadingAnimations() {
*/
hideFailIcon = new ParallelTransition(rotateOutFailIcon, scaleOutFailIcon);
hideFailIcon.setOnFinished(event -> algorithmFailIcon.setVisible(false));

/*
* Set shrink and expand runtime menu animations
*/
TranslateTransition pullUpRuntimeMenu = new TranslateTransition(Duration.millis(500), runtimeMenu);
pullUpRuntimeMenu.setToY(-120);
TranslateTransition pullDownRuntimeMenu = new TranslateTransition(Duration.millis(500), runtimeMenu);
pullDownRuntimeMenu.setToY(15);
FadeTransition fadeInRuntimeMenu = new FadeTransition(Duration.millis(500), runtimeMenu);
fadeInRuntimeMenu.setToValue(1);
FadeTransition fadeOutRuntimeMenu = new FadeTransition(Duration.millis(500), runtimeMenu);
fadeOutRuntimeMenu.setToValue(.5);

/*
* Set parallel transitions
*/
this.shrinkRuntimeMenu = new ParallelTransition(pullUpRuntimeMenu, fadeOutRuntimeMenu);
this.expandRuntimeMenu = new ParallelTransition(pullDownRuntimeMenu, fadeInRuntimeMenu);
}

/**
Expand Down Expand Up @@ -536,6 +556,24 @@ public void hideRuntimeMenu() {
hideRuntimeMenu.play();
}

/**
* Expand runtime menu
*/

public void expandRuntimeMenu() {
shrinkRuntimeMenu.stop();
expandRuntimeMenu.play();
}

/**
* Shrink runtime menu
*/

public void shrinkRuntimeMenu() {
expandRuntimeMenu.stop();
shrinkRuntimeMenu.play();
}

/**
* Show menu
*/
Expand Down
18 changes: 12 additions & 6 deletions Graph/src/elements/SceneGestures.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class SceneGestures {
private App app;

private boolean isPanning = false;
private boolean enterPressed = false;

public SceneGestures(PannableCanvas canvas, App app, PannableGridPane background) {
this.canvas = canvas;
Expand Down Expand Up @@ -318,6 +319,16 @@ public void handle(KeyEvent event) {
app.pressShift();
}

break;
case ENTER:
/*
* Press enter key
*/
if (app.isCtrlPressed() && !enterPressed) {
enterPressed = true;
app.pressEnter();
}

break;
default:
break;
Expand Down Expand Up @@ -346,12 +357,7 @@ public void handle(KeyEvent event) {

break;
case ENTER:
/*
* Press enter key
*/
if (app.isCtrlPressed()) {
app.pressEnter();
}
enterPressed = false;

break;

Expand Down
10 changes: 0 additions & 10 deletions Graph/src/elements/TransitionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@ public void start(HashMap<GraphNode, CubicCurve> nodesAndEdges) throws Interrupt
*/
setAfterFinished(node);

/*
* Set stroke on graph edge
*/
edge.setStroke();

/*
* Iterate through animations
*/
Expand Down Expand Up @@ -161,11 +156,6 @@ public void start(HashMap<GraphNode, CubicCurve> nodesAndEdges) throws Interrupt
*/
setAfterFinished(node);

/*
* Set stroke on graph edge
*/
edge.setStroke();

/*
* Iterate through animations
*/
Expand Down
85 changes: 54 additions & 31 deletions Graph/src/graph/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.*;

import static graph.Main.app;
import static graph.Main.main;

/**
* The type App.
Expand Down Expand Up @@ -324,6 +325,11 @@ public void set(Scene scene, Stage primaryStage) {
*/
setTimerThread();

/*
* Set runtime menu mouse listeners
*/
setRuntimeMenuListeners();

/*
* Set current mode to node mode
*/
Expand Down Expand Up @@ -423,7 +429,7 @@ private void setHiddenDrawingTools() {
* Sets selections
*/

public void setSelections() {
private void setSelections() {
this.selectionManager = new SelectionManager(menuManager, this);
}

Expand All @@ -436,6 +442,24 @@ private void setExpandingMenuListeners() {
this.expandingProblemsMenu.addEventFilter(MouseEvent.MOUSE_EXITED, event -> leaveExpandingProblemsMenu());
}

/**
* Sets runtime menu listeners
*/

private void setRuntimeMenuListeners() {
this.runtimeMenu.addEventFilter(MouseEvent.MOUSE_ENTERED, event -> {
if (getCurrentState() == State.PLAYING) {
menuManager.expandRuntimeMenu();
}
});
this.runtimeMenu.addEventFilter(MouseEvent.MOUSE_EXITED, event -> {
if (getCurrentState() == State.PLAYING) {
menuManager.shrinkRuntimeMenu();
}
});

}

/**
* Set menus in the menu manager
*/
Expand Down Expand Up @@ -676,19 +700,10 @@ private void startPlayingThread() {
playingThread = new Thread(() -> {
this.transitionManager = new TransitionManager(this, menuManager);

switch (getCurrentProblem()) {
case SHORTEST_PATH:

break;
case DYNAMIC_PROGRAMMING:
playTravellingSalesman();

break;
case ANT_COLONY:
playTravellingSalesman();

break;
}
/*
* Start traversing through nodes and edges
*/
traverse();
});

/*
Expand Down Expand Up @@ -1329,7 +1344,7 @@ public void batchAddEdges(GraphNode sourceNode, boolean nonDirectional) {
if (nonDirectional) {
placeNewNonDirectionalEdge(Math.round(weight), sourceNode, node);
} else {
placeNewEdge(Math.round(weight * 4) / 4f, sourceNode, node);
placeNewEdge(Math.round(weight), sourceNode, node);
}
}
}
Expand Down Expand Up @@ -2138,34 +2153,28 @@ private void playResults() {
*/
setCurrentState(State.PLAYING);
resetSpeed();
menuManager.shrinkRuntimeMenu();

/*
* Start the playing thread
*/
startPlayingThread();
}

/**
* Play shortest path
*/

private void playShortestPath(PathData pathData) {
// System.out.println("Distance: " + pathData.);
}

/**
* Play travelling salesman
*/

private void playTravellingSalesman() {
private void traverse() {
GraphNode source, target;
LinkedHashMap<GraphNode, CubicCurve> dataMap = new LinkedHashMap<>();

/*
* Get the shortest distance from the results
*/
double distance = getCurrentProblem() == Problem.ANT_COLONY ?
antColonyResult.getShortestDistance() : dynamicProgrammingResult.getShortestDistance();
antColonyResult.getShortestDistance() : (getCurrentProblem() == Problem.DYNAMIC_PROGRAMMING ?
dynamicProgrammingResult.getShortestDistance() : shortestPathResult.getShortestDistance());

/*
* Print the distance of the runtime menu
Expand All @@ -2181,7 +2190,8 @@ private void playTravellingSalesman() {
* Get the results array list according to current problems
*/
ArrayList<GraphNode> results = getCurrentProblem() == Problem.ANT_COLONY ?
antColonyResult.getpathSecond() : dynamicProgrammingResult.getpathSecond();
antColonyResult.getpathSecond() : (getCurrentProblem() == Problem.DYNAMIC_PROGRAMMING ?
dynamicProgrammingResult.getpathSecond() : shortestPathResult.getPathNodesToTargetNode());

for (int i = 0; i < results.size() - 1; i++) {
source = results.get(i);
Expand All @@ -2190,12 +2200,25 @@ private void playTravellingSalesman() {
/*
* Get the edge connecting the two nodes together
*/
NonDirectionalEdge edge = mainGraph.getTwoWayEdge(source, target);
NonDirectionalEdge nonDirectionalEdge = mainGraph.getTwoWayEdge(source, target);

/*
* Add node and edge to hash map
*/
dataMap.put(target, edge);
if (nonDirectionalEdge != null) {
/*
* Add node and edge to hash map
*/
dataMap.put(target, nonDirectionalEdge);

} else {
/*
* Check for directional edge between source and target
*/
GraphEdge directionalEdge = mainGraph.getOutgoingEdge(source, target);

/*
* Add node and edge to hash map
*/
dataMap.put(target, directionalEdge);
}
}

try {
Expand Down

0 comments on commit 7a76179

Please sign in to comment.