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:at.bestsolution.efxclipse.tooling.ui.preview.LivePreviewPart.java

License:Open Source License

@Override
public void createPartControl(final Composite parent) {
    final Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new GridLayout(3, false));

    folder = new CTabFolder(container, SWT.BOTTOM | SWT.BORDER);
    folder.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 3, 1));

    parent.getDisplay().asyncExec(new Runnable() {

        @Override//w w w .  j  a v a 2 s .  c o  m
        public void run() {

            {
                CTabItem item = new CTabItem(folder, SWT.NONE);

                item.setText("Preview");
                item.setImage(JFaceResources.getImage(IMAGE_PREVIEW));

                swtFXContainer = new FXCanvas(folder, SWT.NONE);
                swtFXContainer.setEnabled(false);

                item.setControl(swtFXContainer);

                rootPane_new = new BorderPane();
                Scene scene = new Scene((Parent) rootPane_new, 1000, 1000);
                currentScene = scene;
                swtFXContainer.setScene(scene);
            }

            {
                logItem = new CTabItem(folder, SWT.NONE);
                logItem.setText("Error log");
                logItem.setImage(JFaceResources.getImage(IMAGE_OK));

                logStatement = new Text(folder, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
                logStatement.setEditable(false);
                logItem.setControl(logStatement);

                Menu m = new Menu(logStatement);
                logStatement.setMenu(m);
                MenuItem clearItem = new MenuItem(m, SWT.PUSH);
                clearItem.setText("Clear Log");
                clearItem.addSelectionListener(new SelectionAdapter() {
                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        logStatement.setText("");
                    }
                });
            }

            {
                CTabItem fxmlContent = new CTabItem(folder, SWT.NONE);
                fxmlContent.setText("FXML-Source");
                fxmlContent.setImage(JFaceResources.getImage(IMAGE_FXML_CONTENT));

                final AnnotationModel model = new AnnotationModel();
                VerticalRuler verticalRuler = new VerticalRuler(VERTICAL_RULER_WIDTH, new AnnotationAccess());
                int styles = SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION;
                SourceViewer sourceViewer = new SourceViewer(folder, verticalRuler, styles);
                sourceViewer.configure(new XMLConfiguration(new ColorManager()));
                sourceViewer.setEditable(false);
                sourceViewer.getTextWidget().setFont(JFaceResources.getTextFont());

                document = new Document();
                IDocumentPartitioner partitioner = new FastPartitioner(new XMLPartitionScanner(),
                        new String[] { XMLPartitionScanner.XML_TAG, XMLPartitionScanner.XML_COMMENT });
                partitioner.connect(document);
                document.setDocumentPartitioner(partitioner);
                sourceViewer.setDocument(document);
                verticalRuler.setModel(model);
                fxmlContent.setControl(sourceViewer.getControl());
            }

            folder.setSelection(0);

            statusLabelIcon = new Label(container, SWT.NONE);
            statusLabelIcon.setImage(JFaceResources.getImage(IMAGE_STATUS_NOPREVIEW));

            statusLabelText = new Label(container, SWT.NONE);
            statusLabelText.setText(NO_PREVIEW_TEXT);
            statusLabelText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

            Composite scaleControl = new Composite(container, SWT.NONE);
            scaleControl.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
            scaleControl.setLayout(new GridLayout(2, false));

            Label l = new Label(scaleControl, SWT.NONE);
            l.setText("Zoom");

            scale = new Spinner(scaleControl, SWT.BORDER);
            scale.setMinimum(10);
            scale.setMaximum(500);
            scale.setIncrement(10);
            scale.setSelection(100);
            scale.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    rootPane_new.setScaleX(scale.getSelection() / 100.0);
                    rootPane_new.setScaleY(scale.getSelection() / 100.0);
                    if (currentFile != null) {
                        scaleMap.put(currentFile, scale.getSelection());
                    }
                }
            });

            parent.layout(true, true);

            if (currentData != null) {
                refreshContent(currentData);
            }
        }
    });

    parent.layout(true, true);

    Action loadController = new Action("", IAction.AS_CHECK_BOX) {
        @Override
        public void run() {
            preference.putBoolean(PREF_LOAD_CONTROLLER, !preference.getBoolean(PREF_LOAD_CONTROLLER, false));
            try {
                preference.flush();
                synchronizer.refreshPreview();
            } catch (BackingStoreException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    };
    loadController.setChecked(preference.getBoolean(PREF_LOAD_CONTROLLER, false));
    loadController.setImageDescriptor(JFaceResources.getImageRegistry().getDescriptor(IMAGE_LOAD_CONTROLLER));
    loadController.setToolTipText("Load the controller");

    Action refresh = new Action("", JFaceResources.getImageRegistry().getDescriptor(IMAGE_REFRESH)) {
        @Override
        public void run() {
            synchronizer.refreshPreview();
        }
    };
    refresh.setToolTipText("Force a refresh");

    getViewSite().getActionBars().getToolBarManager().add(refresh);
    getViewSite().getActionBars().getToolBarManager().add(loadController);
}

From source file:br.com.tecsinapse.glimpse.views.ReplView.java

License:Apache License

@Override
public void createPartControl(Composite parent) {
    SashForm split = new SashForm(parent, SWT.VERTICAL);
    split.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_GRAY));

    Font font = JFaceResources.getTextFont();

    console = new StyledText(split, SWT.V_SCROLL | SWT.WRAP);
    console.setFont(font);/*w  w w  . ja v a 2  s.c o  m*/
    console.setEditable(false);
    resetConsole();

    command = new StyledText(split, SWT.V_SCROLL | SWT.WRAP);
    command.setFont(font);
    command.addVerifyKeyListener(new VerifyKeyListener() {

        @Override
        public void verifyKey(VerifyEvent e) {
            if (e.stateMask == SWT.CTRL && (e.keyCode == SWT.LF || e.keyCode == SWT.CR)) {
                e.doit = false;

                DisplayUtil.asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        checkPreferencesStillValid();
                        if (repl == null) {
                            repl = replManager.createRepl();
                            resetConsole();
                        }
                        String exp = command.getText();
                        command.setEnabled(false);
                        ExpressionEvaluator evaluator = new ExpressionEvaluator(exp);
                        executor.execute(evaluator);
                    }
                });
            }
        }
    });
}

From source file:cc.warlock.rcp.ui.style.DefaultStyleProvider.java

License:Open Source License

public StyleRangeWithData getStyleRange(IWarlockStyle style) {
    StyleRangeWithData range = new StyleRangeWithData();
    range.fontStyle = SWT.NORMAL;/*from w w w .j a v a2s  . co m*/

    for (IWarlockStyle.StyleType styleType : style.getStyleTypes()) {
        if (styleType == null)
            continue;

        if (styleType.equals(IWarlockStyle.StyleType.BOLD))
            range.fontStyle |= SWT.BOLD;
        else if (styleType.equals(IWarlockStyle.StyleType.ITALIC))
            range.fontStyle |= SWT.ITALIC;
        else if (styleType.equals(IWarlockStyle.StyleType.UNDERLINE)
                || styleType.equals(IWarlockStyle.StyleType.LINK))
            range.underline = true;
        else if (styleType.equals(IWarlockStyle.StyleType.MONOSPACE)) {
            WarlockFont font = client.getClientSettings().getMainWindowSettings().getColumnFont();
            if (!font.isDefaultFont()
                    && Display.getDefault().getFontList(font.getFamilyName(), true).length > 0) {
                range.font = FontUtil.warlockFontToFont(font);
            } else {
                range.font = JFaceResources.getTextFont();
            }
        }
    }

    WarlockColor foreground = style.getForegroundColor();
    WarlockColor background = style.getBackgroundColor();
    if (foreground != null && !foreground.isDefault())
        range.foreground = ColorUtil.warlockColorToColor(foreground);
    if (background != null && !background.isDefault())
        range.background = ColorUtil.warlockColorToColor(background);

    return range;
}

From source file:com.aptana.git.ui.dialogs.CreatePullRequestDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);

    // --- Overview of the two endpoints this PR is for
    Composite overview = new Composite(composite, SWT.NONE);
    overview.setLayout(GridLayoutFactory.fillDefaults().numColumns(5).create());

    // icon//w w w  .java2 s. co m
    Label icon = new Label(overview, SWT.NONE);
    icon.setImage(GitUIPlugin.getImage("icons/obj16/pull_request.gif")); //$NON-NLS-1$

    Color lightBlue = ThemePlugin.getDefault().getColorManager().getColor(new RGB(209, 227, 237));
    // base
    baseRepoCombo = new Combo(overview, SWT.DROP_DOWN | SWT.READ_ONLY);
    baseRepoCombo.setFont(JFaceResources.getTextFont());
    baseRepoCombo.setBackground(lightBlue);
    List<String> names = CollectionsUtil.map(repos, new IMap<IGithubRepository, String>() {
        public String map(IGithubRepository item) {
            return item.getFullName();
        }
    });
    baseRepoCombo.setItems(names.toArray(new String[names.size()]));
    baseRepoCombo.setText(baseRepo.getFullName());
    baseRepoCombo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            final String repoOwnerAndName = baseRepoCombo.getText();
            // Get the repo out of some map?
            baseRepo = CollectionsUtil.find(repos, new IFilter<IGithubRepository>() {
                public boolean include(IGithubRepository item) {
                    return item.getFullName().equals(repoOwnerAndName);
                }
            });
            baseBranch = baseRepo.getDefaultBranch();

            // Reload the branches in the branch combo!
            Set<String> branches = baseRepo.getBranches();
            baseBranchCombo.setItems(branches.toArray(new String[branches.size()]));
            baseBranchCombo.setText(baseBranch);
        }
    });

    // FIXME Use toolbars so we want maintain the blue bg?
    baseBranchCombo = new Combo(overview, SWT.DROP_DOWN | SWT.READ_ONLY);
    baseBranchCombo.setFont(JFaceResources.getTextFont());
    baseBranchCombo.setBackground(lightBlue);

    baseBranchCombo.setItems(new String[] { baseBranch });
    baseBranchCombo.setText(baseBranch);
    // We need to set the items to be the list of branches on the base repo
    Display.getCurrent().asyncExec(new Runnable() {
        public void run() {
            Set<String> branches = baseRepo.getBranches();
            baseBranchCombo.setItems(branches.toArray(new String[branches.size()]));
            baseBranchCombo.setText(baseBranch);
        }
    });
    baseBranchCombo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            baseBranch = baseBranchCombo.getText();
        }
    });

    // ...
    Label ellipsis = new Label(overview, SWT.WRAP);
    ellipsis.setText(" ... "); //$NON-NLS-1$
    ellipsis.setFont(JFaceResources.getTextFont());
    ellipsis.setEnabled(false);

    // head
    Label headLabel = new Label(overview, SWT.WRAP);
    headLabel.setText(head);
    headLabel.setFont(JFaceResources.getTextFont());
    headLabel.setBackground(lightBlue);

    // ------- END OVERVIEW --------------------------

    // Title
    Label titleLabel = new Label(composite, SWT.WRAP);
    titleLabel.setText(Messages.CreatePullRequestDialog_TitleFieldLabel);
    GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL
            | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
    data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
    titleLabel.setLayoutData(data);
    titleLabel.setFont(parent.getFont());

    titleText = new Text(composite, SWT.SINGLE | SWT.BORDER);
    titleText.setText(title);
    titleText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
    titleText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            title = titleText.getText();
            validate();
        }
    });

    // Body
    Label label = new Label(composite, SWT.NONE);
    label.setText(Messages.CreatePullRequestDialog_BodyFieldLabel);

    bodyText = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    bodyText.setText(body);
    GridDataFactory.fillDefaults().hint(400, 300).applyTo(bodyText);
    bodyText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            body = bodyText.getText();
            validate();
        }
    });
    return composite;
}

From source file:com.aptana.ide.debug.internal.ui.preferences.JSDetailFormattersPreferencePage.java

License:Open Source License

private Control createFormattersList(Composite parent) {
    Font font = parent.getFont();
    listLabel = new Label(parent, SWT.NONE);
    listLabel.setText(Messages.JSDetailFormattersPreferencePage_TypesWithDetailFormatters);
    GridDataFactory.swtDefaults().span(2, 1).applyTo(listLabel);
    listLabel.setFont(font);//w  ww  .j  a  va  2 s.c o m

    listViewer = CheckboxTableViewer.newCheckList(parent,
            SWT.CHECK | SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    Table table = (Table) listViewer.getControl();
    GridDataFactory.fillDefaults().grab(true, true).hint(convertWidthInCharsToPixels(10), SWT.DEFAULT)
            .applyTo(table);
    table.setFont(font);

    listViewer.setContentProvider(new ArrayContentProvider());
    listViewer.setLabelProvider(new LabelProvider() {
        public String getText(Object element) {
            if (element instanceof DetailFormatter) {
                return ((DetailFormatter) element).getTypeName();
            }
            return null;
        }
    });

    // button container
    Composite composite = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().grab(false, true).applyTo(composite);
    composite.setLayout(GridLayoutFactory.fillDefaults().create());

    // Add button
    addFormatterButton = new Button(composite, SWT.PUSH);
    addFormatterButton.setText(StringUtils.ellipsify(Messages.JSDetailFormattersPreferencePage_Add));
    addFormatterButton
            .setToolTipText(Messages.JSDetailFormattersPreferencePage_AllowToCreateNewDetailFormatter);
    setButtonLayoutData(addFormatterButton);
    addFormatterButton.setFont(font);

    // Edit button
    editFormatterButton = new Button(composite, SWT.PUSH);
    editFormatterButton.setText(StringUtils.ellipsify(Messages.JSDetailFormattersPreferencePage_Edit));
    editFormatterButton.setToolTipText(Messages.JSDetailFormattersPreferencePage_EditSelectedDetailFormatter);
    setButtonLayoutData(editFormatterButton);
    editFormatterButton.setFont(font);

    // Remove button
    removeFormatterButton = new Button(composite, SWT.PUSH);
    removeFormatterButton.setText(Messages.JSDetailFormattersPreferencePage_Remove);
    removeFormatterButton
            .setToolTipText(Messages.JSDetailFormattersPreferencePage_RemoveAllSelectedDetailFormatters);
    setButtonLayoutData(removeFormatterButton);
    removeFormatterButton.setFont(font);

    Label label = new Label(parent, SWT.NONE);
    label.setText(Messages.JSDetailFormattersPreferencePage_DetailFormatterCodeSnippetDefinedForSelectedType);
    GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(label);
    label.setFont(font);

    sourceViewer = new SourceViewer(parent, null, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    sourceViewer.getTextWidget()
            .setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    sourceViewer.getTextWidget().setFont(JFaceResources.getTextFont());
    GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(sourceViewer.getControl());

    // listeners 
    listViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            updatePage((IStructuredSelection) event.getSelection());
        }
    });
    listViewer.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            if (!event.getSelection().isEmpty()) {
                editType();
            }
        }
    });
    listViewer.addCheckStateListener(new ICheckStateListener() {
        public void checkStateChanged(CheckStateChangedEvent event) {
            ((DetailFormatter) event.getElement()).setEnabled(event.getChecked());
        }
    });

    table.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent event) {
            if (event.character == SWT.DEL && event.stateMask == 0) {
                removeTypes();
            }
        }
    });

    addFormatterButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            addType();
        }
    });
    editFormatterButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            editType();
        }
    });
    removeFormatterButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            removeTypes();
        }
    });

    editFormatterButton.setEnabled(false);
    removeFormatterButton.setEnabled(false);

    sourceViewer.setEditable(false);
    sourceViewer.setDocument(new Document());

    loadDetailFormatters();
    listViewer.setInput(formatters);
    updateViewerCheckboxes();

    return parent;
}

From source file:com.aptana.index.core.ui.views.IndexViewLabelProvider.java

License:Open Source License

public Font getFont(Object element) {
    if (!useEditorFont()) {
        return null;
    }/*w ww.java  2 s  .  co  m*/

    Font font = JFaceResources.getFont(IThemeManager.VIEW_FONT_NAME);
    if (font == null) {
        font = JFaceResources.getTextFont();
    }
    return font;
}

From source file:com.aptana.js.debug.ui.internal.preferences.JSDetailFormattersPreferencePage.java

License:Open Source License

private Control createFormattersList(Composite parent) {
    Font font = parent.getFont();
    listLabel = new Label(parent, SWT.NONE);
    listLabel.setText(Messages.JSDetailFormattersPreferencePage_TypesWithDetailFormatters);
    GridDataFactory.swtDefaults().span(2, 1).applyTo(listLabel);
    listLabel.setFont(font);/*from   w  w w .  ja v a  2  s  . c  o m*/

    listViewer = CheckboxTableViewer.newCheckList(parent,
            SWT.CHECK | SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    Table table = (Table) listViewer.getControl();
    GridDataFactory.fillDefaults().grab(true, true).hint(convertWidthInCharsToPixels(10), SWT.DEFAULT)
            .applyTo(table);
    table.setFont(font);

    listViewer.setContentProvider(ArrayContentProvider.getInstance());
    listViewer.setLabelProvider(new LabelProvider() {
        public String getText(Object element) {
            if (element instanceof DetailFormatter) {
                return ((DetailFormatter) element).getTypeName();
            }
            return null;
        }
    });

    // button container
    Composite composite = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().grab(false, true).applyTo(composite);
    composite.setLayout(GridLayoutFactory.fillDefaults().create());

    // Add button
    addFormatterButton = new Button(composite, SWT.PUSH);
    addFormatterButton.setText(StringUtil.ellipsify(Messages.JSDetailFormattersPreferencePage_Add));
    addFormatterButton
            .setToolTipText(Messages.JSDetailFormattersPreferencePage_AllowToCreateNewDetailFormatter);
    setButtonLayoutData(addFormatterButton);
    addFormatterButton.setFont(font);

    // Edit button
    editFormatterButton = new Button(composite, SWT.PUSH);
    editFormatterButton.setText(StringUtil.ellipsify(Messages.JSDetailFormattersPreferencePage_Edit));
    editFormatterButton.setToolTipText(Messages.JSDetailFormattersPreferencePage_EditSelectedDetailFormatter);
    setButtonLayoutData(editFormatterButton);
    editFormatterButton.setFont(font);

    // Remove button
    removeFormatterButton = new Button(composite, SWT.PUSH);
    removeFormatterButton.setText(Messages.JSDetailFormattersPreferencePage_Remove);
    removeFormatterButton
            .setToolTipText(Messages.JSDetailFormattersPreferencePage_RemoveAllSelectedDetailFormatters);
    setButtonLayoutData(removeFormatterButton);
    removeFormatterButton.setFont(font);

    Label label = new Label(parent, SWT.NONE);
    label.setText(Messages.JSDetailFormattersPreferencePage_DetailFormatterCodeSnippetDefinedForSelectedType);
    GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(label);
    label.setFont(font);

    sourceViewer = new SourceViewer(parent, null, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    sourceViewer.getTextWidget()
            .setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    sourceViewer.getTextWidget().setFont(JFaceResources.getTextFont());
    GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(sourceViewer.getControl());

    // listeners
    listViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            updatePage((IStructuredSelection) event.getSelection());
        }
    });
    listViewer.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            if (!event.getSelection().isEmpty()) {
                editType();
            }
        }
    });
    listViewer.addCheckStateListener(new ICheckStateListener() {
        public void checkStateChanged(CheckStateChangedEvent event) {
            ((DetailFormatter) event.getElement()).setEnabled(event.getChecked());
        }
    });

    table.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent event) {
            if (event.character == SWT.DEL && event.stateMask == 0) {
                removeTypes();
            }
        }
    });

    addFormatterButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            addType();
        }
    });
    editFormatterButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            editType();
        }
    });
    removeFormatterButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            removeTypes();
        }
    });

    editFormatterButton.setEnabled(false);
    removeFormatterButton.setEnabled(false);

    sourceViewer.setEditable(false);
    sourceViewer.setDocument(new Document());

    loadDetailFormatters();
    listViewer.setInput(formatters);
    updateViewerCheckboxes();

    return parent;
}

From source file:com.aptana.snippets.ui.views.SnippetPopupDialog.java

License:Open Source License

private ISourceViewer createSnippetViewer(Composite parent) {
    ProjectionViewer viewer = new ProjectionViewer(parent, null, null, false, SWT.V_SCROLL | SWT.H_SCROLL);
    StyledText styledText = viewer.getTextWidget();
    styledText.setFont(JFaceResources.getTextFont());

    IScriptFormatterFactory factory = null;
    String contentType = getContentType();

    if (contentType != null) {
        factory = ScriptFormatterManager.getSelected(contentType);
    }/*from   www .ja va  2 s.com*/

    IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
    // TODO - Note that we pass the factory's preferences store and not calling to this.getPrefereceStore.
    // In case we decide to unify the preferences into the this plugin, we might need to change this.

    if (factory != null) {
        IPreferenceStore store = new ChainedPreferenceStore(
                new IPreferenceStore[] { factory.getPreferenceStore(), generalTextStore });

        SourceViewerConfiguration configuration = (SourceViewerConfiguration) factory
                .createSimpleSourceViewerConfiguration(colorManager, store, null, false);
        viewer.configure(configuration);
        new ScriptSourcePreviewerUpdater(viewer, configuration, store);
    }

    if (viewer.getTextWidget().getTabs() == 0) {
        viewer.getTextWidget().setTabs(4);
    }
    viewer.getTextWidget().setEnabled(false);

    viewer.setEditable(false);
    IDocument document = new Document();
    viewer.setDocument(document);

    String expansion = snippet.getExpansion();

    if (expansion != null) {
        expansion = SnippetTemplateUtil.evaluateSnippet(snippet, document, new Position(0));
    }

    if (factory != null) {
        IPartitioningConfiguration partitioningConfiguration = (IPartitioningConfiguration) factory
                .getPartitioningConfiguration();
        CompositePartitionScanner partitionScanner = new CompositePartitionScanner(
                partitioningConfiguration.createSubPartitionScanner(), new NullSubPartitionScanner(),
                new NullPartitionerSwitchStrategy());
        IDocumentPartitioner partitioner = new ExtendedFastPartitioner(partitionScanner,
                partitioningConfiguration.getContentTypes());
        partitionScanner.setPartitioner((IExtendedPartitioner) partitioner);
        partitioner.connect(document);
        document.setDocumentPartitioner(partitioner);

        IProfileManager manager = ProfileManager.getInstance();
        IResource selectedResource = UIUtils.getSelectedResource();
        IProject project = null;

        if (selectedResource == null) {
            IEditorPart activeEditor = UIUtils.getActiveEditor();
            if (activeEditor instanceof AbstractThemeableEditor) {
                project = EditorUtil.getProject((AbstractThemeableEditor) activeEditor);
            }
        } else {
            project = selectedResource.getProject();
        }

        if (project != null) {
            FormatterPreviewUtils.updatePreview(viewer, expansion, null, factory,
                    manager.getSelected(project).getSettings());
        } else {
            document.set(expansion);
        }
    } else {
        document.set(expansion);
    }

    if (translatedQualifiedType != null) {
        for (String part : translatedQualifiedType.getParts()) {
            viewer.removeTextHovers(part);
        }
    }
    return viewer;
}

From source file:com.aptana.snippets.ui.views.SnippetsView.java

License:Open Source License

protected Font getFont() {
    Font font = JFaceResources.getFont(IThemeManager.VIEW_FONT_NAME);
    if (font == null) {
        font = JFaceResources.getTextFont();
    }/*from w  ww.  ja v a2s . c  o m*/
    return font;
}

From source file:com.aptana.terminal.internal.emulator.VT100TerminalControl.java

License:Open Source License

public VT100TerminalControl(ITerminalListener target, Composite wndParent, ITerminalConnector[] connectors) {
    super(target, wndParent, connectors);
    getRootControl().setBackground(ThemedTextLineRenderer.getStyleMap().getBackgroundColor());
    preferenceChangeListener = new IPreferenceChangeListener() {
        public void preferenceChange(PreferenceChangeEvent event) {
            if (IThemeManager.THEME_CHANGED.equals(event.getKey())) {
                Control control = getRootControl();
                if (!control.isDisposed()) {
                    control.setBackground(ThemedTextLineRenderer.getStyleMap().getBackgroundColor());
                    getCtlText().redraw();
                }// www  . java  2  s  . c  o m
            }
        }
    };
    EclipseUtil.instanceScope().getNode(ThemePlugin.PLUGIN_ID)
            .addPreferenceChangeListener(preferenceChangeListener);
    propertyChangeListener = new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (JFaceResources.TEXT_FONT.equals(event.getProperty())) {
                setFont(JFaceResources.getTextFont());
            }
        }
    };
    JFaceResources.getFontRegistry().addListener(propertyChangeListener);
    getCtlText().addMouseListener(new MouseAdapter() {
        public void mouseDown(MouseEvent e) {
            if (e.button == 2) { // paste clipboard selection
                String text = (String) getClipboard().getContents(TextTransfer.getInstance(),
                        DND.SELECTION_CLIPBOARD);
                if (text != null && text.length() > 0) {
                    pasteString(text);
                }
            }
        }
    });
}