Search in sources :

Example 1 with ValueItem

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

the class AdmComponentProxy method getValue.

public Object getValue() {
    if (item == null)
        return component.getDefaultValue();
    switch(component.getType()) {
        case STRING:
        case TEXT:
            return ((TextValueItem) item).getText();
        case BUTTON:
            return ((Button) item).getText();
        case NUMBER:
            return ((ValueItem) item).getValue();
        case SLIDER:
            double value = ((ValueItem) item).getValue() / factor;
            Double inc = component.getIncrement();
            if (inc != null) {
                double pre = value;
                value = Math.round(value / inc) * inc;
                if (pre != value)
                    ((ValueItem) item).setValue((float) (value * factor));
            }
            return value;
        case BOOLEAN:
            return ((ToggleItem) item).isChecked();
        case LIST:
            ListEntry selected = ((PopupList) item).getSelectedEntry();
            if (selected != null)
                return component.getOption(selected.getIndex());
            break;
        case COLOR:
            return ((ColorButton) item).getColor();
        case FONT:
            return ((FontPopupList) item).getFontWeight();
    }
    return null;
}
Also used : FontPopupList(com.scriptographer.adm.FontPopupList) ColorButton(com.scriptographer.adm.ColorButton) ColorButton(com.scriptographer.adm.ColorButton) Button(com.scriptographer.adm.Button) ToggleItem(com.scriptographer.adm.ToggleItem) TextValueItem(com.scriptographer.adm.TextValueItem) ValueItem(com.scriptographer.adm.ValueItem) PopupList(com.scriptographer.adm.PopupList) FontPopupList(com.scriptographer.adm.FontPopupList) TextValueItem(com.scriptographer.adm.TextValueItem) ListEntry(com.scriptographer.adm.ListEntry)

Example 2 with ValueItem

use of com.scriptographer.adm.ValueItem 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

TextValueItem (com.scriptographer.adm.TextValueItem)2 ToggleItem (com.scriptographer.adm.ToggleItem)2 ValueItem (com.scriptographer.adm.ValueItem)2 Border (com.scriptographer.adm.Border)1 Button (com.scriptographer.adm.Button)1 ColorButton (com.scriptographer.adm.ColorButton)1 FontPopupList (com.scriptographer.adm.FontPopupList)1 Item (com.scriptographer.adm.Item)1 ItemGroup (com.scriptographer.adm.ItemGroup)1 ListEntry (com.scriptographer.adm.ListEntry)1 PopupList (com.scriptographer.adm.PopupList)1 TextEditItem (com.scriptographer.adm.TextEditItem)1 TextPane (com.scriptographer.adm.TextPane)1