|
@@ -0,0 +1,98 @@
|
|
|
+package mdd.client;
|
|
|
+
|
|
|
+import javafx.beans.value.ChangeListener;
|
|
|
+import javafx.beans.value.ObservableValue;
|
|
|
+import javafx.geometry.Bounds;
|
|
|
+import javafx.scene.Group;
|
|
|
+import javafx.scene.control.Label;
|
|
|
+import javafx.scene.layout.GridPane;
|
|
|
+import javafx.scene.layout.VBox;
|
|
|
+import javafx.scene.paint.Color;
|
|
|
+import javafx.scene.shape.Rectangle;
|
|
|
+import org.json.simple.JSONArray;
|
|
|
+import org.json.simple.JSONObject;
|
|
|
+
|
|
|
+public class Permutation extends Group implements IGUIEventClient, ChangeListener<Bounds> {
|
|
|
+ private GridPane header = new GridPane();
|
|
|
+ private VBox dna = new VBox();
|
|
|
+ private Rectangle titlebar;
|
|
|
+ private Rectangle background;
|
|
|
+
|
|
|
+ protected GUIEventHandler _eventHandler;
|
|
|
+
|
|
|
+ /*
|
|
|
+ staus: " " | fitness: | time:
|
|
|
+ dna:
|
|
|
+ */
|
|
|
+ public Permutation(JSONObject json){
|
|
|
+ _eventHandler = GUIEventHandler.getEventHandler();
|
|
|
+ _eventHandler.addEventListener(this, 5);
|
|
|
+ setFocusTraversable(true);
|
|
|
+ dna.setSpacing(10);
|
|
|
+ dna.setTranslateX(5);
|
|
|
+ dna.setTranslateY(30);
|
|
|
+
|
|
|
+ titlebar = new Rectangle(0.0f, 0.0f, 1.0, 20f);
|
|
|
+ titlebar.setArcWidth(10.0f);
|
|
|
+ titlebar.setArcHeight(10.0f);
|
|
|
+
|
|
|
+ //background = new Rectangle(0.0f, 0.0f, 150-20, 150 + 40);
|
|
|
+ background = new Rectangle(0.0f, 0.0f, 1.0, 1.0);
|
|
|
+ background.setArcWidth(10.0f);
|
|
|
+ background.setArcHeight(10.0f);
|
|
|
+ background.setFill(Color.GRAY);
|
|
|
+ header.setTranslateX(10);
|
|
|
+ Color color = Color.DARKCYAN;
|
|
|
+ titlebar.setFill(color);
|
|
|
+ configure(json);
|
|
|
+ getChildren().clear();
|
|
|
+ getChildren().addAll( background, titlebar, header, dna);
|
|
|
+ dna.layoutBoundsProperty().addListener(this);
|
|
|
+ header.layoutBoundsProperty().addListener(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void configure(JSONObject json){
|
|
|
+ if(json.containsKey("status")){
|
|
|
+ header.add(new Label("status: "+ json.get("status").toString()),0,0);
|
|
|
+ }
|
|
|
+ if(json.containsKey("fitness")){
|
|
|
+ header.add(new Label("fitness: "+ json.get("fitness").toString()),0,1);
|
|
|
+ }
|
|
|
+ if(json.containsKey("time")){
|
|
|
+ header.add(new Label("time: "+ json.get("time").toString()),0,2);
|
|
|
+ }
|
|
|
+ if(json.containsKey("dna")){
|
|
|
+ dna.getChildren().clear();
|
|
|
+ JSONArray jarray = (JSONArray)json.get("dna");
|
|
|
+ for (int i = 0; i < jarray.size(); ++i){
|
|
|
+ dna.getChildren().add(new Label(jarray.get(i).toString()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void changed(ObservableValue<? extends Bounds> observableValue, Bounds oldValue, Bounds newValue) {
|
|
|
+ double width = header.getWidth();
|
|
|
+ if (newValue.getWidth() > width){
|
|
|
+ width =newValue.getWidth();
|
|
|
+ width += 10;
|
|
|
+ }else{
|
|
|
+ width += 10;
|
|
|
+ width +=10;
|
|
|
+ }
|
|
|
+ titlebar.setWidth(width);
|
|
|
+ titlebar.setHeight(20.0f);
|
|
|
+ background.setWidth(width);
|
|
|
+ background.setHeight(newValue.getHeight()+dna.getTranslateY()+10);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void processGUIEvent(String event, JSONObject args) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void close() throws Exception {
|
|
|
+
|
|
|
+ }
|
|
|
+}
|