2017-05-01 2 views
2

JavaFX 2.0에서 프로젝트를 개발 중입니다.ScrollPane을 원하는 위치로 설정

enter image description here

사용자가 소스 코드의 동기화 버튼을 클릭하면, 응용 프로그램과 같은 UML 모델 주위에 거품 관련된 소스 코드를 표시 사용자가 다음과 같은 UML 모델을 생성 할 때

는 시나리오가 시작 다음

enter image description here

을하지만, 당신은 상단에 생성 된 기포는 완전히 창에 맞게되지 않는다는 것을 인식 할 수있다. 창의 원하는보기는 다음과 같이해야합니다 :

enter image description here

을 나는 이러한 목표를 달성하기 위해 HValueVValue 속성을 사용한다는 것을 알고있는 경우에도 마찬가지입니다. ScrollPane의 새로운 값을 어떻게 설정해야하는지 이해할 수 없습니다.

ScrollPane의 크기는 8000 x 8000이며 rescaleView() 함수를 호출하여 모든 UML 모델과 거품을 포함하는 보이지 않는 사각형을 만듭니다. 그래서이 사각형의 값에 따라 ScrollPane을 다시 스케일링하고 있지만 뷰포트 센터를 다시 움직일 수는 없습니다. 여기 스케일링하는 기능은 다음과 같습니다

private void rescaleView() { 
    double MARGIN = 5.0; 

    List<BubbleView> bubbleViews = new ArrayList<>(diagramController.getAllBubbleViews()); 

    double xMin = bubbleViews.get(0).getX(); 
    double yMin = bubbleViews.get(0).getY(); 
    double xMax = bubbleViews.get(0).getX() + bubbleViews.get(0).getWidth(); 
    double yMax = bubbleViews.get(0).getY() + bubbleViews.get(0).getHeight(); 

    if(bubbleViews.size() > 0) { 
     for(int i = 1; i < bubbleViews.size(); i++) { 
      if((bubbleViews.get(i).getX() + bubbleViews.get(i).getWidth()) > xMax) { 
       xMax = bubbleViews.get(i).getX() + bubbleViews.get(i).getWidth(); 
      } 

      if(bubbleViews.get(i).getX() < xMin) { 
       xMin = bubbleViews.get(i).getX(); 
      } 

      if((bubbleViews.get(i).getY() + bubbleViews.get(i).getHeight()) > yMax) { 
       yMax = bubbleViews.get(i).getY() + bubbleViews.get(i).getHeight(); 
      } 

      if(bubbleViews.get(i).getY() < yMin) { 
       yMin = bubbleViews.get(i).getY(); 
      } 
     } 

     double toBeScaled = Math.min((Math.max(diagramController.getScrollPane().getWidth(), diagramController.getScrollPane().getHeight())/Math.max((xMax - xMin), (yMax - yMin))),(Math.min(diagramController.getScrollPane().getWidth(), diagramController.getScrollPane().getHeight())/Math.min((xMax - xMin), (yMax - yMin)))) * 100; 
     diagramController.getGraphController().zoomPane(toBeScaled - MARGIN); 
     diagramController.getGraphController().center(xMin, yMin); 
    } 
} 

하지만 아래 center(x,y) 기능은 뷰포트 센터하지 않습니다

public void center(double x, double y) { 
    ScrollPane scrollPane = diagramController.getScrollPane(); 

    double xScroll = x/8000; //8000 is the size of aDrawPane set in view.classDiagramView.fxml 
    double yScroll = y/8000; 

    scrollPane.setHvalue(xScroll); 
    scrollPane.setVvalue(yScroll); 
} 

나는이 setHValuesetVValue을 설정해야 어떻게?

미리 감사드립니다.

답변

2

잘 모르겠다.


double xScroll = (x - scrollPane.getWidth()/2)/(8000 - scrollPane.getWidth()); 
double yScroll = (y - scrollPane.getHeight()/2)/(8000 - scrollPane.getHeight()); 

diagramController.getGraphController().center((xMax + xMin)/2, (yMax + yMin)/2); 
그리고 toBeScaled 등 다양한 내용으로 세로로 긴 스크롤로 바람직하지 않은 경우가있는 것. 오해의 소지가 있다면 아래의 코드를 무시하십시오.

final double scrollPaneWidth = diagramController.getScrollPane().getWidth(); 
final double scrollPaneHeight = diagramController.getScrollPane().getHeight(); 
final double contentsWidth = xMax - xMin; 
final double contentsHeight = yMax - yMin; 
double toBeScaled = Math.min(scrollPaneHeight/contentsHeight, scrollPaneWidth/contentsWidth) * 100; 
+0

완벽하게 작동합니다. 고마워요! 그건 그렇고, 당신은 BeScaled의 실수에 대해 옳았습니다. 나는 네가 말한대로 그것을 바꿨다. –

관련 문제