Search in sources :

Example 1 with ColorDialog

use of org.eclipse.swt.widgets.ColorDialog in project tdi-studio-se by Talend.

the class ColorController method createCommand.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties2.editors.AbstractElementPropertySectionController#createCommand()
     */
private Command createCommand(SelectionEvent event) {
    Control ctrl = (Control) event.getSource();
    if (ctrl instanceof Button) {
        String paramName = (String) ctrl.getData(PARAMETER_NAME);
        if (paramName != null) {
            ColorDialog colorDialog = new ColorDialog(ctrl.getShell());
            colorDialog.setRGB(ColorUtils.parseStringToRGB((String) elem.getPropertyValue(paramName)));
            RGB rgb = colorDialog.open();
            if (rgb != null) {
                setButtonColor((Button) ctrl, rgb);
                Command cmd;
                cmd = new PropertyChangeCommand(elem, paramName, ColorUtils.getRGBValue(rgb));
                return cmd;
            }
        }
    }
    return null;
}
Also used : Control(org.eclipse.swt.widgets.Control) ColorDialog(org.eclipse.swt.widgets.ColorDialog) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) Button(org.eclipse.swt.widgets.Button) Command(org.eclipse.gef.commands.Command) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) RGB(org.eclipse.swt.graphics.RGB)

Example 2 with ColorDialog

use of org.eclipse.swt.widgets.ColorDialog in project eclipse.platform.swt by eclipse.

the class DialogTab method createButtonSelected.

/**
 * Handle the create button selection event.
 *
 * @param event org.eclipse.swt.events.SelectionEvent
 */
void createButtonSelected(SelectionEvent event) {
    /* Compute the appropriate dialog style */
    int style = getDefaultStyle();
    if (okButton.getEnabled() && okButton.getSelection())
        style |= SWT.OK;
    if (cancelButton.getEnabled() && cancelButton.getSelection())
        style |= SWT.CANCEL;
    if (yesButton.getEnabled() && yesButton.getSelection())
        style |= SWT.YES;
    if (noButton.getEnabled() && noButton.getSelection())
        style |= SWT.NO;
    if (retryButton.getEnabled() && retryButton.getSelection())
        style |= SWT.RETRY;
    if (abortButton.getEnabled() && abortButton.getSelection())
        style |= SWT.ABORT;
    if (ignoreButton.getEnabled() && ignoreButton.getSelection())
        style |= SWT.IGNORE;
    if (iconErrorButton.getEnabled() && iconErrorButton.getSelection())
        style |= SWT.ICON_ERROR;
    if (iconInformationButton.getEnabled() && iconInformationButton.getSelection())
        style |= SWT.ICON_INFORMATION;
    if (iconQuestionButton.getEnabled() && iconQuestionButton.getSelection())
        style |= SWT.ICON_QUESTION;
    if (iconWarningButton.getEnabled() && iconWarningButton.getSelection())
        style |= SWT.ICON_WARNING;
    if (iconWorkingButton.getEnabled() && iconWorkingButton.getSelection())
        style |= SWT.ICON_WORKING;
    if (primaryModalButton.getEnabled() && primaryModalButton.getSelection())
        style |= SWT.PRIMARY_MODAL;
    if (applicationModalButton.getEnabled() && applicationModalButton.getSelection())
        style |= SWT.APPLICATION_MODAL;
    if (systemModalButton.getEnabled() && systemModalButton.getSelection())
        style |= SWT.SYSTEM_MODAL;
    if (sheetButton.getSelection())
        style |= SWT.SHEET;
    if (saveButton.getEnabled() && saveButton.getSelection())
        style |= SWT.SAVE;
    if (openButton.getEnabled() && openButton.getSelection())
        style |= SWT.OPEN;
    if (multiButton.getEnabled() && multiButton.getSelection())
        style |= SWT.MULTI;
    /* Open the appropriate dialog type */
    String name = dialogCombo.getText();
    if (name.equals(ControlExample.getResourceString("ColorDialog"))) {
        ColorDialog dialog = new ColorDialog(shell, style);
        if (usePreviousResultButton.getSelection()) {
            dialog.setRGB(colorDialogResult);
            dialog.setRGBs(colorDialogCustomColors);
        }
        dialog.setText(ControlExample.getResourceString("Title"));
        RGB result = dialog.open();
        textWidget.append(ControlExample.getResourceString("ColorDialog") + Text.DELIMITER);
        textWidget.append(ControlExample.getResourceString("Result", "" + result) + Text.DELIMITER);
        textWidget.append("getRGB() = " + dialog.getRGB() + Text.DELIMITER);
        textWidget.append("getRGBs() =" + Text.DELIMITER);
        RGB[] rgbs = dialog.getRGBs();
        if (rgbs != null) {
            for (RGB rgbColor : rgbs) {
                textWidget.append("\t" + rgbColor + Text.DELIMITER);
            }
        }
        textWidget.append(Text.DELIMITER);
        colorDialogResult = result;
        colorDialogCustomColors = rgbs;
        return;
    }
    if (name.equals(ControlExample.getResourceString("DirectoryDialog"))) {
        DirectoryDialog dialog = new DirectoryDialog(shell, style);
        if (usePreviousResultButton.getSelection()) {
            dialog.setFilterPath(directoryDialogResult);
        }
        dialog.setMessage(ControlExample.getResourceString("Example_string"));
        dialog.setText(ControlExample.getResourceString("Title"));
        String result = dialog.open();
        textWidget.append(ControlExample.getResourceString("DirectoryDialog") + Text.DELIMITER);
        textWidget.append(ControlExample.getResourceString("Result", "" + result) + Text.DELIMITER + Text.DELIMITER);
        directoryDialogResult = result;
        return;
    }
    if (name.equals(ControlExample.getResourceString("FileDialog"))) {
        FileDialog dialog = new FileDialog(shell, style);
        if (usePreviousResultButton.getSelection()) {
            dialog.setFileName(fileDialogResult);
            dialog.setFilterIndex(fileDialogIndexResult);
        }
        dialog.setFilterNames(FilterNames);
        dialog.setFilterExtensions(FilterExtensions);
        dialog.setText(ControlExample.getResourceString("Title"));
        String result = dialog.open();
        textWidget.append(ControlExample.getResourceString("FileDialog") + Text.DELIMITER);
        textWidget.append(ControlExample.getResourceString("Result", "" + result) + Text.DELIMITER);
        textWidget.append("getFilterIndex() =" + dialog.getFilterIndex() + Text.DELIMITER);
        textWidget.append("getFilterPath() =" + dialog.getFilterPath() + Text.DELIMITER);
        textWidget.append("getFileName() =" + dialog.getFileName() + Text.DELIMITER);
        textWidget.append("getFileNames() =" + Text.DELIMITER);
        String[] files = dialog.getFileNames();
        for (String file : files) {
            textWidget.append("\t" + file + Text.DELIMITER);
        }
        textWidget.append(Text.DELIMITER);
        fileDialogResult = result;
        fileDialogIndexResult = dialog.getFilterIndex();
        return;
    }
    if (name.equals(ControlExample.getResourceString("FontDialog"))) {
        FontDialog dialog = new FontDialog(shell, style);
        if (usePreviousResultButton.getSelection()) {
            dialog.setFontList(fontDialogFontListResult);
            dialog.setRGB(fontDialogColorResult);
        }
        dialog.setEffectsVisible(effectsVisibleButton.getSelection());
        dialog.setText(ControlExample.getResourceString("Title"));
        FontData result = dialog.open();
        textWidget.append(ControlExample.getResourceString("FontDialog") + Text.DELIMITER);
        textWidget.append(ControlExample.getResourceString("Result", "" + result) + Text.DELIMITER);
        textWidget.append("getFontList() =" + Text.DELIMITER);
        FontData[] fonts = dialog.getFontList();
        if (fonts != null) {
            for (FontData font : fonts) {
                textWidget.append("\t" + font + Text.DELIMITER);
            }
        }
        textWidget.append("getEffectsVisible() = " + dialog.getEffectsVisible() + Text.DELIMITER);
        textWidget.append("getRGB() = " + dialog.getRGB() + Text.DELIMITER + Text.DELIMITER);
        fontDialogFontListResult = dialog.getFontList();
        fontDialogColorResult = dialog.getRGB();
        return;
    }
    if (name.equals(ControlExample.getResourceString("PrintDialog"))) {
        PrintDialog dialog = new PrintDialog(shell, style);
        if (usePreviousResultButton.getSelection()) {
            dialog.setPrinterData(printDialogResult);
        }
        dialog.setText(ControlExample.getResourceString("Title"));
        PrinterData result = dialog.open();
        textWidget.append(ControlExample.getResourceString("PrintDialog") + Text.DELIMITER);
        textWidget.append(ControlExample.getResourceString("Result", "" + result) + Text.DELIMITER);
        if (result != null) {
            textWidget.append("printerData.scope = " + (result.scope == PrinterData.PAGE_RANGE ? "PAGE_RANGE" : result.scope == PrinterData.SELECTION ? "SELECTION" : "ALL_PAGES") + Text.DELIMITER);
            textWidget.append("printerData.startPage = " + result.startPage + Text.DELIMITER);
            textWidget.append("printerData.endPage = " + result.endPage + Text.DELIMITER);
            textWidget.append("printerData.printToFile = " + result.printToFile + Text.DELIMITER);
            textWidget.append("printerData.fileName = " + result.fileName + Text.DELIMITER);
            textWidget.append("printerData.orientation = " + (result.orientation == PrinterData.LANDSCAPE ? "LANDSCAPE" : "PORTRAIT") + Text.DELIMITER);
            textWidget.append("printerData.copyCount = " + result.copyCount + Text.DELIMITER);
            textWidget.append("printerData.collate = " + result.collate + Text.DELIMITER);
            textWidget.append("printerData.duplex = " + (result.duplex == PrinterData.DUPLEX_LONG_EDGE ? "DUPLEX_LONG_EDGE" : result.duplex == PrinterData.DUPLEX_SHORT_EDGE ? "DUPLEX_SHORT_EDGE" : "NONE") + Text.DELIMITER);
        }
        textWidget.append(Text.DELIMITER);
        printDialogResult = result;
        return;
    }
    if (name.equals(ControlExample.getResourceString("MessageBox"))) {
        MessageBox dialog = new MessageBox(shell, style);
        dialog.setMessage(ControlExample.getResourceString("Example_string"));
        dialog.setText(ControlExample.getResourceString("Title"));
        int result = dialog.open();
        textWidget.append(ControlExample.getResourceString("MessageBox") + Text.DELIMITER);
        /*
			 * The resulting integer depends on the original
			 * dialog style.  Decode the result and display it.
			 */
        switch(result) {
            case SWT.OK:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.OK"));
                break;
            case SWT.YES:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.YES"));
                break;
            case SWT.NO:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.NO"));
                break;
            case SWT.CANCEL:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.CANCEL"));
                break;
            case SWT.ABORT:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.ABORT"));
                break;
            case SWT.RETRY:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.RETRY"));
                break;
            case SWT.IGNORE:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.IGNORE"));
                break;
            default:
                textWidget.append(ControlExample.getResourceString("Result", "" + result));
                break;
        }
        textWidget.append(Text.DELIMITER + Text.DELIMITER);
    }
}
Also used : FontDialog(org.eclipse.swt.widgets.FontDialog) PrintDialog(org.eclipse.swt.printing.PrintDialog) FontData(org.eclipse.swt.graphics.FontData) RGB(org.eclipse.swt.graphics.RGB) MessageBox(org.eclipse.swt.widgets.MessageBox) ColorDialog(org.eclipse.swt.widgets.ColorDialog) PrinterData(org.eclipse.swt.printing.PrinterData) FileDialog(org.eclipse.swt.widgets.FileDialog) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Example 3 with ColorDialog

use of org.eclipse.swt.widgets.ColorDialog in project eclipse.platform.swt by eclipse.

the class Tab method createColorAndFontGroup.

/**
 * Creates the "Colors and Fonts" group. This is typically
 * a child of the "Control" group. Subclasses override
 * this method to customize color and font settings.
 */
void createColorAndFontGroup() {
    /* Create the group. */
    colorGroup = new Group(controlGroup, SWT.NONE);
    colorGroup.setLayout(new GridLayout(2, true));
    colorGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    colorGroup.setText(ControlExample.getResourceString("Colors"));
    colorAndFontTable = new Table(colorGroup, SWT.BORDER | SWT.V_SCROLL);
    colorAndFontTable.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1));
    TableItem item = new TableItem(colorAndFontTable, SWT.None);
    item.setText(ControlExample.getResourceString("Foreground_Color"));
    colorAndFontTable.setSelection(0);
    item = new TableItem(colorAndFontTable, SWT.None);
    item.setText(ControlExample.getResourceString("Background_Color"));
    item = new TableItem(colorAndFontTable, SWT.None);
    item.setText(ControlExample.getResourceString("Font"));
    Button changeButton = new Button(colorGroup, SWT.PUSH);
    changeButton.setText(ControlExample.getResourceString("Change"));
    changeButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    Button defaultsButton = new Button(colorGroup, SWT.PUSH);
    defaultsButton.setText(ControlExample.getResourceString("Defaults"));
    defaultsButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    /* Add listeners to set/reset colors and fonts. */
    colorDialog = new ColorDialog(shell);
    fontDialog = new FontDialog(shell);
    colorAndFontTable.addSelectionListener(widgetDefaultSelectedAdapter(event -> changeFontOrColor(colorAndFontTable.getSelectionIndex())));
    changeButton.addSelectionListener(widgetSelectedAdapter(event -> changeFontOrColor(colorAndFontTable.getSelectionIndex())));
    defaultsButton.addSelectionListener(widgetSelectedAdapter(e -> resetColorsAndFonts()));
    shell.addDisposeListener(event -> {
        if (foregroundColor != null)
            foregroundColor.dispose();
        if (backgroundColor != null)
            backgroundColor.dispose();
        if (font != null)
            font.dispose();
        foregroundColor = null;
        backgroundColor = null;
        font = null;
        if (colorAndFontTable != null && !colorAndFontTable.isDisposed()) {
            TableItem[] items = colorAndFontTable.getItems();
            for (TableItem currentItem : items) {
                Image image = currentItem.getImage();
                if (image != null)
                    image.dispose();
            }
        }
    });
}
Also used : DisposeEvent(org.eclipse.swt.events.DisposeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) TypedEvent(org.eclipse.swt.events.TypedEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) ColorDialog(org.eclipse.swt.widgets.ColorDialog) MenuEvent(org.eclipse.swt.events.MenuEvent) Composite(org.eclipse.swt.widgets.Composite) KeyEvent(org.eclipse.swt.events.KeyEvent) Widget(org.eclipse.swt.widgets.Widget) Method(java.lang.reflect.Method) KeyAdapter(org.eclipse.swt.events.KeyAdapter) SelectionListener.widgetDefaultSelectedAdapter(org.eclipse.swt.events.SelectionListener.widgetDefaultSelectedAdapter) TraverseEvent(org.eclipse.swt.events.TraverseEvent) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) ArmEvent(org.eclipse.swt.events.ArmEvent) Display(org.eclipse.swt.widgets.Display) MouseEvent(org.eclipse.swt.events.MouseEvent) Item(org.eclipse.swt.widgets.Item) MenuItem(org.eclipse.swt.widgets.MenuItem) SWT(org.eclipse.swt.SWT) Label(org.eclipse.swt.widgets.Label) SelectionListener(org.eclipse.swt.events.SelectionListener) TabFolder(org.eclipse.swt.widgets.TabFolder) Image(org.eclipse.swt.graphics.Image) Rectangle(org.eclipse.swt.graphics.Rectangle) Table(org.eclipse.swt.widgets.Table) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) SelectionListener.widgetSelectedAdapter(org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter) VerifyEvent(org.eclipse.swt.events.VerifyEvent) Listener(org.eclipse.swt.widgets.Listener) RGB(org.eclipse.swt.graphics.RGB) TreeEvent(org.eclipse.swt.events.TreeEvent) Font(org.eclipse.swt.graphics.Font) GridData(org.eclipse.swt.layout.GridData) TableItem(org.eclipse.swt.widgets.TableItem) Combo(org.eclipse.swt.widgets.Combo) Shell(org.eclipse.swt.widgets.Shell) ShellEvent(org.eclipse.swt.events.ShellEvent) HelpEvent(org.eclipse.swt.events.HelpEvent) FontDialog(org.eclipse.swt.widgets.FontDialog) Group(org.eclipse.swt.widgets.Group) Color(org.eclipse.swt.graphics.Color) FontData(org.eclipse.swt.graphics.FontData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) Control(org.eclipse.swt.widgets.Control) GridLayout(org.eclipse.swt.layout.GridLayout) Group(org.eclipse.swt.widgets.Group) GridLayout(org.eclipse.swt.layout.GridLayout) ColorDialog(org.eclipse.swt.widgets.ColorDialog) Table(org.eclipse.swt.widgets.Table) FontDialog(org.eclipse.swt.widgets.FontDialog) Button(org.eclipse.swt.widgets.Button) TableItem(org.eclipse.swt.widgets.TableItem) GridData(org.eclipse.swt.layout.GridData) Image(org.eclipse.swt.graphics.Image)

Example 4 with ColorDialog

use of org.eclipse.swt.widgets.ColorDialog in project archi by archimatetool.

the class FillColorAction method run.

@Override
public void run() {
    List<?> selection = getSelectedObjects();
    IDiagramModelObject model = (IDiagramModelObject) getFirstValidSelectedModelObject(selection);
    if (model == null) {
        return;
    }
    ColorDialog colorDialog = new ColorDialog(getWorkbenchPart().getSite().getShell());
    // Set default RGB on first selected object
    RGB defaultRGB = null;
    String s = model.getFillColor();
    if (s == null) {
        defaultRGB = ColorFactory.getDefaultFillColor(model).getRGB();
    } else {
        defaultRGB = ColorFactory.convertStringToRGB(s);
    }
    if (defaultRGB != null) {
        colorDialog.setRGB(defaultRGB);
    }
    RGB newColor = colorDialog.open();
    if (newColor != null) {
        execute(createCommand(selection, newColor));
    }
}
Also used : ColorDialog(org.eclipse.swt.widgets.ColorDialog) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) RGB(org.eclipse.swt.graphics.RGB)

Example 5 with ColorDialog

use of org.eclipse.swt.widgets.ColorDialog in project archi by archimatetool.

the class ColorChooser method chooseColor.

/**
 * Activate the editor for this selector. This causes the color selection
 * dialog to appear and wait for user input.
 */
public void chooseColor() {
    ColorDialog colorDialog = new ColorDialog(fColorButton.getShell());
    colorDialog.setRGB(fColorValue);
    RGB newColor = colorDialog.open();
    if (newColor != null) {
        RGB oldValue = fColorValue;
        fColorValue = newColor;
        fireActionListenerEvent(PROP_COLORCHANGE, oldValue, newColor);
        updateColorImage();
    }
}
Also used : ColorDialog(org.eclipse.swt.widgets.ColorDialog) RGB(org.eclipse.swt.graphics.RGB)

Aggregations

ColorDialog (org.eclipse.swt.widgets.ColorDialog)31 RGB (org.eclipse.swt.graphics.RGB)27 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