use of org.apache.pivot.wtk.Dimensions in project pivot by apache.
the class TerraMenuSkin method getPreferredSize.
@Override
public Dimensions getPreferredSize() {
int preferredWidth = 0;
int preferredHeight = 0;
Menu menu = (Menu) getComponent();
Menu.SectionSequence sections = menu.getSections();
for (int i = 0, n = sections.getLength(); i < n; i++) {
Menu.Section section = sections.get(i);
for (Menu.Item item : section) {
if (item.isVisible()) {
preferredWidth = Math.max(item.getPreferredWidth(), preferredWidth);
preferredHeight += item.getPreferredHeight();
}
}
if (i > 0) {
preferredHeight += sectionSpacing;
}
}
return new Dimensions(preferredWidth, preferredHeight);
}
use of org.apache.pivot.wtk.Dimensions in project pivot by apache.
the class TerraMeterSkin method getPreferredSize.
@Override
public Dimensions getPreferredSize() {
Meter meter = (Meter) getComponent();
String text = meter.getText();
int preferredWidth = 0;
int preferredHeight = 0;
if (text != null && text.length() > 0) {
FontRenderContext fontRenderContext = Platform.getFontRenderContext();
Rectangle2D stringBounds = font.getStringBounds(text, fontRenderContext);
preferredWidth = (int) Math.ceil(stringBounds.getWidth()) + 2;
LineMetrics lm = font.getLineMetrics("", fontRenderContext);
preferredHeight = (int) Math.ceil(lm.getHeight()) + 2;
}
// If meter has no content, its preferred size is hard coded by the class
preferredWidth = Math.max(preferredWidth, DEFAULT_WIDTH);
preferredHeight = Math.max(preferredHeight, DEFAULT_HEIGHT);
Dimensions preferredSize;
if (meter.getOrientation() == Orientation.HORIZONTAL) {
preferredSize = new Dimensions(preferredWidth, preferredHeight);
} else {
preferredSize = new Dimensions(preferredHeight, preferredWidth);
}
return preferredSize;
}
use of org.apache.pivot.wtk.Dimensions in project pivot by apache.
the class TerraPanoramaSkin method layout.
@Override
public void layout() {
Panorama panorama = (Panorama) getComponent();
int width = getWidth();
int height = getHeight();
Component view = panorama.getView();
if (view != null) {
Dimensions viewSize = view.getPreferredSize();
view.setSize(Math.max(width, viewSize.width), Math.max(height, viewSize.height));
int viewWidth = view.getWidth();
int viewHeight = view.getHeight();
int maxScrollTop = getMaxScrollTop();
if (panorama.getScrollTop() > maxScrollTop) {
panorama.setScrollTop(maxScrollTop);
}
int maxScrollLeft = getMaxScrollLeft();
if (panorama.getScrollLeft() > maxScrollLeft) {
panorama.setScrollLeft(maxScrollLeft);
}
if (width < viewWidth) {
// Show east/west buttons
eastButton.setSize(eastButton.getPreferredWidth(), height);
eastButton.setLocation(width - eastButton.getWidth(), 0);
westButton.setSize(westButton.getPreferredWidth(), height);
westButton.setLocation(0, 0);
}
if (height < viewHeight) {
// Show north/south buttons
northButton.setSize(width, northButton.getPreferredHeight());
northButton.setLocation(0, 0);
southButton.setSize(width, southButton.getPreferredHeight());
southButton.setLocation(0, height - southButton.getHeight());
}
}
updateScrollButtonVisibility();
}
use of org.apache.pivot.wtk.Dimensions in project pivot by apache.
the class TerraRadioButtonSkin method getPreferredSize.
@Override
public Dimensions getPreferredSize() {
RadioButton radioButton = (RadioButton) getComponent();
Button.DataRenderer dataRenderer = radioButton.getDataRenderer();
int preferredWidth = BUTTON_DIAMETER;
int preferredHeight = BUTTON_DIAMETER;
Object buttonData = radioButton.getButtonData();
if (buttonData != null) {
dataRenderer.render(buttonData, radioButton, false);
preferredWidth += dataRenderer.getPreferredWidth(-1) + spacing * 2;
preferredHeight = Math.max(preferredHeight, dataRenderer.getPreferredHeight(-1));
}
return new Dimensions(preferredWidth, preferredHeight);
}
use of org.apache.pivot.wtk.Dimensions in project pivot by apache.
the class TerraScrollBarSkin method getPreferredSize.
@Override
public Dimensions getPreferredSize() {
ScrollBar scrollBar = (ScrollBar) getComponent();
int preferredWidth = 0;
int preferredHeight = 0;
if (scrollBar.getOrientation() == Orientation.HORIZONTAL) {
preferredWidth = DEFAULT_LENGTH;
preferredHeight = DEFAULT_THICKNESS;
} else {
preferredWidth = DEFAULT_THICKNESS;
preferredHeight = DEFAULT_LENGTH;
}
return new Dimensions(preferredWidth, preferredHeight);
}
Aggregations