Example usage for org.eclipse.jface.resource JFaceResources getTextFont

List of usage examples for org.eclipse.jface.resource JFaceResources getTextFont

Introduction

In this page you can find the example usage for org.eclipse.jface.resource JFaceResources getTextFont.

Prototype

public static Font getTextFont() 

Source Link

Document

Returns JFace's text font.

Usage

From source file:org.eclipse.wst.internet.monitor.ui.internal.viewers.HeaderViewer.java

License:Open Source License

/**
 * Create a new header viewer.//w  w  w . j  a va  2s.  co m
 * 
 * @param parent
 * @param message
 */
public HeaderViewer(Composite parent, byte message) {
    displayHeader = true;
    hidden = false;

    headerComp = new Composite(parent, SWT.NONE);
    layout = new MonitorStackLayout();
    headerComp.setLayout(layout);

    headerText = new Text(headerComp, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL);
    Display display = headerComp.getDisplay();
    headerText.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));
    headerText.setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
    headerText.setFont(JFaceResources.getTextFont());
    PlatformUI.getWorkbench().getHelpSystem().setHelp(headerText, ContextIds.VIEW_RESPONSE);

    headerLabel = new Text(headerComp, SWT.READ_ONLY);

    layout.topControl = headerText;

    rr = null;
    msg = message;

    setDisplayHeader(false);
}

From source file:org.eclipse.wst.internet.monitor.ui.internal.viewers.XMLViewer.java

License:Open Source License

/** (non-Javadoc)
 * @see ContentViewer#init(Composite)//  w w  w.  ja  v  a 2s  .  com
 */
public void init(Composite parent) {
    viewerComp = new Composite(parent, SWT.NONE);
    layout = new StackLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    viewerComp.setLayout(layout);

    messageText = new Text(viewerComp, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL);
    Display display = viewerComp.getDisplay();
    messageText.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));
    messageText.setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
    messageText.setFont(JFaceResources.getTextFont());
    messageText.setVisible(true);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(messageText, ContextIds.VIEW_RESPONSE);

    messageLabel = new Label(viewerComp, SWT.NONE);
    messageLabel.setVisible(false);

    layout.topControl = messageText;
}

From source file:org.eclipse.wst.sse.ui.internal.preferences.ui.StyledTextColorPicker.java

License:Open Source License

protected void createControls(Composite parent) {
    Composite styleRow = createComposite(parent, 3);
    // row 1 - content type label, combo box, restore defaults
    createLabel(styleRow, SSEUIMessages.Content_type__UI_); //$NON-NLS-1$ = "Content type:"
    // Contexts combo box
    fStyleCombo = createCombo(styleRow, new String[0], -1);
    fClearStyle = createPushButton(styleRow, SSEUIMessages.Restore_Default_UI_); //$NON-NLS-1$ = "Restore Default"
    Composite styleRow2;/*from www. ja  va  2  s.c o  m*/
    if (showItalic)
        styleRow2 = createComposite(parent, 7);
    else
        styleRow2 = createComposite(parent, 6);
    // row 2 - foreground label, button, background label, button, bold,
    // italics?
    fForegroundLabel = createLabel(styleRow2, SSEUIMessages.Foreground_UI_); //$NON-NLS-1$ = "Foreground"
    fForeground = new ColorSelector(styleRow2);
    fForeground.getButton().setLayoutData(new GridData());
    setAccessible(fForeground.getButton(), fForegroundLabel.getText());
    fForeground.getButton().getAccessible().addAccessibleControlListener(foregroundAccListener); // defect
    // 200764
    // -
    // ACC:display
    // values
    // for
    // color
    // buttons
    ((GridData) fForeground.getButton().getLayoutData()).minimumWidth = 20;
    fBackgroundLabel = createLabel(styleRow2, SSEUIMessages.Background_UI_); //$NON-NLS-1$ = "Background"
    fBackground = new ColorSelector(styleRow2);
    fBackground.getButton().setLayoutData(new GridData());
    setAccessible(fBackground.getButton(), fBackgroundLabel.getText());
    fBackground.getButton().getAccessible().addAccessibleControlListener(backgroundAccListener); // defect
    // 200764
    // -
    // ACC:display
    // values
    // for
    // color
    // buttons
    ((GridData) fBackground.getButton().getLayoutData()).minimumWidth = 20;
    createLabel(styleRow2, ""); //$NON-NLS-1$
    fBold = createCheckBox(styleRow2, SSEUIMessages.Bold_UI_);
    if (showItalic)
        fItalic = createCheckBox(styleRow2, SSEUIMessages.Italics_UI);
    //      // Defaults checkbox
    fForeground.setEnabled(false);
    fBackground.setEnabled(false);
    fClearStyle.setEnabled(false);
    fBold.setEnabled(false);
    if (showItalic)
        fItalic.setEnabled(false);
    fForegroundLabel.setEnabled(false);
    fBackgroundLabel.setEnabled(false);
    Composite sample = createComposite(parent, 1);
    createLabel(sample, SSEUIMessages.Sample_text__UI_); //$NON-NLS-1$ = "&Sample text:"
    // BUG141089 - make sure text is left-aligned
    fText = new StyledText(sample,
            SWT.LEFT_TO_RIGHT | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.READ_ONLY);
    GridData data = new GridData(GridData.FILL_BOTH);
    fText.setLayoutData(data);
    fText.setEditable(false);
    fText.setBackground(fDefaultBackground);
    fText.setFont(JFaceResources.getTextFont());
    fText.addKeyListener(getTextKeyListener());
    fText.addSelectionListener(getTextSelectionListener());
    fText.addMouseListener(getTextMouseListener());
    fText.addTraverseListener(getTraverseListener()); // defect 220377 -
    // Provide tab
    // traversal for
    // fText widget
    setAccessible(fText, SSEUIMessages.Sample_text__UI_); //$NON-NLS-1$ = "&Sample text:"
    fForeground.addListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(ColorSelector.PROP_COLORCHANGE)) {
                // get current (newly old) style
                String namedStyle = getStyleName(fStyleCombo.getItem(fStyleCombo.getSelectionIndex()));
                String prefString = getPreferenceStore().getString(namedStyle);
                String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
                if (stylePrefs != null) {
                    String oldValue = stylePrefs[0];
                    String newValue = "null"; //$NON-NLS-1$
                    Object newValueObject = event.getNewValue();
                    if (newValueObject instanceof RGB) {
                        newValue = ColorHelper.toRGBString((RGB) newValueObject);
                    }

                    if (!newValue.equals(oldValue)) {
                        stylePrefs[0] = newValue;
                        String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                        getPreferenceStore().setValue(namedStyle, newPrefString);
                        refresh();
                    }
                }
            }
        }
    });
    fBackground.addListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(ColorSelector.PROP_COLORCHANGE)) {
                // get current (newly old) style
                String namedStyle = getStyleName(fStyleCombo.getItem(fStyleCombo.getSelectionIndex()));
                String prefString = getPreferenceStore().getString(namedStyle);
                String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
                if (stylePrefs != null) {
                    String oldValue = stylePrefs[1];

                    String newValue = "null"; //$NON-NLS-1$
                    Object newValueObject = event.getNewValue();
                    if (newValueObject instanceof RGB) {
                        newValue = ColorHelper.toRGBString((RGB) newValueObject);
                    }

                    if (!newValue.equals(oldValue)) {
                        stylePrefs[1] = newValue;
                        String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                        getPreferenceStore().setValue(namedStyle, newPrefString);
                        refresh();
                    }
                }
            }
        }
    });

    fClearStyle.addSelectionListener(buttonListener);
    fBold.addSelectionListener(buttonListener);
    if (showItalic)
        fItalic.addSelectionListener(buttonListener);
    fStyleCombo.addSelectionListener(comboListener);
}

From source file:org.eclipse.wst.sse.ui.internal.preferences.ui.StyledTextColorPicker.java

License:Open Source License

public void refresh() {
    fText.setRedraw(false);// w ww  . j a  v  a 2  s.c  om
    int selectedIndex = fStyleCombo.getSelectionIndex();
    String description = selectedIndex >= 0 ? fStyleCombo.getItem(selectedIndex) : null;
    activate(getStyleName(description));
    // update Font
    fText.setFont(JFaceResources.getTextFont());
    // reapplyStyles
    applyStyles();
    fText.setRedraw(true);
}

From source file:org.eclipse.xtext.builder.trace.TraceEditor.java

License:Open Source License

@Override
protected Composite createPageContainer(final Composite parent) {
    Composite tree = new Composite(parent, SWT.NONE);
    final Sash sash = new Sash(parent, SWT.HORIZONTAL);
    text = new StyledText(parent, SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
    text.setFont(JFaceResources.getTextFont());

    final FormLayout form = new FormLayout();
    parent.setLayout(form);/* ww  w . j av a2  s  .com*/

    FormData treeData = new FormData();
    treeData.left = new FormAttachment(0, 0);
    treeData.right = new FormAttachment(100, 0);
    treeData.top = new FormAttachment(0, 0);
    treeData.bottom = new FormAttachment(sash, 0);
    tree.setLayoutData(treeData);

    final int limit = 20, percent = 50;
    final FormData sashData = new FormData();
    sashData.left = new FormAttachment(0, 0);
    sashData.top = new FormAttachment(percent, 0);
    sashData.right = new FormAttachment(100, 0);
    sash.setLayoutData(sashData);
    sash.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event e) {
            Rectangle sashRect = sash.getBounds();
            Rectangle parentRect = parent.getClientArea();
            int bottom = parentRect.height - sashRect.height - limit;
            e.y = Math.max(Math.min(e.y, bottom), limit);
            if (e.y != sashRect.y) {
                sashData.top = new FormAttachment(0, e.y);
                parent.layout();
            }
        }
    });
    FormData textData = new FormData();
    textData.left = new FormAttachment(0, 0);
    textData.right = new FormAttachment(100, 0);
    textData.top = new FormAttachment(sash, 0);
    textData.bottom = new FormAttachment(100, 0);
    text.setLayoutData(textData);
    addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (selection instanceof IStructuredSelection) {
                try {
                    Object x = ((IStructuredSelection) selection).getFirstElement();
                    if (x instanceof EObject)
                        updateText((EObject) x);
                    if (x instanceof Resource)
                        updateText(((Resource) x).getContents().get(0));
                } catch (Exception e) {
                    text.setText(Throwables.getStackTraceAsString(e));
                }
            }
        }
    });
    return tree;
}

From source file:org.eclipse.xtext.ui.editor.syntaxcoloring.PreferenceStoreAccessor.java

License:Open Source License

public void populateTextStyle(String id, TextStyle style, TextStyle defaults) {
    IPreferenceStore editorsStore = EditorsUI.getPreferenceStore();
    RGB fontColorDefaultDefault = editorsStore
            .getBoolean(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT)
                    ? getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB()
                    : PreferenceConverter.getColor(editorsStore,
                            AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND);
    RGB backgrounColorDefaultDefault = editorsStore
            .getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)
                    ? getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB()
                    : PreferenceConverter.getColor(editorsStore,
                            AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);
    FontData[] fontDataDefaultDefault = JFaceResources.getTextFont().getFontData();

    IPreferenceStore preferenceStore = getPreferenceStore();
    String cssID = CSS_PREFIX + id;
    IPreferenceStore cssPrefStore = getPluginCssPreferenceStore();

    String colorKey = PREFERENCE_TAG + getTokenColorPreferenceKey(id);
    String cssFontColor = cssPrefStore.getString(getTokenColorPreferenceKey(cssID));
    if (!Strings.isEmpty(cssFontColor)) {
        preferenceStore.setDefault(colorKey, cssFontColor);
    } else if (defaults.getColor() != null) {
        PreferenceConverter.setDefault(preferenceStore, colorKey, defaults.getColor());
    } else {//from  w  w  w.j a  va  2s.co  m
        PreferenceConverter.setDefault(preferenceStore, colorKey, fontColorDefaultDefault);
    }

    String backgroundKey = PREFERENCE_TAG + getTokenBackgroundColorPreferenceKey(id);
    String cssBgColor = cssPrefStore.getString(getTokenBackgroundColorPreferenceKey(cssID));
    if (!Strings.isEmpty(cssBgColor)) {
        preferenceStore.setDefault(backgroundKey, cssBgColor);
    } else if (defaults.getBackgroundColor() != null) {
        PreferenceConverter.setDefault(preferenceStore, backgroundKey, defaults.getBackgroundColor());
    } else {
        PreferenceConverter.setDefault(preferenceStore, backgroundKey, backgrounColorDefaultDefault);
    }

    String fontKey = PREFERENCE_TAG + getTokenFontPreferenceKey(id);
    String cssFont = cssPrefStore.getString(getTokenFontPreferenceKey(cssID));
    if (!Strings.isEmpty(cssFont)) {
        preferenceStore.setDefault(fontKey, cssFont);
    } else if (defaults.getFontData() != null)
        PreferenceConverter.setDefault(preferenceStore, fontKey, defaults.getFontData());
    else {
        PreferenceConverter.setDefault(preferenceStore, fontKey, fontDataDefaultDefault);
    }

    String styleKey = PREFERENCE_TAG + getTokenStylePreferenceKey(id);
    int cssStyle = cssPrefStore.getInt(getTokenStylePreferenceKey(cssID));
    if (cssStyle != 0) {
        preferenceStore.setDefault(styleKey, cssStyle);
    } else {
        preferenceStore.setDefault(styleKey, defaults.getStyle());
    }

    // populate
    RGB color = PreferenceConverter.getColor(preferenceStore, colorKey);
    if (!color.equals(fontColorDefaultDefault))
        style.setColor(color);
    RGB background = PreferenceConverter.getColor(preferenceStore, backgroundKey);
    if (!background.equals(backgrounColorDefaultDefault))
        style.setBackgroundColor(background);
    FontData[] fontDataArray = PreferenceConverter.getFontDataArray(preferenceStore, fontKey);
    if (!Arrays.equals(fontDataArray, fontDataDefaultDefault)) {
        style.setFontData(fontDataArray);
    }
    style.setStyle(preferenceStore.getInt(styleKey));
}

From source file:org.ejs.gui.properties.ListPropertyEditor.java

License:Open Source License

/**
 * @param composite//from w  w  w.j a  v a  2s .  c o  m
 */
private void createList(Composite parent) {
    Composite composite = new Composite(parent, SWT.BORDER_DOT);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite);
    //GridDataFactory.fillDefaults().grab(true, true).minSize(100,-1).applyTo(composite);
    GridDataFactory.fillDefaults().grab(true, true).minSize(50, -1).applyTo(composite);

    viewer = new ListViewer(composite);
    GridDataFactory.fillDefaults().grab(true, true).span(1, 4).applyTo(viewer.getControl());
    //GridDataFactory.swtDefaults().span(1, 4).applyTo(viewer.getControl());

    if (property.getElementClassFactory() != null) {
        FontDescriptor desc = FontUtils.getFontDescriptor(JFaceResources.getTextFont());
        desc = desc.setHeight(8);
        final Font smallFont = desc.createFont(parent.getShell().getDisplay());

        parent.addDisposeListener(new DisposeListener() {
            /* (non-Javadoc)
             * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
             */
            public void widgetDisposed(DisposeEvent e) {
                smallFont.dispose();
            }
        });

        final Button addButton = new Button(composite, SWT.PUSH);
        addButton.setFont(smallFont);
        GridDataFactory.swtDefaults().minSize(50, -1).applyTo(addButton);
        addButton.setText("+");
        addButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                addNewElement(addButton, property.getElementClassFactory());
            }
        });

        final Button removeButton = new Button(composite, SWT.PUSH);
        removeButton.setFont(smallFont);
        GridDataFactory.swtDefaults().minSize(50, -1).applyTo(removeButton);
        removeButton.setText("-");
        removeButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                if (currentElement != null) {
                    property.getList().remove(currentElement);
                    viewer.remove(currentElement);
                    updateList();
                }
            }
        });

        final Button upButton = new Button(composite, SWT.PUSH);
        upButton.setFont(smallFont);
        GridDataFactory.swtDefaults().minSize(50, -1).applyTo(upButton);
        upButton.setText("");
        upButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                if (currentElement != null) {
                    List<Object> list = property.getList();
                    int index = list.indexOf(currentElement);
                    if (index > 0) {
                        Object el = list.remove(index - 1);
                        list.add(index, el);
                    }
                    viewer.refresh();
                    updateList();
                }
            }
        });

        final Button downButton = new Button(composite, SWT.PUSH);
        downButton.setFont(smallFont);
        GridDataFactory.swtDefaults().minSize(50, -1).applyTo(downButton);
        downButton.setText("");
        downButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                if (currentElement != null) {
                    List<Object> list = property.getList();
                    int index = list.indexOf(currentElement);
                    if (index < list.size()) {
                        Object el = list.remove(index + 1);
                        list.add(index, el);
                    }
                    viewer.refresh();
                    updateList();
                }
            }
        });
        viewer.addSelectionChangedListener(new ISelectionChangedListener() {

            public void selectionChanged(SelectionChangedEvent event) {
                Object el = ((IStructuredSelection) event.getSelection()).getFirstElement();
                removeButton.setEnabled(el != null);
            }

        });
    }

    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            Object el = ((IStructuredSelection) event.getSelection()).getFirstElement();
            currentElement = el;
            updateEditor();
        }

    });

    viewer.setLabelProvider(new LabelProvider() {
        /* (non-Javadoc)
         * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
         */
        @Override
        public String getText(Object element) {
            if (element instanceof IPropertyEditorProvider)
                return ((IPropertyEditorProvider) element).getLabel(property);
            return super.getText(element);
        }
    });
    viewer.setContentProvider(new ArrayContentProvider());
    List<Object> list = property.getList();
    viewer.setInput(list);
    if (list != null && list.size() > 0) {
        Object el = list.get(0);
        viewer.setSelection(new StructuredSelection(el));
    }

}

From source file:org.emftext.language.dbschema.resource.dbschema.ui.DbschemaConnectionParameterPage.java

License:Open Source License

public void createControl(Composite parent) {
    Listener changeListener = new Listener() {

        public void handleEvent(Event event) {
            update();/* w w  w  .ja v a2  s.  c om*/
        }
    };

    Composite container = new Composite(parent, SWT.FILL);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);
    layout.numColumns = 1;
    //layout.verticalSpacing = 9;
    GridData gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    container.setLayoutData(gd);

    Group keywordGroup = createGroup(container, "Select creation method", 1);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    //gd.grabExcessVerticalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    keywordGroup.setLayoutData(gd);

    Button button1 = new Button(keywordGroup, SWT.RADIO);
    button1.setText("&Create empty database schema");
    button1.addListener(SWT.Selection, changeListener);

    selectImportButton = new Button(keywordGroup, SWT.RADIO);
    selectImportButton.setText("&Import database schema using JDBC");
    selectImportButton.addListener(SWT.Selection, changeListener);
    selectImportButton.setSelection(false);
    button1.setSelection(true);

    Composite parameterContainer = new Composite(keywordGroup, SWT.NULL);
    layout = new GridLayout();
    layout.numColumns = 2;
    parameterContainer.setLayout(layout);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    parameterContainer.setLayoutData(gd);

    Label label1 = new Label(parameterContainer, SWT.NULL);
    label1.setText("JDBC driver class");
    driverText = new Text(parameterContainer, SWT.BORDER);
    driverText.setText("com.mysql.jdbc.Driver");
    driverText.addListener(SWT.Modify, changeListener);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    driverText.setLayoutData(gd);

    Label label2 = new Label(parameterContainer, SWT.NULL);
    label2.setText("JDBC connection string");
    connnectionText = new Text(parameterContainer, SWT.BORDER);
    connnectionText.setText("jdbc:mysql://localhost/mySchema");
    connnectionText.addListener(SWT.Modify, changeListener);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    connnectionText.setLayoutData(gd);

    Label label3 = new Label(parameterContainer, SWT.NULL);
    label3.setText("JDBC database name");
    databaseText = new Text(parameterContainer, SWT.BORDER);
    databaseText.setText("mySchema");
    databaseText.addListener(SWT.Modify, changeListener);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    databaseText.setLayoutData(gd);

    Label label4 = new Label(parameterContainer, SWT.NULL);
    label4.setText("JDBC user");
    userText = new Text(parameterContainer, SWT.BORDER);
    userText.setText("user");
    userText.addListener(SWT.Modify, changeListener);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    userText.setLayoutData(gd);

    Label label5 = new Label(parameterContainer, SWT.NULL);
    label5.setText("JDBC passwort");
    passwordText = new Text(parameterContainer, SWT.BORDER | SWT.PASSWORD);
    passwordText.setText("pass");
    passwordText.addListener(SWT.Modify, changeListener);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    passwordText.setLayoutData(gd);

    Group previewGroup = createGroup(container, "Preview", 1);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.verticalAlignment = SWT.FILL;
    gd.horizontalAlignment = SWT.FILL;
    previewGroup.setLayoutData(gd);

    sourceViewer = new SourceViewer(previewGroup, null,
            SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
    sourceViewer.getTextWidget().setFont(JFaceResources.getTextFont());
    sourceViewer.setDocument(new Document());
    sourceViewer.getTextWidget().setLayoutData(gd);
    colorManager = new DbschemaColorManager();
    sourceViewer.configure(new DbschemaSourceViewerConfiguration(this, null, null, colorManager));

    setControl(container);
    update();
}

From source file:org.emftext.sdk.ui.wizards.CustomSyntaxPage.java

License:Open Source License

public void createControl(Composite parent) {
    Composite composite = createComposite(parent, 2);

    GridLayout gl = new GridLayout();
    Composite viewer = new Composite(composite, SWT.NONE);
    GridData gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;/*from   w  w  w  . j a v  a2 s.c o m*/
    gd.verticalAlignment = SWT.FILL;
    gd.horizontalAlignment = SWT.FILL;
    gd.horizontalSpan = 2;
    viewer.setLayoutData(gd);
    viewer.setLayout(gl);

    sourceViewer = new SourceViewer(viewer, null, SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
    sourceViewer.getTextWidget().setFont(JFaceResources.getTextFont());
    sourceViewer.setDocument(new Document());
    sourceViewer.getTextWidget().setLayoutData(gd);
    csColorManager = new CsColorManager();
    sourceViewer.configure(new CsSourceViewerConfiguration(this, null, csColorManager));

    Listener changeListener = new Listener() {

        public void handleEvent(Event event) {
            update();
        }
    };

    createKeywordsGroup(composite, changeListener);
    createFeatureQualificationGroup(composite, changeListener);
    createCommentsGroup(composite, changeListener);
    createFeatureOptionsGroup(composite, changeListener);
    createAttributeGroup(composite, changeListener);
    createIdentifiersGroup(composite, changeListener);
    createImportsGroup(composite, changeListener);

    setControl(composite);
    setPageComplete(true);

    update();
}

From source file:org.erlide.ui.console.ErlangConsolePage.java

License:Open Source License

/**
 * @wbp.parser.entryPoint/*w  w w .  ja va 2  s  .  com*/
 */
@Override
public void createControl(final Composite parent) {
    composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));

    final SashForm sashForm = new SashForm(composite, SWT.VERTICAL);
    sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    consoleOutputViewer = new SourceViewer(sashForm, null,
            SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.READ_ONLY);
    consoleText = (StyledText) consoleOutputViewer.getControl();
    consoleText.setFont(JFaceResources.getTextFont());
    consoleText.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(final KeyEvent e) {
            if (fConsole.isStopped()) {
                return;
            }
            final boolean isHistoryCommand = (e.stateMask & SWT.CTRL) == SWT.CTRL
                    && (e.keyCode == SWT.ARROW_UP || e.keyCode == SWT.ARROW_DOWN);
            if (e.character != (char) 0 || isHistoryCommand) {
                e.doit = false;
            }
        }

    });
    consoleText.addFocusListener(new FocusListener() {
        @Override
        public void focusLost(final FocusEvent e) {
        }

        @Override
        public void focusGained(final FocusEvent e) {
            consoleInput.setFocus();
        }
    });
    consoleOutputViewer.setDocument(fDoc);
    consoleOutputViewer.configure(new ErlangConsoleSourceViewerConfiguration());

    consoleInputViewer = new SourceViewer(sashForm, null, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
    consoleInputViewer.setDocument(new Document());
    consoleInputViewer.configure(new ErlangConsoleSourceViewerConfiguration());
    consoleInput = (StyledText) consoleInputViewer.getControl();

    sashForm.setWeights(new int[] { 2, 1 });

    final Label helpLabel = new Label(composite, SWT.NONE);
    helpLabel.setText("Press Ctrl-Enter to send the input to the console. Press Esc to clear input.");
    helpLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    consoleInput.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(final KeyEvent e) {
            final boolean ctrlPressed = (e.stateMask & SWT.CTRL) == SWT.CTRL;
            if (e.keyCode == 13 && ctrlPressed && isInputComplete()) {
                sendInput();
                e.doit = true;
            } else if (ctrlPressed && e.keyCode == SWT.ARROW_UP) {
                history.prev();
                final String s = history.get();
                if (s != null) {
                    consoleInput.setText(s);
                    consoleInput.setSelection(consoleInput.getText().length());
                }
            } else if (ctrlPressed && e.keyCode == SWT.ARROW_DOWN) {
                history.next();
                final String s = history.get();
                if (s != null) {
                    consoleInput.setText(s);
                    consoleInput.setSelection(consoleInput.getText().length());
                }
            } else if (e.keyCode == SWT.ESC) {
                consoleInput.setText("");
            }
        }
    });
    consoleInput.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(final ModifyEvent e) {
            if (isInputComplete()) {
                consoleInput.setBackground(bgColor_Ok);
            } else {
                final Color bgColorErr = bgColor_Err;
                consoleInput.setBackground(bgColorErr);
            }
        }
    });
    consoleInput.setFont(consoleText.getFont());
    consoleInput.setBackground(consoleText.getBackground());
    consoleInput.setWordWrap(true);
    consoleInput.setFocus();

    // end layout

    final IDocumentListener documentListener = new IDocumentListener() {
        @Override
        public void documentAboutToBeChanged(final DocumentEvent event) {
        }

        @Override
        public void documentChanged(final DocumentEvent event) {
            final int end = consoleOutputViewer.getDocument().getLength();
            consoleOutputViewer.setSelectedRange(end, end);
            consoleOutputViewer.revealRange(end, 0);
        }
    };
    fDoc.addDocumentListener(documentListener);

    final String id = "#ContextMenu"; //$NON-NLS-1$
    // if (getConsole().getType() != null) {
    //         id = getConsole().getType() + "." + id; //$NON-NLS-1$
    // }
    fMenuManager = new MenuManager("#ContextMenu", id); //$NON-NLS-1$
    fMenuManager.setRemoveAllWhenShown(true);
    fMenuManager.addMenuListener(new IMenuListener() {
        @Override
        public void menuAboutToShow(final IMenuManager m) {
            contextMenuAboutToShow(m);
        }
    });
    final Menu menu = fMenuManager.createContextMenu(getControl());
    getControl().setMenu(menu);

    createActions();
    configureToolBar(getSite().getActionBars().getToolBarManager());

    getSite().registerContextMenu(id, fMenuManager, consoleOutputViewer);
    getSite().setSelectionProvider(consoleOutputViewer);
    consoleOutputViewer.getSelectionProvider().addSelectionChangedListener(selectionChangedListener);

}