Search in sources :

Example 6 with Separator

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

the class SeparatorSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    int preferredWidth = 0;
    int preferredHeight = thickness;
    Separator separator = (Separator) getComponent();
    String heading = separator.getHeading();
    if (heading != null && heading.length() > 0) {
        FontRenderContext fontRenderContext = Platform.getFontRenderContext();
        Rectangle2D headingBounds = font.getStringBounds(heading, fontRenderContext);
        LineMetrics lm = font.getLineMetrics(heading, fontRenderContext);
        preferredWidth = (int) Math.ceil(headingBounds.getWidth());
        preferredHeight = Math.max((int) Math.ceil(lm.getAscent() + lm.getDescent() + lm.getLeading()), preferredHeight);
    }
    preferredHeight += padding.getHeight();
    preferredWidth += padding.getWidth();
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) Dimensions(org.apache.pivot.wtk.Dimensions) FontRenderContext(java.awt.font.FontRenderContext) LineMetrics(java.awt.font.LineMetrics) Separator(org.apache.pivot.wtk.Separator)

Example 7 with Separator

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

the class SeparatorSkin method paint.

@Override
public void paint(Graphics2D graphics) {
    Separator separator = (Separator) getComponent();
    int width = getWidth();
    int separatorY = padding.top;
    String heading = separator.getHeading();
    if (heading != null && heading.length() > 0) {
        FontRenderContext fontRenderContext = GraphicsUtilities.prepareForText(graphics, font, headingColor);
        LineMetrics lm = font.getLineMetrics(heading, fontRenderContext);
        graphics.drawString(heading, padding.left, lm.getAscent() + padding.top);
        Rectangle2D headingBounds = font.getStringBounds(heading, fontRenderContext);
        Area titleClip = new Area(graphics.getClip());
        titleClip.subtract(new Area(new Rectangle2D.Double(padding.left, padding.top, headingBounds.getWidth() + padding.right, headingBounds.getHeight())));
        graphics.clip(titleClip);
        separatorY += (lm.getAscent() + lm.getDescent()) / 2 + 1;
    }
    graphics.setStroke(new BasicStroke(thickness));
    graphics.setColor(color);
    graphics.drawLine(0, separatorY, width, separatorY);
}
Also used : BasicStroke(java.awt.BasicStroke) Area(java.awt.geom.Area) Rectangle2D(java.awt.geom.Rectangle2D) FontRenderContext(java.awt.font.FontRenderContext) LineMetrics(java.awt.font.LineMetrics) Separator(org.apache.pivot.wtk.Separator)

Example 8 with Separator

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

the class SeparatorSkin method getPreferredHeight.

@Override
public int getPreferredHeight(int width) {
    int preferredHeight = thickness;
    Separator separator = (Separator) getComponent();
    String heading = separator.getHeading();
    if (heading != null && heading.length() > 0) {
        FontRenderContext fontRenderContext = Platform.getFontRenderContext();
        LineMetrics lm = font.getLineMetrics(heading, fontRenderContext);
        preferredHeight = Math.max((int) Math.ceil(lm.getAscent() + lm.getDescent() + lm.getLeading()), preferredHeight);
    }
    preferredHeight += padding.getHeight();
    return preferredHeight;
}
Also used : FontRenderContext(java.awt.font.FontRenderContext) LineMetrics(java.awt.font.LineMetrics) Separator(org.apache.pivot.wtk.Separator)

Example 9 with Separator

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

the class TerraFormSkin method insertSection.

private void insertSection(Form.Section section, int index) {
    Form form = (Form) getComponent();
    // Insert separator
    Separator separator = new Separator(section.getHeading());
    separator.getStyles().put(Style.color, separatorColor);
    separator.getStyles().put(Style.headingColor, separatorHeadingColor);
    separators.insert(separator, index);
    form.add(separator);
    // Insert label list
    ArrayList<Label> sectionLabels = new ArrayList<>();
    labels.insert(sectionLabels, index);
    // Insert fields
    for (int i = 0, n = section.getLength(); i < n; i++) {
        insertField(section, section.get(i), i);
    }
    invalidateComponent();
}
Also used : Form(org.apache.pivot.wtk.Form) Label(org.apache.pivot.wtk.Label) ArrayList(org.apache.pivot.collections.ArrayList) Separator(org.apache.pivot.wtk.Separator) Point(org.apache.pivot.wtk.Point)

Example 10 with Separator

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

the class TerraFormSkin method updateSectionHeading.

private void updateSectionHeading(Form.Section section) {
    Form form = (Form) getComponent();
    int sectionIndex = form.getSections().indexOf(section);
    Separator separator = separators.get(sectionIndex);
    separator.setHeading(section.getHeading());
}
Also used : Form(org.apache.pivot.wtk.Form) Point(org.apache.pivot.wtk.Point) Separator(org.apache.pivot.wtk.Separator)

Aggregations

Separator (org.apache.pivot.wtk.Separator)12 Form (org.apache.pivot.wtk.Form)7 Point (org.apache.pivot.wtk.Point)7 Label (org.apache.pivot.wtk.Label)5 FontRenderContext (java.awt.font.FontRenderContext)4 Component (org.apache.pivot.wtk.Component)4 Dimensions (org.apache.pivot.wtk.Dimensions)4 LineMetrics (java.awt.font.LineMetrics)3 Rectangle2D (java.awt.geom.Rectangle2D)3 BasicStroke (java.awt.BasicStroke)1 Area (java.awt.geom.Area)1 ArrayList (org.apache.pivot.collections.ArrayList)1 Theme (org.apache.pivot.wtk.Theme)1