package greenfoot.guifx;

import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.Pane;
import threadchecker.OnThread;
import threadchecker.Tag;


| The content pane for GreenfootStage. This needs to be a custom pane to get the layout | algorithm implemented as we want. | @OnThread(Tag.FXPlatform) class GreenfootStageContentPane extends Pane{ private static final int CLASS_DIAGRAM_PADDING = 12; private static final int IDEAL_WORLD_PADDING = 30; private final Pane worldViewScroll; private final Button shareButton; private final ScrollPane classDiagramScroll; private final Pane controlPanel;
| Construct a content pane for the three major components: the world view, | the class diagram, and the control panel. | public GreenfootStageContentPane(Pane worldViewScroll, Button shareButton, ScrollPane classDiagramScroll, ControlPanel controlPanel) { this.worldViewScroll = worldViewScroll; this.shareButton = shareButton; this.classDiagramScroll = classDiagramScroll; this.controlPanel = controlPanel; getChildren().addAll(worldViewScroll, shareButton, classDiagramScroll, controlPanel); } @Override @OnThread(value = Tag.FXPlatform, ignoreParent = true) protected void layoutChildren() { final double ourWidth = getWidth(); final double ourHeight = getHeight(); final double idealWorldWidth = worldViewScroll.prefWidth(-1); final double shareButtonWidth = shareButton.prefWidth(-1); final double shareButtonHeight = shareButton.prefHeight(-1); final double classDiagramHeight = ourHeight - 3 * CLASS_DIAGRAM_PADDING - shareButtonHeight; final double idealClassDiagramWidth = classDiagramScroll.prefWidth(classDiagramHeight); double classDiagramWidth; if (idealClassDiagramWidth + 2 * CLASS_DIAGRAM_PADDING + idealWorldWidth > ourWidth) { double minClassDiagramWidth = classDiagramScroll.minWidth(classDiagramHeight); classDiagramWidth = Math.max(minClassDiagramWidth, ourWidth - idealWorldWidth - 2 * CLASS_DIAGRAM_PADDING); } else { classDiagramWidth = idealClassDiagramWidth; } classDiagramWidth = Math.max(classDiagramWidth, shareButtonWidth + 2 * CLASS_DIAGRAM_PADDING); final double worldWidth = ourWidth - (classDiagramWidth + 2 * CLASS_DIAGRAM_PADDING); final double controlPanelHeight = controlPanel.prefHeight(worldWidth); worldViewScroll.resizeRelocate(0, 0, worldWidth, ourHeight - controlPanelHeight); shareButton.resizeRelocate(worldWidth + CLASS_DIAGRAM_PADDING, CLASS_DIAGRAM_PADDING, classDiagramWidth, shareButtonHeight); classDiagramScroll.resizeRelocate(worldWidth + CLASS_DIAGRAM_PADDING, 2 * CLASS_DIAGRAM_PADDING + shareButtonHeight, classDiagramWidth, classDiagramHeight); controlPanel.resizeRelocate(0, ourHeight - controlPanelHeight, worldWidth, controlPanelHeight); } @Override @OnThread(value = Tag.FXPlatform, ignoreParent = true) protected double computePrefWidth(double height) { return worldViewScroll.prefWidth(height) + 2 * IDEAL_WORLD_PADDING | Some world spacing | + Math.max(shareButton.prefWidth(-1), classDiagramScroll.prefWidth(height)) + 2 * CLASS_DIAGRAM_PADDING; } @Override @OnThread(value = Tag.FXPlatform, ignoreParent = true) protected double computePrefHeight(double width) { return Math.max(shareButton.prefHeight(-1) + classDiagramScroll.prefHeight(-1) + 3 * CLASS_DIAGRAM_PADDING, worldViewScroll.prefHeight(-1) + 2 * IDEAL_WORLD_PADDING + controlPanel.prefHeight(-1)); } }

.   - GreenfootStageContentPane
.   GreenfootStageContentPane
.   layoutChildren
.   computePrefWidth
.   computePrefHeight




119 neLoCode + 5 LoComm