/** Opens editing dialog. */ private void openDialog(Property property) throws Exception { // set initial color { Object value = property.getValue(); if (value instanceof String) { RGB rgb = ColorDialog.getRGB((String) value); if (rgb != null) { m_colorDialog.setColorInfo(new ColorInfo(null, rgb)); } } } // open dialog if (m_colorDialog.open() == Window.OK) { ColorInfo colorInfo = m_colorDialog.getColorInfo(); String colorString = getColorString(colorInfo); property.setValue(colorString); } }
@Override public void paint(Property property, GC gc, int x, int y, int width, int height) throws Exception { String text = getText(property); if (text != null) { // draw color sample { RGB rgb = ColorDialog.getRGB(text); if (rgb != null) { Color swtColor = new Color(null, rgb); // Color oldBackground = gc.getBackground(); Color oldForeground = gc.getForeground(); try { int width_c = SAMPLE_SIZE; int height_c = SAMPLE_SIZE; int x_c = x; int y_c = y + (height - height_c) / 2; // update rest bounds { int delta = SAMPLE_SIZE + SAMPLE_MARGIN; x += delta; width -= delta; } // fill { gc.setBackground(swtColor); gc.fillRectangle(x_c, y_c, width_c, height_c); } // draw line gc.setForeground(IColorConstants.gray); gc.drawRectangle(x_c, y_c, width_c, height_c); } finally { gc.setBackground(oldBackground); gc.setForeground(oldForeground); swtColor.dispose(); } } } // draw color text DrawUtils.drawStringCV(gc, text, x, y, width, height); } }
ColorPropertyEditor() { super(ColorDialog.getColorNames()); }