use of org.apache.pivot.wtk.Meter in project pivot by apache.
the class TerraMeterSkin method getPreferredHeight.
@Override
public int getPreferredHeight(int width) {
Meter meter = (Meter) getComponent();
int preferredHeight;
if (meter.getOrientation() == Orientation.HORIZONTAL) {
preferredHeight = getPreferredWidth(width);
} else {
String text = meter.getText();
if (text != null && text.length() > 0) {
FontRenderContext fontRenderContext = Platform.getFontRenderContext();
LineMetrics lm = font.getLineMetrics("", fontRenderContext);
preferredHeight = (int) Math.ceil(lm.getHeight()) + 2;
} else {
preferredHeight = 0;
}
// If the meter has no content, its preferred height is hard-coded by the
// class and is not affected by the width constraint
preferredHeight = Math.max(preferredHeight, DEFAULT_HEIGHT);
}
return preferredHeight;
}
use of org.apache.pivot.wtk.Meter in project pivot by apache.
the class TerraMeterSkin method getBaseline.
@Override
public int getBaseline(int width, int height) {
int baseline = -1;
Meter meter = (Meter) getComponent();
if (meter.getOrientation() == Orientation.HORIZONTAL) {
String text = meter.getText();
if (text != null && text.length() > 0) {
FontRenderContext fontRenderContext = Platform.getFontRenderContext();
LineMetrics lm = font.getLineMetrics("", fontRenderContext);
float ascent = lm.getAscent();
float textHeight = lm.getHeight();
baseline = Math.round((height - textHeight) / 2 + ascent);
}
}
return baseline;
}
use of org.apache.pivot.wtk.Meter in project pivot by apache.
the class MeterTest method testListeners.
@Test
public void testListeners() {
Meter meter = new Meter();
meter.getMeterListeners().add(this);
// Test all the listeners getting fired as they should
meter.setText("abc");
meter.setText(null);
meter.setText(null);
meter.setText("123");
meter.setText("123");
meter.setOrientation(Orientation.HORIZONTAL);
meter.setOrientation(Orientation.VERTICAL);
meter.setOrientation(Orientation.HORIZONTAL);
meter.setPercentage(0.25);
meter.setPercentage(0.25);
meter.setPercentage(0.5);
meter.setPercentage(0.75);
meter.setPercentage(1.0);
// Now check for proper listener event counts
assertEquals(percentChangeCount, 4);
assertEquals(textChangeCount, 3);
assertEquals(orientationChangeCount, 2);
}
use of org.apache.pivot.wtk.Meter in project pivot by apache.
the class TerraMeterSkin method getPreferredWidth.
@Override
public int getPreferredWidth(int height) {
Meter meter = (Meter) getComponent();
int preferredWidth;
if (meter.getOrientation() == Orientation.HORIZONTAL) {
String text = meter.getText();
if (text != null && text.length() > 0) {
FontRenderContext fontRenderContext = Platform.getFontRenderContext();
Rectangle2D stringBounds = font.getStringBounds(text, fontRenderContext);
preferredWidth = (int) Math.ceil(stringBounds.getWidth()) + 2;
} else {
preferredWidth = 0;
}
// If the meter has no content, its preferred width is hard-coded by the
// class and is not affected by the height constraint
preferredWidth = Math.max(preferredWidth, DEFAULT_WIDTH);
} else {
preferredWidth = getPreferredHeight(-1);
}
return preferredWidth;
}
use of org.apache.pivot.wtk.Meter 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;
}
Aggregations