Example usage for org.eclipse.jface.preference JFacePreferences getPreferenceStore

List of usage examples for org.eclipse.jface.preference JFacePreferences getPreferenceStore

Introduction

In this page you can find the example usage for org.eclipse.jface.preference JFacePreferences getPreferenceStore.

Prototype

public static IPreferenceStore getPreferenceStore() 

Source Link

Document

Return the preference store for the receiver.

Usage

From source file:com.mentor.nucleus.bp.ui.canvas.Gr_c.java

License:Open Source License

public static GCDelegate Getcontext() {
    if (cur_canvas == null) {
        return null;
    }/*from  w w w.j ava  2 s . com*/
    Diagram_c diagram = Diagram_c.getOneDIM_DIAOnR18(cur_model);
    if (diagram == null) {
        return null;
    }
    GCDelegate gc = new GCDelegate(Display.getDefault());
    String prefFont = JFacePreferences.getPreferenceStore().getString("com.mentor.nucleus.bp.canvas.font");//$NON-NLS-1$
    prefFont = prefFont.substring(0, prefFont.indexOf(';'));
    FontData prefFontData = new FontData(prefFont);
    int fontSize = (int) (prefFontData.getHeight() * diagram.getZoom());
    prefFontData.setHeight(fontSize);
    Font displayFont = new Font(cur_canvas.getDisplay(), prefFontData);
    gc.setFont(displayFont);
    return gc;
}

From source file:com.mentor.nucleus.bp.ui.graphics.editor.GraphicalEditor.java

License:Open Source License

public static Font getFont() {
    if (diagramFont == null || diagramFont.isDisposed()) {
        String prefFont = JFacePreferences.getPreferenceStore().getString("com.mentor.nucleus.bp.canvas.font");//$NON-NLS-1$
        if (prefFont == null || prefFont.equals("")) {
            // something strange has happened, should not occur
            // but to be safe set a default
            diagramFont = PlatformUI.getWorkbench().getDisplay().getSystemFont();
        } else {/*from   ww  w  .jav a  2s  .c o  m*/
            prefFont = prefFont.substring(0, prefFont.indexOf(';'));
            FontData prefFontData = new FontData(prefFont);
            int fontSize = (int) (prefFontData.getHeight());
            prefFontData.setHeight(fontSize);
            diagramFont = new Font(PlatformUI.getWorkbench().getDisplay(), prefFontData);
        }
    }
    return diagramFont;
}

From source file:com.mentor.nucleus.bp.ui.graphics.parts.DiagramEditPart.java

License:Open Source License

@Override
public void activate() {
    super.activate();
    CanvasPlugin.getDefault().getPluginPreferences().addPropertyChangeListener(this);
    CorePlugin.getDefault().getPluginPreferences().addPropertyChangeListener(this);
    JFacePreferences.getPreferenceStore().addPropertyChangeListener(this);
    GraphicalEditor editor = GraphicalEditor.getEditor((Model_c) getModel());
    if (editor != null) {
        FigureCanvas canvas = (FigureCanvas) editor.getCanvas();
        Point persistedViewportLocation = editor.getPersistedViewportLocation();
        if (persistedViewportLocation.x != -1 && persistedViewportLocation.y != -1) {
            ((GraphicsViewport) canvas.getViewport())
                    .setViewportLocationOnceConfigured(persistedViewportLocation);
        }//w  w  w  .  j  a v  a  2s.c  o m
    }
}

From source file:com.mentor.nucleus.bp.ui.graphics.parts.DiagramEditPart.java

License:Open Source License

@Override
public void deactivate() {
    super.deactivate();
    CanvasPlugin.getDefault().getPluginPreferences().removePropertyChangeListener(this);
    CorePlugin.getDefault().getPluginPreferences().removePropertyChangeListener(this);
    JFacePreferences.getPreferenceStore().removePropertyChangeListener(this);
    // clear the layer cache data
    List<UserDefinedLayer> layers = UserDefinedLayer.getLayers(this);
    for (UserDefinedLayer layer : layers) {
        layer.removeLayerFromModelMap(this);
    }//from  w ww. ja  v  a 2s  . co  m
}

From source file:fede.workspace.eclipse.java.fields.JavaSourceViewerField.java

License:Apache License

/**
 * Creates the source viewer./*  w ww.j ava 2 s  . com*/
 * 
 * @param parent
 *            the parent
 * @param verticalRuler
 *            the vertical ruler
 * @param styles
 *            the styles
 * 
 * @return the i source viewer
 */
protected final ISourceViewer createSourceViewer(Composite parent, IVerticalRuler verticalRuler, int styles) {

    IPreferenceStore store = JFacePreferences.getPreferenceStore();
    ISourceViewer viewer = createJavaSourceViewer(parent, verticalRuler, getOverviewRuler(),
            isOverviewRulerVisible(), styles, store);

    /*
     * This is a performance optimization to reduce the computation of the
     * text presentation triggered by {@link #setVisibleDocument(IDocument)}
     */
    ProjectionViewer projectionViewer = (ProjectionViewer) viewer;
    fProjectionSupport = new ProjectionSupport(projectionViewer, getAnnotationAccess(), getSharedColors());
    fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.error"); //$NON-NLS-1$
    fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.warning"); //$NON-NLS-1$
    fProjectionSupport.setHoverControlCreator(new IInformationControlCreator() {
        public IInformationControl createInformationControl(Shell shell) {
            return null; // TODO new
            // SourceViewerInformationControl(shell,
            // SWT.TOOL | SWT.NO_TRIM, SWT.NONE);
        }
    });
    fProjectionSupport.install();

    // ensure source viewer decoration support has been created and
    // configured
    // getSourceViewerDecorationSupport(viewer);

    return viewer;
}

From source file:mesfavoris.internal.views.comment.SpellcheckableMessageArea.java

License:Open Source License

/**
 * @param parent/*  ww  w  .  j  ava 2  s  .c  om*/
 * @param initialText
 * @param readOnly
 * @param styles
 */
public SpellcheckableMessageArea(Composite parent, String initialText, boolean readOnly, int styles) {
    super(parent, styles);
    setLayout(new FillLayout());

    AnnotationModel annotationModel = new AnnotationModel();
    sourceViewer = new HyperlinkSourceViewer(this, null, null, true, SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);
    getTextWidget().setAlwaysShowScrollBars(false);
    //      getTextWidget().setFont(UIUtils
    //            .getFont(UIPreferences.THEME_CommitMessageEditorFont));

    int endSpacing = 2;
    int textWidth = getCharWidth() * MAX_LINE_WIDTH + endSpacing;
    int textHeight = getLineHeight() * 7;
    Point size = getTextWidget().computeSize(textWidth, textHeight);
    getTextWidget().setSize(size);

    computeBrokenBidiPlatformTextWidth(size.x);

    getTextWidget().setEditable(!readOnly);

    createMarginPainter();

    final IPropertyChangeListener syntaxColoringChangeListener = new IPropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (JFacePreferences.HYPERLINK_COLOR.equals(event.getProperty())) {
                getDisplay().asyncExec(new Runnable() {
                    @Override
                    public void run() {
                        if (!isDisposed()) {
                            sourceViewer.refresh();
                        }
                    }
                });
            }
        }
    };
    JFacePreferences.getPreferenceStore().addPropertyChangeListener(syntaxColoringChangeListener);
    final SourceViewerDecorationSupport support = configureAnnotationPreferences();
    if (isEditable(sourceViewer)) {
        quickFixActionHandler = createQuickFixActionHandler(sourceViewer);
    }

    Document document = new Document(initialText);

    configuration = new HyperlinkSourceViewer.Configuration(EditorsUI.getPreferenceStore()) {

        @Override
        public int getHyperlinkStateMask(ISourceViewer targetViewer) {
            if (!targetViewer.isEditable()) {
                return SWT.NONE;
            }
            return super.getHyperlinkStateMask(targetViewer);
        }

        @Override
        protected Map getHyperlinkDetectorTargets(ISourceViewer targetViewer) {
            return getHyperlinkTargets();
        }

        @Override
        public IReconciler getReconciler(ISourceViewer viewer) {
            if (!isEditable(viewer))
                return null;
            return super.getReconciler(sourceViewer);
        }

        @Override
        public IContentAssistant getContentAssistant(ISourceViewer viewer) {
            if (!viewer.isEditable())
                return null;
            IContentAssistant assistant = createContentAssistant(viewer);
            // Add content assist proposal handler if assistant exists
            if (assistant != null)
                contentAssistActionHandler = createContentAssistActionHandler(sourceViewer);
            return assistant;
        }

        @Override
        public IPresentationReconciler getPresentationReconciler(ISourceViewer viewer) {
            PresentationReconciler reconciler = new PresentationReconciler();
            reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(viewer));
            DefaultDamagerRepairer hyperlinkDamagerRepairer = new DefaultDamagerRepairer(
                    new HyperlinkTokenScanner(this, viewer));
            reconciler.setDamager(hyperlinkDamagerRepairer, IDocument.DEFAULT_CONTENT_TYPE);
            reconciler.setRepairer(hyperlinkDamagerRepairer, IDocument.DEFAULT_CONTENT_TYPE);
            return reconciler;
        }

    };

    sourceViewer.configure(configuration);
    sourceViewer.setDocument(document, annotationModel);

    configureContextMenu();

    getTextWidget().addDisposeListener(new DisposeListener() {
        @Override
        public void widgetDisposed(DisposeEvent disposeEvent) {
            support.uninstall();
            JFacePreferences.getPreferenceStore().removePropertyChangeListener(syntaxColoringChangeListener);
        }
    });
}

From source file:org.eclipse.ui.internal.ide.dialogs.WelcomeEditor.java

License:Open Source License

/**
 * Creates the SWT controls for this workbench part.
 * <p>/*  ww w .  j  av a2  s .c o  m*/
 * Clients should not call this method (the workbench calls this method at
 * appropriate times).
 * </p>
 * <p>
 * For implementors this is a multi-step process:
 * <ol>
 *   <li>Create one or more controls within the parent.</li>
 *   <li>Set the parent layout as needed.</li>
 *   <li>Register any global actions with the <code>IActionService</code>.</li>
 *   <li>Register any popup menus with the <code>IActionService</code>.</li>
 *   <li>Register a selection provider with the <code>ISelectionService</code>
 *     (optional). </li>
 * </ol>
 * </p>
 *
 * @param parent the parent control
 */
public void createPartControl(Composite parent) {
    // read our contents
    readFile();
    if (parser == null) {
        return;
    }

    handCursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
    busyCursor = new Cursor(parent.getDisplay(), SWT.CURSOR_WAIT);

    editorComposite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.verticalSpacing = 0;
    layout.horizontalSpacing = 0;
    editorComposite.setLayout(layout);

    createTitleArea(editorComposite);

    Label titleBarSeparator = new Label(editorComposite, SWT.HORIZONTAL | SWT.SEPARATOR);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    titleBarSeparator.setLayoutData(gd);

    createInfoArea(editorComposite);

    getSite().getWorkbenchWindow().getWorkbench().getHelpSystem().setHelp(editorComposite,
            IIDEHelpContextIds.WELCOME_EDITOR);

    this.colorListener = new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(JFacePreferences.HYPERLINK_COLOR)) {
                Color fg = JFaceColors.getHyperlinkText(editorComposite.getDisplay());
                Iterator links = hyperlinkRanges.iterator();
                while (links.hasNext()) {
                    StyleRange range = (StyleRange) links.next();
                    range.foreground = fg;
                }
            }
        }
    };

    JFacePreferences.getPreferenceStore().addPropertyChangeListener(this.colorListener);

}

From source file:org.eclipse.ui.internal.ide.dialogs.WelcomeEditor.java

License:Open Source License

/**
 * The <code>WorkbenchPart</code> implementation of this 
 * <code>IWorkbenchPart</code> method disposes the title image
 * loaded by <code>setInitializationData</code>. Subclasses may extend.
 *///from ww w.j a  va2  s .c  om
public void dispose() {
    super.dispose();
    if (busyCursor != null) {
        busyCursor.dispose();
    }
    if (handCursor != null) {
        handCursor.dispose();
    }
    if (this.colorListener != null) {
        JFacePreferences.getPreferenceStore().removePropertyChangeListener(this.colorListener);
    }
}

From source file:org.jlibrary.client.extraction.MetaDataExtractor.java

License:Open Source License

/**
 * Extracts the metadata information of a file
 * /*from   www .  jav  a  2  s  .  c o  m*/
 * @param file File to be parsed
 * 
 * @return HeaderMetaData Metadata information for the file
 */
public static HeaderMetaData extractMetaData(String file) {

    HeaderMetaData metadata = null;
    Extractor extractor = null;
    try {
        extractor = TextExtractionService.getInstance().getExtractor(file);
        if (extractor != null) {
            metadata = extractor.extractHeader(new File(file));
            if ((metadata.getKeywords() == null) || (metadata.getKeywords().equals(""))) {

                // manual metadata find
                boolean find = JFacePreferences.getPreferenceStore()
                        .getBoolean(JLibraryExtractionPreferences.P_FIND_KEYWORDS);
                if (find) {
                    int numKeywords = JFacePreferences.getPreferenceStore()
                            .getInt(JLibraryExtractionPreferences.P_NUMBER_OF_KEYWORDS);

                    LocaleService ls = LocaleService.getInstance();
                    Locale locale = ls.getUserLocale();
                    if (metadata.getLanguage() != null) {
                        locale = new Locale(metadata.getLanguage());
                    }

                    String text = extractor.extractText(new File(file));
                    StringBuilder buffer = new StringBuilder();
                    List palabras = WordCounter.busca(locale, text);
                    //logger.debug("Listado de palabras y sus frecuencias:");
                    if (palabras.size() > 0) {
                        int i = 0;
                        while ((i < palabras.size()) && (i < numKeywords)) {
                            buffer.append(palabras.get(i) + " ");
                            //info = new StringBuffer(p.toString()).append(": ").append(p.getOcurrencias()).append(" ocurrencias. Frecuencia: ").append(p.getFrecuencia());                        
                            i++;
                        }
                    }
                    metadata.setKeywords(buffer.toString());
                }
            }
        }

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    return metadata;
}

From source file:org.jlibrary.client.preferences.JLibraryExtractionPreferences.java

License:Open Source License

public JLibraryExtractionPreferences() {

    super(GRID);/*from  ww w . j av a 2 s. co  m*/
    setPreferenceStore(JFacePreferences.getPreferenceStore());
    setDescription(Messages.getMessage("preferences_extraction_description"));
    setTitle(Messages.getMessage("preferences_extraction"));
    initializeDefaults();
}