Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mpd.first.gantt;
- import java.util.ArrayList;
- import java.util.Map;
- import javafx.geometry.VPos;
- import javafx.scene.canvas.Canvas;
- import javafx.scene.canvas.GraphicsContext;
- import javafx.scene.paint.Color;
- import javafx.scene.text.TextAlignment;
- import mpd.first.algorithm.SortedTask;
- public class GanttChart {
- GraphicsContext gc;
- double posX,posY1,posY2;
- double th=0; //wysokosc komorki (podobno :P)
- int unitSize=20;
- double splitLineH;
- double downLineH;
- public GanttChart(GraphicsContext gc){
- this.gc = gc;
- gc.clearRect(0, 0, gc.getCanvas().getWidth(), gc.getCanvas().getHeight());
- }
- public void getErrorMessage(){
- gc.setTextAlign(TextAlignment.CENTER);
- gc.setTextBaseline(VPos.CENTER);
- gc.fillText(
- "Nie wszystkie dane zostały wprowadzone!",
- Math.round(gc.getCanvas().getWidth() / 2),
- Math.round(gc.getCanvas().getHeight() / 2)
- );
- }
- public void getTable(ArrayList<Map<Integer,SortedTask>> john, int maxTime){
- double canH = gc.getCanvas().getHeight();
- double canW = gc.getCanvas().getWidth();
- double xS = 20;
- double yS = 10;
- int taskAmount = john.get(0).size();
- gc.setFill(Color.BLACK);
- //gc.strokeLine(xS, yS, canW, yS); //pierwsze dluga pionowa
- gc.strokeLine(xS, yS, xS, yS+11); //linia pionowa (m od czasy
- gc.fillText("Kolejność ", xS+5, yS+11);
- gc.strokeLine(xS+60, yS, xS+60, yS+77);
- gc.strokeLine(xS, yS+15, canW, yS+15); //dluga pionowa za kolejnosc
- //kolejnosc
- double xSs=xS+60, ySs=yS+11;
- double txS=xS+60, tyS=yS+11;
- double txE=xS+60, tyE=yS+11;
- for(Map.Entry<Integer, SortedTask> task : john.get(0).entrySet()){
- xSs+=60;
- SortedTask t = task.getValue();
- gc.fillText("Z"+t.getNumber(), xSs-45, ySs);
- gc.strokeLine(xSs, ySs-11, xSs, yS+77);
- }
- tyS=yS+27;
- gc.fillText("M1 start", xS+5, yS+27);
- gc.strokeLine(xS, yS+29, canW, yS+29);
- gc.fillText("M1 stop", xS+5, yS+43);
- gc.strokeLine(xS, yS+45, canW, yS+45);
- gc.fillText("M2 start", xS+5, yS+59);
- gc.strokeLine(xS, yS+61, canW, yS+61);
- gc.fillText("M2 stop", xS+5, yS+75);
- gc.strokeLine(xS, yS, canW, yS);
- gc.strokeLine(xS, yS+77, canW, yS+77); //dluga pozioma
- gc.setLineWidth(1);
- for(Map.Entry<Integer, SortedTask> task : john.get(0).entrySet()){
- SortedTask t =task.getValue();
- gc.strokeText(String.valueOf(t.getTimeStart()), txS+5, tyS);
- gc.strokeText(String.valueOf(t.getTimeEnd()), txS+5,tyS+16);
- txS+=60;
- }
- tyE+=27;
- for(Map.Entry<Integer, SortedTask> task : john.get(1).entrySet()){
- SortedTask t =task.getValue();
- gc.strokeText(String.valueOf(t.getTimeStart()), txE+5, tyE+18);
- gc.strokeText(String.valueOf(t.getTimeEnd()), txE+5,tyE+34);
- txE+=60;
- }
- //napis M1
- }
- public void getChart(ArrayList<Map<Integer,SortedTask>> john, int maxTime){
- Map<Integer,SortedTask> machineOne = john.get(0);
- Map<Integer,SortedTask> machineTwo = john.get(0);
- double canW = gc.getCanvas().getWidth();
- double canH = gc.getCanvas().getHeight();
- double hQuarter = (int) canH/4;
- gc.clearRect(0, 0, canW, canH);
- drawInitialStuff();
- double x = posX;
- for(Map.Entry<Integer, SortedTask> e : john.get(0).entrySet()){
- SortedTask t = e.getValue();
- for(int i=0;i<t.getExecutionTime();i++){
- gc.setFill(task2Color(t.getNumber()));
- gc.fillRect(x, posY1+2, unitSize, th);
- gc.setFill(Color.BLACK);
- gc.fillText(String.valueOf(t.getNumber()), x+3, hQuarter);
- x+=unitSize;
- }
- }
- x = posX;
- for(Map.Entry<Integer, SortedTask> e : john.get(1).entrySet()){
- SortedTask t = e.getValue();
- x=posX+ unitSize*t.getTimeStart();
- gc.setFill(task2Color(t.getNumber()));
- gc.fillRect(x,posY1+th+3, unitSize*t.getExecutionTime(), th);
- gc.setFill(Color.BLACK);
- gc.fillText(String.valueOf(t.getNumber()),x+10,posY1+th*2);
- }
- }
- public Color task2Color(int num){
- switch(num){
- case 0:
- return Color.BLACK;
- case 1:
- return Color.RED;
- case 2:
- return Color.YELLOW;
- case 3:
- return Color.GREEN;
- case 4:
- return Color.BLUE;
- case 5:
- return Color.BROWN;
- case 6:
- return Color.BURLYWOOD;
- case 7:
- return Color.CYAN;
- case 8:
- return Color.ALICEBLUE;
- case 9:
- return Color.YELLOW;
- case 10:
- return Color.PALEGOLDENROD;
- default:
- return Color.SNOW;
- }
- }
- private void drawInitialStuff(){
- double canW = gc.getCanvas().getWidth();
- double canH = gc.getCanvas().getHeight();
- double hCenter = canH/2;
- double hQuarter = canH/4;
- gc.setFill(Color.BLACK);
- gc.setLineWidth(2);
- gc.strokeLine(posX=25,posY1=20, posX, hQuarter*2.6); //oddziela M od zadan
- gc.fillText("M1", 5,hQuarter);
- splitLineH = hQuarter*1.3;
- gc.strokeLine(0,splitLineH,canW,splitLineH); //linia nad m2;
- gc.fillText("M2", 5, posY2 =(hQuarter*1.8));
- downLineH = hQuarter*2;
- gc.strokeLine(0,downLineH,canW,downLineH); //linia nad numerami
- gc.setLineWidth(1);
- for(int i = (int) posX,j=1;i<canW;i+=this.unitSize,j++){
- gc.fillText(String.valueOf(j), i+5, posY2+20);
- gc.strokeLine(i, 20, i, hQuarter*2.6);
- }
- this.th=(int) (downLineH-splitLineH);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement