/** * Returns the component's unconstrained preferred width. */ public int getPreferredWidth() { return getPreferredWidth(-1); }
/** * Returns the component's unconstrained preferred width. */ public int getPreferredWidth() { return getPreferredWidth(-1); }
@Override public int getPreferredWidth(int height) { int preferredWidth = 0; StackPane stackPane = (StackPane)getComponent(); for (Component component : stackPane) { preferredWidth = Math.max(preferredWidth, component.getPreferredWidth(height)); } preferredWidth += (padding.left + padding.right); return preferredWidth; }
@Override public int getPreferredWidth(int height) { int preferredWidth = 0; StackPane stackPane = (StackPane)getComponent(); for (Component component : stackPane) { preferredWidth = Math.max(preferredWidth, component.getPreferredWidth(height)); } preferredWidth += (padding.left + padding.right); return preferredWidth; }
@Override public int getPreferredWidth(int height) { Window window = (Window)getComponent(); Component content = window.getContent(); return (content != null) ? content.getPreferredWidth(height) : 0; }
@Override public int getPreferredWidth(int height) { Window window = (Window)getComponent(); Component content = window.getContent(); return (content != null) ? content.getPreferredWidth(height) : 0; }
@Override public int getPreferredWidth(int height) { int preferredWidth = 0; Border border = (Border)getComponent(); int topThickness = thickness; String title = border.getTitle(); if (title != null && title.length() > 0) { FontRenderContext fontRenderContext = Platform.getFontRenderContext(); Rectangle2D headingBounds = font.getStringBounds(title, fontRenderContext); preferredWidth = (int)Math.ceil(headingBounds.getWidth()); LineMetrics lm = font.getLineMetrics(title, fontRenderContext); topThickness = Math.max((int)Math.ceil(lm.getHeight()), topThickness); } Component content = border.getContent(); if (content != null) { int heightUpdated = height; if (heightUpdated != -1) { heightUpdated = Math.max(heightUpdated - (topThickness + thickness) - padding.top - padding.bottom, 0); } preferredWidth = Math.max(preferredWidth, content.getPreferredWidth(heightUpdated)); } preferredWidth += (padding.left + padding.right) + (thickness * 2); return preferredWidth; }
@Override public int getPreferredWidth(int height) { int preferredWidth = 0; Border border = (Border)getComponent(); int topThickness = thickness; String title = border.getTitle(); if (title != null && title.length() > 0) { FontRenderContext fontRenderContext = Platform.getFontRenderContext(); Rectangle2D headingBounds = font.getStringBounds(title, fontRenderContext); preferredWidth = (int)Math.ceil(headingBounds.getWidth()); LineMetrics lm = font.getLineMetrics(title, fontRenderContext); topThickness = Math.max((int)Math.ceil(lm.getHeight()), topThickness); } Component content = border.getContent(); if (content != null) { if (height != -1) { height = Math.max(height - (topThickness + thickness) - padding.top - padding.bottom, 0); } preferredWidth = Math.max(preferredWidth, content.getPreferredWidth(height)); } preferredWidth += (padding.left + padding.right) + (thickness * 2); return preferredWidth; }
@Override public Dimensions getPreferredSize(int breakWidth) { ComponentNode componentNode = (ComponentNode) getNode(); Component component = componentNode.getComponent(); if (component == null) { return new Dimensions(0, 0); } else { return new Dimensions(component.getPreferredWidth(), component.getPreferredHeight()); } }
@Override public Dimensions getPreferredSize(int breakWidth) { ComponentNode componentNode = (ComponentNode) getNode(); Component component = componentNode.getComponent(); if (component == null) { return new Dimensions(0, 0); } return new Dimensions(component.getPreferredWidth(), component.getPreferredHeight()); }
@Override public int getPreferredWidth(int height) { FlowPane flowPane = (FlowPane)getComponent(); int preferredWidth = 0; // Preferred width is the sum of the preferred widths of all components // (height constraint is ignored) int j = 0; for (int i = 0, n = flowPane.getLength(); i < n; i++) { Component component = flowPane.get(i); if (component.isVisible()) { preferredWidth += component.getPreferredWidth(); j++; } } // Include spacing if (j > 1) { preferredWidth += horizontalSpacing * (j - 1); } // Include left and right padding values preferredWidth += padding.left + padding.right; return preferredWidth; }
@Override public int getPreferredWidth(int height) { FlowPane flowPane = (FlowPane)getComponent(); int preferredWidth = 0; // Preferred width is the sum of the preferred widths of all components // (height constraint is ignored) int j = 0; for (int i = 0, n = flowPane.getLength(); i < n; i++) { Component component = flowPane.get(i); if (component.isVisible()) { preferredWidth += component.getPreferredWidth(); j++; } } // Include spacing if (j > 1) { preferredWidth += horizontalSpacing * (j - 1); } // Include left and right padding values preferredWidth += padding.left + padding.right; return preferredWidth; }
/** * Gets the preferred width of a table pane column, which is defined as the * maximum preferred width of the column's visible components. * <p> * Because their preferred width relates to the preferred widths of other * columns, components that span multiple columns will not be considered in * this calculation (even if they live in the column directly). It is up to * the caller to factor such components into the column widths calculation. * * @param columnIndex * The index of the column whose preferred width we're calculating */ private int getPreferredColumnWidth(int columnIndex) { TablePane tablePane = (TablePane)getComponent(); TablePane.RowSequence rows = tablePane.getRows(); int preferredWidth = 0; for (int i = 0, n = rows.getLength(); i < n; i++) { TablePane.Row row = rows.get(i); if (row.getLength() > columnIndex) { Component component = row.get(columnIndex); if (component != null && component.isVisible() && TablePane.getColumnSpan(component) == 1) { preferredWidth = Math.max(preferredWidth, component.getPreferredWidth(-1)); } } } return preferredWidth; }
/** * Gets the preferred width of a table pane column, which is defined as the * maximum preferred width of the column's visible components. * <p> * Because their preferred width relates to the preferred widths of other * columns, components that span multiple columns will not be considered in * this calculation (even if they live in the column directly). It is up to * the caller to factor such components into the column widths calculation. * * @param columnIndex * The index of the column whose preferred width we're calculating */ private int getPreferredColumnWidth(int columnIndex) { TablePane tablePane = (TablePane)getComponent(); TablePane.RowSequence rows = tablePane.getRows(); int preferredWidth = 0; for (int i = 0, n = rows.getLength(); i < n; i++) { TablePane.Row row = rows.get(i); if (row.getLength() > columnIndex) { Component component = row.get(columnIndex); if (component != null && component.isVisible() && TablePane.getColumnSpan(component) == 1) { preferredWidth = Math.max(preferredWidth, component.getPreferredWidth(-1)); } } } return preferredWidth; }
@Override protected void childLayout(int breakWidth) { ComponentNode componentNode = (ComponentNode) getNode(); Component component = componentNode.getComponent(); if (component == null) { setSize(0, 0); } else { component.validate(); component.setSize(component.getPreferredWidth(), component.getPreferredHeight()); setSize(component.getWidth(), component.getHeight()); } }
@Override protected void childLayout(int breakWidth) { ComponentNode componentNode = (ComponentNode) getNode(); Component component = componentNode.getComponent(); if (component == null) { setSize(0, 0); } else { component.validate(); component.setSize(component.getPreferredWidth(), component.getPreferredHeight()); setSize(component.getWidth(), component.getHeight()); } }
@Override public int getPreferredWidth(int height) { GridPane gridPane = (GridPane)getComponent(); GridPane.RowSequence rows = gridPane.getRows(); int columnCount = gridPane.getColumnCount(); int rowCount = rows.getLength(); Metadata metadata = new Metadata(); int cellHeightLocal = getCellHeight(height, metadata); int preferredCellWidth = 0; for (int i = 0; i < rowCount; i++) { GridPane.Row row = rows.get(i); for (int j = 0, n = row.getLength(); j < n && j < columnCount; j++) { Component component = row.get(j); if (component != null && component.isVisible()) { preferredCellWidth = Math.max(preferredCellWidth, component.getPreferredWidth(cellHeightLocal)); } } } // The preferred width of the grid pane is the sum of the column // widths, plus padding and spacing int preferredWidth = padding.left + padding.right + metadata.visibleColumnCount * preferredCellWidth; if (metadata.visibleColumnCount > 1) { preferredWidth += (metadata.visibleColumnCount - 1) * horizontalSpacing; } return preferredWidth; }
@Override public int getPreferredWidth(int height) { GridPane gridPane = (GridPane)getComponent(); GridPane.RowSequence rows = gridPane.getRows(); int columnCount = gridPane.getColumnCount(); int rowCount = rows.getLength(); Metadata metadata = new Metadata(); int cellHeight = getCellHeight(height, metadata); int preferredCellWidth = 0; for (int i = 0; i < rowCount; i++) { GridPane.Row row = rows.get(i); for (int j = 0, n = row.getLength(); j < n && j < columnCount; j++) { Component component = row.get(j); if (component != null && component.isVisible()) { preferredCellWidth = Math.max(preferredCellWidth, component.getPreferredWidth(cellHeight)); } } } // The preferred width of the grid pane is the sum of the column // widths, plus padding and spacing int preferredWidth = padding.left + padding.right + metadata.visibleColumnCount * preferredCellWidth; if (metadata.visibleColumnCount > 1) { preferredWidth += (metadata.visibleColumnCount - 1) * horizontalSpacing; } return preferredWidth; }
@Override public Dimensions getPreferredSize() { ScrollPane scrollPane = (ScrollPane)getComponent(); int preferredWidth = 0; int preferredHeight = 0; Component view = scrollPane.getView(); if (view != null) { Dimensions preferredViewSize = view.getPreferredSize(); preferredWidth += preferredViewSize.width; preferredHeight += preferredViewSize.height; Component rowHeader = scrollPane.getRowHeader(); if (rowHeader != null) { preferredWidth += rowHeader.getPreferredWidth(-1); } Component columnHeader = scrollPane.getColumnHeader(); if (columnHeader != null) { preferredHeight += columnHeader.getPreferredHeight(-1); } if (scrollPane.getHorizontalScrollBarPolicy() == ScrollBarPolicy.ALWAYS) { preferredHeight += horizontalScrollBar.getPreferredHeight(-1); } if (scrollPane.getVerticalScrollBarPolicy() == ScrollBarPolicy.ALWAYS) { preferredWidth += verticalScrollBar.getPreferredWidth(-1); } } return new Dimensions(preferredWidth, preferredHeight); }
@Override public Dimensions getPreferredSize() { ScrollPane scrollPane = (ScrollPane)getComponent(); int preferredWidth = 0; int preferredHeight = 0; Component view = scrollPane.getView(); if (view != null) { Dimensions preferredViewSize = view.getPreferredSize(); preferredWidth += preferredViewSize.width; preferredHeight += preferredViewSize.height; Component rowHeader = scrollPane.getRowHeader(); if (rowHeader != null) { preferredWidth += rowHeader.getPreferredWidth(-1); } Component columnHeader = scrollPane.getColumnHeader(); if (columnHeader != null) { preferredHeight += columnHeader.getPreferredHeight(-1); } if (scrollPane.getHorizontalScrollBarPolicy() == ScrollBarPolicy.ALWAYS) { preferredHeight += horizontalScrollBar.getPreferredHeight(-1); } if (scrollPane.getVerticalScrollBarPolicy() == ScrollBarPolicy.ALWAYS) { preferredWidth += verticalScrollBar.getPreferredWidth(-1); } } return new Dimensions(preferredWidth, preferredHeight); }