XkcdColorPicker.java 文件源码

java
阅读 53 收藏 0 点赞 0 评论 0

项目:rxjava-and-swt 作者:
public XkcdColorPicker(Composite parent, RGB initRGB) {
    super(new Composite(parent, SWT.NONE));
    RGB initYCbCr = ColorPicker.toYCbCr(initRGB);

    // create a scale and bind it to an RxBox<Integer>
    RxBox<Integer> luminance = RxBox.of(initYCbCr.red);

    // colorpanel in the center
    ColorPicker cbcrPanel = new ColorPicker(wrapped);
    Rx.subscribe(luminance, cbcrPanel::setY);

    // controls at the right
    Composite rightCmp = new Composite(wrapped, SWT.NONE);

    // scale below
    Scale scale = new Scale(wrapped, SWT.HORIZONTAL);
    scale.setMinimum(0);
    scale.setMaximum(255);
    Rx.subscribe(luminance, scale::setSelection);
    scale.addListener(SWT.Selection, e -> {
        luminance.set(scale.getSelection());
    });

    Layouts.setGrid(wrapped).numColumns(2);
    Layouts.setGridData(cbcrPanel).grabAll();
    Layouts.setGridData(rightCmp).grabVertical().verticalSpan(2);
    Layouts.setGridData(scale).grabHorizontal();

    // populate the bottom
    Layouts.setGrid(rightCmp).margin(0);
    XkcdColors.Lookup xkcdLookup = new XkcdColors.Lookup(rightCmp);

    Group hoverGrp = new Group(rightCmp, SWT.SHADOW_ETCHED_IN);
    hoverGrp.setText("Hover");
    createGroup(hoverGrp, cbcrPanel.rxMouseMove(), xkcdLookup);

    Group clickGrp = new Group(rightCmp, SWT.SHADOW_ETCHED_IN);
    clickGrp.setText("Click");
    createGroup(clickGrp, cbcrPanel.rxMouseDown(), xkcdLookup);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号