use of org.eclipse.swt.widgets.ColorDialog in project yamcs-studio by yamcs.
the class OPIColorDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
var parent_Composite = (Composite) super.createDialogArea(parent);
var mainComposite = new Composite(parent_Composite, SWT.None);
mainComposite.setLayout(new GridLayout(2, false));
var gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
gridData.heightHint = 300;
mainComposite.setLayoutData(gridData);
var leftComposite = new Composite(mainComposite, SWT.None);
leftComposite.setLayout(new GridLayout(1, false));
var gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.widthHint = 220;
leftComposite.setLayoutData(gd);
createLabel(leftComposite, "Choose from Predefined Colors:");
preDefinedColorsViewer = createPredefinedColorsTableViewer(leftComposite);
preDefinedColorsViewer.setInput(MediaService.getInstance().getAllPredefinedColors());
var rightComposite = new Composite(mainComposite, SWT.None);
rightComposite.setLayout(new GridLayout(1, false));
gd = new GridData(SWT.LEFT, SWT.BEGINNING, true, true);
rightComposite.setLayoutData(gd);
createLabel(rightComposite, "");
var colorDialogButton = new Button(rightComposite, SWT.PUSH);
colorDialogButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
colorDialogButton.setText("Choose from Color Dialog");
colorDialogButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
var dialog = new ColorDialog(Display.getCurrent().getActiveShell());
dialog.setRGB(opiColor.getRGBValue());
var rgb = dialog.open();
if (rgb != null) {
opiColor.setColorValue(rgb);
preDefinedColorsViewer.setSelection(null);
setRGBEditValue(rgb);
outputTextLabel.setText(opiColor.getColorName());
colorCanvas.setBackground(CustomMediaFactory.getInstance().getColor(opiColor.getRGBValue()));
}
}
});
createRGBEditGroup(rightComposite);
var group = new Group(rightComposite, SWT.None);
group.setLayoutData(new GridData(SWT.FILL, SWT.END, true, true));
group.setLayout(new GridLayout(3, false));
group.setText("Output");
colorCanvas = new Canvas(group, SWT.BORDER);
colorCanvas.setBackground(CustomMediaFactory.getInstance().getColor(opiColor.getRGBValue()));
gd = new GridData(SWT.LEFT, SWT.TOP, false, false);
gd.widthHint = 30;
gd.heightHint = 30;
colorCanvas.setLayoutData(gd);
outputTextLabel = new Label(group, SWT.None);
outputTextLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
outputTextLabel.setText(opiColor.getColorName());
if (opiColor.isPreDefined()) {
preDefinedColorsViewer.setSelection(new StructuredSelection(opiColor));
} else {
preDefinedColorsViewer.setSelection(null);
}
return parent_Composite;
}
use of org.eclipse.swt.widgets.ColorDialog in project dbeaver by dbeaver.
the class SetRowColorAction method run.
@Override
public void run() {
RGB color;
final Shell shell = UIUtils.createCenteredShell(resultSetViewer.getControl().getShell());
try {
ColorDialog cd = new ColorDialog(shell);
color = cd.open();
if (color == null) {
return;
}
} finally {
UIUtils.disposeCenteredShell(shell);
}
try {
final DBVEntity vEntity = getColorsVirtualEntity();
vEntity.setColorOverride(attribute, value, null, StringConverter.asString(color));
updateColors(vEntity);
} catch (IllegalStateException e) {
DBWorkbench.getPlatformUI().showError("Row color", "Can't set row color", e);
}
}
use of org.eclipse.swt.widgets.ColorDialog in project cogtool by cogtool.
the class DefaultInteraction method selectColor.
/**
* Open up a widget color wheel with the specified title.
* Should be platform specific.
* the specified integer should be in the following format.
* lowest order 8 bits red
* middle order 8 bits green
* highest order 8 bits blue
* ie: xxxxxxxx xxxxxxxx xxxxxxxx
* BLUE GREEN RED
*/
public Integer selectColor(int oldColor, String dialogTitle) {
RGB old = GraphicsUtil.getRGBFromColor(oldColor);
// Open the platform specific color chooser
ColorDialog dialog = new ColorDialog(window);
dialog.setRGB(old);
if (dialogTitle != null) {
dialog.setText(dialogTitle);
}
RGB newColor = dialog.open();
if (newColor != null) {
return new Integer(GraphicsUtil.getColorFromRGB(newColor));
}
return null;
}
use of org.eclipse.swt.widgets.ColorDialog in project dbeaver by dbeaver.
the class SetPartColorAction method createColorCommand.
private Command createColorCommand(final Object[] objects) {
return new Command() {
private final Map<IColorizedPart, Color> oldColors = new HashMap<>();
private Color newColor;
@Override
public void execute() {
final Shell shell = UIUtils.createCenteredShell(getWorkbenchPart().getSite().getShell());
try {
ColorDialog colorDialog = new ColorDialog(shell);
RGB color = colorDialog.open();
if (color == null) {
return;
}
newColor = new Color(Display.getCurrent(), color);
for (Object item : objects) {
if (item instanceof IColorizedPart) {
IColorizedPart colorizedPart = (IColorizedPart) item;
oldColors.put(colorizedPart, colorizedPart.getCustomBackgroundColor());
colorizedPart.customizeBackgroundColor(newColor);
}
}
} finally {
shell.dispose();
}
}
@Override
public void undo() {
for (Object item : objects) {
if (item instanceof IColorizedPart) {
IColorizedPart colorizedPart = (IColorizedPart) item;
colorizedPart.customizeBackgroundColor(oldColors.get(colorizedPart));
}
}
}
@Override
public void redo() {
for (Object item : objects) {
if (item instanceof IColorizedPart) {
IColorizedPart colorizedPart = (IColorizedPart) item;
colorizedPart.customizeBackgroundColor(newColor);
}
}
}
};
}
use of org.eclipse.swt.widgets.ColorDialog in project knime-core by knime.
the class StyledTextEditor method bgColor.
private void bgColor() {
ColorDialog colDlg = new ColorDialog(m_styledText.getShell());
RGB[] toSet = lastColors == null ? DEFAULT_COLORS : lastColors;
colDlg.setText("Change the Background Color");
colDlg.setRGBs(toSet);
if (m_backgroundColor != null) {
colDlg.setRGB(m_backgroundColor.getRGB());
}
RGB newBGCol = colDlg.open();
if (newBGCol == null) {
// user canceled
return;
}
lastColors = colDlg.getRGBs();
m_backgroundColor = new Color(null, newBGCol);
applyBackgroundColor();
}
Aggregations