Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.13 KB | None | 0 0
  1. package mpd.first.gantt;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Map;
  5.  
  6. import javafx.geometry.VPos;
  7. import javafx.scene.canvas.Canvas;
  8. import javafx.scene.canvas.GraphicsContext;
  9. import javafx.scene.paint.Color;
  10. import javafx.scene.text.TextAlignment;
  11. import mpd.first.algorithm.SortedTask;
  12.  
  13. public class GanttChart {
  14.     GraphicsContext gc;
  15.     double posX,posY1,posY2;
  16.     double th=0; //wysokosc komorki (podobno :P)
  17.     int unitSize=20;
  18.     double splitLineH;
  19.     double downLineH;
  20.     public GanttChart(GraphicsContext gc){
  21.         this.gc = gc;
  22.         gc.clearRect(0, 0, gc.getCanvas().getWidth(), gc.getCanvas().getHeight());
  23.     }
  24.    
  25.     public void getErrorMessage(){
  26.         gc.setTextAlign(TextAlignment.CENTER);
  27.         gc.setTextBaseline(VPos.CENTER);
  28.         gc.fillText(
  29.             "Nie wszystkie dane zostały wprowadzone!",
  30.             Math.round(gc.getCanvas().getWidth()  / 2),
  31.             Math.round(gc.getCanvas().getHeight() / 2)
  32.         );
  33.     }
  34.     public void getTable(ArrayList<Map<Integer,SortedTask>> john, int maxTime){
  35.         double canH = gc.getCanvas().getHeight();
  36.         double canW = gc.getCanvas().getWidth();
  37.         double xS = 20;
  38.         double yS = 10;
  39.         int taskAmount = john.get(0).size();
  40.         gc.setFill(Color.BLACK);
  41.         //gc.strokeLine(xS, yS, canW, yS); //pierwsze dluga pionowa
  42.         gc.strokeLine(xS, yS, xS, yS+11); //linia pionowa (m od czasy
  43.         gc.fillText("Kolejność ", xS+5, yS+11);
  44.         gc.strokeLine(xS+60, yS, xS+60, yS+77);
  45.         gc.strokeLine(xS, yS+15, canW, yS+15); //dluga pionowa za kolejnosc
  46.         //kolejnosc
  47.         double xSs=xS+60, ySs=yS+11;
  48.         double txS=xS+60, tyS=yS+11;
  49.         double txE=xS+60, tyE=yS+11;
  50.         for(Map.Entry<Integer, SortedTask> task : john.get(0).entrySet()){
  51.             xSs+=60;
  52.             SortedTask t = task.getValue();
  53.             gc.fillText("Z"+t.getNumber(), xSs-45, ySs);
  54.             gc.strokeLine(xSs, ySs-11, xSs, yS+77);
  55.         }
  56.         tyS=yS+27;
  57.         gc.fillText("M1 start", xS+5, yS+27);
  58.         gc.strokeLine(xS, yS+29, canW, yS+29);
  59.         gc.fillText("M1 stop", xS+5, yS+43);
  60.         gc.strokeLine(xS, yS+45, canW, yS+45);
  61.         gc.fillText("M2 start", xS+5, yS+59);
  62.         gc.strokeLine(xS, yS+61, canW, yS+61);
  63.         gc.fillText("M2 stop", xS+5, yS+75);
  64.         gc.strokeLine(xS, yS, canW, yS);
  65.         gc.strokeLine(xS, yS+77, canW, yS+77); //dluga pozioma
  66.         gc.setLineWidth(1);
  67.         for(Map.Entry<Integer, SortedTask> task : john.get(0).entrySet()){
  68.             SortedTask t =task.getValue();
  69.             gc.strokeText(String.valueOf(t.getTimeStart()), txS+5, tyS);
  70.             gc.strokeText(String.valueOf(t.getTimeEnd()), txS+5,tyS+16);
  71.             txS+=60;
  72.         }
  73.         tyE+=27;
  74.         for(Map.Entry<Integer, SortedTask> task : john.get(1).entrySet()){
  75.             SortedTask t =task.getValue();
  76.             gc.strokeText(String.valueOf(t.getTimeStart()), txE+5, tyE+18);
  77.             gc.strokeText(String.valueOf(t.getTimeEnd()), txE+5,tyE+34);
  78.             txE+=60;
  79.         }
  80.        
  81.        
  82.         //napis M1
  83.     }
  84.     public void getChart(ArrayList<Map<Integer,SortedTask>> john, int maxTime){
  85.         Map<Integer,SortedTask> machineOne = john.get(0);
  86.         Map<Integer,SortedTask> machineTwo = john.get(0);
  87.         double canW = gc.getCanvas().getWidth();
  88.         double canH = gc.getCanvas().getHeight();
  89.         double hQuarter = (int) canH/4;
  90.         gc.clearRect(0, 0, canW, canH);
  91.         drawInitialStuff();
  92.         double x = posX;
  93.         for(Map.Entry<Integer, SortedTask> e : john.get(0).entrySet()){
  94.             SortedTask t = e.getValue();
  95.             for(int i=0;i<t.getExecutionTime();i++){
  96.                 gc.setFill(task2Color(t.getNumber()));
  97.                 gc.fillRect(x, posY1+2, unitSize, th);
  98.                 gc.setFill(Color.BLACK);
  99.                 gc.fillText(String.valueOf(t.getNumber()), x+3, hQuarter);
  100.                 x+=unitSize;
  101.             }
  102.         }
  103.         x = posX;
  104.         for(Map.Entry<Integer, SortedTask> e : john.get(1).entrySet()){
  105.             SortedTask t = e.getValue();
  106.             x=posX+ unitSize*t.getTimeStart();
  107.             gc.setFill(task2Color(t.getNumber()));
  108.             gc.fillRect(x,posY1+th+3, unitSize*t.getExecutionTime(), th);
  109.             gc.setFill(Color.BLACK);
  110.             gc.fillText(String.valueOf(t.getNumber()),x+10,posY1+th*2);
  111.         }  
  112.     }
  113.     public Color task2Color(int num){
  114.         switch(num){
  115.             case 0:
  116.                 return Color.BLACK;
  117.             case 1:
  118.                 return Color.RED;
  119.             case 2:
  120.                 return Color.YELLOW;
  121.             case 3:
  122.                 return Color.GREEN;
  123.             case 4:
  124.                 return Color.BLUE;
  125.             case 5:
  126.                 return Color.BROWN;
  127.             case 6:
  128.                 return Color.BURLYWOOD;
  129.             case 7:
  130.                 return Color.CYAN;
  131.             case 8:
  132.                 return Color.ALICEBLUE;
  133.             case 9:
  134.                 return Color.YELLOW;
  135.             case 10:
  136.                 return Color.PALEGOLDENROD;
  137.             default:
  138.                 return Color.SNOW;
  139.         }
  140.     }
  141.     private void drawInitialStuff(){
  142.         double canW = gc.getCanvas().getWidth();
  143.         double canH = gc.getCanvas().getHeight();
  144.         double hCenter = canH/2;
  145.         double hQuarter = canH/4;
  146.         gc.setFill(Color.BLACK);
  147.         gc.setLineWidth(2);
  148.         gc.strokeLine(posX=25,posY1=20, posX, hQuarter*2.6); //oddziela M od zadan
  149.         gc.fillText("M1", 5,hQuarter);
  150.         splitLineH = hQuarter*1.3;
  151.         gc.strokeLine(0,splitLineH,canW,splitLineH); //linia nad m2;
  152.         gc.fillText("M2", 5, posY2 =(hQuarter*1.8));
  153.         downLineH = hQuarter*2;
  154.         gc.strokeLine(0,downLineH,canW,downLineH); //linia nad numerami
  155.         gc.setLineWidth(1);
  156.         for(int i = (int) posX,j=1;i<canW;i+=this.unitSize,j++){
  157.             gc.fillText(String.valueOf(j), i+5, posY2+20);
  158.             gc.strokeLine(i, 20, i, hQuarter*2.6);
  159.         }
  160.         this.th=(int) (downLineH-splitLineH);
  161.     }
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement