Search in sources :

Example 1 with NumberRange

use of org.polymap.core.style.model.feature.NumberRange in project polymap4-core by Polymap4.

the class ConstantNumberEditor method createContents.

@Override
public Composite createContents(Composite parent) {
    Composite contents = super.createContents(parent);
    Spinner s = new Spinner(contents, SWT.BORDER);
    NumberRange nd = (NumberRange) prop.info().getAnnotation(NumberRange.class);
    if (nd != null) {
        int digits = nd.digits();
        double currentValue = (double) prop.get().constantNumber.get();
        double factorX = Math.pow(10, digits);
        s.setDigits(digits);
        s.setMinimum((int) (nd.from() * factorX));
        s.setMaximum((int) (nd.to() * factorX));
        s.setIncrement((int) (nd.increment() * factorX));
        s.setPageIncrement((int) (nd.increment() * factorX * 10));
        s.setSelection((int) (currentValue * factorX));
    }
    s.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            int selection = s.getSelection();
            int digits = s.getDigits();
            prop.get().constantNumber.set(selection / Math.pow(10, digits));
        }
    });
    return contents;
}
Also used : NumberRange(org.polymap.core.style.model.feature.NumberRange) Composite(org.eclipse.swt.widgets.Composite) Spinner(org.eclipse.swt.widgets.Spinner) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Aggregations

SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Composite (org.eclipse.swt.widgets.Composite)1 Spinner (org.eclipse.swt.widgets.Spinner)1 NumberRange (org.polymap.core.style.model.feature.NumberRange)1