Search in sources :

Example 11 with ColorDialog

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;
}
Also used : Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Canvas(org.eclipse.swt.widgets.Canvas) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) ColorDialog(org.eclipse.swt.widgets.ColorDialog) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 12 with ColorDialog

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);
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ColorDialog(org.eclipse.swt.widgets.ColorDialog) RGB(org.eclipse.swt.graphics.RGB) DBVEntity(org.jkiss.dbeaver.model.virtual.DBVEntity)

Example 13 with ColorDialog

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;
}
Also used : ColorDialog(org.eclipse.swt.widgets.ColorDialog) RGB(org.eclipse.swt.graphics.RGB)

Example 14 with ColorDialog

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);
                }
            }
        }
    };
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ColorDialog(org.eclipse.swt.widgets.ColorDialog) Command(org.eclipse.gef.commands.Command) Color(org.eclipse.swt.graphics.Color) RGB(org.eclipse.swt.graphics.RGB) HashMap(java.util.HashMap) Map(java.util.Map) IColorizedPart(org.jkiss.dbeaver.ext.erd.part.IColorizedPart)

Example 15 with ColorDialog

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();
}
Also used : ColorDialog(org.eclipse.swt.widgets.ColorDialog) Color(org.eclipse.swt.graphics.Color) RGB(org.eclipse.swt.graphics.RGB)

Aggregations

ColorDialog (org.eclipse.swt.widgets.ColorDialog)26 RGB (org.eclipse.swt.graphics.RGB)22 Button (org.eclipse.swt.widgets.Button)12 Composite (org.eclipse.swt.widgets.Composite)10 SelectionEvent (org.eclipse.swt.events.SelectionEvent)9 Color (org.eclipse.swt.graphics.Color)9 GridData (org.eclipse.swt.layout.GridData)9 GridLayout (org.eclipse.swt.layout.GridLayout)9 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)8 Label (org.eclipse.swt.widgets.Label)8 Shell (org.eclipse.swt.widgets.Shell)8 Text (org.eclipse.swt.widgets.Text)8 FontData (org.eclipse.swt.graphics.FontData)7 FontDialog (org.eclipse.swt.widgets.FontDialog)7 Combo (org.eclipse.swt.widgets.Combo)5 Command (org.eclipse.gef.commands.Command)4 FileDialog (org.eclipse.swt.widgets.FileDialog)4 Group (org.eclipse.swt.widgets.Group)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3