Search in sources :

Example 16 with ColorDialog

use of org.eclipse.swt.widgets.ColorDialog in project yamcs-studio by yamcs.

the class CreateAnnotationDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite area = (Composite) super.createDialogArea(parent);
    Composite container = new Composite(area, SWT.NONE);
    container.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layout = new GridLayout(2, false);
    layout.marginHeight = 20;
    layout.marginWidth = 20;
    layout.verticalSpacing = 2;
    container.setLayout(layout);
    Label lbl = new Label(container, SWT.NONE);
    lbl.setText("Name");
    Composite tagAndColorWrapper = new Composite(container, SWT.NONE);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    tagAndColorWrapper.setLayoutData(gd);
    GridLayout gl = new GridLayout(2, false);
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    tagAndColorWrapper.setLayout(gl);
    tag = new Text(tagAndColorWrapper, SWT.BORDER);
    tag.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    tag.setText(tagValue);
    // Some ugly tricks to get a border around a label, which should have been a button in the first place
    // but at least OSX doesn't support buttons with custom backgrounds. May be getting time to draw GC ourselves..
    Composite labelBorder = new Composite(tagAndColorWrapper, SWT.BORDER);
    labelBorder.setLayout(new FillLayout());
    colorSelector = new Label(labelBorder, SWT.NONE);
    colorSelector.setText("         ");
    colorSelector.setCursor(handCursor);
    colorSelector.setBackground(resourceManager.createColor(colorValue));
    colorSelector.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            ColorDialog colorDialog = new ColorDialog(colorSelector.getShell());
            colorDialog.setRGB(colorSelector.getBackground().getRGB());
            RGB newColor = colorDialog.open();
            if (newColor != null)
                colorSelector.setBackground(resourceManager.createColor(newColor));
        }
    });
    lbl = new Label(container, SWT.NONE);
    lbl.setText("Description");
    gd = new GridData();
    gd.verticalAlignment = SWT.TOP;
    lbl.setLayoutData(gd);
    description = new Text(container, SWT.MULTI | SWT.BORDER);
    gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = description.getLineHeight() * 3;
    description.setLayoutData(gd);
    description.setText(descriptionValue);
    Composite startLabelWrapper = new Composite(container, SWT.NONE);
    gl = new GridLayout(2, false);
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    startLabelWrapper.setLayout(gl);
    lbl = new Label(startLabelWrapper, SWT.NONE);
    lbl.setText("Start");
    startClosed = new Button(startLabelWrapper, SWT.CHECK | SWT.NONE);
    startClosed.setSelection(true);
    startClosed.addListener(SWT.Selection, e -> {
        startDate.setVisible(startClosed.getSelection());
        startTime.setVisible(startClosed.getSelection());
        validate();
    });
    Composite startComposite = new Composite(container, SWT.NONE);
    RowLayout rl = new RowLayout();
    rl.marginLeft = 0;
    rl.marginTop = 0;
    rl.marginBottom = 0;
    rl.center = true;
    startComposite.setLayout(rl);
    startDate = new DateTime(startComposite, SWT.DATE | SWT.LONG | SWT.DROP_DOWN | SWT.BORDER);
    startDate.addListener(SWT.Selection, e -> validate());
    startTime = new DateTime(startComposite, SWT.TIME | SWT.LONG | SWT.BORDER);
    startTime.addListener(SWT.Selection, e -> validate());
    if (startTimeValue != null) {
        startDate.setDate(startTimeValue.get(Calendar.YEAR), startTimeValue.get(Calendar.MONTH), startTimeValue.get(Calendar.DAY_OF_MONTH));
        startTime.setTime(startTimeValue.get(Calendar.HOUR_OF_DAY), startTimeValue.get(Calendar.MINUTE), startTimeValue.get(Calendar.SECOND));
    }
    Composite stopLabelWrapper = new Composite(container, SWT.NONE);
    gl = new GridLayout(2, false);
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    stopLabelWrapper.setLayout(gl);
    lbl = new Label(stopLabelWrapper, SWT.NONE);
    lbl.setText("Stop");
    stopClosed = new Button(stopLabelWrapper, SWT.CHECK | SWT.NONE);
    stopClosed.setSelection(true);
    stopClosed.addListener(SWT.Selection, e -> {
        stopDate.setVisible(stopClosed.getSelection());
        stopTime.setVisible(stopClosed.getSelection());
        validate();
    });
    Composite stopComposite = new Composite(container, SWT.NONE);
    rl = new RowLayout();
    rl.marginLeft = 0;
    rl.marginTop = 0;
    rl.marginBottom = 0;
    rl.center = true;
    rl.fill = true;
    stopComposite.setLayout(rl);
    stopDate = new DateTime(stopComposite, SWT.DATE | SWT.LONG | SWT.DROP_DOWN | SWT.BORDER);
    stopDate.addListener(SWT.Selection, e -> validate());
    stopTime = new DateTime(stopComposite, SWT.TIME | SWT.LONG | SWT.BORDER);
    stopTime.addListener(SWT.Selection, e -> validate());
    if (stopTimeValue != null) {
        stopDate.setDate(stopTimeValue.get(Calendar.YEAR), stopTimeValue.get(Calendar.MONTH), stopTimeValue.get(Calendar.DAY_OF_MONTH));
        stopTime.setTime(stopTimeValue.get(Calendar.HOUR_OF_DAY), stopTimeValue.get(Calendar.MINUTE), stopTimeValue.get(Calendar.SECOND));
    }
    return container;
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Text(org.eclipse.swt.widgets.Text) FillLayout(org.eclipse.swt.layout.FillLayout) RGB(org.eclipse.swt.graphics.RGB) DateTime(org.eclipse.swt.widgets.DateTime) GridLayout(org.eclipse.swt.layout.GridLayout) ColorDialog(org.eclipse.swt.widgets.ColorDialog) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) GridData(org.eclipse.swt.layout.GridData)

Example 17 with ColorDialog

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

the class ColoursFontsPreferencePage method openColorDialog.

/**
 * @param object Selected object
 * @return the RGB value or null
 * Open the color dialog to edit color for an object
 */
private RGB openColorDialog(Object object) {
    ColorDialog colorDialog = new ColorDialog(getShell());
    colorDialog.setRGB(fColorsCache.get(object).getRGB());
    return colorDialog.open();
}
Also used : ColorDialog(org.eclipse.swt.widgets.ColorDialog)

Example 18 with ColorDialog

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

the class DialogTab method createControlWidgets.

/**
 * Creates the "Control" widget children.
 */
@Override
void createControlWidgets() {
    /* Create the combo */
    String[] strings = { ControlExample.getResourceString("ColorDialog"), ControlExample.getResourceString("DirectoryDialog"), ControlExample.getResourceString("FileDialog"), ControlExample.getResourceString("FontDialog"), ControlExample.getResourceString("PrintDialog"), ControlExample.getResourceString("MessageBox") };
    dialogCombo = new Combo(dialogStyleGroup, SWT.READ_ONLY);
    dialogCombo.setItems(strings);
    dialogCombo.setText(strings[0]);
    dialogCombo.setVisibleItemCount(strings.length);
    /* Create the create dialog button */
    createButton = new Button(dialogStyleGroup, SWT.NONE);
    createButton.setText(ControlExample.getResourceString("Create_Dialog"));
    createButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
    /* Create a group for the various dialog button style controls */
    Group buttonStyleGroup = new Group(controlGroup, SWT.NONE);
    buttonStyleGroup.setLayout(new GridLayout());
    buttonStyleGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
    buttonStyleGroup.setText(ControlExample.getResourceString("Button_Styles"));
    /* Create the button style buttons */
    okButton = new Button(buttonStyleGroup, SWT.CHECK);
    okButton.setText("SWT.OK");
    cancelButton = new Button(buttonStyleGroup, SWT.CHECK);
    cancelButton.setText("SWT.CANCEL");
    yesButton = new Button(buttonStyleGroup, SWT.CHECK);
    yesButton.setText("SWT.YES");
    noButton = new Button(buttonStyleGroup, SWT.CHECK);
    noButton.setText("SWT.NO");
    retryButton = new Button(buttonStyleGroup, SWT.CHECK);
    retryButton.setText("SWT.RETRY");
    abortButton = new Button(buttonStyleGroup, SWT.CHECK);
    abortButton.setText("SWT.ABORT");
    ignoreButton = new Button(buttonStyleGroup, SWT.CHECK);
    ignoreButton.setText("SWT.IGNORE");
    /* Create a group for the icon style controls */
    Group iconStyleGroup = new Group(controlGroup, SWT.NONE);
    iconStyleGroup.setLayout(new GridLayout());
    iconStyleGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
    iconStyleGroup.setText(ControlExample.getResourceString("Icon_Styles"));
    /* Create the icon style buttons */
    iconErrorButton = new Button(iconStyleGroup, SWT.RADIO);
    iconErrorButton.setText("SWT.ICON_ERROR");
    iconInformationButton = new Button(iconStyleGroup, SWT.RADIO);
    iconInformationButton.setText("SWT.ICON_INFORMATION");
    iconQuestionButton = new Button(iconStyleGroup, SWT.RADIO);
    iconQuestionButton.setText("SWT.ICON_QUESTION");
    iconWarningButton = new Button(iconStyleGroup, SWT.RADIO);
    iconWarningButton.setText("SWT.ICON_WARNING");
    iconWorkingButton = new Button(iconStyleGroup, SWT.RADIO);
    iconWorkingButton.setText("SWT.ICON_WORKING");
    noIconButton = new Button(iconStyleGroup, SWT.RADIO);
    noIconButton.setText(ControlExample.getResourceString("No_Icon"));
    /* Create a group for the modal style controls */
    Group modalStyleGroup = new Group(controlGroup, SWT.NONE);
    modalStyleGroup.setLayout(new GridLayout());
    modalStyleGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
    modalStyleGroup.setText(ControlExample.getResourceString("Modal_Styles"));
    /* Create the modal style buttons */
    primaryModalButton = new Button(modalStyleGroup, SWT.RADIO);
    primaryModalButton.setText("SWT.PRIMARY_MODAL");
    applicationModalButton = new Button(modalStyleGroup, SWT.RADIO);
    applicationModalButton.setText("SWT.APPLICATION_MODAL");
    systemModalButton = new Button(modalStyleGroup, SWT.RADIO);
    systemModalButton.setText("SWT.SYSTEM_MODAL");
    /* Create a group for the file dialog style controls */
    Group fileDialogStyleGroup = new Group(controlGroup, SWT.NONE);
    fileDialogStyleGroup.setLayout(new GridLayout());
    fileDialogStyleGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
    fileDialogStyleGroup.setText(ControlExample.getResourceString("File_Dialog_Styles"));
    /* Create the file dialog style buttons */
    openButton = new Button(fileDialogStyleGroup, SWT.RADIO);
    openButton.setText("SWT.OPEN");
    saveButton = new Button(fileDialogStyleGroup, SWT.RADIO);
    saveButton.setText("SWT.SAVE");
    multiButton = new Button(fileDialogStyleGroup, SWT.CHECK);
    multiButton.setText("SWT.MULTI");
    /* Create the orientation group */
    if (RTL_SUPPORT_ENABLE) {
        createOrientationGroup();
    }
    /* Create a group for other style and setting controls */
    Group otherGroup = new Group(controlGroup, SWT.NONE);
    otherGroup.setLayout(new GridLayout());
    otherGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
    otherGroup.setText(ControlExample.getResourceString("Other"));
    /* Create the other style and setting controls */
    sheetButton = new Button(otherGroup, SWT.CHECK);
    sheetButton.setText("SWT.SHEET");
    usePreviousResultButton = new Button(otherGroup, SWT.CHECK);
    usePreviousResultButton.setText(ControlExample.getResourceString("Use_Previous_Result"));
    effectsVisibleButton = new Button(otherGroup, SWT.CHECK);
    effectsVisibleButton.setText("FontDialog.setEffectsVisible");
    /* Add the listeners */
    dialogCombo.addSelectionListener(widgetSelectedAdapter(event -> dialogSelected(event)));
    createButton.addSelectionListener(widgetSelectedAdapter(event -> createButtonSelected(event)));
    SelectionListener buttonStyleListener = widgetSelectedAdapter(event -> buttonStyleSelected(event));
    okButton.addSelectionListener(buttonStyleListener);
    cancelButton.addSelectionListener(buttonStyleListener);
    yesButton.addSelectionListener(buttonStyleListener);
    noButton.addSelectionListener(buttonStyleListener);
    retryButton.addSelectionListener(buttonStyleListener);
    abortButton.addSelectionListener(buttonStyleListener);
    ignoreButton.addSelectionListener(buttonStyleListener);
    /* Set default values for style buttons */
    okButton.setEnabled(false);
    cancelButton.setEnabled(false);
    yesButton.setEnabled(false);
    noButton.setEnabled(false);
    retryButton.setEnabled(false);
    abortButton.setEnabled(false);
    ignoreButton.setEnabled(false);
    iconErrorButton.setEnabled(false);
    iconInformationButton.setEnabled(false);
    iconQuestionButton.setEnabled(false);
    iconWarningButton.setEnabled(false);
    iconWorkingButton.setEnabled(false);
    noIconButton.setEnabled(false);
    saveButton.setEnabled(false);
    openButton.setEnabled(false);
    openButton.setSelection(true);
    multiButton.setEnabled(false);
    noIconButton.setSelection(true);
    effectsVisibleButton.setEnabled(false);
    effectsVisibleButton.setSelection(true);
}
Also used : Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) Button(org.eclipse.swt.widgets.Button) PrinterData(org.eclipse.swt.printing.PrinterData) FileDialog(org.eclipse.swt.widgets.FileDialog) FontDialog(org.eclipse.swt.widgets.FontDialog) Group(org.eclipse.swt.widgets.Group) SelectionListener.widgetSelectedAdapter(org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter) ColorDialog(org.eclipse.swt.widgets.ColorDialog) PrintDialog(org.eclipse.swt.printing.PrintDialog) SWT(org.eclipse.swt.SWT) FontData(org.eclipse.swt.graphics.FontData) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) MessageBox(org.eclipse.swt.widgets.MessageBox) RGB(org.eclipse.swt.graphics.RGB) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) Widget(org.eclipse.swt.widgets.Widget) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) Group(org.eclipse.swt.widgets.Group) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) Combo(org.eclipse.swt.widgets.Combo) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 19 with ColorDialog

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

the class Test_org_eclipse_swt_widgets_ColorDialog method setUp.

@Override
@Before
public void setUp() {
    super.setUp();
    colorDialog = new ColorDialog(shell, SWT.NULL);
    setDialog(colorDialog);
}
Also used : ColorDialog(org.eclipse.swt.widgets.ColorDialog) Before(org.junit.Before)

Example 20 with ColorDialog

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

the class TextEditor method createToolBar.

void createToolBar() {
    coolBar = new CoolBar(shell, SWT.FLAT);
    ToolBar styleToolBar = new ToolBar(coolBar, SWT.FLAT);
    boldControl = new ToolItem(styleToolBar, SWT.CHECK);
    boldControl.setImage(iBold);
    // $NON-NLS-1$
    boldControl.setToolTipText(getResourceString("Bold"));
    boldControl.addSelectionListener(widgetSelectedAdapter(event -> setStyle(BOLD)));
    italicControl = new ToolItem(styleToolBar, SWT.CHECK);
    italicControl.setImage(iItalic);
    // $NON-NLS-1$
    italicControl.setToolTipText(getResourceString("Italic"));
    italicControl.addSelectionListener(widgetSelectedAdapter(event -> setStyle(ITALIC)));
    final Menu underlineMenu = new Menu(shell, SWT.POP_UP);
    underlineSingleItem = new MenuItem(underlineMenu, SWT.RADIO);
    // $NON-NLS-1$
    underlineSingleItem.setText(getResourceString("Single_menuitem"));
    underlineSingleItem.addSelectionListener(widgetSelectedAdapter(event -> {
        if (underlineSingleItem.getSelection()) {
            setStyle(UNDERLINE_SINGLE);
        }
    }));
    underlineSingleItem.setSelection(true);
    underlineDoubleItem = new MenuItem(underlineMenu, SWT.RADIO);
    // $NON-NLS-1$
    underlineDoubleItem.setText(getResourceString("Double_menuitem"));
    underlineDoubleItem.addSelectionListener(widgetSelectedAdapter(event -> {
        if (underlineDoubleItem.getSelection()) {
            setStyle(UNDERLINE_DOUBLE);
        }
    }));
    underlineSquiggleItem = new MenuItem(underlineMenu, SWT.RADIO);
    // $NON-NLS-1$
    underlineSquiggleItem.setText(getResourceString("Squiggle_menuitem"));
    underlineSquiggleItem.addSelectionListener(widgetSelectedAdapter(event -> {
        if (underlineSquiggleItem.getSelection()) {
            setStyle(UNDERLINE_SQUIGGLE);
        }
    }));
    underlineErrorItem = new MenuItem(underlineMenu, SWT.RADIO);
    // $NON-NLS-1$
    underlineErrorItem.setText(getResourceString("Error_menuitem"));
    underlineErrorItem.addSelectionListener(widgetSelectedAdapter(event -> {
        if (underlineErrorItem.getSelection()) {
            setStyle(UNDERLINE_ERROR);
        }
    }));
    MenuItem underlineColorItem = new MenuItem(underlineMenu, SWT.PUSH);
    // $NON-NLS-1$
    underlineColorItem.setText(getResourceString("Color_menuitem"));
    underlineColorItem.addSelectionListener(widgetSelectedAdapter(event -> {
        ColorDialog dialog = new ColorDialog(shell);
        RGB rgb = underlineColor != null ? underlineColor.getRGB() : null;
        dialog.setRGB(rgb);
        RGB newRgb = dialog.open();
        if (newRgb != null) {
            if (!newRgb.equals(rgb)) {
                disposeResource(underlineColor);
                underlineColor = new Color(display, newRgb);
            }
            if (underlineSingleItem.getSelection())
                setStyle(UNDERLINE_SINGLE);
            else if (underlineDoubleItem.getSelection())
                setStyle(UNDERLINE_DOUBLE);
            else if (underlineErrorItem.getSelection())
                setStyle(UNDERLINE_ERROR);
            else if (underlineSquiggleItem.getSelection())
                setStyle(UNDERLINE_SQUIGGLE);
        }
    }));
    final ToolItem underlineControl = new ToolItem(styleToolBar, SWT.DROP_DOWN);
    underlineControl.setImage(iUnderline);
    // $NON-NLS-1$
    underlineControl.setToolTipText(getResourceString("Underline"));
    underlineControl.addSelectionListener(widgetSelectedAdapter(event -> {
        if (event.detail == SWT.ARROW) {
            Rectangle rect = underlineControl.getBounds();
            Point pt = new Point(rect.x, rect.y + rect.height);
            underlineMenu.setLocation(display.map(underlineControl.getParent(), null, pt));
            underlineMenu.setVisible(true);
        } else {
            if (underlineSingleItem.getSelection())
                setStyle(UNDERLINE_SINGLE);
            else if (underlineDoubleItem.getSelection())
                setStyle(UNDERLINE_DOUBLE);
            else if (underlineErrorItem.getSelection())
                setStyle(UNDERLINE_ERROR);
            else if (underlineSquiggleItem.getSelection())
                setStyle(UNDERLINE_SQUIGGLE);
        }
    }));
    ToolItem strikeoutControl = new ToolItem(styleToolBar, SWT.DROP_DOWN);
    strikeoutControl.setImage(iStrikeout);
    // $NON-NLS-1$
    strikeoutControl.setToolTipText(getResourceString("Strikeout"));
    strikeoutControl.addSelectionListener(widgetSelectedAdapter(event -> {
        if (event.detail == SWT.ARROW) {
            ColorDialog dialog = new ColorDialog(shell);
            RGB rgb = strikeoutColor != null ? strikeoutColor.getRGB() : null;
            dialog.setRGB(rgb);
            RGB newRgb = dialog.open();
            if (newRgb == null)
                return;
            if (!newRgb.equals(rgb)) {
                disposeResource(strikeoutColor);
                strikeoutColor = new Color(display, newRgb);
            }
        }
        setStyle(STRIKEOUT);
    }));
    final Menu borderMenu = new Menu(shell, SWT.POP_UP);
    borderSolidItem = new MenuItem(borderMenu, SWT.RADIO);
    // $NON-NLS-1$
    borderSolidItem.setText(getResourceString("Solid"));
    borderSolidItem.addSelectionListener(widgetSelectedAdapter(event -> {
        if (borderSolidItem.getSelection()) {
            setStyle(BORDER_SOLID);
        }
    }));
    borderSolidItem.setSelection(true);
    borderDashItem = new MenuItem(borderMenu, SWT.RADIO);
    // $NON-NLS-1$
    borderDashItem.setText(getResourceString("Dash"));
    borderDashItem.addSelectionListener(widgetSelectedAdapter(event -> {
        if (borderDashItem.getSelection()) {
            setStyle(BORDER_DASH);
        }
    }));
    borderDotItem = new MenuItem(borderMenu, SWT.RADIO);
    // $NON-NLS-1$
    borderDotItem.setText(getResourceString("Dot"));
    borderDotItem.addSelectionListener(widgetSelectedAdapter(event -> {
        if (borderDotItem.getSelection()) {
            setStyle(BORDER_DOT);
        }
    }));
    MenuItem borderColorItem = new MenuItem(borderMenu, SWT.PUSH);
    // $NON-NLS-1$
    borderColorItem.setText(getResourceString("Color_menuitem"));
    borderColorItem.addSelectionListener(widgetSelectedAdapter(event -> {
        ColorDialog dialog = new ColorDialog(shell);
        RGB rgb = borderColor != null ? borderColor.getRGB() : null;
        dialog.setRGB(rgb);
        RGB newRgb = dialog.open();
        if (newRgb != null) {
            if (!newRgb.equals(rgb)) {
                disposeResource(borderColor);
                borderColor = new Color(display, newRgb);
            }
            if (borderDashItem.getSelection())
                setStyle(BORDER_DASH);
            else if (borderDotItem.getSelection())
                setStyle(BORDER_DOT);
            else if (borderSolidItem.getSelection())
                setStyle(BORDER_SOLID);
        }
    }));
    final ToolItem borderControl = new ToolItem(styleToolBar, SWT.DROP_DOWN);
    borderControl.setImage(iBorderStyle);
    // $NON-NLS-1$
    borderControl.setToolTipText(getResourceString("Box"));
    borderControl.addSelectionListener(widgetSelectedAdapter(event -> {
        if (event.detail == SWT.ARROW) {
            Rectangle rect = borderControl.getBounds();
            Point pt = new Point(rect.x, rect.y + rect.height);
            borderMenu.setLocation(display.map(borderControl.getParent(), null, pt));
            borderMenu.setVisible(true);
        } else {
            if (borderDashItem.getSelection())
                setStyle(BORDER_DASH);
            else if (borderDotItem.getSelection())
                setStyle(BORDER_DOT);
            else if (borderSolidItem.getSelection())
                setStyle(BORDER_SOLID);
        }
    }));
    ToolItem foregroundItem = new ToolItem(styleToolBar, SWT.DROP_DOWN);
    foregroundItem.setImage(iTextForeground);
    // $NON-NLS-1$
    foregroundItem.setToolTipText(getResourceString("TextForeground"));
    foregroundItem.addSelectionListener(widgetSelectedAdapter(event -> {
        if (event.detail == SWT.ARROW || textForeground == null) {
            ColorDialog dialog = new ColorDialog(shell);
            RGB rgb = textForeground != null ? textForeground.getRGB() : null;
            dialog.setRGB(rgb);
            RGB newRgb = dialog.open();
            if (newRgb == null)
                return;
            if (!newRgb.equals(rgb)) {
                disposeResource(textForeground);
                textForeground = new Color(display, newRgb);
            }
        }
        setStyle(FOREGROUND);
    }));
    ToolItem backgroundItem = new ToolItem(styleToolBar, SWT.DROP_DOWN);
    backgroundItem.setImage(iTextBackground);
    // $NON-NLS-1$
    backgroundItem.setToolTipText(getResourceString("TextBackground"));
    backgroundItem.addSelectionListener(widgetSelectedAdapter(event -> {
        if (event.detail == SWT.ARROW || textBackground == null) {
            ColorDialog dialog = new ColorDialog(shell);
            RGB rgb = textBackground != null ? textBackground.getRGB() : null;
            dialog.setRGB(rgb);
            RGB newRgb = dialog.open();
            if (newRgb == null)
                return;
            if (!newRgb.equals(rgb)) {
                disposeResource(textBackground);
                textBackground = new Color(display, newRgb);
            }
        }
        setStyle(BACKGROUND);
    }));
    ToolItem baselineUpItem = new ToolItem(styleToolBar, SWT.PUSH);
    baselineUpItem.setImage(iBaselineUp);
    // $NON-NLS-1$
    String tooltip = "IncreaseFont";
    // $NON-NLS-1$
    if (USE_BASELINE)
        tooltip = "IncreaseBaseline";
    baselineUpItem.setToolTipText(getResourceString(tooltip));
    baselineUpItem.addSelectionListener(widgetSelectedAdapter(event -> {
        if (USE_BASELINE) {
            setStyle(BASELINE_UP);
        } else {
            adjustFontSize(1);
        }
    }));
    ToolItem baselineDownItem = new ToolItem(styleToolBar, SWT.PUSH);
    baselineDownItem.setImage(iBaselineDown);
    // $NON-NLS-1$
    tooltip = "DecreaseFont";
    // $NON-NLS-1$
    if (USE_BASELINE)
        tooltip = "DecreaseBaseline";
    baselineDownItem.setToolTipText(getResourceString(tooltip));
    baselineDownItem.addSelectionListener(widgetSelectedAdapter(event -> {
        if (USE_BASELINE) {
            setStyle(BASELINE_DOWN);
        } else {
            adjustFontSize(-1);
        }
    }));
    ToolItem linkItem = new ToolItem(styleToolBar, SWT.PUSH);
    linkItem.setImage(iLink);
    // $NON-NLS-1$
    linkItem.setToolTipText(getResourceString("Link"));
    linkItem.addSelectionListener(widgetSelectedAdapter(event -> setLink()));
    CoolItem coolItem = new CoolItem(coolBar, SWT.NONE);
    coolItem.setControl(styleToolBar);
    Composite composite = new Composite(coolBar, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    layout.marginHeight = 1;
    composite.setLayout(layout);
    fontNameControl = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
    fontNameControl.setItems(getFontNames());
    fontNameControl.setVisibleItemCount(12);
    fontSizeControl = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
    fontSizeControl.setItems(FONT_SIZES);
    fontSizeControl.setVisibleItemCount(8);
    SelectionListener adapter = widgetSelectedAdapter(event -> {
        String name = fontNameControl.getText();
        int size = Integer.parseInt(fontSizeControl.getText());
        disposeResource(textFont);
        textFont = new Font(display, name, size, SWT.NORMAL);
        setStyle(FONT);
    });
    fontSizeControl.addSelectionListener(adapter);
    fontNameControl.addSelectionListener(adapter);
    coolItem = new CoolItem(coolBar, SWT.NONE);
    coolItem.setControl(composite);
    ToolBar alignmentToolBar = new ToolBar(coolBar, SWT.FLAT);
    blockSelectionItem = new ToolItem(alignmentToolBar, SWT.CHECK);
    blockSelectionItem.setImage(iBlockSelection);
    // $NON-NLS-1$
    blockSelectionItem.setToolTipText(getResourceString("BlockSelection"));
    blockSelectionItem.addSelectionListener(widgetSelectedAdapter(event -> styledText.invokeAction(ST.TOGGLE_BLOCKSELECTION)));
    leftAlignmentItem = new ToolItem(alignmentToolBar, SWT.RADIO);
    leftAlignmentItem.setImage(iLeftAlignment);
    // $NON-NLS-1$
    leftAlignmentItem.setToolTipText(getResourceString("AlignLeft"));
    leftAlignmentItem.setSelection(true);
    leftAlignmentItem.addSelectionListener(widgetSelectedAdapter(event -> {
        Point selection = styledText.getSelection();
        int lineStart = styledText.getLineAtOffset(selection.x);
        int lineEnd = styledText.getLineAtOffset(selection.y);
        styledText.setLineAlignment(lineStart, lineEnd - lineStart + 1, SWT.LEFT);
    }));
    leftAlignmentItem.setEnabled(false);
    centerAlignmentItem = new ToolItem(alignmentToolBar, SWT.RADIO);
    centerAlignmentItem.setImage(iCenterAlignment);
    // $NON-NLS-1$
    centerAlignmentItem.setToolTipText(getResourceString("Center_menuitem"));
    centerAlignmentItem.addSelectionListener(widgetSelectedAdapter(event -> {
        Point selection = styledText.getSelection();
        int lineStart = styledText.getLineAtOffset(selection.x);
        int lineEnd = styledText.getLineAtOffset(selection.y);
        styledText.setLineAlignment(lineStart, lineEnd - lineStart + 1, SWT.CENTER);
    }));
    centerAlignmentItem.setEnabled(false);
    rightAlignmentItem = new ToolItem(alignmentToolBar, SWT.RADIO);
    rightAlignmentItem.setImage(iRightAlignment);
    // $NON-NLS-1$
    rightAlignmentItem.setToolTipText(getResourceString("AlignRight"));
    rightAlignmentItem.addSelectionListener(widgetSelectedAdapter(event -> {
        Point selection = styledText.getSelection();
        int lineStart = styledText.getLineAtOffset(selection.x);
        int lineEnd = styledText.getLineAtOffset(selection.y);
        styledText.setLineAlignment(lineStart, lineEnd - lineStart + 1, SWT.RIGHT);
    }));
    rightAlignmentItem.setEnabled(false);
    justifyAlignmentItem = new ToolItem(alignmentToolBar, SWT.CHECK);
    justifyAlignmentItem.setImage(iJustifyAlignment);
    // $NON-NLS-1$
    justifyAlignmentItem.setToolTipText(getResourceString("Justify"));
    justifyAlignmentItem.addSelectionListener(widgetSelectedAdapter(event -> {
        Point selection = styledText.getSelection();
        int lineStart = styledText.getLineAtOffset(selection.x);
        int lineEnd = styledText.getLineAtOffset(selection.y);
        styledText.setLineJustify(lineStart, lineEnd - lineStart + 1, justifyAlignmentItem.getSelection());
    }));
    justifyAlignmentItem.setEnabled(false);
    ToolItem bulletListItem = new ToolItem(alignmentToolBar, SWT.PUSH);
    bulletListItem.setImage(iBulletList);
    // $NON-NLS-1$
    bulletListItem.setToolTipText(getResourceString("BulletList"));
    bulletListItem.addSelectionListener(widgetSelectedAdapter(event -> setBullet(ST.BULLET_DOT)));
    ToolItem numberedListItem = new ToolItem(alignmentToolBar, SWT.PUSH);
    numberedListItem.setImage(iNumberedList);
    // $NON-NLS-1$
    numberedListItem.setToolTipText(getResourceString("NumberedList"));
    numberedListItem.addSelectionListener(widgetSelectedAdapter(event -> setBullet(ST.BULLET_NUMBER | ST.BULLET_TEXT)));
    coolItem = new CoolItem(coolBar, SWT.NONE);
    coolItem.setControl(alignmentToolBar);
    composite = new Composite(coolBar, SWT.NONE);
    layout = new GridLayout(4, false);
    layout.marginHeight = 1;
    composite.setLayout(layout);
    Label label = new Label(composite, SWT.NONE);
    // $NON-NLS-1$
    label.setText(getResourceString("Indent"));
    Spinner indent = new Spinner(composite, SWT.BORDER);
    indent.addSelectionListener(widgetSelectedAdapter(event -> {
        Spinner spinner = (Spinner) event.widget;
        styledText.setIndent(spinner.getSelection());
    }));
    label = new Label(composite, SWT.NONE);
    // $NON-NLS-1$
    label.setText(getResourceString("Spacing"));
    Spinner spacing = new Spinner(composite, SWT.BORDER);
    spacing.addSelectionListener(widgetSelectedAdapter(event -> {
        Spinner spinner = (Spinner) event.widget;
        styledText.setLineSpacing(spinner.getSelection());
    }));
    coolItem = new CoolItem(coolBar, SWT.NONE);
    coolItem.setControl(composite);
    CoolItem[] coolItems = coolBar.getItems();
    for (CoolItem item : coolItems) {
        Control control = item.getControl();
        Point size = control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        item.setMinimumSize(size);
        size = item.computeSize(size.x, size.y);
        item.setPreferredSize(size);
        item.setSize(size);
    }
    coolBar.addControlListener(ControlListener.controlResizedAdapter(event -> handleResize(event)));
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) CoolBar(org.eclipse.swt.widgets.CoolBar) ToolBar(org.eclipse.swt.widgets.ToolBar) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) ColorDialog(org.eclipse.swt.widgets.ColorDialog) MenuEvent(org.eclipse.swt.events.MenuEvent) Composite(org.eclipse.swt.widgets.Composite) Bullet(org.eclipse.swt.custom.Bullet) Text(org.eclipse.swt.widgets.Text) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) MissingResourceException(java.util.MissingResourceException) GlyphMetrics(org.eclipse.swt.graphics.GlyphMetrics) Display(org.eclipse.swt.widgets.Display) ToolItem(org.eclipse.swt.widgets.ToolItem) MenuListener.menuShownAdapter(org.eclipse.swt.events.MenuListener.menuShownAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) SWT(org.eclipse.swt.SWT) PaintObjectEvent(org.eclipse.swt.custom.PaintObjectEvent) Label(org.eclipse.swt.widgets.Label) SelectionListener(org.eclipse.swt.events.SelectionListener) Image(org.eclipse.swt.graphics.Image) Rectangle(org.eclipse.swt.graphics.Rectangle) Spinner(org.eclipse.swt.widgets.Spinner) ControlListener(org.eclipse.swt.events.ControlListener) MenuAdapter(org.eclipse.swt.events.MenuAdapter) ImageData(org.eclipse.swt.graphics.ImageData) 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) ResourceBundle(java.util.ResourceBundle) StringTokenizer(java.util.StringTokenizer) Listener(org.eclipse.swt.widgets.Listener) RGB(org.eclipse.swt.graphics.RGB) Font(org.eclipse.swt.graphics.Font) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) Resource(org.eclipse.swt.graphics.Resource) Browser(org.eclipse.swt.browser.Browser) Combo(org.eclipse.swt.widgets.Combo) Shell(org.eclipse.swt.widgets.Shell) FileDialog(org.eclipse.swt.widgets.FileDialog) FileWriter(java.io.FileWriter) StyleRange(org.eclipse.swt.custom.StyleRange) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) FontDialog(org.eclipse.swt.widgets.FontDialog) InputStreamReader(java.io.InputStreamReader) CoolItem(org.eclipse.swt.widgets.CoolItem) Color(org.eclipse.swt.graphics.Color) ST(org.eclipse.swt.custom.ST) FontData(org.eclipse.swt.graphics.FontData) MessageBox(org.eclipse.swt.widgets.MessageBox) BufferedReader(java.io.BufferedReader) Menu(org.eclipse.swt.widgets.Menu) Control(org.eclipse.swt.widgets.Control) InputStream(java.io.InputStream) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Spinner(org.eclipse.swt.widgets.Spinner) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) Label(org.eclipse.swt.widgets.Label) MenuItem(org.eclipse.swt.widgets.MenuItem) Combo(org.eclipse.swt.widgets.Combo) Point(org.eclipse.swt.graphics.Point) RGB(org.eclipse.swt.graphics.RGB) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font) ColorDialog(org.eclipse.swt.widgets.ColorDialog) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) CoolBar(org.eclipse.swt.widgets.CoolBar) ToolBar(org.eclipse.swt.widgets.ToolBar) Menu(org.eclipse.swt.widgets.Menu) CoolItem(org.eclipse.swt.widgets.CoolItem) ToolItem(org.eclipse.swt.widgets.ToolItem) SelectionListener(org.eclipse.swt.events.SelectionListener)

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