2017-12-18 4 views
0

원 다이어그램 소프트웨어를 만들려고합니다. 마우스 끌기 이벤트로 원 구성 요소를 변경합니다.Java 원치 않는 리스너 호출 및 함수 매개 변수가 반전 됨

있어 2 문제 :

1) - SG의 centerXProperty의 리스너가 그러나 그 X가 변경되지 않은 좌표라고, 어떻게?

2) - 나는 updateComponents()에서 동일한 매개 변수를 제공하지만 일단 원에 대한 설명을 인쇄하면 매개 변수가 centerXProperty 수신기에 대해 반전 된 콘솔에 나타납니다. 여기

코드 및 자세한 내용은 콘솔 인쇄 :

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(); 
} 

콘솔 인쇄의 일부 : 내가 발견

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] 
--------------------------------------------- 

답변

0

해결되었습니다.

무엇이 문제인지는 모르겠지만 랩톱에서 내 데스크톱 컴퓨터로 동일한 프로젝트가 완성되어 모든 것이 정상적으로 작동합니다.

하지만 여전히 유용 할 수 있습니다, 그것은 비논리적 인 문제가 발생하는 사람들을 위해

, 난 다른 컴퓨터로 프로젝트를 변경하는 것이 좋습니다 ... 이상한 것을 행동하는 이유를 궁금해 ...

0

하나의 잠재적 인 오류 :

dy은 두 번 사용되며 dx는 사용되지 않습니다.

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(); 
     ... 
    } 
} 

이것은 복사/붙여 넣기 오류로 인한 것 같습니다. 매우 일반적입니다. 컴파일러 경고를 켜면 이런 오류를 잡을 수 있습니다. 이 경우 사용되지 않는 메소드 매개 변수에 대한 경고는 dx이 사용되지 않는다고 경고했을 것입니다. 이처럼 보인다 나에게,

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("---------------------------------------------"); 
}); 
또한

: 이클립스에서

나는 value 다른 observable들처럼되지 않습니다 것을 발견,이 컴파일러 경고가 청취자에게 관련 Window -> Preferences -> Java -> Compiler -> Errors/Warnings -> Unnecessary code -> Value of method parameter is not used [set to Warning]

로 이동 설정 the Sommet Gauche droot (right) centerX보다 큰 gauche (왼쪽) centerX가있는 X/Y 이벤트 (Sommet Gauche/Droit X 이벤트가 아님).

+0

감사하지만 난 해요 dx가 사용되지 않는다는 사실을 알고 있어야합니다. 나중에 다른 용도로 사용하기를 기대하고 있습니다. 지금까지는 단지 dy 만 필요합니다. 2 개의 매개 변수 sg와 sd는 호출자가 sg의 x 속성 수신기와 sd의 x 속성 수신기에서 호출 할 때 상호 교환됩니다. 자세한 내용은 결과를 확인하십시오. 그리고 sg의 x 속성에 대한 리스너 이벤트가 전혀 변경되지 않은 경우에도 (드래그 이벤트를 사용하여) – Mouley

+0

@Mouley 문제가 무엇인지 이해하는 데 문제가 있습니다. 나는 내가 프랑스 사람을 이해했다고 생각한다. 그러나 나는 결과의 중요성을 이해하지 못한다. 그리고 코드에서 무슨 일이 벌어지고 있는지 이해하는 것은 약간 어렵습니다. 방법을 간단히 설명하기 위해 (영어로 표시하는) 의견을 추가 할 수 있습니까? 또한 내 대답에 추가 할 수있는 잘못된 것 같습니다. – xtratic

+0

두 가지 문제 : 문제 : 출력에서 ​​"SD X 이벤트"이벤트의 첫 번째 두 블록에서 볼 수 있습니다. "SG X 이벤트"는 해고되었지만, 내 프로그램에서는 SD 원의 좌표 만 변경합니다. 두 번째 행사가 왜 발포하고 있습니까? 문제 b : 각 청취자에서 동일한 매개 변수를 사용하여 updateComponents 메소드를 호출하지만 마지막 두 매개 변수가 교환됩니다. 두 번째 첫 번째 출력 블록의 원 설명을 확인하십시오 더 많은 정보가 필요하면 죄송합니다. – Mouley

관련 문제