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);
}
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);
}
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;
}
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();
}
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());
}
Aggregations