2017-12-18 3 views
0

Der Versuch, eine Kreise Diagramm Software zu machen. Ändern der Kreise Komponenten mit einem Maus-Drag-Ereignis.Java unerwünschte Listener Aufruf und Funktion Parameter invertiert

Got 2 Probleme:

1) - centerXProperty des Zuhörers von sg jedoch aufgerufen wird seine X nicht ändern koordinieren, wie kommt das?

2) - Ich gebe die gleichen Parameter in der updateComponents(), aber sobald ich einige Beschreibungen über die Kreise, erscheint es in der Konsole, dass die Parameter für centerXProperty Listener invertiert wurden.

hier der Code und die Konsole druckt, um weitere Informationen:

public class TDGAPIUI extends Application { 

    @Override 
    public void start(Stage primaryStage) throws NoSommet2DException, RelationMismatchException { 
     Sommet sommetA = new Sommet("A"); 
     Sommet sommetB = new Sommet("B"); 

     ArcPondere e1 = new ArcPondere("e1", 5, sommetA, sommetB); 

     Sommet2D sommet2DA = new Sommet2D(sommetA); 
     Sommet2D sommet2DB = new Sommet2D(sommetB); 

     Relation2D relation2De1 = new Relation2D(e1); 

     StackPane root = new StackPane(); 
        root.setStyle("-fx-background-color: white;"); 
        root.getChildren().addAll(relation2De1); 
        root.getChildren().addAll(sommet2DA,sommet2DB); 

     Scene scene = new Scene(root, 800, 600); 

     primaryStage.setTitle("Hello World!"); 
     primaryStage.setScene(scene); 
     primaryStage.show(); 
    } 

    /** 
    * @param args the command line arguments 
    */ 
    public static void main(String[] args) { 
     launch(args); 
    } 
} 

public class Sommet implements Comparable{ 

    private SimpleObjectProperty<ArrayList<Relation>> listeRelations = new SimpleObjectProperty<ArrayList<Relation>>(new ArrayList<Relation>()); 
    private SimpleObjectProperty<Sommet2D> sommet2D = new SimpleObjectProperty<Sommet2D>(null); 
    private SimpleStringProperty label = new SimpleStringProperty("No Label"); 

    public Sommet(String label){ 
     this.label.set(label); 
    } 

    public Sommet(String label,Relation ... relations){ 
     this.label.set(label); 
     this.listeRelations.getValue().addAll(Arrays.asList(relations)); 
    } 

    public SimpleStringProperty labelProperty(){ 
     return this.label; 
    } 

    public SimpleObjectProperty<ArrayList<Relation>> listeRelationsProperty(){ 
     return this.listeRelations; 
    } 

    public SimpleObjectProperty<Sommet2D> sommet2DProperty(){ 
     return this.sommet2D; 
    } 

    /** 
    * @return the label 
    */ 
    public String getLabel() { 
     return label.getValue(); 
    } 

    /** 
    * @param label the label to set 
    */ 
    public void setLabel(String label) { 
     this.label.setValue(label); 
    } 

    /** 
    * @return the listeRelations 
    */ 
    public ArrayList<Relation> getListeRelations() { 
     return listeRelations.getValue(); 
    } 

    /** 
    * @param listeRelations the listeRelations to set 
    */ 
    public void setListeRelations(ArrayList<Relation> listeRelations) { 
     this.listeRelations.setValue(listeRelations); 
    } 

    public Sommet2D getSommet2D(){ 
     return this.sommet2D.get(); 
    } 

    public void setSommet2D(Sommet2D sommet2D){ 
     this.sommet2D.setValue(sommet2D); 
    } 

    @Override 
    public String toString(){ 
     return "Description du Sommet: " + this.label.getValue() + "\n"; 
    } 

    @Override 
    public boolean equals(Object o){ 
     if(o instanceof Sommet) 
      return this.label.getValue().equals(((Sommet) o).getLabel()); 
     return false; 
    } 

    @Override 
    public int compareTo(Object o) { 
     if(o instanceof Sommet) 
      return this.label.getValue().compareTo(((Sommet) o).label.getValue()); 
     return 0; 
    } 

    public boolean isIncidentTo(Relation relation){ 
     for(Relation r: this.listeRelations.getValue()) 
      if(relation.equals(r)) return true; 
     return false; 
    } 
} 

public class ArcPondere extends Arc {  
    public ArcPondere(String label, double poid, Sommet sommetGauche, Sommet sommetDroit) { 
     super(label, sommetGauche, sommetDroit); 
     this.ponderationValue.setValue(new ValuePonderation(poid)); 
    } 

    /** 
    * @return the poid 
    */ 
    public double getPoid() { 
     return this.ponderationValue.getValue().getPoid(); 
    } 

    /** 
    * @param poid the poid to set 
    */ 
    public void setPoid(double poid) { 
     this.ponderationValue.getValue().setPoid(poid); 
    } 

    public SimpleDoubleProperty poidProperty(){ 
     return this.ponderationValue.getValue().poidProperty(); 
    } 

    @Override 
    public boolean equals(Object o){ 
     if(o instanceof ArcPondere) 
      return super.equals(o) && this.ponderationValue.getValue().getPoid() == ((ArcPondere) o).ponderationValue 
        .getValue().getPoid(); 
     return false; 
    } 

    @Override 
    public int compareTo(Object o){ 
     if(o instanceof ArcPondere) 
      return (int)(this.getPoid() - ((ArcPondere) o).getPoid()); 
     return 0; 
    } 
} 

public class Sommet2D extends Circle { 

    private SimpleObjectProperty<Sommet> sommet = new SimpleObjectProperty<Sommet>(null); 
    private Text label = new Text(); 

    public Sommet2D(Sommet sommet){ 
     this.sommet.setValue(sommet); 
     this.sommet.getValue().setSommet2D(this); 

     this.initGraphicSettings(
        "-fx-fill: rgb(255,255,255); " 
       + "-fx-stroke-width: 2px; " 
       + "-fx-stroke: rgba(0,0,0,1);", 
        "-fx-fill: rgb(0,0,0);"); 

     this.setRadius(25.0); 
     this.setCenterX(Screen.getMainScreen().getWidth()/2); 
     this.setCenterY(Screen.getMainScreen().getHeight()/2); 

     this.layoutXProperty().addListener((observable) -> { this.setLayoutX(0.0); }); 
     this.layoutYProperty().addListener((observable) -> { this.setLayoutY(0.0); }); 

     this.label.textProperty().bind(sommet.labelProperty()); 
     this.label.layoutXProperty().addListener((observable) -> { this.label.setLayoutX(0.0); }); 
     this.label.layoutYProperty().addListener((observable) -> { this.label.setLayoutY(0.0); }); 
     this.label.xProperty().bind(this.centerXProperty().subtract(this.label.prefWidth(0)/2)); 
     this.label.yProperty().bind(this.centerYProperty().add(this.label.prefHeight(0)/4)); 

     this.setOnMouseDragged(new EventHandler<MouseEvent>(){ 
      @Override 
      public void handle(MouseEvent event) {  
       double xPos = event.getSceneX(); 
       double yPos = event.getSceneY(); 

       setCenterX(xPos); 
       setCenterY(yPos); 
      }    
     }); 

     this.parentProperty().addListener(new ChangeListener<Parent>(){ 
      @Override 
      public void changed(ObservableValue<? extends Parent> observable, Parent oldValue, Parent newValue) { 
       if(newValue != null){ 
        if(label.getParent() != null) 
         (((Pane)label.getParent()).getChildren()).remove(label); 
        (((Pane)newValue).getChildren()).add(label); 
       } 
      } 
     }); 
    } 

    public void setSommet(Sommet sommet){ 
     this.sommet.setValue(sommet); 
    } 

    public Sommet getSommet(){ 
     return this.sommet.getValue(); 
    } 

    public void initGraphicSettings(String circleCss,String labelCss){  
     this.label.setStyle(labelCss); 
     this.setStyle(circleCss); 
    } 
} 

public class Relation2D extends Line{ 

    private SimpleObjectProperty<Relation> relation = new SimpleObjectProperty<Relation>(null); 
    private Line[] arrows = new Line[2]; 
    private Text label = new Text(); 

    public Relation2D(Relation relation) throws NoSommet2DException { 
     Sommet2D sg = relation.getSommetGauche().getSommet2D(); 
     Sommet2D sd = relation.getSommetDroit().getSommet2D(); 

     if(sd == null || sg == null) 
      throw new NoSommet2DException(); 

     this.relation.setValue(relation);   

     this.initLabelBindings(); 
     this.initComponentsBindings(); 
     this.initParentBindings(); 
     this.initGraphicSettings("-fx-fill: rgb(255,255,255); -fx-stroke-width: 5px; -fx-stroke: rgba(0,0,0,1);", 
       "-fx-fill: rgb(0,0,0);"); 

     if(relation instanceof Arc) 
      this.initArrows(); 
    } 

    public void setSommet(Relation relation){ 
     this.relation.setValue(relation); 
    } 

    public Relation getRelation(){ 
     return this.relation.getValue(); 
    } 

    public void initGraphicSettings(String lineCss,String labelCss){ 
     this.setStyle(labelCss); 
     this.label.setStyle(labelCss); 
    } 

    private void initLabelBindings(){ 
     this.label.setX(Double.MIN_VALUE); 
     this.label.setY(Double.MIN_VALUE); 

     Relation relation = this.getRelation(); 

     this.label.textProperty().bind(relation.labelProperty().concat(
      (relation instanceof AretePondere ? ": " + ((AretePondere) relation).getPoid() : (
        relation instanceof ArcPondere ? ": " + ((ArcPondere) relation).getPoid() : "")))); 

     this.label.layoutXProperty().addListener(event -> this.setLayoutX(0.0)); 
     this.label.layoutYProperty().addListener(event -> this.setLayoutY(0.0)); 

     this.label.layoutXProperty().addListener(event -> this.label.setLayoutX(0.0)); 
     this.label.layoutYProperty().addListener(event -> this.label.setLayoutY(0.0)); 

     this.label.xProperty().bind((this.startXProperty().add((this.endXProperty().subtract(this.startXProperty())).divide(2))).subtract(this.label.getText().length() * 7/2 * this.label.getStrokeWidth())); 
     this.label.yProperty().bind((this.startYProperty().add((this.endYProperty().subtract(this.startYProperty())).divide(2))).subtract(this.label.getText().length() * this.label.getStrokeWidth())); 
    } 

    private void initComponentsBindings(){ 
     // Layout ne doit pas influencer les composantes des vecteurs   
     this.layoutXProperty().addListener(event -> this.setLayoutX(0.0)); 
     this.layoutYProperty().addListener(event -> this.setLayoutY(0.0)); 
     // 
     this.setStartX(Double.MIN_VALUE); 
     this.setEndX(Double.MAX_VALUE); 
     this.setStartY(Double.MIN_VALUE); 
     this.setEndY(Double.MAX_VALUE); 

     Sommet2D sg = this.getRelation().getSommetGauche().getSommet2D(); 
     Sommet2D sd = this.getRelation().getSommetDroit().getSommet2D(); 

     DoubleBinding dx = sd.centerXProperty().subtract(sg.centerXProperty()); 
     DoubleBinding dy = sd.centerYProperty().subtract(sg.centerYProperty()); 

     sg.centerXProperty().addListener((observable) -> { 
      System.out.println("SG X Event:"); 
      updateComponents(dx.getValue(),dy.getValue(),sg,sd); 
      //updateArrowsComponents(dx.getValue(),dy.getValue()); 
      System.out.println("---------------------------------------------"); 
     }); 
     sg.centerYProperty().addListener((value) -> { 
      System.out.println("SG Y Event:"); 
      updateComponents(dx.getValue(),dy.getValue(),sg,sd); 
      //updateArrowsComponents(dx.getValue(),dy.getValue()); 
      System.out.println("---------------------------------------------"); 
     }); 

     sd.centerXProperty().addListener((observable) -> { 
      System.out.println("SD X Event:");  
      updateComponents(dx.getValue(),dy.getValue(),sg,sd); 
      //updateArrowsComponents(dx.getValue(),dy.getValue()); 
      System.out.println("---------------------------------------------"); 
     }); 
     sd.centerYProperty().addListener((observable) -> { 
      System.out.println("SD Y Event:"); 
      updateComponents(dx.getValue(),dy.getValue(),sg,sd); 
      //updateArrowsComponents(dx.getValue(),dy.getValue()); 
      System.out.println("---------------------------------------------"); 
     }); 
    } 

    private void initParentBindings(){   
     this.parentProperty().addListener(new ChangeListener<Parent>(){ 
      @Override 
      public void changed(ObservableValue<? extends Parent> observable, Parent oldValue, Parent newValue) { 
       if(newValue != null){ 
        if(label.getParent() != null) 
         (((Pane)label.getParent()).getChildren()).removeAll(label); 
        (((Pane)newValue).getChildren()).addAll(label); 
       } 
      } 
     }); 
    } 

    private synchronized void updateComponents(double dx, double dy, Sommet2D sg, Sommet2D sd){ 

     double x1 = sg.getCenterX(); 
     double y1 = sg.getCenterY(); 

     double x2 = sd.getCenterX(); 
     double y2 = sd.getCenterY(); 

     System.out.println("SG: " + sg); 
     System.out.println("SD: " + sd); 

     double newModule = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); 
     double cosAlpha = (x2 - x1)/newModule; 
     double alpha = Math.acos(cosAlpha); 
     double sinAlpha = Math.sin(alpha); 

     double r1x = cosAlpha * sg.getRadius(); 
     double r1y = sinAlpha * Math.signum(dy) * sg.getRadius(); 

     double r2x = cosAlpha * sd.getRadius(); 
     double r2y = sinAlpha * Math.signum(dy) * sd.getRadius(); 

     this.setStartX(x1 + r1x); 
     this.setStartY(y1 + r1y); 
     this.setEndX(x2 - r2x); 
     this.setEndY(y2 - r2y); 
    } 

    private synchronized void initArrows(){ 

     this.arrows[0] = new Line(); 
     this.arrows[1] = new Line(); 

     this.arrows[0].layoutXProperty().addListener(event -> this.arrows[0].setLayoutX(0.0)); 
     this.arrows[0].layoutYProperty().addListener(event -> this.arrows[0].setLayoutY(0.0)); 
     this.arrows[1].layoutXProperty().addListener(event -> this.arrows[1].setLayoutX(0.0)); 
     this.arrows[1].layoutYProperty().addListener(event -> this.arrows[1].setLayoutY(0.0)); 

     this.arrows[0].setStroke(Paint.valueOf("#FF0000")); 
     this.arrows[1].setStroke(Paint.valueOf("#0000FF")); 

     this.parentProperty().addListener(new ChangeListener<Parent>(){ 
      @Override 
      public void changed(ObservableValue<? extends Parent> observable, Parent oldValue, Parent newValue) { 
       if(newValue != null){ 
        if(arrows[0].getParent() != null) 
         (((Pane)arrows[0].getParent()).getChildren()).removeAll(arrows[0]); 
        if(arrows[1].getParent() != null) 
         (((Pane)arrows[1].getParent()).getChildren()).removeAll(arrows[1]); 
        (((Pane)newValue).getChildren()).addAll(arrows[0]); 
        (((Pane)newValue).getChildren()).addAll(arrows[1]); 
       } 
      } 
     }); 
    } 

    private synchronized void updateArrowsComponents(double dx, double dy){ 

     this.arrows[0].setEndX(this.getEndX()); 
     this.arrows[0].setEndY(this.getEndY()); 
     this.arrows[1].setEndX(this.getEndX()); 
     this.arrows[1].setEndY(this.getEndY()); 

     final double h = 0.5; 
     final double d = 25; 

     double[] lineVector = new double[]{ 
      1, (this.getEndY() - this.getStartY())/(this.getEndX() - this.getStartX()) 
     }; 

     double[] wVector = new double[]{ 
      - Math.signum(dy) * lineVector[1] * h/Math.sqrt(lineVector[1] * lineVector[1] + 1), 
      Math.signum(dy) * h/Math.sqrt(lineVector[1] * lineVector[1] + 1), 
     }; 

     double[] wPrVector = new double[]{ 
      -wVector[0], -wVector[1] 
     }; 

     double[] uwVector = new double[]{ 
      wVector[0] - lineVector[0], 
      wVector[1] - lineVector[1] 
     }; 

     double[] uwPrVector = new double[]{ 
      wPrVector[0] - lineVector[0], 
      wPrVector[1] - lineVector[1] 
     }; 

     //System.out.println("wVector: " + Arrays.toString(wVector)); 
     //System.out.println("wPrVector: " + Arrays.toString(wPrVector)); 


     //System.out.println("EndX: " + this.getEndX()); 
     double Xp = this.getEndX() - d * Math.signum(dx) * Math.cos(Math.atan(h/d)); 

     double Yp = lineVector[1] * Xp + (this.getEndY() - lineVector[1] * Xp); 
     //System.out.println("P(X,Y) = (" + Xp + "," + Yp + ")"); 

     double Xw = (this.getEndY() - Yp + (wVector[1]/wVector[0]) * Xp - (uwVector[1]/uwVector[0]) * this.getEndX())/(
       (wVector[1]/wVector[0]) - (uwVector[1]/uwVector[0])); 

     double XwPr = (this.getEndY() - Yp + (wPrVector[1]/wPrVector[0]) * Xp - (uwPrVector[1]/uwPrVector[0]) * this.getEndX())/(
       (wPrVector[1]/wPrVector[0]) - (uwPrVector[1]/uwPrVector[0])); 

     double Yw = (wVector[1]/wVector[0]) * Xw + Yp - (wVector[1]/wVector[0]) * Xp; 
     double YwPr = (wPrVector[1]/wPrVector[0]) * XwPr + Yp - (wPrVector[1]/wPrVector[0]) * Xp; 

     this.arrows[0].setStartX(Xw); 
     this.arrows[0].setStartY(Yw); 

     this.arrows[1].setStartX(XwPr); 
     this.arrows[1].setStartY(YwPr); 
    } 
} 

public abstract class Relation implements Comparable { 

    private SimpleStringProperty label = new SimpleStringProperty("No Label"); 
    private SimpleObjectProperty<Sommet> sommetGauche = new SimpleObjectProperty<Sommet>(null), 
             sommetDroit = new SimpleObjectProperty<Sommet>(null); 
    private SimpleObjectProperty<Relation2D> relation2D = new SimpleObjectProperty<Relation2D>(null); 
    protected SimpleObjectProperty<ComportementPonderation> ponderationValue = new SimpleObjectProperty<ComportementPonderation>(
     new NoPonderation()); 

    public Relation(String label, Sommet sommetGauche, Sommet sommetDroit){ 
     this.label.set(label); 
     this.sommetGauche.setValue(sommetGauche); 
     this.sommetDroit.setValue(sommetDroit); 

     this.sommetDroit.getValue().getListeRelations().add(this); 
     this.sommetGauche.getValue().getListeRelations().add(this); 
    } 

    /** 
    * @return the label 
    */ 
    public String getLabel() { 
     return label.getValue(); 
    } 

    /** 
    * @param label the label to set 
    */ 
    public void setLabel(String label) { 
     this.label.setValue(label); 
    } 

    /** 
    * @return the sommetGauche 
    */ 
    public Sommet getSommetGauche() { 
     return sommetGauche.getValue(); 
    } 

    /** 
    * @param sommetGauche the sommetGauche to set 
    */ 
    public void setSommetGauche(Sommet sommetGauche) { 
     this.sommetGauche.setValue(sommetGauche); 
    } 

    /** 
    * @return the sommetDroit 
    */ 
    public Sommet getSommetDroit() { 
     return sommetDroit.getValue(); 
    } 

    /** 
    * @param sommetDroit the sommetDroit to set 
    */ 
    public void setSommetDroit(Sommet sommetDroit) { 
     this.sommetDroit.setValue(sommetDroit); 
    } 

    public void setRelation2D(Relation2D relation2D){ 
     this.relation2D.setValue(relation2D); 
    } 

    public Relation2D getRelation2D(){ 
     return this.relation2D.getValue(); 
    } 

    @Override 
    public int compareTo(Object o) { 
     return (int)(this.label.getValue().compareTo(((Relation)o).getLabel())); 
    } 

    @Override 
    public boolean equals(Object o){ 
     if(o instanceof Relation) 
      return this.label.getValue().equals(((Relation) o).getLabel()); 
     return false; 
    } 

    public SimpleObjectProperty<Sommet> sommetGaucheProperty(){ 
     return this.sommetGauche; 
    } 

    public SimpleObjectProperty<Sommet> sommetDroitProperty(){ 
     return this.sommetDroit; 
    } 

    public SimpleStringProperty labelProperty(){ 
     return this.label; 
    } 

    public SimpleObjectProperty<Relation2D> relation2DProperty(){ 
     return this.relation2D; 
    } 

    public boolean isIncidentTo(Sommet sommet){ 
     return (this.sommetDroit.getValue().equals(sommet) || this.sommetGauche.getValue().equals(sommet)); 
    }  

    @Override 
    public String toString(){ 
     return "Description de l'arete: " + this.label.getValue() + "\n" 
       + "Sommet Gauche: " + this.sommetGauche.getValue().getLabel() + "\n" 
       + "Sommet Droit: " + this.sommetDroit.getValue().getLabel() + "\n"; 
    } 

    public ComportementPonderation getPonderation(){ 
     return this.ponderationValue.getValue(); 
    } 
} 

public class ValuePonderation implements ComportementPonderation{ 

    private SimpleDoubleProperty ponderationValue = new SimpleDoubleProperty(0.0); 

    public ValuePonderation(double value){ 
     this.setPoid(value); 
    } 
    @Override 
    public double getPoid() { 
     return this.ponderationValue.getValue(); 
    } 

    @Override 
    public void setPoid(double poid) { 
     this.ponderationValue.setValue(poid); 
    } 

    @Override 
    public SimpleDoubleProperty poidProperty() { 
     return this.ponderationValue; 
    } 
} 

public interface ComportementPonderation { 
    public abstract double getPoid(); 
    public abstract void setPoid(double poid); 
    public abstract SimpleDoubleProperty poidProperty(); 
} 

Einige der Konsole druckt:

SD X Event: 
SG: Circle[centerX=683.0, centerY=384.0, radius=25.0, fill=0xffffffff, stroke=0x000000ff, strokeWidth=2.0] 
SD: Circle[centerX=694.0, centerY=384.0, radius=25.0, fill=0xffffffff, stroke=0x000000ff, strokeWidth=2.0] 
--------------------------------------------- 
SG X Event: 
SG: Circle[centerX=694.0, centerY=384.0, radius=25.0, fill=0xffffffff, stroke=0x000000ff, strokeWidth=2.0] 
SD: Circle[centerX=683.0, centerY=384.0, radius=25.0, fill=0x000000ff] 
--------------------------------------------- 
SD Y Event: 
SG: Circle[centerX=683.0, centerY=384.0, radius=25.0, fill=0xffffffff, stroke=0x000000ff, strokeWidth=2.0] 
SD: Circle[centerX=694.0, centerY=380.0, radius=25.0, fill=0xffffffff, stroke=0x000000ff, strokeWidth=2.0] 
--------------------------------------------- 
SG Y Event: 
SG: Circle[centerX=694.0, centerY=380.0, radius=25.0, fill=0xffffffff, stroke=0x000000ff, strokeWidth=2.0] 
SD: Circle[centerX=683.0, centerY=384.0, radius=25.0, fill=0x000000ff] 
--------------------------------------------- 
SD X Event: 
SG: Circle[centerX=683.0, centerY=384.0, radius=25.0, fill=0xffffffff, stroke=0x000000ff, strokeWidth=2.0] 
SD: Circle[centerX=410.0, centerY=380.0, radius=25.0, fill=0xffffffff, stroke=0x000000ff, strokeWidth=2.0] 
--------------------------------------------- 
SG X Event: 
SG: Circle[centerX=410.0, centerY=380.0, radius=25.0, fill=0xffffffff, stroke=0x000000ff, strokeWidth=2.0] 
SD: Circle[centerX=683.0, centerY=384.0, radius=25.0, fill=0x000000ff] 
--------------------------------------------- 
SD Y Event: 
SG: Circle[centerX=683.0, centerY=384.0, radius=25.0, fill=0xffffffff, stroke=0x000000ff, strokeWidth=2.0] 
SD: Circle[centerX=410.0, centerY=235.0, radius=25.0, fill=0xffffffff, stroke=0x000000ff, strokeWidth=2.0] 
--------------------------------------------- 
SG Y Event: 
SG: Circle[centerX=410.0, centerY=235.0, radius=25.0, fill=0xffffffff, stroke=0x000000ff, strokeWidth=2.0] 
SD: Circle[centerX=683.0, centerY=384.0, radius=25.0, fill=0x000000ff] 
--------------------------------------------- 

Antwort

0

Gelöst.

Ich weiß nicht, was das Problem war, aber mooved das gleiche Projekt von meinem Laptop auf meinem Desktop-Computer und alles funktioniert gut.

Aber immer noch fragen, warum es handelt so seltsam ...

Für diejenigen, die unlogisch Probleme haben, schlage ich vor, Projekt auf einem anderen Computer zu ändern, kann nützlich sein ...

0

Ein möglicher Fehler Ich bemerkte:

dy wird zweimal verwendet und dx wird nie verwendet.

public class Relation2D extends Line{ 
    ... 
    private synchronized void updateComponents(double dx, double dy, Sommet2D sg, Sommet2D sd){ 
     ... 
     double r1x = cosAlpha * sg.getRadius(); 
     double r1y = sinAlpha * Math.signum(dy) * sg.getRadius(); 

     double r2x = cosAlpha * sd.getRadius(); 
     double r2y = sinAlpha * Math.signum(dy) * sd.getRadius(); 
     ... 
    } 
} 

Dies ist wahrscheinlich aufgrund eines Kopieren/Einfügen-Fehlers, es ist ziemlich häufig. Durch das Aktivieren von Compiler-Warnungen können Fehler wie diese behoben werden. In diesem Fall hätte eine Warnung für nicht verwendete Methodenparameter davor gewarnt, dass dx nicht verwendet wird.

in Eclipse dieser Compiler-Warnung für den Hörer zu Window -> Preferences -> Java -> Compiler -> Errors/Warnings -> Unnecessary code -> Value of method parameter is not used [set to Warning]

Verwandte gehen zu setzen, bemerkte ich, dass value nicht die anderen observable s mag:

sg.centerXProperty().addListener((observable) -> { 
    System.out.println("SG X Event:"); 
    updateComponents(dx.getValue(),dy.getValue(),sg,sd); 
    //updateArrowsComponents(dx.getValue(),dy.getValue()); 
    System.out.println("---------------------------------------------"); 
}); 
// ### 'value' is the only different one, I'm not sure if it's important ### 
sg.centerYProperty().addListener((value) -> { 
    System.out.println("SG Y Event:"); 
    updateComponents(dx.getValue(),dy.getValue(),sg,sd); 
    //updateArrowsComponents(dx.getValue(),dy.getValue()); 
    System.out.println("---------------------------------------------"); 
}); 

sd.centerXProperty().addListener((observable) -> { 
    System.out.println("SD X Event:");  
    updateComponents(dx.getValue(),dy.getValue(),sg,sd); 
    //updateArrowsComponents(dx.getValue(),dy.getValue()); 
    System.out.println("---------------------------------------------"); 
}); 
sd.centerYProperty().addListener((observable) -> { 
    System.out.println("SD Y Event:"); 
    updateComponents(dx.getValue(),dy.getValue(),sg,sd); 
    //updateArrowsComponents(dx.getValue(),dy.getValue()); 
    System.out.println("---------------------------------------------"); 
}); 

Auch mir scheint es, wie es ist die Sommet Gauche X/Y Ereignisse (nicht die Sommet Gauche/Droit X Ereignisse), die gauche (links) centerX größer als droit (rechts) centerX haben.

+0

Danke, aber ich bin bewusst über die Tatsache, dass dx nicht verwendet wird. Ich erwarte es später für andere Zwecke zu verwenden und bis jetzt brauche ich nur dy. Die 2 Parameter sg und sd werden vom Aufrufer vertauscht, wenn ich sie aus dem x-Eigenschaft-Listener von sg und dem x-Eigenschaft-Listener von sd abrufe. Überprüfen Sie das Ergebnis für weitere Details. Und warum ist das Listener-Ereignis der X-Eigenschaft von sg feuern, auch wenn es überhaupt nicht geändert wurde (mit dem Drag-Ereignis) – Mouley

+0

@Mouley Ich habe Probleme zu verstehen, was das Problem ist. Ich denke, ich habe die Französisch, aber ich verstehe nicht die Bedeutung der Ausgabe. Und es ist ein bisschen schwierig zu verstehen, was im Code vor sich geht. Können Sie Kommentare hinzufügen (vorzugsweise auf Englisch), um die Methoden kurz zu erklären? Auch bemerkte ich eine andere Sache, die aussieht, als könnte es falsch sein, die ich zu meiner Antwort hinzufügen .. – xtratic

+0

gibt es 2 Ausgaben: Ausgabe a: in der Ausgabe können Sie aus den 2 ersten Blöcke, dass Ereignis "SD X Event" und sehen "SG X Event" wird ausgelöst, aber in meinem Programm ändere ich nur die Koordinaten des SD-Kreises. Warum feuert das zweite Ereignis? Problem b: Ich rufe die Methode updateComponents mit den gleichen Parametern in jedem Listener, aber die 2 letzten Parameter ausgetauscht werden, schauen Sie sich die Kreise Beschreibungen der 2 ersten Ausgangsblöcke Sorry für die Französisch, wenn weitere Informationen benötigt werden, sagen Sie mir – Mouley