Search in sources :

Example 26 with Label

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;
}
Also used : BoxPane(org.apache.pivot.wtk.BoxPane) Color(java.awt.Color) Label(org.apache.pivot.wtk.Label) Border(org.apache.pivot.wtk.Border) StackPane(org.apache.pivot.wtk.StackPane)

Example 27 with Label

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
        }
    }
}
Also used : Label(org.apache.pivot.wtk.Label) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer) IOException(java.io.IOException) JSONSerializer(org.apache.pivot.json.JSONSerializer)

Example 28 with Label

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());
    }
}
Also used : Tooltip(org.apache.pivot.wtk.Tooltip) Label(org.apache.pivot.wtk.Label) Point(org.apache.pivot.wtk.Point) Point(org.apache.pivot.wtk.Point) Display(org.apache.pivot.wtk.Display)

Example 29 with Label

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);
}
Also used : Label(org.apache.pivot.wtk.Label) Rectangle2D(java.awt.geom.Rectangle2D) Dimensions(org.apache.pivot.wtk.Dimensions) FontRenderContext(java.awt.font.FontRenderContext) LineMetrics(java.awt.font.LineMetrics)

Example 30 with Label

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;
}
Also used : Label(org.apache.pivot.wtk.Label) Rectangle2D(java.awt.geom.Rectangle2D) FontRenderContext(java.awt.font.FontRenderContext)

Aggregations

Label (org.apache.pivot.wtk.Label)44 Component (org.apache.pivot.wtk.Component)20 BoxPane (org.apache.pivot.wtk.BoxPane)15 Point (org.apache.pivot.wtk.Point)13 Form (org.apache.pivot.wtk.Form)10 TextInput (org.apache.pivot.wtk.TextInput)8 ComponentStateListener (org.apache.pivot.wtk.ComponentStateListener)7 FlowPane (org.apache.pivot.wtk.FlowPane)7 IntValidator (org.apache.pivot.wtk.validation.IntValidator)7 TablePane (org.apache.pivot.wtk.TablePane)6 FontRenderContext (java.awt.font.FontRenderContext)5 Rectangle2D (java.awt.geom.Rectangle2D)5 Dimensions (org.apache.pivot.wtk.Dimensions)5 Frame (org.apache.pivot.wtk.Frame)5 Separator (org.apache.pivot.wtk.Separator)5 Color (java.awt.Color)3 Font (java.awt.Font)3 LineMetrics (java.awt.font.LineMetrics)3 IOException (java.io.IOException)3 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)3