2016-07-01 2 views
0

개체 필드를 기반으로 특정 색의 원을 동적으로 그려주는 ListView를 만들었습니다. 셀에는 수출 된 세 가지 상태가있을 수 있으며 필수 정보가 있으며 둘 중 하나가 없습니다. 처음 두 개는 자신 만의 원색을 가지고 있는데 두 그래픽 모두를 구현하는 "어느 것도 가지고 싶지 않다"라고 말합니다. 두 개의 원. 문제는 셀에 대해 하나의 그래픽 만 설정할 수 있다는 것입니다.두 개의 원이있는 모양을 만드는 방법은 무엇입니까?

원의 centerX를 변경하고 두면 모두에서 Shape.union을 사용하여 해결 방법을 찾으려고 시도했지만 circEx 만 표시합니다. 이 방법을 구현할 수 있습니까?

listView.setCellFactory(new Callback<ListView<BusinessCard>, ListCell<BusinessCard>>(){ 
        @Override 
        public ListCell<BusinessCard> call(ListView<BusinessCard> list){ 
         return new ColorCell(); 
        } 
}); 



//Colors circled that indicates status of card on listView 
static class ColorCell extends ListCell<BusinessCard> { 
    @Override 
    public void updateItem(BusinessCard item, boolean empty) { 
     super.updateItem(item, empty); 

     //Probably should have one circle and setFil in if statements 
     Circle circMan = new Circle(0,0,3,Color.web("#ff9999")); 
     Circle circEx = new Circle(10,0,3,Color.web("#808080")); // old #e1eaea 
     Circle circDone = new Circle(0,0,3,Color.web("#99ff99")); //old #99ff99  

     if(item != null){ 
      setTextFill(Color.BLACK); 
      setText(item.toString()); 

      if(item.wasExported() && !item.hasMand()){ 
       setGraphic(Shape.union(circMan, circEx)); //TODO 
      }    
      else if(item.wasExported()){ 
       setGraphic(circEx); 
      }    
      else if(!item.hasMand()){ 
       setGraphic(circMan); 
      } 
      else{ 
       setGraphic(circDone); 
      } 
     } 
    } 
} 
+0

반원형의 반원을 만들 수 있습니까? – trashgod

+0

흠, 내가 두 개의 원을 만들 수 있고 두 개의 원 사이의 결합으로 모양을 만들 수 있는지 알 수 있습니다.하지만이 두 원을 사용해야한다고 생각합니다. – Javant

답변

0

당신은 Panegraphic로, 예를 들어, 사용할 수 있습니다 HBox.

또한 updateItem 방법으로 서클을 반복해서 다시 만들어서는 안됩니다.

static class ColorCell extends ListCell<BusinessCard> { 

    private final Circle manDone = new Circle(3); 
    private final Circle ex = new Circle(3); 
    private final HBox circles = new HBox(4, manDone, ex); 

    private static final Color EXPORTED_COLOR = Color.web("#808080"); 
    private static final Color MAN_COLOR = Color.web("#ff9999"); 
    private static final Color DONE_COLOR = Color.web("#99ff99"); 

    { 
     setGraphic(circles); 

     // hide circles 
     manDone.setFill(Color.TRANSPARENT); 
     ex.setFill(Color.TRANSPARENT); 

     setTextFill(Color.BLACK); 
    } 

    @Override 
    public void updateItem(BusinessCard item, boolean empty) { 
     super.updateItem(item, empty); 

     if (item == null) { 
      // hide circles 
      manDone.setFill(Color.TRANSPARENT); 
      ex.setFill(Color.TRANSPARENT); 

      setText(null); 
     } else { 
      setText(item.toString()); 

      ex.setFill(item.wasExported() ? EXPORTED_COLOR : Color.TRANSPARENT); 
      manDone.setFill(item.hasMand() 
           ? (item.wasExported() ? DONE_COLOR : Color.TRANSPARENT) 
           : MAN_COLOR); 
     } 
    } 
} 
관련 문제