Search in sources :

Example 1 with ItemGroup

use of com.scriptographer.adm.ItemGroup in project scriptographer by scriptographer.

the class AdmComponentProxy method createItem.

protected Item createItem(Dialog dialog) {
    // Item:
    item = null;
    ComponentType type = component.getType();
    switch(type) {
        case NUMBER:
            {
                Boolean steppers = component.getSteppers();
                if (steppers != null && steppers) {
                    item = new SpinEdit(dialog) {

                        protected void onChange() {
                            AdmComponentProxy.this.onChange(true);
                        }
                    };
                } else {
                    TextEditItem textItem = new TextEdit(dialog) {

                        protected void onChange() {
                            AdmComponentProxy.this.onChange(true);
                        }
                    };
                    textItem.setAllowMath(true);
                    textItem.setAllowUnits(true);
                    item = textItem;
                }
            }
            break;
        case STRING:
            {
                Boolean multiline = component.getMultiline();
                TextOption[] options = multiline != null && multiline ? new TextOption[] { TextOption.MULTILINE } : null;
                item = new TextEdit(dialog, options) {

                    protected void onChange() {
                        AdmComponentProxy.this.onChange(true);
                    }
                };
            }
            break;
        case TEXT:
            {
                item = new TextPane(dialog);
                // Space a bit more to the top, to compensate the descender space.
                item.setMargin(new Border(1, 0, 0, 0));
            }
            break;
        case RULER:
            {
                // If the ruler has a label, add it to the left of it, using an
                // ItemGroup and a TableLayout. The ItemGroup needs to be created
                // before the frame, otherwise layouting issues arise...
                // Ideally this should be resolved, but as ADM is on its way out,
                // just work around it for now.
                ItemGroup group;
                String label = component.getLabel();
                if (label != null && !label.equals("")) {
                    group = new ItemGroup(dialog);
                    TextPane labelItem = new TextPane(dialog);
                    labelItem.setText(label);
                    // Use 3 rows, so the center one with the ruler gets centered,
                    // then span the label across all three.
                    double[][] sizes = { new double[] { TableLayout.PREFERRED, TableLayout.FILL }, new double[] { TableLayout.FILL, TableLayout.PREFERRED, TableLayout.FILL } };
                    group.setLayout(new TableLayout(sizes));
                    group.add(labelItem, "0, 0, 0, 2");
                    group.setMarginTop(2);
                } else {
                    group = null;
                }
                Frame frame = new Frame(dialog);
                frame.setStyle(FrameStyle.SUNKEN);
                // Margin needs to be set before changing size...
                // TODO: Fix this in UI package?
                int top = label != null ? 2 : 4, bottom = 4;
                frame.setMargin(top, 0, bottom, 0);
                // Margin is included inside size, not added. This is different
                // to how things works with CSS...
                // TODO: Fix this in UI package?
                frame.setHeight(2 + top + bottom);
                // Now finish setting up the layout group and label
                if (group != null) {
                    group.add(frame, "1, 1, full, center");
                    item = group;
                } else {
                    item = frame;
                }
            }
            break;
        case SLIDER:
            {
                item = new Slider(dialog) {

                    protected void onChange() {
                        AdmComponentProxy.this.onChange(true);
                    }
                };
            }
            break;
        case BOOLEAN:
            {
                item = new CheckBox(dialog) {

                    protected void onClick() {
                        AdmComponentProxy.this.onChange(true);
                    }
                };
            }
            break;
        case LIST:
            {
                item = new PopupList(dialog, true) {

                    protected void onChange() {
                        selectedIndex = this.getSelectedEntry().getIndex();
                        AdmComponentProxy.this.onChange(true);
                    }
                };
            }
            break;
        case BUTTON:
            {
                item = new Button(dialog) {

                    protected void onClick() {
                        AdmComponentProxy.this.onClick();
                    }
                };
            }
            break;
        case COLOR:
            {
                item = new ColorButton(dialog) {

                    protected void onClick() {
                        AdmComponentProxy.this.onChange(true);
                    }
                };
            }
            break;
        case FONT:
            {
                item = new FontPopupList(dialog, new FontPopupListOption[] { FontPopupListOption.EDITABLE, FontPopupListOption.VERTICAL }) {

                    protected void onChange() {
                        AdmComponentProxy.this.onChange(true);
                    }
                };
            }
            break;
        case MENU_ENTRY:
        case MENU_SEPARATOR:
            {
                PopupMenu menu = dialog.getPopupMenu();
                if (menu != null) {
                    entry = new ListEntry(menu) {

                        protected void onSelect() {
                            AdmComponentProxy.this.onSelect();
                        }
                    };
                    if (type == ComponentType.MENU_SEPARATOR)
                        entry.setSeparator(true);
                }
            }
            break;
    }
    initialize();
    return item;
}
Also used : FontPopupList(com.scriptographer.adm.FontPopupList) ComponentType(com.scriptographer.ui.ComponentType) Frame(com.scriptographer.adm.Frame) Slider(com.scriptographer.adm.Slider) TextOption(com.scriptographer.adm.TextOption) TextEditItem(com.scriptographer.adm.TextEditItem) TextPane(com.scriptographer.adm.TextPane) ItemGroup(com.scriptographer.adm.ItemGroup) ColorButton(com.scriptographer.adm.ColorButton) ColorButton(com.scriptographer.adm.ColorButton) Button(com.scriptographer.adm.Button) TextEdit(com.scriptographer.adm.TextEdit) CheckBox(com.scriptographer.adm.CheckBox) SpinEdit(com.scriptographer.adm.SpinEdit) Border(com.scriptographer.adm.Border) TableLayout(com.scriptographer.adm.layout.TableLayout) PopupList(com.scriptographer.adm.PopupList) FontPopupList(com.scriptographer.adm.FontPopupList) PopupMenu(com.scriptographer.adm.PopupMenu) ListEntry(com.scriptographer.adm.ListEntry)

Example 2 with ItemGroup

use of com.scriptographer.adm.ItemGroup in project scriptographer by scriptographer.

the class AdmComponentProxy method addToContent.

protected int addToContent(Dialog dialog, LinkedHashMap<String, com.scriptographer.adm.Component> content, int column, int row) {
    Item valueItem = createItem(dialog);
    String label = component.getLabel();
    boolean isRuler = component.getType() == ComponentType.RULER;
    boolean hasLabel = !isRuler && label != null && !"".equals(label);
    if (hasLabel) {
        TextPane labelItem = new TextPane(dialog);
        labelItem.setText(label + ":");
        // Adjust top margin of label to reflect the native margin
        // in the value item.
        Item marginItem = valueItem;
        // This is only needed for FontPopupList so far.
        if (marginItem instanceof ItemGroup)
            marginItem = (Item) ((ItemGroup) marginItem).getContent().get(0);
        Border margin = marginItem.getVisualMargin();
        // Also take into account any margins the component might have set
        if (valueItem != marginItem)
            margin = margin.add(valueItem.getMargin());
        labelItem.setMargin(margin.top + 3, 4, 0, 0);
        content.put(column + ", " + row + ", right, top", labelItem);
    }
    boolean fullSize = component.getFullSize();
    String justification = isRuler || component.getFullSize() ? "full, center" : "left, center";
    content.put(isRuler || !hasLabel && fullSize ? column + ", " + row + ", " + (column + 1) + ", " + row + ", " + justification : (column + 1) + ", " + row + ", " + justification, valueItem);
    return row + 1;
}
Also used : TextValueItem(com.scriptographer.adm.TextValueItem) ValueItem(com.scriptographer.adm.ValueItem) Item(com.scriptographer.adm.Item) ToggleItem(com.scriptographer.adm.ToggleItem) TextEditItem(com.scriptographer.adm.TextEditItem) TextPane(com.scriptographer.adm.TextPane) ItemGroup(com.scriptographer.adm.ItemGroup) Border(com.scriptographer.adm.Border)

Aggregations

Border (com.scriptographer.adm.Border)2 ItemGroup (com.scriptographer.adm.ItemGroup)2 TextEditItem (com.scriptographer.adm.TextEditItem)2 TextPane (com.scriptographer.adm.TextPane)2 Button (com.scriptographer.adm.Button)1 CheckBox (com.scriptographer.adm.CheckBox)1 ColorButton (com.scriptographer.adm.ColorButton)1 FontPopupList (com.scriptographer.adm.FontPopupList)1 Frame (com.scriptographer.adm.Frame)1 Item (com.scriptographer.adm.Item)1 ListEntry (com.scriptographer.adm.ListEntry)1 PopupList (com.scriptographer.adm.PopupList)1 PopupMenu (com.scriptographer.adm.PopupMenu)1 Slider (com.scriptographer.adm.Slider)1 SpinEdit (com.scriptographer.adm.SpinEdit)1 TextEdit (com.scriptographer.adm.TextEdit)1 TextOption (com.scriptographer.adm.TextOption)1 TextValueItem (com.scriptographer.adm.TextValueItem)1 ToggleItem (com.scriptographer.adm.ToggleItem)1 ValueItem (com.scriptographer.adm.ValueItem)1