|
@@ -1,111 +1,117 @@
|
|
|
package mdd.client.optimization;
|
|
|
|
|
|
-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 mdd.client.GUIEventHandler;
|
|
|
import mdd.client.IGUIEventClient;
|
|
|
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;
|
|
|
+import java.util.*;
|
|
|
|
|
|
+public class Permutation implements IData, IGUIEventClient {
|
|
|
+ private Vector<String> _skeys = new Vector<>();
|
|
|
+ private Vector<Integer> _ikeys = new Vector<>();
|
|
|
+ private Vector<Double> _vals = new Vector<>();
|
|
|
protected GUIEventHandler _eventHandler;
|
|
|
- protected JSONObject _jprocessor;
|
|
|
- protected JSONArray _dna;
|
|
|
- protected long _gen;
|
|
|
+ public JSONObject jprocessor;
|
|
|
+ public JSONArray jdna;
|
|
|
+ public long step;
|
|
|
|
|
|
- Label _status = new Label();
|
|
|
- Label _fitness = new Label();
|
|
|
- Label _time = new Label();
|
|
|
+ private DataTable _model;
|
|
|
+ private int _row;
|
|
|
|
|
|
- /*
|
|
|
- staus: " " | fitness: | time:
|
|
|
- dna:
|
|
|
- */
|
|
|
public Permutation(long gen, JSONObject json){
|
|
|
- _gen = gen;
|
|
|
+ step = gen;
|
|
|
_eventHandler = GUIEventHandler.getEventHandler();
|
|
|
_eventHandler.addEventListener(this, 5);
|
|
|
- setFocusTraversable(true);
|
|
|
- dna.setSpacing(10);
|
|
|
- dna.setTranslateX(5);
|
|
|
- dna.setTranslateY(30);
|
|
|
+ setValue("step", (double)gen);
|
|
|
+ configure(json);
|
|
|
+ }
|
|
|
|
|
|
- titlebar = new Rectangle(0.0f, 0.0f, 1.0, 20f);
|
|
|
- titlebar.setArcWidth(10.0f);
|
|
|
- titlebar.setArcHeight(10.0f);
|
|
|
+ @Override
|
|
|
+ public void setDataModel(DataTable table, int row){
|
|
|
+ _model = table;
|
|
|
+ _row = row;
|
|
|
+ for (int i = 0; i < _skeys.size(); ++i){
|
|
|
+ _ikeys.set(i, _model.addColumn(_skeys.get(i)));
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- //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);
|
|
|
+ @Override
|
|
|
+ public Vector<String> getKeys(){
|
|
|
+ return _skeys;
|
|
|
+ }
|
|
|
|
|
|
- header.add(_status,0,0);
|
|
|
- header.add(_fitness,1,0);
|
|
|
- header.add(_time,2,0);
|
|
|
+ @Override
|
|
|
+ public Vector<Integer> getIDs(){
|
|
|
+ return _ikeys;
|
|
|
+ }
|
|
|
|
|
|
- header.setHgap(5.0f);
|
|
|
+ @Override
|
|
|
+ public Double getValue(int column){
|
|
|
+ for (int i = 0; i < _skeys.size(); ++i){
|
|
|
+ if (_ikeys.get(i).equals(column)){
|
|
|
+ return _vals.get(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
- configure(json);
|
|
|
- getChildren().clear();
|
|
|
- getChildren().addAll( background, titlebar, header, dna);
|
|
|
- dna.layoutBoundsProperty().addListener(this);
|
|
|
- header.layoutBoundsProperty().addListener(this);
|
|
|
+ @Override
|
|
|
+ public void setValue(String key, Double val){
|
|
|
+ for (int i = 0; i < _skeys.size(); ++i){
|
|
|
+ if (_skeys.get(i).equals(key)){
|
|
|
+ if (!_vals.get(i).equals(val)){
|
|
|
+ _vals.set(i,val);
|
|
|
+ if (_model != null){
|
|
|
+ _model.callback_change(_row, _ikeys.get(i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //key doesnt exist
|
|
|
+ _skeys.add(key);
|
|
|
+ _ikeys.add(null);
|
|
|
+ _vals.add(val);
|
|
|
+ if (_model != null){
|
|
|
+ _ikeys.set(_ikeys.size()-1, _model.addColumn(key));
|
|
|
+ _model.callback_change(_row, _ikeys.lastElement());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
protected void configure(JSONObject json){
|
|
|
if(json.containsKey("status")){
|
|
|
- _status.setText("status: "+ json.get("status").toString());
|
|
|
+ switch(json.get("status").toString()){
|
|
|
+ case "ok":
|
|
|
+ setValue("status", 1.0);
|
|
|
+ break;
|
|
|
+ case "error":
|
|
|
+ setValue("status", -1.0);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ setValue("status", 0.0);
|
|
|
+ }
|
|
|
}
|
|
|
if(json.containsKey("fitness")){
|
|
|
- _fitness.setText("fitness: "+ json.get("fitness").toString());
|
|
|
+ setValue("fitness", (double)json.get("fitness"));
|
|
|
}
|
|
|
if(json.containsKey("time")){
|
|
|
- _time.setText("time: "+ json.get("time").toString());
|
|
|
+ setValue("time", (double)json.get("time"));
|
|
|
}
|
|
|
- if (_dna == null){
|
|
|
+ if (jdna == null){
|
|
|
if(json.containsKey("dna")){
|
|
|
- dna.getChildren().clear();
|
|
|
- _dna = (JSONArray)json.get("dna");
|
|
|
- for (int i = 0; i < _dna.size(); ++i){
|
|
|
- dna.getChildren().add(new Label(_dna.get(i).toString()));
|
|
|
+ jdna = (JSONArray)json.get("dna");
|
|
|
+ for (int i = 0; i < jdna.size(); ++i){
|
|
|
+ JSONArray params = (JSONArray) jdna.get(i);
|
|
|
+ for (int j = 0; j < params.size(); ++j){
|
|
|
+ setValue("param["+i+","+j+"]", (double) params.get(j));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if(json.containsKey("processor")){
|
|
|
- _jprocessor = (JSONObject) json.get("processor");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @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;
|
|
|
+ jprocessor = (JSONObject) json.get("processor");
|
|
|
}
|
|
|
- titlebar.setWidth(width);
|
|
|
- titlebar.setHeight(20.0f);
|
|
|
- background.setWidth(width);
|
|
|
- background.setHeight(dna.getTranslateY()+dna.getHeight()+10);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -132,7 +138,7 @@ public class Permutation extends Group implements IGUIEventClient, ChangeListene
|
|
|
if (!jobj.containsKey("step")) {
|
|
|
return;
|
|
|
}
|
|
|
- if (_gen!=(long)jobj.get("step")){
|
|
|
+ if (step !=(long)jobj.get("step")){
|
|
|
return;
|
|
|
}
|
|
|
if (!jobj.containsKey("permutation")) {
|
|
@@ -140,10 +146,10 @@ public class Permutation extends Group implements IGUIEventClient, ChangeListene
|
|
|
}
|
|
|
JSONObject jind = (JSONObject)jobj.get("permutation");
|
|
|
//System.out.println("Permutation: " + _dna.toString());
|
|
|
- if (!_dna.equals((JSONArray)jind.get("dna"))) {
|
|
|
+ if (!jdna.equals((JSONArray)jind.get("dna"))) {
|
|
|
return;
|
|
|
}else{
|
|
|
- if (!_dna.toString().equals(jind.get("dna").toString())){
|
|
|
+ if (!jdna.toString().equals(jind.get("dna").toString())){
|
|
|
System.out.println("It happened!");
|
|
|
}
|
|
|
configure(jind);
|