Search in sources :

Example 6 with FontDialog

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

the class OPIFontDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    final Composite parent_Composite = (Composite) super.createDialogArea(parent);
    final Composite mainComposite = new Composite(parent_Composite, SWT.None);
    mainComposite.setLayout(new GridLayout(2, false));
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData.heightHint = 300;
    mainComposite.setLayoutData(gridData);
    final Composite leftComposite = new Composite(mainComposite, SWT.None);
    leftComposite.setLayout(new GridLayout(1, false));
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.widthHint = 250;
    leftComposite.setLayoutData(gd);
    createLabel(leftComposite, "Choose from Predefined Fonts:");
    preDefinedFontsViewer = createPredefinedFontsTableViewer(leftComposite);
    preDefinedFontsViewer.setInput(MediaService.getInstance().getAllPredefinedFonts());
    Composite rightComposite = new Composite(mainComposite, SWT.None);
    rightComposite.setLayout(new GridLayout(1, false));
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.widthHint = 250;
    rightComposite.setLayoutData(gd);
    // This label doesn't need to do anything but exist.
    @SuppressWarnings("unused") Label spacer = new Label(rightComposite, SWT.NONE);
    Button fontDialogButton = new Button(rightComposite, SWT.PUSH);
    // Push radioButtons to bottom of rightComposite.
    Label spacer2 = new Label(rightComposite, SWT.NONE);
    GridData gd2 = new GridData();
    gd2.grabExcessVerticalSpace = true;
    spacer2.setLayoutData(gd2);
    pixelsOrPointsBox = new PixelsOrPointsBox(rightComposite, SWT.NONE);
    pixelsOrPointsBox.setSizeInPixels(opiFont.isSizeInPixels());
    fontDialogButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    fontDialogButton.setText("Choose from Font Dialog");
    fontDialogButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            FontDialog dialog = new FontDialog(Display.getCurrent().getActiveShell());
            dialog.setFontList(new FontData[] { opiFont.getRawFontData() });
            FontData fontdata = dialog.open();
            pixelsOrPointsBox.setEnabled(true);
            if (fontdata != null) {
                opiFont = new OPIFont(fontdata);
                opiFont.setSizeInPixels(pixelsOrPointsBox.isSizeInPixels());
                preDefinedFontsViewer.setSelection(null);
                outputTextLabel.setText(opiFont.getFontMacroName());
                outputTextLabel.setFont(CustomMediaFactory.getInstance().getFont(opiFont.getFontData()));
                getShell().layout(true, true);
            }
        }
    });
    SelectionListener radioSelectionListener = new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            opiFont.setSizeInPixels(pixelsOrPointsBox.isSizeInPixels());
            outputTextLabel.setText(opiFont.getFontMacroName());
            outputTextLabel.setFont(CustomMediaFactory.getInstance().getFont(opiFont.getFontData()));
            getShell().layout(true, true);
        }
    };
    pixelsOrPointsBox.addSelectionListener(radioSelectionListener);
    Group group = new Group(mainComposite, SWT.None);
    gd = new GridData(SWT.FILL, SWT.END, true, true, 2, 1);
    gd.heightHint = 100;
    group.setLayoutData(gd);
    group.setLayout(new GridLayout(1, false));
    group.setText("Output");
    outputTextLabel = new Label(group, SWT.None);
    outputTextLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    outputTextLabel.setText(opiFont.getFontMacroName());
    outputTextLabel.setFont(opiFont.getSWTFont());
    if (opiFont.isPreDefined())
        preDefinedFontsViewer.setSelection(new StructuredSelection(opiFont));
    else
        preDefinedFontsViewer.setSelection(null);
    return parent_Composite;
}
Also used : OPIFont(org.csstudio.opibuilder.util.OPIFont) Group(org.eclipse.swt.widgets.Group) FontDialog(org.eclipse.swt.widgets.FontDialog) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FontData(org.eclipse.swt.graphics.FontData) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 7 with FontDialog

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

the class FontCellEditor method activate.

/**
 * {@inheritDoc}
 */
@Override
public void activate() {
    FontDialog dialog = new FontDialog(_shell);
    if (_value != null) {
        dialog.setFontList(new FontData[] { _value });
    }
    _value = dialog.open();
    if (_value != null) {
        fireApplyEditorValue();
    }
}
Also used : FontDialog(org.eclipse.swt.widgets.FontDialog)

Example 8 with FontDialog

use of org.eclipse.swt.widgets.FontDialog 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 9 with FontDialog

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

the class TextEditor method createMenuBar.

void createMenuBar() {
    Menu menu = new Menu(shell, SWT.BAR);
    shell.setMenuBar(menu);
    MenuItem fileItem = new MenuItem(menu, SWT.CASCADE);
    Menu fileMenu = new Menu(shell, SWT.DROP_DOWN);
    // $NON-NLS-1$
    fileItem.setText(getResourceString("File_menuitem"));
    fileItem.setMenu(fileMenu);
    MenuItem openItem = new MenuItem(fileMenu, SWT.PUSH);
    // $NON-NLS-1$
    openItem.setText(getResourceString("Open_menuitem"));
    openItem.addSelectionListener(widgetSelectedAdapter(event -> {
        FileDialog dialog = new FileDialog(shell, SWT.OPEN);
        // $NON-NLS-1$
        dialog.setFilterNames(new String[] { getResourceString("Text_Documents") });
        // $NON-NLS-1$
        dialog.setFilterExtensions(new String[] { "*.txt" });
        String name = dialog.open();
        if (name == null)
            return;
        fileName = name;
        try (FileInputStream file = new FileInputStream(name)) {
            styledText.setText(openFile(file));
        } catch (IOException e) {
            // $NON-NLS-1$
            showError(getResourceString("Error"), e.getMessage());
        }
    }));
    final MenuItem saveItem = new MenuItem(fileMenu, SWT.PUSH);
    // $NON-NLS-1$
    saveItem.setText(getResourceString("Save_menuitem"));
    saveItem.addSelectionListener(widgetSelectedAdapter(event -> saveFile()));
    fileMenu.addMenuListener(new MenuAdapter() {

        @Override
        public void menuShown(MenuEvent event) {
            saveItem.setEnabled(fileName != null);
        }
    });
    MenuItem saveAsItem = new MenuItem(fileMenu, SWT.PUSH);
    // $NON-NLS-1$
    saveAsItem.setText(getResourceString("SaveAs_menuitem"));
    saveAsItem.addSelectionListener(widgetSelectedAdapter(event -> {
        FileDialog dialog = new FileDialog(shell, SWT.SAVE);
        // $NON-NLS-1$
        dialog.setFilterNames(new String[] { getResourceString("Text_Documents") });
        // $NON-NLS-1$
        dialog.setFilterExtensions(new String[] { "*.txt" });
        if (fileName != null)
            dialog.setFileName(fileName);
        String name = dialog.open();
        if (name != null) {
            fileName = name;
            saveFile();
        }
    }));
    new MenuItem(fileMenu, SWT.SEPARATOR);
    MenuItem exitItem = new MenuItem(fileMenu, SWT.PUSH);
    // $NON-NLS-1$
    exitItem.setText(getResourceString("Exit_menuitem"));
    exitItem.addSelectionListener(widgetSelectedAdapter(event -> shell.dispose()));
    MenuItem editItem = new MenuItem(menu, SWT.CASCADE);
    final Menu editMenu = new Menu(shell, SWT.DROP_DOWN);
    // $NON-NLS-1$
    editItem.setText(getResourceString("Edit_menuitem"));
    editItem.setMenu(editMenu);
    final MenuItem cutItem = new MenuItem(editMenu, SWT.PUSH);
    // $NON-NLS-1$
    cutItem.setText(getResourceString("Cut_menuitem"));
    cutItem.setImage(iCut);
    cutItem.setAccelerator(SWT.MOD1 | 'x');
    cutItem.addSelectionListener(widgetSelectedAdapter(event -> styledText.cut()));
    final MenuItem copyItem = new MenuItem(editMenu, SWT.PUSH);
    // $NON-NLS-1$
    copyItem.setText(getResourceString("Copy_menuitem"));
    copyItem.setImage(iCopy);
    copyItem.setAccelerator(SWT.MOD1 | 'c');
    copyItem.addSelectionListener(widgetSelectedAdapter(event -> styledText.copy()));
    MenuItem pasteItem = new MenuItem(editMenu, SWT.PUSH);
    // $NON-NLS-1$
    pasteItem.setText(getResourceString("Paste_menuitem"));
    pasteItem.setImage(iPaste);
    pasteItem.setAccelerator(SWT.MOD1 | 'v');
    pasteItem.addSelectionListener(widgetSelectedAdapter(event -> styledText.paste()));
    new MenuItem(editMenu, SWT.SEPARATOR);
    final MenuItem selectAllItem = new MenuItem(editMenu, SWT.PUSH);
    // $NON-NLS-1$
    selectAllItem.setText(getResourceString("SelectAll_menuitem"));
    selectAllItem.setAccelerator(SWT.MOD1 | 'a');
    selectAllItem.addSelectionListener(widgetSelectedAdapter(event -> styledText.selectAll()));
    editMenu.addMenuListener(menuShownAdapter(event -> {
        int selectionCount = styledText.getSelectionCount();
        cutItem.setEnabled(selectionCount > 0);
        copyItem.setEnabled(selectionCount > 0);
        selectAllItem.setEnabled(selectionCount < styledText.getCharCount());
    }));
    MenuItem wrapItem = new MenuItem(editMenu, SWT.CHECK);
    // $NON-NLS-1$
    wrapItem.setText(getResourceString("Wrap_menuitem"));
    wrapItem.addSelectionListener(widgetSelectedAdapter(event -> {
        MenuItem item = (MenuItem) event.widget;
        boolean enabled = item.getSelection();
        styledText.setWordWrap(enabled);
        editMenu.getItem(6).setEnabled(enabled);
        editMenu.getItem(8).setEnabled(enabled);
        leftAlignmentItem.setEnabled(enabled);
        centerAlignmentItem.setEnabled(enabled);
        rightAlignmentItem.setEnabled(enabled);
        justifyAlignmentItem.setEnabled(enabled);
        blockSelectionItem.setEnabled(!enabled);
    }));
    MenuItem justifyItem = new MenuItem(editMenu, SWT.CHECK);
    // $NON-NLS-1$
    justifyItem.setText(getResourceString("Justify_menuitem"));
    justifyItem.addSelectionListener(widgetSelectedAdapter(event -> {
        MenuItem item = (MenuItem) event.widget;
        styledText.setJustify(item.getSelection());
        updateToolBar();
    }));
    justifyItem.setEnabled(false);
    MenuItem setFontItem = new MenuItem(editMenu, SWT.PUSH);
    // $NON-NLS-1$
    setFontItem.setText(getResourceString("SetFont_menuitem"));
    setFontItem.addSelectionListener(widgetSelectedAdapter(event -> {
        FontDialog fontDialog = new FontDialog(shell);
        fontDialog.setFontList(styledText.getFont().getFontData());
        FontData data = fontDialog.open();
        if (data != null) {
            Font newFont = new Font(display, data);
            styledText.setFont(newFont);
            if (font != null)
                font.dispose();
            font = newFont;
            updateToolBar();
        }
    }));
    MenuItem alignmentItem = new MenuItem(editMenu, SWT.CASCADE);
    // $NON-NLS-1$
    alignmentItem.setText(getResourceString("Alignment_menuitem"));
    Menu alignmentMenu = new Menu(shell, SWT.DROP_DOWN);
    alignmentItem.setMenu(alignmentMenu);
    final MenuItem leftAlignmentItem = new MenuItem(alignmentMenu, SWT.RADIO);
    // $NON-NLS-1$
    leftAlignmentItem.setText(getResourceString("Left_menuitem"));
    leftAlignmentItem.setSelection(true);
    leftAlignmentItem.addSelectionListener(widgetSelectedAdapter(event -> {
        styledText.setAlignment(SWT.LEFT);
        updateToolBar();
    }));
    alignmentItem.setEnabled(false);
    final MenuItem centerAlignmentItem = new MenuItem(alignmentMenu, SWT.RADIO);
    // $NON-NLS-1$
    centerAlignmentItem.setText(getResourceString("Center_menuitem"));
    centerAlignmentItem.addSelectionListener(widgetSelectedAdapter(event -> {
        styledText.setAlignment(SWT.CENTER);
        updateToolBar();
    }));
    MenuItem rightAlignmentItem = new MenuItem(alignmentMenu, SWT.RADIO);
    // $NON-NLS-1$
    rightAlignmentItem.setText(getResourceString("Right_menuitem"));
    rightAlignmentItem.addSelectionListener(widgetSelectedAdapter(event -> {
        styledText.setAlignment(SWT.RIGHT);
        updateToolBar();
    }));
    MenuItem editOrientationItem = new MenuItem(editMenu, SWT.CASCADE);
    // $NON-NLS-1$
    editOrientationItem.setText(getResourceString("Orientation_menuitem"));
    Menu editOrientationMenu = new Menu(shell, SWT.DROP_DOWN);
    editOrientationItem.setMenu(editOrientationMenu);
    MenuItem leftToRightItem = new MenuItem(editOrientationMenu, SWT.RADIO);
    // $NON-NLS-1$
    leftToRightItem.setText(getResourceString("LeftToRight_menuitem"));
    leftToRightItem.addSelectionListener(widgetSelectedAdapter(event -> styledText.setOrientation(SWT.LEFT_TO_RIGHT)));
    leftToRightItem.setSelection(true);
    MenuItem rightToLeftItem = new MenuItem(editOrientationMenu, SWT.RADIO);
    // $NON-NLS-1$
    rightToLeftItem.setText(getResourceString("RightToLeft_menuitem"));
    rightToLeftItem.addSelectionListener(widgetSelectedAdapter(event -> styledText.setOrientation(SWT.RIGHT_TO_LEFT)));
    new MenuItem(editMenu, SWT.SEPARATOR);
    MenuItem insertObjectItem = new MenuItem(editMenu, SWT.CASCADE);
    // $NON-NLS-1$
    insertObjectItem.setText(getResourceString("InsertObject_menuitem"));
    Menu insertObjectMenu = new Menu(shell, SWT.DROP_DOWN);
    insertObjectItem.setMenu(insertObjectMenu);
    MenuItem insertControlItem = new MenuItem(insertObjectMenu, SWT.CASCADE);
    // $NON-NLS-1$
    insertControlItem.setText(getResourceString("Controls_menuitem"));
    Menu controlChoice = new Menu(shell, SWT.DROP_DOWN);
    insertControlItem.setMenu(controlChoice);
    MenuItem buttonItem = new MenuItem(controlChoice, SWT.PUSH);
    // $NON-NLS-1$
    buttonItem.setText(getResourceString("Button_menuitem"));
    MenuItem comboItem = new MenuItem(controlChoice, SWT.PUSH);
    // $NON-NLS-1$
    comboItem.setText(getResourceString("Combo_menuitem"));
    buttonItem.addSelectionListener(widgetSelectedAdapter(event -> {
        Button button = new Button(styledText, SWT.PUSH);
        // $NON-NLS-1$
        button.setText(getResourceString("Button_menuitem"));
        addControl(button);
    }));
    comboItem.addSelectionListener(widgetSelectedAdapter(event -> {
        Combo combo = new Combo(styledText, SWT.NONE);
        // $NON-NLS-1$
        combo.setText(getResourceString("Combo_menuitem"));
        addControl(combo);
    }));
    MenuItem insertImageItem = new MenuItem(insertObjectMenu, SWT.PUSH);
    // $NON-NLS-1$
    insertImageItem.setText(getResourceString("Image_menuitem"));
    insertImageItem.addSelectionListener(widgetSelectedAdapter(event -> {
        FileDialog fileDialog = new FileDialog(shell, SWT.OPEN);
        String fileName = fileDialog.open();
        if (fileName != null) {
            try {
                Image image = new Image(display, fileName);
                addImage(image);
            } catch (Exception e) {
                // $NON-NLS-1$
                showError(getResourceString("Bad_image"), e.getMessage());
            }
        }
    }));
    if (SAMPLE_TEXT) {
        new MenuItem(editMenu, SWT.SEPARATOR);
        MenuItem loadProfileItem = new MenuItem(editMenu, SWT.CASCADE);
        // $NON-NLS-1$
        loadProfileItem.setText(getResourceString("LoadProfile_menuitem"));
        Menu loadProfileMenu = new Menu(shell, SWT.DROP_DOWN);
        loadProfileItem.setMenu(loadProfileMenu);
        SelectionListener adapter = widgetSelectedAdapter(event -> {
            int profile = Integer.parseInt((String) event.widget.getData());
            loadProfile(profile);
        });
        MenuItem profileItem = new MenuItem(loadProfileMenu, SWT.PUSH);
        // $NON-NLS-1$
        profileItem.setText(getResourceString("Profile1_menuitem"));
        // $NON-NLS-1$
        profileItem.setData("1");
        profileItem.addSelectionListener(adapter);
        profileItem = new MenuItem(loadProfileMenu, SWT.PUSH);
        // $NON-NLS-1$
        profileItem.setText(getResourceString("Profile2_menuitem"));
        // $NON-NLS-1$
        profileItem.setData("2");
        profileItem.addSelectionListener(adapter);
        profileItem = new MenuItem(loadProfileMenu, SWT.PUSH);
        // $NON-NLS-1$
        profileItem.setText(getResourceString("Profile3_menuitem"));
        // $NON-NLS-1$
        profileItem.setData("3");
        profileItem.addSelectionListener(adapter);
        profileItem = new MenuItem(loadProfileMenu, SWT.PUSH);
        // $NON-NLS-1$
        profileItem.setText(getResourceString("Profile4_menuitem"));
        // $NON-NLS-1$
        profileItem.setData("4");
        profileItem.addSelectionListener(adapter);
    }
}
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) FontDialog(org.eclipse.swt.widgets.FontDialog) FontData(org.eclipse.swt.graphics.FontData) MenuAdapter(org.eclipse.swt.events.MenuAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) Combo(org.eclipse.swt.widgets.Combo) IOException(java.io.IOException) Image(org.eclipse.swt.graphics.Image) FileInputStream(java.io.FileInputStream) Font(org.eclipse.swt.graphics.Font) MissingResourceException(java.util.MissingResourceException) IOException(java.io.IOException) Point(org.eclipse.swt.graphics.Point) Button(org.eclipse.swt.widgets.Button) Menu(org.eclipse.swt.widgets.Menu) FileDialog(org.eclipse.swt.widgets.FileDialog) MenuEvent(org.eclipse.swt.events.MenuEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

FontDialog (org.eclipse.swt.widgets.FontDialog)9 FontData (org.eclipse.swt.graphics.FontData)7 RGB (org.eclipse.swt.graphics.RGB)5 GridData (org.eclipse.swt.layout.GridData)5 GridLayout (org.eclipse.swt.layout.GridLayout)5 Button (org.eclipse.swt.widgets.Button)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 SelectionListener (org.eclipse.swt.events.SelectionListener)4 ColorDialog (org.eclipse.swt.widgets.ColorDialog)4 Text (org.eclipse.swt.widgets.Text)4 SWT (org.eclipse.swt.SWT)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionListener.widgetSelectedAdapter (org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter)3 Font (org.eclipse.swt.graphics.Font)3 Composite (org.eclipse.swt.widgets.Composite)3 Group (org.eclipse.swt.widgets.Group)3 Label (org.eclipse.swt.widgets.Label)3 ControlEvent (org.eclipse.swt.events.ControlEvent)2 MenuEvent (org.eclipse.swt.events.MenuEvent)2 ModifyEvent (org.eclipse.swt.events.ModifyEvent)2