Skip to content

Commit

Permalink
Should be about ready for presenting tomorrow
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt-Crow committed Mar 10, 2021
1 parent f4839ca commit a96f318
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
Binary file modified build/libs/WayfindingNodeManager.jar
Binary file not shown.
3 changes: 3 additions & 0 deletions src/main/java/nodemanager/gui/ApplicationMenuBar.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package nodemanager.gui;

import nodemanager.gui.mapComponents.NodeIcon;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
Expand Down Expand Up @@ -135,12 +136,14 @@ private JMenu createOptionMenu() {
JMenuItem showAllConn = new JMenuItem("Draw all connections");
showAllConn.addActionListener((e) -> {
Node.getAll().forEach(node -> node.getIcon().setDrawLinks(true));
parent.getBody().repaint();
});
m.add(showAllConn);

JMenuItem hideAllConn = new JMenuItem("Hide all connections");
hideAllConn.addActionListener((e) -> {
Node.getAll().forEach(node -> node.getIcon().setDrawLinks(false));
parent.getBody().repaint();
});
m.add(hideAllConn);

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/nodemanager/gui/mapComponents/MapImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import nodemanager.node.Node;
import nodemanager.*;
import nodemanager.events.*;
import nodemanager.gui.NodeIcon;
import nodemanager.gui.Scale;

/**
Expand Down Expand Up @@ -260,7 +259,9 @@ public void paintComponent(Graphics g) {
} else {
g2d.drawImage(buff, 0, 0, this);
}
nodeIcons.values().stream().forEach(icon -> icon.draw(g2d));
// draw icons above the connections
nodeIcons.values().stream().forEach((icon) -> icon.drawAllLinks(g2d));
nodeIcons.values().stream().forEach((icon) -> icon.draw(g2d));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package nodemanager.gui;
package nodemanager.gui.mapComponents;

import nodemanager.gui.mapComponents.MapImage;
import java.awt.*;
import java.awt.event.*;
import nodemanager.Mode;
import nodemanager.Session;
import nodemanager.events.*;
import nodemanager.gui.Scale;
import nodemanager.node.Node;

/**
Expand Down Expand Up @@ -190,10 +189,7 @@ public void resetPos(){
* @return whether or not this was clicked on
*/
public boolean isIn(int xc, int yc){
return x <= xc &&
x + size >= xc &&
y <= yc &&
y + size >= yc;
return Math.sqrt(Math.pow(x - xc, 2) + Math.pow(y - yc, 2)) <= size / 2;
}

/**
Expand Down Expand Up @@ -240,26 +236,24 @@ public void mouseExited(MouseEvent me) {
*/
public void draw(Graphics g){
g.setColor(color);
g.fillRect(x, y, size, size);
g.fillOval(x - size / 2, y - size / 2, size, size);

g.setColor(Color.black);
g.drawString(Integer.toString(id), x, y);

if(drawLinks){
drawAllLinks(g);
}
}


/**
* Graphically display all the connections between this icon's Nodes and its adjacent Nodes
* @param g the Graphics context to draw on
*/
private void drawAllLinks(Graphics g){
node.getAdjIds()
public void drawAllLinks(Graphics g){
if(drawLinks){
node.getAdjIds()
.stream()
.map(id -> Node.get(id))
.forEach(node -> drawLink(g, node));
}
}


Expand Down
2 changes: 1 addition & 1 deletion src/main/java/nodemanager/node/Node.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package nodemanager.node;

import java.util.*;
import nodemanager.gui.NodeIcon;
import nodemanager.gui.mapComponents.NodeIcon;
import static java.lang.System.out;


Expand Down

0 comments on commit a96f318

Please sign in to comment.