|
@@ -6,6 +6,8 @@ import java.awt.Graphics;
|
|
|
import java.awt.Graphics2D;
|
|
|
import java.awt.RenderingHints;
|
|
|
import java.awt.ScrollPane;
|
|
|
+import java.awt.event.ActionEvent;
|
|
|
+import java.awt.event.ActionListener;
|
|
|
import java.awt.event.MouseWheelEvent;
|
|
|
import java.awt.event.MouseWheelListener;
|
|
|
import java.util.ArrayList;
|
|
@@ -19,6 +21,11 @@ import classes.HolonObject;
|
|
|
import classes.SubNet;
|
|
|
import ui.controller.Control;
|
|
|
import ui.model.Model;
|
|
|
+import javax.swing.JTextArea;
|
|
|
+import java.awt.List;
|
|
|
+
|
|
|
+import javax.swing.JComboBox;
|
|
|
+import javax.swing.JMenuBar;
|
|
|
|
|
|
public class HolonCanvas extends JPanel implements MouseWheelListener {
|
|
|
|
|
@@ -37,21 +44,27 @@ public class HolonCanvas extends JPanel implements MouseWheelListener {
|
|
|
// Frames
|
|
|
private int currentFrameRate;
|
|
|
|
|
|
- long previousTime = System.currentTimeMillis();
|
|
|
- long currentTime = previousTime;
|
|
|
- long elapsedTime;
|
|
|
- long totalElapsedTime = 0;
|
|
|
- int frameCount = 0;
|
|
|
+ private long previousTime = System.currentTimeMillis();
|
|
|
+ private long currentTime = previousTime;
|
|
|
+ private long elapsedTime;
|
|
|
+ private long totalElapsedTime = 0;
|
|
|
+ private int frameCount = 0;
|
|
|
private Dimension center;
|
|
|
private ArrayList<SubNet> subnets;
|
|
|
|
|
|
private Control controller;
|
|
|
private Model model;
|
|
|
+ private int maxX;
|
|
|
+ private int maxY;
|
|
|
+ private JComboBox<String> combo = new JComboBox<>();
|
|
|
+ private int comboChoice = 0;
|
|
|
+ private String info;
|
|
|
|
|
|
public HolonCanvas(Model mod, Control control) {
|
|
|
// Wire up Events
|
|
|
this.controller = control;
|
|
|
this.model = mod;
|
|
|
+ this.add(combo);
|
|
|
subnets = controller.getSimManager().getSubNets();
|
|
|
subCount = subnets.size();
|
|
|
previousTime = System.currentTimeMillis();
|
|
@@ -59,10 +72,17 @@ public class HolonCanvas extends JPanel implements MouseWheelListener {
|
|
|
totalElapsedTime = 0;
|
|
|
frameCount = 0;
|
|
|
this.addMouseWheelListener(this);
|
|
|
+ combo.addItem("ID");
|
|
|
+
|
|
|
+ combo.addActionListener(new ActionListener() {
|
|
|
+ @Override
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
+ comboChoice = combo.getSelectedIndex();
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
// Start Render and Update Threads
|
|
|
-
|
|
|
public void paintComponent(Graphics g) {
|
|
|
super.paintComponent(g);
|
|
|
|
|
@@ -77,11 +97,10 @@ public class HolonCanvas extends JPanel implements MouseWheelListener {
|
|
|
subnets = controller.getSimManager().getSubNets();
|
|
|
subCount = subnets.size();
|
|
|
calcCenter();
|
|
|
- if (bodies.isEmpty()) {
|
|
|
- createBodies(subCount);
|
|
|
- } else {
|
|
|
- addNewBodies(subCount);
|
|
|
- }
|
|
|
+ maxX = center.width;
|
|
|
+ maxY = center.height;
|
|
|
+ addNewBodies(subCount);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
currentTime = System.currentTimeMillis();
|
|
@@ -94,7 +113,7 @@ public class HolonCanvas extends JPanel implements MouseWheelListener {
|
|
|
totalElapsedTime = 0;
|
|
|
}
|
|
|
|
|
|
- updateGame(elapsedTime / 1000f);
|
|
|
+ updateBodies(elapsedTime / 1000f);
|
|
|
render(g);
|
|
|
|
|
|
try {
|
|
@@ -116,10 +135,15 @@ public class HolonCanvas extends JPanel implements MouseWheelListener {
|
|
|
for (int i = 0; i < subCount; i++) {
|
|
|
for (int j = 0; j < bodies.size(); j++) {
|
|
|
if (model.getSubNetColors().get(i) == bodies.get(j).getColor()) {
|
|
|
- bodies.get(j).setRadius(subnets.get(i).getObjects().size() * 5 + 10);
|
|
|
- bodies.get(j).setMass(subnets.get(i).getObjects().size() * 5 + 10);
|
|
|
+ bodies.get(j).setRadius(
|
|
|
+ (subnets.get(i).getObjects().size() * 5 + 10) * controller.getHolonBodyScale() / 100);
|
|
|
+ bodies.get(j).setMass((float) Math.pow((subnets.get(i).getObjects().size() + 1) * 5, 3));
|
|
|
newBodies.add(bodies.get(j));
|
|
|
newBodies.get(i).setId(i);
|
|
|
+ if (newBodies.get(i).position.getX() > maxX)
|
|
|
+ maxX = (int) newBodies.get(i).position.getX();
|
|
|
+ if (newBodies.get(i).position.getY() > maxY)
|
|
|
+ maxY = (int) newBodies.get(i).position.getY();
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -127,24 +151,18 @@ public class HolonCanvas extends JPanel implements MouseWheelListener {
|
|
|
|
|
|
bodies = newBodies;
|
|
|
for (int i = bodies.size(); i < subCount; i++) {
|
|
|
- HolonBody temp = new HolonBody((center.width + 1) + (-1 * i), (center.height + 1) + (-1 * i),
|
|
|
- subnets.get(i).getObjects().size() * 5 + 10, subnets.get(i).getObjects().size() * 5 + 10,
|
|
|
- model.getSubNetColors().get(i));
|
|
|
+ float radius = (subnets.get(i).getObjects().size() * 5 + 10) * controller.getHolonBodyScale() / 100;
|
|
|
+ HolonBody temp = new HolonBody(maxX + radius, maxY + radius, radius,
|
|
|
+ (float) Math.pow((subnets.get(i).getObjects().size() + 1) * 5, 3), model.getSubNetColors().get(i));
|
|
|
temp.setId(i);
|
|
|
bodies.add(temp);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
- // creates the first round of bodies
|
|
|
- private void createBodies(int subCount) {
|
|
|
- for (int i = 0; i < subCount; i++) {
|
|
|
- HolonBody temp = new HolonBody((center.width + 1) + (-1 * i), (center.height + 1) + (-1 * i),
|
|
|
- subnets.get(i).getObjects().size() * 5 + 10, subnets.get(i).getObjects().size() * 5 + 10,
|
|
|
- model.getSubNetColors().get(i));
|
|
|
- temp.setId(i);
|
|
|
- bodies.add(temp);
|
|
|
+ if (bodies.get(i).position.getX() > maxX)
|
|
|
+ maxX = (int) newBodies.get(i).position.getX();
|
|
|
+ if (bodies.get(i).position.getY() > maxY)
|
|
|
+ maxY = (int) newBodies.get(i).position.getY();
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public void render(Graphics g) {
|
|
@@ -157,13 +175,22 @@ public class HolonCanvas extends JPanel implements MouseWheelListener {
|
|
|
|
|
|
// Render Game Objects
|
|
|
for (int i = 0; i < subCount; i++) {
|
|
|
+ switch (comboChoice) {
|
|
|
+ case 0:
|
|
|
+ info = "" + bodies.get(i).getId();
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ info = "" + bodies.get(i).getId();
|
|
|
+ break;
|
|
|
+ }
|
|
|
bodies.get(i).setRadius((subnets.get(bodies.get(i).getId()).getObjects().size() * 5 + 10)
|
|
|
* controller.getHolonBodyScale() / 100);
|
|
|
- bodies.get(i).draw(this.g2);
|
|
|
+ bodies.get(i).draw(this.g2, info);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void updateGame(float elapsedSeconds) {
|
|
|
+ public void updateBodies(float elapsedSeconds) {
|
|
|
|
|
|
// step the position of movable objects based off their velocity/gravity
|
|
|
// and elapsedTime
|
|
@@ -171,26 +198,23 @@ public class HolonCanvas extends JPanel implements MouseWheelListener {
|
|
|
for (int i = 0; i < subCount; i++) {
|
|
|
bodies.get(i).position
|
|
|
.setX((float) (bodies.get(i).position.getX() + (bodies.get(i).velocity.getX() * (elapsedSeconds))
|
|
|
- - ((bodies.get(i).position.getX() - center.getWidth()) / 100)));
|
|
|
+ - ((bodies.get(i).position.getX() - center.getWidth()) / (50 + subCount))));
|
|
|
bodies.get(i).position
|
|
|
.setY((float) (bodies.get(i).position.getY() + (bodies.get(i).velocity.getY() * (elapsedSeconds))
|
|
|
- - ((bodies.get(i).position.getY() - center.getHeight()) / 100)));
|
|
|
+ - ((bodies.get(i).position.getY() - center.getHeight()) / (50 + subCount))));
|
|
|
|
|
|
if (Math.abs(bodies.get(i).velocity.getX()) < Constants.epsilon)
|
|
|
bodies.get(i).velocity.setX(0);
|
|
|
if (Math.abs(bodies.get(i).velocity.getY()) < Constants.epsilon)
|
|
|
bodies.get(i).velocity.setY(0);
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
checkCollisions();
|
|
|
-
|
|
|
}
|
|
|
|
|
|
// Insertion sort for Sweep and Prune
|
|
|
public void insertionSort(ArrayList<HolonBody> a) {
|
|
|
for (int p = 1; p < subCount; p++) {
|
|
|
- Comparable tmp = a.get(p);
|
|
|
+ Comparable<HolonBody> tmp = a.get(p);
|
|
|
int j = p;
|
|
|
|
|
|
for (; j > 0 && tmp.compareTo(a.get(j - 1)) < 0; j--)
|