|
@@ -1,6 +1,7 @@
|
|
|
package ui.view;
|
|
|
|
|
|
import classes.*;
|
|
|
+import javafx.scene.input.KeyCode;
|
|
|
|
|
|
import com.google.gson.JsonParseException;
|
|
|
|
|
@@ -23,6 +24,9 @@ import javax.swing.*;
|
|
|
|
|
|
import java.awt.*;
|
|
|
import java.awt.datatransfer.UnsupportedFlavorException;
|
|
|
+import java.awt.event.ActionEvent;
|
|
|
+import java.awt.event.KeyEvent;
|
|
|
+import java.awt.event.KeyListener;
|
|
|
import java.awt.event.MouseEvent;
|
|
|
import java.awt.event.MouseListener;
|
|
|
import java.awt.event.MouseMotionListener;
|
|
@@ -40,7 +44,7 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
|
|
|
MouseMotionListener {
|
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
-
|
|
|
+ private int displayOther = 0;
|
|
|
/**
|
|
|
* Constructor.
|
|
|
*
|
|
@@ -55,13 +59,13 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
|
|
|
this.controller = control;
|
|
|
this.model = mod;
|
|
|
scalediv20 = model.getScale() / 20;
|
|
|
-
|
|
|
+
|
|
|
showedInformation[0] = true;
|
|
|
showedInformation[1] = true;
|
|
|
showedInformation[3] = false;
|
|
|
showedInformation[4] = true;
|
|
|
control.setMaxCapacity(10000);
|
|
|
-
|
|
|
+ setKeyBindings();
|
|
|
popmenu.add(itemCut);
|
|
|
popmenu.add(itemCopy);
|
|
|
popmenu.add(itemPaste);
|
|
@@ -400,11 +404,16 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
|
|
|
g.setColor(statecolor);
|
|
|
g.fillRect(pos.x - controller.getScaleDiv2(), pos.y - controller.getScaleDiv2(), controller.getScale(), controller.getScale());
|
|
|
drawCanvasObject(g, decoratedHolonObject.getModel().getImage(), pos);
|
|
|
-
|
|
|
+ }
|
|
|
+ private void drawCanvasObjectString(Graphics2D g, Position posOfCanvasObject, float energy) {
|
|
|
+ g.setColor(Color.BLACK);
|
|
|
+ g.setFont(new Font("TimesNewRoman", Font.PLAIN, (int) (controller.getScale() / 4f) ));
|
|
|
+ g.drawString((energy > 0)? "+" + Float.toString(energy): Float.toString(energy), posOfCanvasObject.x - controller.getScaleDiv2(), posOfCanvasObject.y - controller.getScaleDiv2() - 1);
|
|
|
}
|
|
|
private void paintConsumer(Graphics2D g, Consumer con){
|
|
|
paintCanvasObject(g, con);
|
|
|
paintSupplyBar(g,con.getSupplyBarPercentage(), getStateColor(con.getState()), con.getModel().getPosition());
|
|
|
+ drawCanvasObjectString(g, con.getModel().getPosition(), con.getEnergyNeededFromNetwork());
|
|
|
}
|
|
|
private void drawCanvasObject(Graphics2D g, String Image, Position pos) {
|
|
|
g.drawImage(Util.loadImage(Image) ,
|
|
@@ -433,6 +442,7 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
|
|
|
}
|
|
|
g.drawLine(start.x, start.y, end.x, end.y);
|
|
|
Position middle = new Position((start.x + end.x) / 2, (start.y + end.y) / 2);
|
|
|
+ g.setFont(new Font("TimesRoman", Font.PLAIN, Math.max((int) (controller.getScale() / 3.5f), 10) ));
|
|
|
g.drawString(currentEnergy + "/" + capacity , middle.x, middle.y);
|
|
|
}
|
|
|
private void paintSwitch(Graphics2D g, DecoratedSwitch dSwitch)
|
|
@@ -450,7 +460,7 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
|
|
|
g.setColor(Color.BLACK);
|
|
|
g.setStroke(new BasicStroke(1));
|
|
|
g.drawRect(pos.x - controller.getScaleDiv2(), pos.y + controller.getScaleDiv2() - 1, barWidth - 1 , barHeight);
|
|
|
- g.setFont(new Font("TimesRoman", Font.PLAIN, (int) (barHeight * 1.5) - 2));
|
|
|
+ g.setFont(new Font("TimesNewRoman", Font.PLAIN, (int) (barHeight * 1.5) - 2));
|
|
|
String percentageString = (Math.round((percentage * 100))) + "%";
|
|
|
int stringWidth = (int) g.getFontMetrics().getStringBounds(percentageString, g).getWidth();
|
|
|
if(percentage > 1.0f) g.setColor(Color.WHITE); //Just to see better on purple
|
|
@@ -482,11 +492,14 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
|
|
|
g2d.drawLine(tempCps.getPosition().x, tempCps.getPosition().y, x, y);
|
|
|
}
|
|
|
//<--
|
|
|
+ //timstep:
|
|
|
+ g.setFont(new Font("TimesNewRoman", Font.PLAIN, Math.max((int) (controller.getScale() / 3.5f), 10) ));
|
|
|
+ g.drawString("DEBUG Timestep:" + controller.getSimManager().getActualDecorState().getTimestepOfState() + ((displayOther != 0) ? " " + ((displayOther > 0) ? "+" + displayOther: displayOther): "") , 10, 10);
|
|
|
g2d.setColor(Color.BLACK);
|
|
|
- for(DecoratedCable cable : controller.getSimManager().getDecorState().getLeftOverEdges()) {
|
|
|
+ for(DecoratedCable cable : controller.getSimManager().getActualDecorStateWithOffSet(displayOther).getLeftOverEdges()) {
|
|
|
paintCable(g2d, cable);
|
|
|
}
|
|
|
- for(DecoratedNetwork network : controller.getSimManager().getDecorState().getNetworkList()) {
|
|
|
+ for(DecoratedNetwork network : controller.getSimManager().getActualDecorStateWithOffSet(displayOther).getNetworkList()) {
|
|
|
for(DecoratedCable cable : network.getDecoratedCableList()) {
|
|
|
paintCable(g2d, cable);
|
|
|
}
|
|
@@ -504,10 +517,11 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- for(DecoratedSwitch dSwitch : controller.getSimManager().getDecorState().getDecoratedSwitches()) {
|
|
|
+ for(DecoratedSwitch dSwitch : controller.getSimManager().getActualDecorStateWithOffSet(displayOther).getDecoratedSwitches()) {
|
|
|
paintSwitch(g2d, dSwitch);
|
|
|
}
|
|
|
- for(CpsNode node : controller.getSimManager().getMinimumModel().getNodeList()) {
|
|
|
+ //should be in DecorState
|
|
|
+ for(CpsNode node : controller.getSimManager().getActualDecorStateWithOffSet(displayOther).getNodeList()) {
|
|
|
drawCanvasObject(g2d, "/Images/node_selected.png" , node.getPosition());
|
|
|
}
|
|
|
//oldCode
|
|
@@ -1178,4 +1192,48 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private void setKeyBindings() {
|
|
|
+ ActionMap actionMap = getActionMap();
|
|
|
+ int condition = JComponent.WHEN_IN_FOCUSED_WINDOW;
|
|
|
+ InputMap inputMap = getInputMap(condition );
|
|
|
+
|
|
|
+ String vkLeft = "VK_UP";
|
|
|
+ String vkRight = "VK_DOWN";
|
|
|
+ inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), vkLeft);
|
|
|
+ inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), vkRight);
|
|
|
+
|
|
|
+ actionMap.put(vkLeft, new KeyAction(vkLeft));
|
|
|
+ actionMap.put(vkRight, new KeyAction(vkRight));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @SuppressWarnings("serial")
|
|
|
+ private class KeyAction extends AbstractAction {
|
|
|
+ public KeyAction(String actionCommand) {
|
|
|
+ putValue(ACTION_COMMAND_KEY, actionCommand);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void actionPerformed(ActionEvent actionEvent) {
|
|
|
+ // TODO Auto-generated method stub
|
|
|
+ System.out.println(actionEvent.getActionCommand() + " pressed");
|
|
|
+ switch(actionEvent.getActionCommand()) {
|
|
|
+ case "VK_UP":
|
|
|
+ System.out.println("increase");
|
|
|
+ if(displayOther < 0)displayOther++;
|
|
|
+ repaint();
|
|
|
+ break;
|
|
|
+ case "VK_DOWN":
|
|
|
+ System.out.println("decrease");
|
|
|
+ displayOther--;
|
|
|
+ repaint();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|