Search in sources :

Example 36 with BoxPane

use of org.apache.pivot.wtk.BoxPane in project pivot by apache.

the class ComponentInspectorSkin method addSpanControl.

private static Component addSpanControl(final Dictionary<String, Object> dictionary, final String key, Form.Section section) {
    Span span = (Span) dictionary.get(key);
    BoxPane boxPane = new BoxPane(Orientation.VERTICAL);
    section.add(boxPane);
    Form.setLabel(boxPane, key);
    FlowPane flowPane = new FlowPane();
    flowPane.getStyles().put(Style.alignToBaseline, true);
    flowPane.getStyles().put(Style.horizontalSpacing, 5);
    boxPane.add(flowPane);
    TextInput textInput = new TextInput();
    textInput.setTextSize(10);
    textInput.setMaximumLength(10);
    textInput.setValidator(new IntValidator());
    textInput.setText(span == null ? "" : String.valueOf(span.start));
    flowPane.add(textInput);
    textInput.getComponentStateListeners().add(new ComponentStateListener() {

        @Override
        public void focusedChanged(Component component, Component obverseComponent) {
            if (!component.isFocused()) {
                TextInput textInputLocal = (TextInput) component;
                Span spanLocal = (Span) dictionary.get(key);
                try {
                    int start = Integer.parseInt(textInputLocal.getText());
                    dictionary.put(key, new Span(start, spanLocal == null ? start : spanLocal.end));
                } catch (Exception exception) {
                    displayErrorMessage(exception, component.getWindow());
                    textInputLocal.setText(spanLocal == null ? "" : String.valueOf(spanLocal.start));
                }
            }
        }
    });
    Label label = new Label("start");
    label.getStyles().put(Style.font, "{italic:true}");
    flowPane.add(label);
    flowPane = new FlowPane();
    flowPane.getStyles().put(Style.alignToBaseline, true);
    flowPane.getStyles().put(Style.horizontalSpacing, 5);
    boxPane.add(flowPane);
    textInput = new TextInput();
    textInput.setTextSize(10);
    textInput.setMaximumLength(10);
    textInput.setValidator(new IntValidator());
    textInput.setText(span == null ? "" : String.valueOf(span.end));
    flowPane.add(textInput);
    textInput.getComponentStateListeners().add(new ComponentStateListener() {

        @Override
        public void focusedChanged(Component component, Component obverseComponent) {
            if (!component.isFocused()) {
                TextInput textInputLocal = (TextInput) component;
                Span spanLocal = (Span) dictionary.get(key);
                try {
                    int end = Integer.parseInt(textInputLocal.getText());
                    dictionary.put(key, new Span(spanLocal == null ? end : spanLocal.start, end));
                } catch (Exception exception) {
                    displayErrorMessage(exception, component.getWindow());
                    textInputLocal.setText(spanLocal == null ? "" : String.valueOf(spanLocal.end));
                }
            }
        }
    });
    label = new Label("end");
    label.getStyles().put(Style.font, "{italic:true}");
    flowPane.add(label);
    return boxPane;
}
Also used : IntValidator(org.apache.pivot.wtk.validation.IntValidator) BoxPane(org.apache.pivot.wtk.BoxPane) Label(org.apache.pivot.wtk.Label) FlowPane(org.apache.pivot.wtk.FlowPane) TextInput(org.apache.pivot.wtk.TextInput) Component(org.apache.pivot.wtk.Component) Span(org.apache.pivot.wtk.Span) ComponentStateListener(org.apache.pivot.wtk.ComponentStateListener)

Example 37 with BoxPane

use of org.apache.pivot.wtk.BoxPane in project pivot by apache.

the class ComponentInspectorSkin method updateSpanControl.

private void updateSpanControl(Dictionary<String, Object> dictionary, String key) {
    BoxPane boxPane = (BoxPane) controls.get(key);
    if (boxPane != null) {
        Span span = (Span) dictionary.get(key);
        TextInput startTextInput = (TextInput) ((FlowPane) boxPane.get(0)).get(0);
        TextInput endTextInput = (TextInput) ((FlowPane) boxPane.get(1)).get(0);
        startTextInput.setText(span == null ? "" : String.valueOf(span.start));
        endTextInput.setText(span == null ? "" : String.valueOf(span.end));
    }
}
Also used : BoxPane(org.apache.pivot.wtk.BoxPane) TextInput(org.apache.pivot.wtk.TextInput) Span(org.apache.pivot.wtk.Span)

Example 38 with BoxPane

use of org.apache.pivot.wtk.BoxPane in project pivot by apache.

the class SimpleTablePanes method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    tablePane = (TablePane) namespace.get("tablePane");
    tablePane.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener() {

        @Override
        public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
            int rowIndex = tablePane.getRowAt(y);
            int columnIndex = tablePane.getColumnAt(x);
            if (rowIndex >= 0 && columnIndex >= 0) {
                TablePane.Row row = tablePane.getRows().get(rowIndex);
                TablePane.Column column = tablePane.getColumns().get(columnIndex);
                int rowHeight = row.getHeight();
                int columnWidth = column.getWidth();
                String message = "Registered Click At " + rowIndex + "," + columnIndex;
                Label heightLabel = new Label(String.format("The row's height is %d (%s)", rowHeight, rowHeight == -1 ? "default" : (row.isRelative() ? "relative" : "absolute")));
                Label widthLabel = new Label(String.format("The column's width is %d (%s)", columnWidth, columnWidth == -1 ? "default" : (column.isRelative() ? "relative" : "absolute")));
                BoxPane body = new BoxPane(Orientation.VERTICAL);
                body.add(heightLabel);
                body.add(widthLabel);
                Prompt.prompt(MessageType.INFO, message, body, SimpleTablePanes.this);
            }
            return false;
        }
    });
}
Also used : Mouse(org.apache.pivot.wtk.Mouse) BoxPane(org.apache.pivot.wtk.BoxPane) Label(org.apache.pivot.wtk.Label) ComponentMouseButtonListener(org.apache.pivot.wtk.ComponentMouseButtonListener) Component(org.apache.pivot.wtk.Component)

Aggregations

BoxPane (org.apache.pivot.wtk.BoxPane)38 Component (org.apache.pivot.wtk.Component)18 Label (org.apache.pivot.wtk.Label)15 TextInput (org.apache.pivot.wtk.TextInput)15 Button (org.apache.pivot.wtk.Button)9 Frame (org.apache.pivot.wtk.Frame)9 PushButton (org.apache.pivot.wtk.PushButton)9 Window (org.apache.pivot.wtk.Window)8 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)7 ComponentStateListener (org.apache.pivot.wtk.ComponentStateListener)7 FlowPane (org.apache.pivot.wtk.FlowPane)7 IntValidator (org.apache.pivot.wtk.validation.IntValidator)7 Dimensions (org.apache.pivot.wtk.Dimensions)5 Border (org.apache.pivot.wtk.Border)4 TablePane (org.apache.pivot.wtk.TablePane)4 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)3 ListView (org.apache.pivot.wtk.ListView)3 Sheet (org.apache.pivot.wtk.Sheet)3 Spinner (org.apache.pivot.wtk.Spinner)3 Color (java.awt.Color)2