use of org.apache.pivot.wtk.Label in project pivot by apache.
the class ColorPaletteTest method createCell.
private static Component createCell(int index) {
StackPane stackPane = new StackPane();
Border border = new Border();
border.getStyles().put(Style.backgroundColor, index);
stackPane.add(border);
Label label = new Label();
label.setText(Integer.toString(index));
label.getStyles().put(Style.backgroundColor, Color.WHITE);
label.getStyles().put(Style.padding, 2);
Color themeColor = border.getStyles().getColor(Style.backgroundColor);
Label colorLabel = new Label();
colorLabel.setText(String.format("R:%1$d,G:%2$d,B:%3$d", themeColor.getRed(), themeColor.getGreen(), themeColor.getBlue()));
colorLabel.getStyles().put(Style.backgroundColor, Color.WHITE);
colorLabel.getStyles().put(Style.padding, 2);
BoxPane boxPane = new BoxPane(Orientation.VERTICAL);
boxPane.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.CENTER);
boxPane.getStyles().put(Style.verticalAlignment, VerticalAlignment.CENTER);
boxPane.add(new Border(label));
boxPane.add(new Border(colorLabel));
stackPane.add(boxPane);
return stackPane;
}
use of org.apache.pivot.wtk.Label in project pivot by apache.
the class JSONViewer method startup.
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
BXMLSerializer bxmlSerializer = new BXMLSerializer();
bxmlSerializer.getNamespace().put(APPLICATION_KEY, this);
window = (Window) bxmlSerializer.readObject(JSONViewer.class, "json_viewer.bxml");
bxmlSerializer.bind(this);
Label prompt = new Label("Drag or paste JSON here");
prompt.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.CENTER);
prompt.getStyles().put(Style.verticalAlignment, VerticalAlignment.CENTER);
promptDecorator.setOverlay(prompt);
treeView.getDecorators().add(promptDecorator);
window.setTitle(WINDOW_TITLE);
window.open(display);
window.requestFocus();
if (System.in.available() > 0) {
JSONSerializer jsonSerializer = new JSONSerializer();
try {
setValue(jsonSerializer.readObject(System.in));
} catch (Exception exception) {
// No-op
}
}
}
use of org.apache.pivot.wtk.Label in project pivot by apache.
the class ComponentSkin method tooltipTriggered.
@Override
public void tooltipTriggered(Component componentArgument, int x, int y) {
String tooltipText = component.getTooltipText();
if (tooltipText != null) {
Label tooltipLabel = new Label(tooltipText);
boolean tooltipWrapText = component.getTooltipWrapText();
tooltipLabel.getStyles().put(Style.wrapText, tooltipWrapText);
Tooltip tooltip = new Tooltip(tooltipLabel);
Display display = component.getDisplay();
Point location = component.mapPointToAncestor(display, x, y);
// Ensure that the tooltip stays on screen
int tooltipX = location.x + 16;
int tooltipY = location.y;
int tooltipWidth = tooltip.getPreferredWidth();
int tooltipHeight = tooltip.getPreferredHeight();
if (tooltipX + tooltipWidth > display.getWidth()) {
// the cursor
if (tooltipY > tooltipHeight) {
tooltipX = display.getWidth() - tooltipWidth;
} else {
tooltipX = location.x - tooltipWidth - 16;
}
if (tooltipX < 0) {
tooltipX = 0;
}
// these x adjustments
if (tooltipX < location.x && tooltipX + tooltipWidth > location.x) {
tooltipY -= tooltipHeight;
if (tooltipY < 0) {
tooltipY = 0;
}
}
}
if (tooltipY + tooltipHeight > display.getHeight()) {
tooltipY -= tooltipHeight;
}
tooltip.setLocation(tooltipX, tooltipY);
tooltip.open(component.getWindow());
}
}
use of org.apache.pivot.wtk.Label in project pivot by apache.
the class LabelSkin method getPreferredSize.
@Override
public Dimensions getPreferredSize() {
Label label = (Label) getComponent();
String text = label.getText();
FontRenderContext fontRenderContext = Platform.getFontRenderContext();
LineMetrics lm = font.getLineMetrics("", fontRenderContext);
int lineHeight = (int) Math.ceil(lm.getHeight());
int preferredHeight = 0;
int preferredWidth = 0;
if (text != null && text.length() > 0) {
String[] str;
if (wrapText) {
str = text.split("\n");
} else {
str = new String[] { text };
}
for (String line : str) {
Rectangle2D stringBounds = font.getStringBounds(line, fontRenderContext);
int w = (int) Math.ceil(stringBounds.getWidth());
if (w > preferredWidth) {
preferredWidth = w;
}
preferredHeight += lineHeight;
}
} else {
preferredHeight += lineHeight;
}
preferredHeight += (padding.top + padding.bottom);
preferredWidth += (padding.left + padding.right);
return new Dimensions(preferredWidth, preferredHeight);
}
use of org.apache.pivot.wtk.Label in project pivot by apache.
the class LabelSkin method getPreferredWidth.
@Override
public int getPreferredWidth(int height) {
Label label = (Label) getComponent();
String text = label.getText();
int preferredWidth = 0;
if (text != null && text.length() > 0) {
FontRenderContext fontRenderContext = Platform.getFontRenderContext();
String[] str;
if (wrapText) {
str = text.split("\n");
} else {
str = new String[] { text };
}
for (String line : str) {
Rectangle2D stringBounds = font.getStringBounds(line, fontRenderContext);
int w = (int) Math.ceil(stringBounds.getWidth());
if (w > preferredWidth) {
preferredWidth = w;
}
}
}
preferredWidth += (padding.left + padding.right);
return preferredWidth;
}
Aggregations