public ColorPickerField(iColorFactory colorFactory) { this.colorFactory = colorFactory; this.colorPicker = new ColorPicker(); this.colorPicker.addColorChangeListener(new ColorChangeListener() { private static final long serialVersionUID = 1L; @Override public void colorChanged(ColorChangeEvent event) { setValue(ColorPickerField.this.colorFactory.createColor(event.getColor())); } }); }
/** * Constructeur, initialisation du champs */ public RequiredColorPickerField(String caption) { super(); layout = new HorizontalLayout(); layout.setWidth(100, Unit.PERCENTAGE); layout.setSpacing(true); colorTextField = new TextField(); colorTextField.addValueChangeListener(e->showOrHideError()); colorTextField.setNullRepresentation(""); colorTextField.addStyleName(ValoTheme.TEXTFIELD_BORDERLESS); colorTextField.setReadOnly(true); btnColor = new ColorPicker("Couleur de l'alerte"); btnColor.addColorChangeListener(e->{ changeFieldValue(e.getColor().getCSS()); }); btnColor.setPosition(Page.getCurrent().getBrowserWindowWidth() / 2 - 246/2, Page.getCurrent().getBrowserWindowHeight() / 2 - 507/2); btnColor.setSwatchesVisibility(true); btnColor.setHistoryVisibility(false); btnColor.setTextfieldVisibility(true); btnColor.setHSVVisibility(false); layout.addComponent(btnColor); layout.addComponent(colorTextField); layout.setExpandRatio(colorTextField, 1); }
public ChartColorLayout(BeanFieldGroup<DiagrammePreference> preferences) { super(preferences); colorTable.setSizeFull(); colorTable.addStyleName("compact"); colorTable.addStyleName("small"); colorTable.addStyleName("color-table"); setSpacing(true); addComponent(colorTable); colorTable.setWidth("100%"); colorTable.setEditable(false); colorTable.addContainerProperty(Translate.getMessage("identity"), String.class, null); colorTable.addContainerProperty(Translate.getMessage("colour"), ColorPicker.class, null); colorTable.setColumnWidth(Translate.getMessage("colour"), 58); colorTable.setSortEnabled(false); colorTable.setPageLength(9); // TODO dataset descriptor seems to be redundant String header = Translate.getMessage("identity"); String dataSetDescriptor = getPreferenceValue(DiagrammePreference.DATASET_DESCRIPTOR, preferences); if (dataSetDescriptor != null) { header = dataSetDescriptor.substring(0, dataSetDescriptor.indexOf("(java")); } colorTable.setColumnHeaders(header, Translate.getMessage("colour")); fillTable(); setComponentAlignment(colorTable, Alignment.MIDDLE_CENTER); }
private void fillTable() { colorTable.removeAllItems(); int rowIndex = 0; final Map<String, String> valueColourMap = getPreferenceValue(DiagrammePreference.VALUE_COLOUR_MAP, preferences); Iterator<Map.Entry<String, String>> it = valueColourMap.entrySet().iterator(); while (it.hasNext()) { final Map.Entry<String, String> entry = it.next(); int[] d = ColourUtil.decode(entry.getValue()); final Color c = new SolidColor(d[0], d[1], d[2]); ColorPicker picker = new ColorPicker(); picker.setColor(new com.vaadin.shared.ui.colorpicker.Color(ColourUtil.decode(c.toString())[0], ColourUtil.decode(c.toString())[1], ColourUtil.decode(c.toString())[2])); picker.setPosition(Page.getCurrent().getBrowserWindowWidth() / 2 - 246 / 2, Page.getCurrent().getBrowserWindowHeight() / 2 - 507 / 2); picker.addColorChangeListener(new ColorChangeListener() { @Override public void colorChanged(ColorChangeEvent event) { valueColourMap.put(entry.getKey(), event.getColor().getCSS()); preferences.getItemDataSource().getItemProperty(DiagrammePreference.VALUE_COLOUR_MAP).setValue(valueColourMap); // chartLayout.getConfigurationLayout().getLookAndFeelLayout().renderChart(); } }); colorTable.addItem(new Object[]{entry.getKey(), picker}, rowIndex); rowIndex++; } }
public ColorPickerField() { colorPicker = new ColorPicker(); colorPicker.addColorChangeListener(new ColorChangeListener() { @Override public void colorChanged(ColorChangeEvent event) { setColorToField(event.getColor().getRGB()); } }); colorPicker.setHistoryVisibility(false); }
/** * Adds the color picker section to dialog */ private void addColorPickers(StyleSettings styles) { final Panel p = new Panel(main.getUIText(StandardUIConstants.COLORS)); final Layout pL = new VerticalLayout(); p.setContent(pL); p.setStyleName("light"); final Color initColor = styles.getBackgroundColor().equals( "transparent") ? Color.WHITE : Util.colorFromHexString(styles .getBackgroundColor()); background = new ColorPicker( main.getUIText(StandardUIConstants.BACKGROUND), initColor); // this is probably redundant (and not supported) since 7 // background.setButtonCaption(main.getUIText(UIConstants.BACKGROUND)); transparentBG = new CheckBox( main.getUIText(StandardUIConstants.TRANSPARENT)); transparentBG.setImmediate(true); transparentBG.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = -3985282405650622452L; @Override public void valueChange(ValueChangeEvent event) { background.setEnabled(!transparentBG.getValue()); } }); transparentBG.setValue(styles.getBackgroundColor() .equals("transparent")); foreground = new ColorPicker(main.getUIText(StandardUIConstants.TEXT), Util.colorFromHexString(styles.getForegroundColor())); // foreground.setButtonCaption(main.getUIText(UIConstants.TEXT)); final HorizontalLayout hl = new HorizontalLayout(); hl.setSpacing(true); hl.setWidth("100%"); hl.addComponent(background); hl.addComponent(transparentBG); hl.setComponentAlignment(transparentBG, Alignment.BOTTOM_LEFT); final Label spacer = new Label(" "); hl.addComponent(spacer); hl.addComponent(foreground); hl.setComponentAlignment(foreground, new Alignment(Bits.ALIGNMENT_RIGHT)); hl.setExpandRatio(spacer, 1.0f); pL.addComponent(hl); addComponent(p); }