Search in sources :

Example 1 with Label

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

the class ComponentInspectorSkin method addScopeControl.

private static Component addScopeControl(final Dictionary<String, Object> dictionary, final String key, Form.Section section) {
    Scope scope = (Scope) 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(scope == null ? "" : String.valueOf(scope.start));
    flowPane.add(textInput);
    textInput.getComponentStateListeners().add(new ComponentStateListener() {

        @Override
        public void focusedChanged(Component component, Component obverseComponent) {
            if (!component.isFocused()) {
                TextInput textInputLocal = (TextInput) component;
                Scope scopeLocal = (Scope) dictionary.get(key);
                try {
                    int start = Integer.parseInt(textInputLocal.getText());
                    dictionary.put(key, new Scope(start, scopeLocal == null ? start : scopeLocal.end, scopeLocal == null ? start : scopeLocal.extent));
                } catch (Exception exception) {
                    displayErrorMessage(exception, component.getWindow());
                    textInputLocal.setText(scopeLocal == null ? "" : String.valueOf(scopeLocal.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(scope == null ? "" : String.valueOf(scope.end));
    flowPane.add(textInput);
    textInput.getComponentStateListeners().add(new ComponentStateListener() {

        @Override
        public void focusedChanged(Component component, Component obverseComponent) {
            if (!component.isFocused()) {
                TextInput textInputLocal = (TextInput) component;
                Scope scopeLocal = (Scope) dictionary.get(key);
                try {
                    int end = Integer.parseInt(textInputLocal.getText());
                    dictionary.put(key, new Scope(scopeLocal == null ? end : scopeLocal.start, end, scopeLocal == null ? end : scopeLocal.extent));
                } catch (Exception exception) {
                    displayErrorMessage(exception, component.getWindow());
                    textInputLocal.setText(scopeLocal == null ? "" : String.valueOf(scopeLocal.end));
                }
            }
        }
    });
    label = new Label("end");
    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(scope == null ? "" : String.valueOf(scope.extent));
    flowPane.add(textInput);
    textInput.getComponentStateListeners().add(new ComponentStateListener() {

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

Example 2 with Label

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

the class ComponentInspectorSkin method addDimensionsControl.

private static Component addDimensionsControl(final Dictionary<String, Object> dictionary, final String key, Form.Section section) {
    Dimensions dimensions = (Dimensions) 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(4);
    textInput.setMaximumLength(5);
    textInput.setValidator(new IntValidator());
    textInput.setText(String.valueOf(dimensions.width));
    flowPane.add(textInput);
    textInput.getComponentStateListeners().add(new ComponentStateListener() {

        @Override
        public void focusedChanged(Component component, Component obverseComponent) {
            if (!component.isFocused()) {
                TextInput textInputLocal = (TextInput) component;
                Dimensions dimensionsLocal = (Dimensions) dictionary.get(key);
                try {
                    int width = Integer.parseInt(textInputLocal.getText());
                    dictionary.put(key, new Dimensions(width, dimensionsLocal.height));
                } catch (Exception exception) {
                    displayErrorMessage(exception, component.getWindow());
                    textInputLocal.setText(String.valueOf(dimensionsLocal.width));
                }
            }
        }
    });
    Label label = new Label("width");
    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(4);
    textInput.setMaximumLength(5);
    textInput.setValidator(new IntValidator());
    textInput.setText(String.valueOf(dimensions.height));
    flowPane.add(textInput);
    textInput.getComponentStateListeners().add(new ComponentStateListener() {

        @Override
        public void focusedChanged(Component component, Component obverseComponent) {
            if (!component.isFocused()) {
                TextInput textInputLocal = (TextInput) component;
                Dimensions dimensionsLocal = (Dimensions) dictionary.get(key);
                try {
                    int height = Integer.parseInt(textInputLocal.getText());
                    dictionary.put(key, new Dimensions(dimensionsLocal.width, height));
                } catch (Exception exception) {
                    displayErrorMessage(exception, component.getWindow());
                    textInputLocal.setText(String.valueOf(dimensionsLocal.height));
                }
            }
        }
    });
    label = new Label("height");
    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) Dimensions(org.apache.pivot.wtk.Dimensions) FlowPane(org.apache.pivot.wtk.FlowPane) TextInput(org.apache.pivot.wtk.TextInput) Component(org.apache.pivot.wtk.Component) ComponentStateListener(org.apache.pivot.wtk.ComponentStateListener)

Example 3 with Label

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

the class ComponentInspectorSkin method addLimitsControl.

private static Component addLimitsControl(final Dictionary<String, Object> dictionary, final String key, Form.Section section) {
    Limits limits = (Limits) 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(String.valueOf(limits.minimum));
    flowPane.add(textInput);
    textInput.getComponentStateListeners().add(new ComponentStateListener() {

        @Override
        public void focusedChanged(Component component, Component obverseComponent) {
            if (!component.isFocused()) {
                TextInput textInputLocal = (TextInput) component;
                Limits limitsLocal = (Limits) dictionary.get(key);
                try {
                    int min = Integer.parseInt(textInputLocal.getText());
                    dictionary.put(key, new Limits(min, limitsLocal.maximum));
                } catch (Exception exception) {
                    displayErrorMessage(exception, component.getWindow());
                    textInputLocal.setText(String.valueOf(limitsLocal.minimum));
                }
            }
        }
    });
    Label label = new Label("min");
    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(String.valueOf(limits.maximum));
    flowPane.add(textInput);
    textInput.getComponentStateListeners().add(new ComponentStateListener() {

        @Override
        public void focusedChanged(Component component, Component obverseComponent) {
            if (!component.isFocused()) {
                TextInput textInputLocal = (TextInput) component;
                Limits limitsLocal = (Limits) dictionary.get(key);
                try {
                    int max = Integer.parseInt(textInputLocal.getText());
                    dictionary.put(key, new Limits(limitsLocal.minimum, max));
                } catch (Exception exception) {
                    displayErrorMessage(exception, component.getWindow());
                    textInputLocal.setText(String.valueOf(limitsLocal.maximum));
                }
            }
        }
    });
    label = new Label("max");
    label.getStyles().put(Style.font, "{italic:true}");
    flowPane.add(label);
    return boxPane;
}
Also used : Limits(org.apache.pivot.wtk.Limits) 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) ComponentStateListener(org.apache.pivot.wtk.ComponentStateListener)

Example 4 with Label

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

the class Pivot964Pivot method startup.

@Override
public void startup(Display display, Map<String, String> properties) {
    // force dimensions for host frame
    display.getHostWindow().setSize(1028, 600);
    window = new Window();
    prepareSVG();
    final ImageView image = new ImageView(new Drawing(diagram));
    BoxPane bp = new BoxPane();
    TablePane tp = new TablePane();
    setStyles(tp, "{padding: 4}");
    TablePane.Column c1 = new TablePane.Column(-1);
    TablePane.Column c2 = new TablePane.Column(-1);
    tp.getColumns().add(c1);
    tp.getColumns().add(c2);
    TablePane.Row r1 = new TablePane.Row(-1);
    TablePane.Row r2 = new TablePane.Row(-1);
    TablePane.Row r3 = new TablePane.Row(-1);
    PushButton pb1 = new PushButton("Visible");
    PushButton pb2 = new PushButton("Invisible (bug)");
    r1.add(pb1);
    r1.add(pb2);
    final Spinner sp1 = new Spinner(new ListAdapter<>(spinnerData));
    sp1.setPreferredWidth(80);
    sp1.setSelectedIndex(0);
    final Spinner sp2 = new Spinner(new ListAdapter<>(spinnerData));
    sp2.setPreferredWidth(80);
    sp2.setSelectedIndex(0);
    BoxPane bp1 = new BoxPane();
    setStyles(bp1, "{verticalAlignment:'center', padding: 4, spacing: 2}");
    bp1.add(new Label("X:"));
    bp1.add(sp1);
    r2.add(bp1);
    BoxPane bp2 = new BoxPane();
    setStyles(bp2, "{verticalAlignment:'center', padding: 4, spacing: 2}");
    bp2.add(new Label("Y:"));
    bp2.add(sp2);
    r2.add(bp2);
    tp.getRows().add(r1);
    tp.getRows().add(r2);
    r3.add(new Label("   Max X=507"));
    r3.add(new Label("   Max Y=269"));
    tp.getRows().add(r3);
    bp.add(image);
    bp.add(tp);
    pb1.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button arg0) {
            try {
                root.setAttribute("viewBox", AnimationElement.AT_XML, "0 0 2368 1652");
                root.updateTime(0f);
                image.repaint();
            } catch (SVGElementException e) {
                e.printStackTrace();
            } catch (SVGException e) {
                e.printStackTrace();
            }
        }
    });
    pb2.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button arg0) {
            try {
                String xOffset = (String) sp1.getSelectedItem();
                String yOffset = (String) sp2.getSelectedItem();
                String viewBox = String.format("%1$s %2$s 2368 1652", xOffset, yOffset);
                root.setAttribute("viewBox", AnimationElement.AT_XML, viewBox);
                root.updateTime(0f);
                image.repaint();
            } catch (SVGElementException e) {
                e.printStackTrace();
            } catch (SVGException e) {
                e.printStackTrace();
            }
        }
    });
    window.setContent(bp);
    window.setMaximized(true);
    window.open(display);
}
Also used : Window(org.apache.pivot.wtk.Window) Drawing(org.apache.pivot.wtk.media.Drawing) Spinner(org.apache.pivot.wtk.Spinner) SVGException(com.kitfox.svg.SVGException) Label(org.apache.pivot.wtk.Label) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) BoxPane(org.apache.pivot.wtk.BoxPane) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) ImageView(org.apache.pivot.wtk.ImageView) SVGElementException(com.kitfox.svg.SVGElementException) PushButton(org.apache.pivot.wtk.PushButton) TablePane(org.apache.pivot.wtk.TablePane)

Example 5 with Label

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

the class BXMLExplorerDocument method setComponentIconOnTreeNode.

private static void setComponentIconOnTreeNode(TreeNode treeNode, Object comp) {
    String resource = null;
    if (comp instanceof Label) {
        resource = "label.png";
    }
    if (comp instanceof ImageView) {
        resource = "/org/apache/pivot/tutorials/IMG_0725_2.jpg";
    }
    if (comp instanceof PushButton) {
        resource = "pushbutton.png";
    }
    if (comp instanceof RadioButton) {
        resource = "radiobutton.png";
    }
    if (comp instanceof Checkbox) {
        resource = "checkbox.png";
    }
    if (comp instanceof LinkButton) {
        resource = "linkbutton.png";
    }
    if (comp instanceof TablePane) {
        resource = "tablepane.png";
    }
    if (resource != null) {
        URL url = BXMLExplorerDocument.class.getResource(resource);
        if (url == null) {
            throw new IllegalStateException("could not load resource " + resource);
        }
        treeNode.setIcon(url);
    }
}
Also used : Checkbox(org.apache.pivot.wtk.Checkbox) Label(org.apache.pivot.wtk.Label) ImageView(org.apache.pivot.wtk.ImageView) RadioButton(org.apache.pivot.wtk.RadioButton) PushButton(org.apache.pivot.wtk.PushButton) LinkButton(org.apache.pivot.wtk.LinkButton) URL(java.net.URL) TablePane(org.apache.pivot.wtk.TablePane)

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