changeset 29:fe96dd350d9d

add button CheckBox
author sugi
date Tue, 05 Nov 2013 14:02:40 +0900
parents 5902144dc286
children 7306b4ea110e
files src/alice/topology/manager/keeparive/PingScheduler.java src/alice/topology/manager/keeparive/SchedulerViewer.java
diffstat 2 files changed, 83 insertions(+), 59 deletions(-) [+]
line wrap: on
line diff
--- a/src/alice/topology/manager/keeparive/PingScheduler.java	Tue Nov 05 10:58:17 2013 +0900
+++ b/src/alice/topology/manager/keeparive/PingScheduler.java	Tue Nov 05 14:02:40 2013 +0900
@@ -1,6 +1,5 @@
 package alice.topology.manager.keeparive;
 
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
@@ -9,9 +8,12 @@
 
 public class PingScheduler extends CodeSegment{
 	private LinkedList<TaskInfo> list = new LinkedList<TaskInfo>();
-	private ArrayList<TaskInfo> regist = new ArrayList<TaskInfo>();
 	private HashMap<String, Integer> map = new HashMap<String, Integer>();
+	private long INTERVAL = 60 * 1000;
+	
 	public boolean updateFlag = false;
+	private boolean postponeFlag = false;
+	
 	public long time = 0;
 	public int taskNum = 0;
 	public TaskInfo nowTask;
@@ -21,22 +23,32 @@
 		return totalTime;
 	}
 	
-	public List<TaskInfo> nameList(){
-		return regist;
-	}
-	
 	public List<TaskInfo> getTaskList(){
 		return list;
 	}
 	
-	public synchronized void wake(){
-		long t = System.currentTimeMillis();
-		long addTime = nowTask.getTime() - (t - time);
-		TaskInfo ti = list.get(0);
-		ti.setTime(ti.getTime() + addTime);
-		this.notify();
+	public synchronized void postpone(String name){
+		long postponeTime = nowTask.getTime() - (System.currentTimeMillis() - time);
+		if (name.equals(nowTask.getName())){
+			TaskInfo nextTask = list.get(0);
+			nextTask.setTime(postponeTime + nextTask.getTime());
+			
+		} else {
+			for (int cnt = 0 ;cnt < list.size();  cnt++){
+				TaskInfo task = list.get(cnt);
+				if (name.equals(task.getName())){
+					list.remove(cnt);
+					task.setTime(INTERVAL);
+					addTask(task);
+					postponeFlag = true;
+					break;
+				}
+			}
+		}
+		notify();
 	}
 	
+	
 	public synchronized void addTask(TaskInfo newInfo){
 		if (map.containsKey(newInfo.getName())){
 			newInfo.setTaskNum(map.get(newInfo.getName()));
@@ -81,9 +93,16 @@
 				time = System.currentTimeMillis();
 				if (nowTask.getTime()!=0)
 					this.wait(nowTask.getTime());
-				totalTime +=nowTask.getTime();
-				nowTask.setTime(30 * 1000);
-				addTask(nowTask);
+				if (postponeFlag){
+					long remainingTime = nowTask.getTime() - (System.currentTimeMillis() - time);
+					nowTask.setTime(remainingTime);
+					list.add(0, nowTask);
+					postponeFlag = false;
+				} else {
+					totalTime +=nowTask.getTime();
+					nowTask.setTime(INTERVAL);
+					addTask(nowTask);					
+				}
 				
 			}
 		} catch (InterruptedException e) {
--- a/src/alice/topology/manager/keeparive/SchedulerViewer.java	Tue Nov 05 10:58:17 2013 +0900
+++ b/src/alice/topology/manager/keeparive/SchedulerViewer.java	Tue Nov 05 14:02:40 2013 +0900
@@ -16,6 +16,9 @@
 import javafx.scene.chart.LineChart;
 import javafx.scene.chart.NumberAxis;
 import javafx.scene.chart.XYChart;
+import javafx.scene.control.Button;
+import javafx.scene.control.ChoiceBox;
+import javafx.scene.layout.VBox;
 import javafx.util.Duration;
 
 /**
@@ -28,28 +31,23 @@
  */
 public class SchedulerViewer extends Application {
 	private PingScheduler ps;
-	private XYChart.Series<Number,Number> hourDataSeries;
+	private XYChart.Series<Number,Number> dataSeries;
+	private ChoiceBox<String> cb;
 	private NumberAxis xAxis;
 	private Timeline animation;
+	private int count;
 
-	private double hours = 0;
-	private double minutes = 0;
-	private double timeInHours = 0;
-	private int count;
-	
 
 	private void init(Stage primaryStage) {
 		Group root = new Group();
 		primaryStage.setScene(new Scene(root));
-		root.getChildren().add(createChart());
+		root.getChildren().addAll(createChart(), createButton(), createChoiceBox());
 		// create timeline to add new data every 60th of second
 		animation = new Timeline();
 		animation.getKeyFrames().add(new KeyFrame(Duration.millis(1000/60), new EventHandler<ActionEvent>() {
 			@Override public void handle(ActionEvent actionEvent) {
 				// 6 minutes data per frame
 				for(int count=0; count < 6; count++) {
-					nextTime();
-					plotTime();
 					plotGraph();
 				}
 			}
@@ -70,64 +68,71 @@
 		xAxis.setLabel("Time");
 		xAxis.setForceZeroInRange(false);
 		yAxis.setLabel("Task Name");
-		yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis,"$",null));
+		yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis,"Task ",null));
 		// add starting data
-		hourDataSeries = new XYChart.Series<Number,Number>();
-		lc.getData().add(hourDataSeries);
+		dataSeries = new XYChart.Series<Number,Number>();
+		lc.getData().add(dataSeries);
 		return lc;
 	}
 
 	private void plotGraph() {
 		if (ps.updateFlag){
-			if(!hourDataSeries.getData().isEmpty())
-				hourDataSeries.getData().clear();
+			if(!dataSeries.getData().isEmpty())
+				dataSeries.getData().clear();
 			count = (int) (ps.getTotalTime()/1000);
-			hourDataSeries.getData().add(new XYChart.Data<Number, Number>(count, ps.nowTask.getTaskNum()));
+			dataSeries.getData().add(new XYChart.Data<Number, Number>(count, ps.nowTask.getTaskNum()));
 			count +=ps.nowTask.getTime()/1000;
-			hourDataSeries.getData().add(new XYChart.Data<Number, Number>(count, ps.nowTask.getTaskNum()));
-			
+			dataSeries.getData().add(new XYChart.Data<Number, Number>(count, ps.nowTask.getTaskNum()));
+
 			for (TaskInfo info : ps.getTaskList()){
-				
-				hourDataSeries.getData().add(new XYChart.Data<Number, Number>(count, info.getTaskNum()));
+				dataSeries.getData().add(new XYChart.Data<Number, Number>(count, info.getTaskNum()));
 				count += info.getTime()/1000;
-				hourDataSeries.getData().add(new XYChart.Data<Number, Number>(count, info.getTaskNum()));
+				dataSeries.getData().add(new XYChart.Data<Number, Number>(count, info.getTaskNum()));
 			}
 			ps.updateFlag = false;
+			//plotTimeLine();
 		}
-		
-		
+	}
+
+	public void plotTimeLine() {		
+		xAxis.setLowerBound(xAxis.getLowerBound()+ 10);
+		xAxis.setUpperBound(xAxis.getUpperBound()+ 10);
 	}
 
-	private void nextTime() {
-		if (minutes == 59) {
-			hours ++;
-			minutes = 0;
-		} else {
-			minutes ++;
-		}
-		timeInHours = hours + ((1d/60d)*minutes);
+	private VBox createButton(){
+		VBox vbox = new VBox();
+		vbox.setId("vbox");
+		Button button = new Button("update");
+		button.setOnAction(new EventHandler<ActionEvent>() {
+            public void handle(ActionEvent t) {
+                ps.postpone(cb.getValue());
+            }
+        });
+		vbox.getChildren().add(button);
+		return vbox;
 	}
 
-	private void plotTime() {
-		
-		if ((timeInHours % 1) == 0) {
-				xAxis.setLowerBound(xAxis.getLowerBound());
-				xAxis.setUpperBound(xAxis.getUpperBound());
-			
-		}
+	private ChoiceBox<String> createChoiceBox(){
+		cb = new ChoiceBox<String>();
+		cb.getItems().add(ps.nowTask.getName());
+		for (TaskInfo info : ps.getTaskList())
+			cb.getItems().add(info.getName());
+		cb.getSelectionModel().selectFirst();
+		cb.setLayoutX(100);
+		return cb;
 	}
 	
 	public void StartScheduler(){
 		ps = new PingScheduler();
 		TaskInfo a = new TaskInfo("a", 10 * 1000);
 		TaskInfo b = new TaskInfo("b", 20 * 1000);
-		
-		
-		TaskInfo c = new TaskInfo("c", 60* 1000);
+
+
+		TaskInfo c = new TaskInfo("c", 60 * 1000);
 		TaskInfo d = new TaskInfo("d", 40 * 1000);
-		TaskInfo e = new TaskInfo("e", 80 * 1000);
-		
-		
+		TaskInfo e = new TaskInfo("e", 30 * 1000);
+
+
 		ps.addTask(a);
 		ps.addTask(b);
 		ps.addTask(c);
@@ -150,5 +155,5 @@
 		primaryStage.show();
 		play();
 	}
-	
+
 }