[英]Setting ScrollPane to the Desired Position
I am developing a project in JavaFX 2.0. 我正在用JavaFX 2.0开发一个项目。
The scenario starts when a user creates a UML model like below: 当用户创建如下所示的UML模型时,该场景开始:
When the user clicks the source code synchronisation button, the application displays the related source codes in Bubbles around the UML model like following: 当用户单击源代码同步按钮时,应用程序将在UML模型周围的Bubbles中显示相关的源代码,如下所示:
However, as you might realize that the bubble, which is created on the top is not fully fit the pane. 但是,您可能会意识到,在顶部创建的气泡并不完全适合窗格。 The desired view of the pane should be like this:
窗格的所需视图应如下所示:
Even if I know that I should use HValue
and VValue
properties to accomplish this. 即使我知道我应该使用
HValue
和VValue
属性来完成此操作。 I couldn't understand how should I set these new value of ScrollPane
. 我不明白如何设置
ScrollPane
这些新值。
The size of the ScrollPane is 8000 x 8000 and I am creating an invisible rectangle which covers all the UML model and the bubbles by calling rescaleView() function. ScrollPane的大小为8000 x 8000,我通过调用rescaleView()函数创建了一个不可见的矩形,该矩形覆盖了所有UML模型和气泡。 So according to the values of this rectangle, I am rescaling the ScrollPane but I couldn't move the viewport centre again.
因此,根据该矩形的值,我正在重新缩放ScrollPane,但无法再次移动视口中心。 Here is the function for rescaling:
这是重新缩放的功能:
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);
}
}
but the center(x,y)
function below doesn't make the viewport center: 但是下面的
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);
}
How should I set these setHValue
and setVValue
? 我应该如何设置这些
setHValue
和setVValue
?
Thanks in advance. 提前致谢。
I'm not sure it works or not. 我不确定它是否有效。
diagramController.getGraphController().center((xMax + xMin) / 2, (yMax + yMin) / 2);
double xScroll = (x - scrollPane.getWidth() / 2) / (8000 - scrollPane.getWidth());
double yScroll = (y - scrollPane.getHeight() / 2) / (8000 - scrollPane.getHeight());
And toBeScaled
seems to have undesirable case such as vertically long scrollPane with wide contents. 并且
toBeScaled
似乎有不受欢迎的情况,例如内容宽度很长的垂直滚动条。 Ignore the code below if it was misunderstanding. 如果误解,请忽略下面的代码。
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.