Search in sources :

Example 71 with Dimensions

use of org.apache.pivot.wtk.Dimensions in project pivot by apache.

the class TerraListButtonSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    ListButton listButton = (ListButton) getComponent();
    Button.DataRenderer dataRenderer = listButton.getDataRenderer();
    // Determine the preferred width and height of the current button data
    dataRenderer.render(listButton.getButtonData(), listButton, false);
    Dimensions contentSize = dataRenderer.getPreferredSize();
    int preferredWidth = contentSize.width;
    int preferredHeight = contentSize.height + padding.getHeight() + 2;
    // The preferred width of the button is the max. width of the rendered
    // content plus padding and the trigger width
    List<?> listData = listButton.getListData();
    for (Object item : listData) {
        dataRenderer.render(item, listButton, false);
        preferredWidth = Math.max(preferredWidth, dataRenderer.getPreferredWidth(-1));
    }
    preferredWidth += TRIGGER_WIDTH + padding.getWidth() + 2;
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : ListButton(org.apache.pivot.wtk.ListButton) Button(org.apache.pivot.wtk.Button) ListButton(org.apache.pivot.wtk.ListButton) Dimensions(org.apache.pivot.wtk.Dimensions) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint)

Example 72 with Dimensions

use of org.apache.pivot.wtk.Dimensions in project pivot by apache.

the class TerraMenuButtonSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    MenuButton menuButton = (MenuButton) getComponent();
    Button.DataRenderer dataRenderer = menuButton.getDataRenderer();
    dataRenderer.render(menuButton.getButtonData(), menuButton, false);
    Dimensions contentSize = dataRenderer.getPreferredSize();
    int preferredWidth = contentSize.width + TRIGGER_WIDTH + padding.left + padding.right + 2;
    int preferredHeight = contentSize.height + padding.top + padding.bottom + 2;
    // Adjust for preferred aspect ratio
    float aspectRatio = (float) preferredWidth / (float) preferredHeight;
    if (!Float.isNaN(minumumAspectRatio) && aspectRatio < minumumAspectRatio) {
        preferredWidth = (int) (preferredHeight * minumumAspectRatio);
    }
    if (!Float.isNaN(maximumAspectRatio) && aspectRatio > maximumAspectRatio) {
        preferredHeight = (int) (preferredWidth / maximumAspectRatio);
    }
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : MenuButton(org.apache.pivot.wtk.MenuButton) Button(org.apache.pivot.wtk.Button) MenuButton(org.apache.pivot.wtk.MenuButton) Dimensions(org.apache.pivot.wtk.Dimensions) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint)

Example 73 with Dimensions

use of org.apache.pivot.wtk.Dimensions in project pivot by apache.

the class TerraCalendarButtonSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    CalendarButton calendarButton = (CalendarButton) getComponent();
    Button.DataRenderer dataRenderer = calendarButton.getDataRenderer();
    dataRenderer.render(calendarButton.getButtonData(), calendarButton, false);
    Dimensions contentSize = dataRenderer.getPreferredSize();
    int preferredWidth = contentSize.width + paddingWidth();
    int preferredHeight = contentSize.height + paddingHeight();
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : CalendarButton(org.apache.pivot.wtk.CalendarButton) Button(org.apache.pivot.wtk.Button) CalendarButton(org.apache.pivot.wtk.CalendarButton) Dimensions(org.apache.pivot.wtk.Dimensions) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint)

Example 74 with Dimensions

use of org.apache.pivot.wtk.Dimensions in project pivot by apache.

the class TerraCheckboxSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    Checkbox checkbox = (Checkbox) getComponent();
    Button.DataRenderer dataRenderer = checkbox.getDataRenderer();
    dataRenderer.render(checkbox.getButtonData(), checkbox, false);
    int preferredWidth = CHECKBOX_SIZE;
    int preferredHeight = CHECKBOX_SIZE;
    Object buttonData = checkbox.getButtonData();
    if (buttonData != null) {
        dataRenderer.render(buttonData, checkbox, false);
        preferredWidth += dataRenderer.getPreferredWidth(-1) + spacing * 2;
        preferredHeight = Math.max(preferredHeight, dataRenderer.getPreferredHeight(-1));
    }
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : Button(org.apache.pivot.wtk.Button) Checkbox(org.apache.pivot.wtk.Checkbox) Dimensions(org.apache.pivot.wtk.Dimensions) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint)

Example 75 with Dimensions

use of org.apache.pivot.wtk.Dimensions in project pivot by apache.

the class TerraColorChooserButtonSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    ColorChooserButton colorChooserButton = (ColorChooserButton) getComponent();
    Button.DataRenderer dataRenderer = colorChooserButton.getDataRenderer();
    dataRenderer.render(colorChooserButton.getButtonData(), colorChooserButton, false);
    Dimensions contentSize = dataRenderer.getPreferredSize();
    int preferredWidth = contentSize.width + paddingWidth();
    int preferredHeight = contentSize.height + paddingHeight();
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : ColorChooserButton(org.apache.pivot.wtk.ColorChooserButton) ColorChooserButton(org.apache.pivot.wtk.ColorChooserButton) Button(org.apache.pivot.wtk.Button) Dimensions(org.apache.pivot.wtk.Dimensions) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint)

Aggregations

Dimensions (org.apache.pivot.wtk.Dimensions)76 Component (org.apache.pivot.wtk.Component)40 GradientPaint (java.awt.GradientPaint)21 Point (org.apache.pivot.wtk.Point)16 FontRenderContext (java.awt.font.FontRenderContext)9 Button (org.apache.pivot.wtk.Button)9 Paint (java.awt.Paint)7 Rectangle2D (java.awt.geom.Rectangle2D)6 LineMetrics (java.awt.font.LineMetrics)5 BoxPane (org.apache.pivot.wtk.BoxPane)5 FlowPane (org.apache.pivot.wtk.FlowPane)5 Label (org.apache.pivot.wtk.Label)5 ScrollPane (org.apache.pivot.wtk.ScrollPane)4 Separator (org.apache.pivot.wtk.Separator)4 Form (org.apache.pivot.wtk.Form)3 ImageView (org.apache.pivot.wtk.ImageView)3 Image (org.apache.pivot.wtk.media.Image)3 Color (java.awt.Color)2 Font (java.awt.Font)2 LineBreakMeasurer (java.awt.font.LineBreakMeasurer)2