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.birt.report.designer.ui.dialogs.TextEditor.java

License:Open Source License

/**
 * Creates the text area for edit operation.
 * //from  www.  j a  v  a  2s  . c  o m
 * @param parent
 *            The composite of the text area.
 */
private void createTextArea(Composite parent) {
    IVerticalRuler ruler = null;
    int style = updateBidiStyle(SWT.WRAP // bidi_hcg changed
            | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    textViewer = new SourceViewer(parent, ruler, style);
    textViewer.setDocument(new Document());
    textEditor = textViewer.getTextWidget();
    {
        GridData gd = new GridData(GridData.FILL_BOTH);
        gd.horizontalSpan = 3;
        gd.widthHint = 600;
        gd.heightHint = 300;
        textEditor.setLayoutData(gd);
        textEditor.setText(oldValue);
        textEditor.setFocus();
        textEditor.setFont(JFaceResources.getTextFont());
    }

    textEditor.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            if (isUndoKeyPress(e)) {
                textViewer.doOperation(ITextOperationTarget.UNDO);
            } else if (isRedoKeyPress(e)) {
                textViewer.doOperation(ITextOperationTarget.REDO);
            }
        }

        public void keyReleased(KeyEvent e) {
            // do nothing
        }

        private boolean isUndoKeyPress(KeyEvent e) {
            return ((e.stateMask & SWT.CONTROL) > 0) && ((e.keyCode == 'z') || (e.keyCode == 'Z'));
        }

        private boolean isRedoKeyPress(KeyEvent e) {
            return ((e.stateMask & SWT.CONTROL) > 0) && ((e.keyCode == 'y') || (e.keyCode == 'Y'));
        }

    });

    textEditor.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            resetOkButtonStatus(true);
        }
    });

    textViewer.configure(new SourceViewerConfiguration());
    textEditor.invokeAction(ST.TEXT_END);

    // create actions for context menu and short cut keys
    ResourceBundle bundle = ResourceBundle.getBundle("org.eclipse.birt.report.designer.nls.messages");//$NON-NLS-1$
    final TextEditorAction undoAction = new EBTextAction(bundle, "TextAreaContextMenu.Undo.", //$NON-NLS-1$
            textViewer, ITextOperationTarget.UNDO);
    undoAction.setAccelerator(SWT.CTRL | 'Z');

    final TextEditorAction redoAction = new EBTextAction(bundle, "TextAreaContextMenu.Redo.", //$NON-NLS-1$
            textViewer, ITextOperationTarget.REDO);
    redoAction.setAccelerator(SWT.CTRL | 'Y');

    final TextEditorAction cutAction = new EBTextAction(bundle, "TextAreaContextMenu.Cut.", //$NON-NLS-1$
            textViewer, ITextOperationTarget.CUT);
    cutAction.setAccelerator(SWT.CTRL | 'X');

    final TextEditorAction copyAction = new EBTextAction(bundle, "TextAreaContextMenu.Copy.", //$NON-NLS-1$
            textViewer, ITextOperationTarget.COPY);
    copyAction.setAccelerator(SWT.CTRL | 'C');

    final TextEditorAction pasteAction = new EBTextAction(bundle, "TextAreaContextMenu.Paste.", //$NON-NLS-1$
            textViewer, ITextOperationTarget.PASTE);
    pasteAction.setAccelerator(SWT.CTRL | 'V');

    final TextEditorAction selectAllAction = new EBTextAction(bundle, "TextAreaContextMenu.SelectAll.", //$NON-NLS-1$
            textViewer, ITextOperationTarget.SELECT_ALL);
    selectAllAction.setAccelerator(SWT.CTRL | 'A');

    // Create context menu
    MenuManager menuMgr = new MenuManager("#EB Context");//$NON-NLS-1$
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager menuManager) {
            menuManager.add(new Separator(ITextEditorActionConstants.GROUP_UNDO));
            menuManager.add(new Separator(ITextEditorActionConstants.GROUP_COPY));
            menuManager.add(new Separator(ITextEditorActionConstants.GROUP_EDIT));
            menuManager.add(new Separator(ITextEditorActionConstants.GROUP_REST));

            undoAction.update();
            redoAction.update();
            copyAction.update();
            cutAction.update();
            pasteAction.update();
            selectAllAction.update();

            menuManager.appendToGroup(ITextEditorActionConstants.GROUP_UNDO, undoAction);
            menuManager.appendToGroup(ITextEditorActionConstants.GROUP_UNDO, redoAction);
            menuManager.appendToGroup(ITextEditorActionConstants.GROUP_COPY, cutAction);
            menuManager.appendToGroup(ITextEditorActionConstants.GROUP_COPY, copyAction);
            menuManager.appendToGroup(ITextEditorActionConstants.GROUP_COPY, pasteAction);
            menuManager.appendToGroup(ITextEditorActionConstants.GROUP_COPY,
                    new Action(Messages.getString("TextEditor.PasteFormattedText")) { //$NON-NLS-1$

                        @Override
                        public void run() {
                            pasteClipboard();
                        }
                    });
            menuManager.appendToGroup(ITextEditorActionConstants.GROUP_EDIT, selectAllAction);

            int index = getContentChoiceType(textTypeChoicer, DesignChoiceConstants.TEXT_CONTENT_TYPE_PLAIN);
            final int PLAIN_INDEX = (index < 0 ? 0 : index);

            IAction action = new Action(ACTION_TEXT_FORMAT_HTML) {

                public boolean isEnabled() {
                    return textTypeChoicer.getSelectionIndex() != PLAIN_INDEX;
                }

                public void run() {
                    String result = " format=\"HTML\""; //$NON-NLS-1$
                    textEditor.insert(result);
                }
            };

            menuManager.appendToGroup(ITextEditorActionConstants.GROUP_REST, action);

            action = new Action(ACTION_TEXT_FORMAT_NUMBER) {

                public boolean isEnabled() {
                    return textTypeChoicer.getSelectionIndex() != PLAIN_INDEX;
                }

                public void run() {
                    insertFormat(FormatBuilder.NUMBER);
                }
            };

            menuManager.appendToGroup(ITextEditorActionConstants.GROUP_REST, action);

            action = new Action(ACTION_TEXT_FORMAT_STRING) {

                public boolean isEnabled() {
                    return textTypeChoicer.getSelectionIndex() != PLAIN_INDEX;
                }

                public void run() {
                    insertFormat(FormatBuilder.STRING);
                }
            };

            menuManager.appendToGroup(ITextEditorActionConstants.GROUP_REST, action);

            action = new Action(ACTION_TEXT_FORMAT_DATE_TIME) {

                public boolean isEnabled() {
                    return textTypeChoicer.getSelectionIndex() != PLAIN_INDEX;
                }

                public void run() {
                    insertFormat(FormatBuilder.DATETIME);
                }
            };

            menuManager.appendToGroup(ITextEditorActionConstants.GROUP_REST, action);

            action = new Action(ACTION_TEXT_EDIT_DYNAMIC_TEXT) {

                public boolean isEnabled() {
                    return textTypeChoicer.getSelectionIndex() != PLAIN_INDEX;
                }

                public void run() {
                    editDynamicTextDirectly();
                }
            };

            menuManager.appendToGroup(ITextEditorActionConstants.GROUP_REST, action);

            // bidi_hcg start

            action = new Action(ACTION_BIDI_DIRECTION) {

                public boolean isEnabled() {
                    return true;
                }

                public void run() {
                    textEditor.setOrientation(this.isChecked() ? SWT.RIGHT_TO_LEFT : SWT.LEFT_TO_RIGHT);
                }
            };
            action.setChecked((textEditor.getOrientation() & SWT.RIGHT_TO_LEFT) != 0);

            menuManager.appendToGroup(ITextEditorActionConstants.GROUP_REST, action);

            // bidi_hcg end

        }
    });
    textEditor.setMenu(menuMgr.createContextMenu(textEditor));
}

From source file:org.eclipse.cdt.cpp.ui.internal.preferences.OutputViewPreferencePage.java

License:Open Source License

public void readFont() {
    String property = new String("OutputViewFont");

    CppPlugin plugin = CppPlugin.getDefault();
    ArrayList fontArray = plugin.readProperty(property);
    if (fontArray.size() > 0) {
        String fontStr = (String) fontArray.get(0);
        fontStr = fontStr.replace(',', '|');
        _control.setFont(fontStr);//  w w  w .  jav  a  2 s. co m
    } else {
        Font textFont = JFaceResources.getTextFont();
        _control.setFont(textFont);
    }
}

From source file:org.eclipse.cdt.cpp.ui.internal.views.CppOutputViewPart.java

License:Open Source License

public void updateViewFont() {
    ArrayList fontArray = _plugin.readProperty("OutputViewFont");
    if (fontArray.size() > 0) {
        String fontStr = (String) fontArray.get(0);
        fontStr = fontStr.replace(',', '|');
        FontData fontData = new FontData(fontStr);
        _viewer.setFont(fontData);//from  w  w w.  j a  v  a2s  . com
    } else {
        Font font = JFaceResources.getTextFont();
        _viewer.setFont(font);

    }
}

From source file:org.eclipse.cdt.dsf.debug.internal.ui.disassembly.DisassemblyPart.java

License:Open Source License

/**
 * Initializes the given viewer's font.// w  w w .ja v a 2 s .  c  o m
 *
 * @param viewer
 *            the viewer
 */
private void initializeViewerFont(ISourceViewer viewer) {

    boolean isSharedFont = true;
    Font font = null;
    String symbolicFontName = getSymbolicFontName();

    if (symbolicFontName != null)
        font = JFaceResources.getFont(symbolicFontName);
    else if (fPreferenceStore != null) {
        // Backward compatibility
        if (fPreferenceStore.contains(JFaceResources.TEXT_FONT)
                && !fPreferenceStore.isDefault(JFaceResources.TEXT_FONT)) {
            FontData data = PreferenceConverter.getFontData(fPreferenceStore, JFaceResources.TEXT_FONT);

            if (data != null) {
                isSharedFont = false;
                font = new Font(viewer.getTextWidget().getDisplay(), data);
            }
        }
    }
    if (font == null)
        font = JFaceResources.getTextFont();

    setFont(viewer, font);

    if (fFont != null) {
        fFont.dispose();
        fFont = null;
    }

    if (!isSharedFont)
        fFont = font;
}

From source file:org.eclipse.dawnsci.plotting.examples.SourceCodeView.java

License:Open Source License

/**
 * Basic source code viewer...//  w ww .  jav a  2s . com
 * @param content
 */
private void createSourceContent(Composite content) {

    JavaLineStyler lineStyler = new JavaLineStyler();

    StyledText text = new StyledText(content, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
    GridData spec = new GridData();
    spec.horizontalAlignment = GridData.FILL;
    spec.grabExcessHorizontalSpace = true;
    spec.verticalAlignment = GridData.FILL;
    spec.grabExcessVerticalSpace = true;
    text.setLayoutData(spec);
    text.addLineStyleListener(lineStyler);
    // Use a monospaced font, which is not as easy as it might be.
    // http://stackoverflow.com/questions/221568/swt-os-agnostic-way-to-get-monospaced-font
    text.setFont(JFaceResources.getTextFont());
    text.setEditable(false);

    // Providing that they run this from a debug session:
    try {
        File dir = BundleUtils.getBundleLocation("org.eclipse.dawnsci.plotting.examples");
        String loc = "/src/" + getClass().getName().replace('.', '/') + ".java";
        File src = new File(dir, loc);
        text.setText(readFile(src).toString());

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.eclipse.debug.internal.ui.actions.expressions.WatchExpressionDialog.java

License:Open Source License

/**
 * Create the dialog area.//from  w  ww .  ja va 2  s.  co  m
 *
 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(Composite)
 */
protected Control createDialogArea(Composite parent) {
    Font font = parent.getFont();

    Composite container = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);
    GridData gd = new GridData(GridData.FILL_BOTH);
    container.setLayoutData(gd);

    // snippet label
    Label label = new Label(container, SWT.NONE);
    label.setText(ActionMessages.WatchExpressionDialog_2);
    gd = new GridData(GridData.BEGINNING);
    label.setLayoutData(gd);
    label.setFont(font);

    fSnippetViewer = new SourceViewer(container, null,
            SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.LEFT_TO_RIGHT);
    fSnippetViewer.setInput(this);

    IDocument document = new Document();
    fSnippetViewer.configure(new SourceViewerConfiguration());
    fSnippetViewer.setEditable(true);
    fSnippetViewer.setDocument(document);
    document.addDocumentListener(new IDocumentListener() {
        public void documentAboutToBeChanged(DocumentEvent event) {
        }

        public void documentChanged(DocumentEvent event) {
            checkValues();
        }
    });

    fSnippetViewer.getTextWidget().setFont(JFaceResources.getTextFont());

    Control control = fSnippetViewer.getControl();
    gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = convertHeightInCharsToPixels(10);
    gd.widthHint = convertWidthInCharsToPixels(80);
    control.setLayoutData(gd);
    fSnippetViewer.getDocument().set(fWatchExpression.getExpressionText());

    // actions
    final TextViewerAction cutAction = new TextViewerAction(fSnippetViewer, ITextOperationTarget.CUT);
    cutAction.setImageDescriptor(
            PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_CUT));
    cutAction.setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
            .getImageDescriptor(ISharedImages.IMG_TOOL_CUT_DISABLED));
    cutAction.setText(ActionMessages.WatchExpressionDialogMenu_0);
    final TextViewerAction copyAction = new TextViewerAction(fSnippetViewer, ITextOperationTarget.COPY);
    copyAction.setImageDescriptor(
            PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
    copyAction.setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
            .getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED));
    copyAction.setText(ActionMessages.WatchExpressionDialogMenu_1);
    final TextViewerAction pasteAction = new TextViewerAction(fSnippetViewer, ITextOperationTarget.PASTE);
    pasteAction.setImageDescriptor(
            PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_PASTE));
    pasteAction.setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
            .getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED));
    pasteAction.setText(ActionMessages.WatchExpressionDialogMenu_2);

    // context menu
    MenuManager menuManager = new MenuManager();
    menuManager.add(cutAction);
    menuManager.add(copyAction);
    menuManager.add(pasteAction);
    menuManager.addMenuListener(new IMenuListener() {
        public void menuAboutToShow(IMenuManager manager) {
            cutAction.update();
            copyAction.update();
            pasteAction.update();
        }
    });
    Menu menu = menuManager.createContextMenu(fSnippetViewer.getTextWidget());
    fSnippetViewer.getTextWidget().setMenu(menu);

    // enable checkbox
    fCheckBox = new Button(container, SWT.CHECK | SWT.LEFT);
    fCheckBox.setText(ActionMessages.WatchExpressionDialog_3);
    fCheckBox.setSelection(fWatchExpression.isEnabled());
    fCheckBox.setFont(font);

    String tipText = MessageFormat.format(ActionMessages.WatchExpressionDialog_5,
            new String[] { getCtrlReturnText() });
    fTip = new Label(container, SWT.LEFT);
    fTip.setText(tipText);
    fTip.setFont(font);

    applyDialogFont(container);
    fSnippetViewer.getControl().setFocus();
    return container;
}

From source file:org.eclipse.e4.tools.emf.ui.internal.common.ModelEditor.java

License:Open Source License

private Control createXMITab(Composite composite) {

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

    final IDocument document = emfDocumentProvider.getDocument();
    IDocumentPartitioner partitioner = new FastPartitioner(new XMLPartitionScanner(),
            new String[] { XMLPartitionScanner.XML_TAG, XMLPartitionScanner.XML_COMMENT });
    partitioner.connect(document);/*  w  w  w  . j  av  a2s.com*/
    document.setDocumentPartitioner(partitioner);
    sourceViewer.setDocument(document);
    verticalRuler.setModel(model);

    emfDocumentProvider.setValidationChangedCallback(new Runnable() {

        @Override
        public void run() {
            model.removeAllAnnotations();

            for (Diagnostic d : emfDocumentProvider.getErrorList()) {
                Annotation a = new Annotation("e4xmi.error", false, d.getMessage()); //$NON-NLS-1$
                int l;
                try {
                    l = document.getLineOffset(d.getLine() - 1);
                    model.addAnnotation(a, new Position(l));
                } catch (BadLocationException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    });

    String property = System.getProperty(ORG_ECLIPSE_E4_TOOLS_MODELEDITOR_FILTEREDTREE_ENABLED_XMITAB_DISABLED);
    if (property != null || preferences.getBoolean("tab-form-search-show", false)) { //$NON-NLS-1$
        sourceViewer.setEditable(false);
        sourceViewer.getTextWidget().setEnabled(false);
    }

    return sourceViewer.getControl();
}

From source file:org.eclipse.edt.ide.ui.internal.record.wizards.AbstractRecordFromStringInputPage.java

License:Open Source License

protected Composite createStringComposite(Composite parent) {
    Composite container = new Composite(parent, 0);
    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;/*  w  w w  . ja  v  a2s  .  c  om*/
    layout.marginHeight = 0;
    container.setLayout(layout);

    Label label = new Label(container, 0);
    label.setText(NewRecordWizardMessages.AbstractRecordFromStringInputPage_stringEntryLabel);

    stringText = new Text(container, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
    stringText.setFont(JFaceResources.getTextFont());
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
    stringText.setLayoutData(data);
    stringText.addModifyListener(this);

    return container;
}

From source file:org.eclipse.equinox.p2.authoring.InformationPage.java

License:Open Source License

@Override
protected void addFormContent(IManagedForm managedForm) {
    // Page uses one edit adapters form part to manage the lifecycle of fields.
    managedForm.addPart(m_editAdapters);

    ScrolledForm form = managedForm.getForm();
    FormToolkit toolkit = managedForm.getToolkit();

    // Modify the default table wrap layout and use a grid layout instead (this to make sure
    // controls gets the full height available).
    GridLayout layout = new GridLayout(m_numColumns, false);
    layout.marginWidth = 10;//w  ww. j  a va 2 s  .c o  m
    form.getBody().setLayout(layout);

    m_tabFolder = new CTabFolder(form.getBody(), SWT.FLAT | SWT.TOP);
    m_tabFolder.setSimple(true);
    // m_tabFolder.setBorderVisible(true); // for visual debug of its size..
    toolkit.adapt(m_tabFolder, true, true);

    // Since there is no data in the tabfolder, set a small height as the default is quite big.
    // (Note if a table wrap layout is used, this height needs to be 20 pixels)
    GridData tabFolderData = new GridData(SWT.FILL, SWT.TOP, true, false);
    tabFolderData.heightHint = 2;
    m_tabFolder.setLayoutData(tabFolderData);

    // TODO: make the gradient look nice
    Color selectedColor = toolkit.getColors().getColor(IFormColors.TB_BG);
    m_tabFolder.setSelectionBackground(new Color[] { selectedColor, toolkit.getColors().getBackground() },
            new int[] { 50 });

    toolkit.paintBordersFor(m_tabFolder);

    // setup for reuse
    FormColors colors = toolkit.getColors();
    Color headerColor = colors.getColor(IFormColors.TITLE);
    Label label = null;

    // --LICENSE TAB
    CTabItem item = new CTabItem(m_tabFolder, SWT.NULL);
    item.setText("License Agreement");
    item.setData(m_currentAdapter = new LicenseAdapter());

    Composite tabComposite = toolkit.createComposite(form.getBody());
    // tabComposite.setBackground(colors.getColor(IFormColors.H_GRADIENT_START)); // debug layout using color

    GridData tabCompositeData = new GridData(SWT.FILL, SWT.FILL, true, true);
    tabComposite.setLayoutData(tabCompositeData);

    GridLayout glayout = new GridLayout();
    glayout.numColumns = 2;
    tabComposite.setLayout(glayout);

    // License URL
    label = toolkit.createLabel(tabComposite, "Optional URL:");
    label.setForeground(headerColor);
    final Text urlText = toolkit.createText(tabComposite, "");
    urlText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    m_editAdapters.createEditAdapter("lurlText", urlText, //$NON-NLS-1$
            URIEditValidator.instance(), new Mutator() {
                @Override
                public String getValue() {
                    return m_currentAdapter.m_urlMutator.getValue();
                }

                @Override
                public void setValue(String input) throws Exception {
                    m_currentAdapter.m_urlMutator.setValue(input);
                }
            });

    // License Body
    label = toolkit.createLabel(tabComposite, "Text:");
    label.setForeground(headerColor);
    label.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false));

    final Composite rect = new Composite(tabComposite, SWT.NONE);
    rect.setLayout(new GridLayout(0, false)); // prevent layout from setting size
    rect.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    final Text licenseText = toolkit.createText(rect, "", SWT.MULTI | SWT.V_SCROLL); //$NON-NLS-1$
    rect.addControlListener(new ControlAdapter() {
        @Override
        public void controlResized(ControlEvent e) {
            licenseText.setBounds(0, 0, rect.getSize().x, rect.getSize().y);
        }

    });

    licenseText.setFont(JFaceResources.getTextFont());
    m_editAdapters.createEditAdapter("licText", licenseText, //$NON-NLS-1$
            NullValidator.instance(), new Mutator() {
                @Override
                public String getValue() {
                    return m_currentAdapter.m_textMutator.getValue();
                }

                @Override
                public void setValue(String input) throws Exception {
                    m_currentAdapter.m_textMutator.setValue(input);
                }
            });

    // --COPYRIGHT
    item = new CTabItem(m_tabFolder, SWT.NULL);
    item.setText("Copyright Notice");
    item.setData(new CopyrightAdapter());

    // --DESCRIPTION
    item = new CTabItem(m_tabFolder, SWT.NULL);
    item.setText("Unit Description");
    item.setData(new DescAdapter());

    m_tabFolder.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            updateSelection();
        }
    });
    m_tabFolder.setSelection(0);
}

From source file:org.eclipse.fx.ide.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));

    document = new Document();

    //      parent.getDisplay().syncExec(new Runnable() {
    ///* w ww.  ja  v  a 2 s  . com*/
    //         @Override
    //         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();
        BorderPane pane = new BorderPane();
        pane.setCenter(rootPane_new);
        defaultScene = new Scene(pane, -1, -1, Platform.isSupported(ConditionalFeature.SCENE3D));
        currentScene = defaultScene;
        swtFXContainer.setScene(defaultScene);
    }

    {
        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());

        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.getTransforms()
                    .setAll(Transform.scale(scale.getSelection() / 100.0, 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");

    MenuManager mgr = new MenuManager();
    for (SCREEN_SIZE s : SCREEN_SIZE.values()) {
        mgr.add(new ScreenAction(s));
    }
    final Menu m = mgr.createContextMenu(parent);

    screenSize = new Action("ScreenSize", IAction.AS_DROP_DOWN_MENU) {
        @Override
        public void runWithEvent(Event event) {
            if (event.detail == SWT.DROP_DOWN) {
                ToolItem i = (ToolItem) event.widget;
                m.setLocation(i.getParent().toDisplay(event.x, event.y));
                m.setVisible(true);
            }
        }
    };
    getViewSite().getActionBars().getToolBarManager().add(screenSize);
    getViewSite().getActionBars().getToolBarManager().add(new Action("Horizontal", Action.AS_CHECK_BOX) {
        @Override
        public void run() {
            updateResolution(currentSize, isChecked());
        }
    });
    getViewSite().getActionBars().getToolBarManager().add(refresh);
    getViewSite().getActionBars().getToolBarManager().add(loadController);
}