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

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

Introduction

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

Prototype

public static Font getDefaultFont() 

Source Link

Document

Returns JFace's standard font.

Usage

From source file:org.eclipse.gmf.runtime.common.ui.preferences.FontFieldEditor.java

License:Open Source License

/**
 * Sets the displayed/selected font to be the font
 * for FontData newFont./*from w w  w.ja v  a  2  s. com*/
 * @param newFont
 */
public void setFont(FontData newFont) {
    FontData[] oldFont = chosenFont;
    if (oldFont == null)
        oldFont = JFaceResources.getDefaultFont().getFontData();
    setPresentsDefaultValue(false);
    FontData[] newData = new FontData[1];
    newData[0] = newFont;
    updateFont(newData);
    fireValueChanged(VALUE, oldFont[0], newFont);
}

From source file:org.eclipse.gmf.runtime.common.ui.services.elementselection.ElementSelectionComposite.java

License:Open Source License

/**
 * Creates the composite./* www  .j  a  v a  2  s.c  o  m*/
 * 
 * @param parent
 *            the parent composite
 * @return the new composite
 */
public Composite createComposite(Composite parent) {

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

    // Add the selection title label
    Label label = new Label(result, SWT.NONE);
    label.setText(title);

    // Add the element selection text widget
    filterText = new Text(result, SWT.SINGLE | SWT.BORDER);
    filterText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    filterText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            handleFilterChange();
        }

    });

    // Add the table viewer
    int selectStyle = SWT.SINGLE;
    tableViewer = new TableViewer(result, selectStyle | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    tableViewer.setUseHashlookup(true);

    Table table = tableViewer.getTable();
    GridData gridData = new GridData(GridData.FILL_BOTH);
    GC gc = new GC(result);
    gc.setFont(JFaceResources.getDefaultFont());
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();
    gridData.widthHint = Dialog.convertWidthInCharsToPixels(fontMetrics, 80);
    gridData.heightHint = table.getItemHeight() * 15;
    table.setLayoutData(gridData);

    table.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            handleSelectionChange();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            handleWidgetDefaultSelected();
        }
    });

    progressBar = new ProgressMonitorPart(result, new GridLayout());
    progressBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    progressBar.setVisible(false);

    tableViewer.setLabelProvider(new LabelProvider() {

        public Image getImage(Object element) {
            assert element instanceof AbstractMatchingObject;
            return ((AbstractMatchingObject) element).getImage();
        }

        public String getText(Object element) {
            assert element instanceof AbstractMatchingObject;
            return ((AbstractMatchingObject) element).getDisplayName();
        }
    });
    tableViewer.setSorter(new ViewerSorter() {

        public int compare(Viewer viewer, Object e1, Object e2) {
            if (e1 instanceof IMatchingObject && e2 instanceof IMatchingObject)
                return ((IMatchingObject) e1).getName().toLowerCase()
                        .compareTo(((IMatchingObject) e2).getName().toLowerCase());

            return super.compare(viewer, e1, e2);
        }
    });

    createCompositeAdditions(result);

    return result;
}

From source file:org.eclipse.gmf.runtime.diagram.ui.preferences.AppearancePreferencePage.java

License:Open Source License

/**
 * Set the default font for this preference store. Assumes that the method
 * executed on the UI thread//from  w  ww.  j  a  va2  s  .  c o m
 * 
 * @param store
 *            IPreferenceStore
 */
private static void initDefaultFontProc(IPreferenceStore store) {
    FontData fontDataArray[] = JFaceResources.getDefaultFont().getFontData();
    FontData fontData = fontDataArray[0];
    fontData.setHeight(9);
    PreferenceConverter.setDefault(store, IPreferenceConstants.PREF_DEFAULT_FONT, fontData);
}

From source file:org.eclipse.gmf.runtime.diagram.ui.printing.internal.util.SWTDiagramPrinter.java

License:Open Source License

/**
 * Print the diagram figure using specified scale factor.
 * //  w  w  w.j a  v  a 2s  .c  o  m
 * @param dgrmEP the DiagramEditPart that will be printed
 * @param loadedPreferences true if existing prefs could be loaded
 * successfully, false if not and defaults are being used.  This parameter
 * is important to obtain the correct page break bounds.
 * @param fPreferences the preferenceStore that could either contain
 * existing preferences or defaults
 */
protected void printToScale(DiagramEditPart dgrmEP, boolean loadedPreferences, IPreferenceStore fPreferences) {

    assert null != printer : "printer must be set"; //$NON-NLS-1$
    Rectangle figureBounds = PrintHelperUtil.getPageBreakBounds(dgrmEP, loadedPreferences);
    org.eclipse.draw2d.geometry.Point pageBounds = PageInfoHelper.getPageSize(fPreferences, getMapMode());

    //translate to offset initial figure position
    translated = new Point((int) (-figureBounds.x * userScale), (int) (-figureBounds.y * userScale));

    //calculate the number of page rows and columns
    int numRows = 0, numCols = 0;

    PageMargins margins = PageInfoHelper.getPageMargins(fPreferences, getMapMode());
    adjustMargins(margins, userScale, getPrinterOffset());

    GC gc_ = new GC(DisplayUtils.getDisplay(), this.gc.getStyle());
    gc_.setAntialias(this.gc.getAntialias());

    FontData fontData = JFaceResources.getDefaultFont().getFontData()[0];
    Font font = new Font(printer, fontData);

    org.eclipse.draw2d.geometry.Point pageCount = getPageCount(dgrmEP, figureBounds, pageBounds, true);
    numCols = pageCount.x;
    numRows = pageCount.y;

    //finalRow and finalColumn will be used if we are printing within a page range...
    int row = 1, col = 1, finalRow = 0, finalColumn = 0;

    if (this.printRangePageSelection) {
        //print only the pages specified in the page range...
        row = calculateRowFromPage(this.pageFrom, numCols);
        col = calculateColumnFromPage(this.pageFrom, numCols, row);

        finalRow = calculateRowFromPage(this.pageTo, numCols);
        finalColumn = calculateColumnFromPage(this.pageTo, numCols, finalRow);
    }

    try {
        //print the pages in row, column order
        for (; row <= numRows; row++) {
            for (; col <= numCols; col++) {
                printer.startPage();
                drawPage(gc_, dgrmEP, fPreferences, figureBounds, margins, font, row, col);
                printer.endPage();

                if (row == finalRow && col == finalColumn && this.printRangePageSelection == true)
                    break;
            }

            if (row == finalRow && col == finalColumn && this.printRangePageSelection == true)
                break;

            col = 1;
        }
    } finally {
        //must dispose resources
        font.dispose();
        gc_.dispose();
    }
}

From source file:org.eclipse.gmf.runtime.diagram.ui.printing.internal.util.SWTDiagramPrinter.java

License:Open Source License

/**
 * Print the diagram figure to fit the number and rows and columns
 * specified by the user./*from   w  w w  .ja v  a 2 s  .c  o m*/
 * 
 * @param dgrmEP the DiagramEditPart that will be printed
 * @param loadedPreferences true if existing prefs could be loaded
 * successfully, false if not and defaults are being used.  This parameter
 * is important to obtain the correct page break bounds.
 * @param fPreferences the preferenceStore that could either contain
 * existing preferences or defaults
 */
protected void printToPages(DiagramEditPart dgrmEP, boolean loadedPreferences, IPreferenceStore fPreferences) {
    assert null != printer : "printer must be set"; //$NON-NLS-1$

    Rectangle figureBounds = PrintHelperUtil.getPageBreakBounds(dgrmEP, loadedPreferences);

    PageMargins margins = PageInfoHelper.getPageMargins(fPreferences, getMapMode());
    //do not include margins
    org.eclipse.draw2d.geometry.Point pageBounds = PageInfoHelper.getPageSize(fPreferences, getMapMode());
    org.eclipse.draw2d.geometry.Point pageCount = getPageCount(dgrmEP, figureBounds, pageBounds, false);
    int numCols = pageCount.x;
    int numRows = pageCount.y;

    float actualWidth = 0;
    float actualHeight = 0;
    if (this.rows == 1 && this.columns == 1 && fitToPage) {
        figureBounds = dgrmEP.getChildrenBounds();
        actualWidth = figureBounds.width;
        actualHeight = figureBounds.height;
    } else {
        actualWidth = numCols * pageBounds.x;
        actualHeight = numRows * pageBounds.y;
    }

    int totalHeight = (this.rows * pageBounds.y);
    int totalWidth = (this.columns * pageBounds.x);

    float vScale = totalHeight / actualHeight;
    float hScale = totalWidth / actualWidth;

    this.userScale = Math.min(hScale, vScale);

    // translate to offset figure position
    translated = new Point((int) (-figureBounds.x * userScale), (int) (-figureBounds.y * userScale));

    adjustMargins(margins, userScale, getPrinterOffset());

    GC gc_ = new GC(DisplayUtils.getDisplay());

    FontData fontData = JFaceResources.getDefaultFont().getFontData()[0];
    Font font = new Font(printer, fontData);

    int row = 1, col = 1, finalRow = 0, finalColumn = 0;

    if (this.printRangePageSelection) {
        //print only the pages specified in the page range
        //this corresponds to the physical pages, not the print range of pages on one physical page.
        row = calculateRowFromPage(this.pageFrom, this.columns);
        col = calculateColumnFromPage(this.pageFrom, this.columns, row);

        finalRow = calculateRowFromPage(this.pageTo, this.columns);
        finalColumn = calculateColumnFromPage(this.pageTo, this.columns, finalRow);
    }

    try {
        // print the pages in row, column order
        for (; row <= rows; row++) {
            for (; col <= columns; col++) {
                printer.startPage();
                drawPage(gc_, dgrmEP, fPreferences, figureBounds, margins, font, row, col);
                printer.endPage();

                if (row == finalRow && col == finalColumn && this.printRangePageSelection == true)
                    break;
            }

            if (row == finalRow && col == finalColumn && this.printRangePageSelection == true)
                break;

            col = 1;
        }
    } finally {
        // must dispose resources
        font.dispose();
        gc_.dispose();
    }
}

From source file:org.eclipse.gmf.runtime.diagram.ui.printing.render.internal.JPSDiagramPrinter.java

License:Open Source License

/**
 * Print the diagram figure using specified scale factor.
 * // w  w w  .  j  a  v a 2  s  .  c  om
 * @param dgrmEP
 *            The diagram edit part to print
 * @param loadedPreferences
 *            true if existing prefs could be loaded successfully, false if
 *            not and defaults are being used. This parameter is important
 *            to obtain the correct page break bounds.
 * @param fPreferences
 *            the preferenceStore that could either contain existing
 *            preferences or defaults
 */
protected void printToScale(DiagramEditPart dgrmEP, boolean loadedPreferences, IPreferenceStore fPreferences) {

    Rectangle figureBounds = PrintHelperUtil.getPageBreakBounds(dgrmEP, loadedPreferences);

    org.eclipse.draw2d.geometry.Point pageBounds = PageInfoHelper.getPageSize(fPreferences, getMapMode());
    //
    // Translate to offset initial figure position
    //
    translated = new Point((int) (-figureBounds.x * userScale), (int) (-figureBounds.y * userScale));
    //
    // Calculate the number of page rows and columns
    //
    int numRows = 0, numCols = 0;

    PageMargins margins = adjustMarginsToScale(PageInfoHelper.getPageMargins(fPreferences, getMapMode()));

    FontData fontData = JFaceResources.getDefaultFont().getFontData()[0];

    org.eclipse.draw2d.geometry.Point pageCount = getPageCount(dgrmEP, figureBounds, pageBounds, true);

    numCols = pageCount.x;
    numRows = pageCount.y;

    int row = 1, col = 1, finalRow = 0, finalColumn = 0;

    List<PageData> pageList = new java.util.ArrayList<PageData>();

    if (this.printRangePageSelection) {
        //
        // Print only the pages specified in the page range...
        //
        row = calculateRowFromPage(this.pageFrom, numCols);
        col = calculateColumnFromPage(this.pageFrom, numCols, row);

        finalRow = calculateRowFromPage(this.pageTo, numCols);
        finalColumn = calculateColumnFromPage(this.pageTo, numCols, finalRow);
    }
    //
    // Print the pages in row, column order
    //
    for (; row <= numRows; row++) {
        for (; col <= numCols; col++) {

            pageList.add(new PageData(pageList.size(), row, col, dgrmEP, figureBounds, margins, fontData,
                    fPreferences));

            if (row == finalRow && col == finalColumn && this.printRangePageSelection == true) {
                break;
            }
        }
        if (row == finalRow && col == finalColumn && this.printRangePageSelection == true) {
            break;
        }
        col = 1;
    }
    pages = pageList.toArray(new PageData[pageList.size()]);
}

From source file:org.eclipse.gmf.runtime.diagram.ui.printing.render.internal.JPSDiagramPrinter.java

License:Open Source License

/**
 * Print the diagram figure to fit the number and rows and columns specified
 * by the user.//  w  w w . j a va 2  s  .  c  om
 * 
 * @param dgrmEP
 *            The diagram edit part to print
 * @param loadedPreferences
 *            true if existing prefs could be loaded successfully, false if
 *            not and defaults are being used. This parameter is important
 *            to obtain the correct page break bounds.
 * @param fPreferences
 *            the preferenceStore that could either contain existing
 *            preferences or defaults
 */
protected void printToPages(DiagramEditPart dgrmEP, boolean loadedPreferences, IPreferenceStore fPreferences) {

    Rectangle figureBounds = PrintHelperUtil.getPageBreakBounds(dgrmEP, loadedPreferences);

    org.eclipse.draw2d.geometry.Point pageBounds = PageInfoHelper.getPageSize(fPreferences, getMapMode());
    org.eclipse.draw2d.geometry.Point pageCount = getPageCount(dgrmEP, figureBounds, pageBounds, false);
    int numCols = pageCount.x;
    int numRows = pageCount.y;

    float actualWidth = 0;
    float actualHeight = 0;
    if (this.rows == 1 && this.columns == 1 && fitToPage) {
        figureBounds = dgrmEP.getChildrenBounds();
        actualWidth = figureBounds.width;
        actualHeight = figureBounds.height;
    } else {
        actualWidth = numCols * pageBounds.x;
        actualHeight = numRows * pageBounds.y;
    }

    int totalHeight = (this.rows * pageBounds.y);
    int totalWidth = (this.columns * pageBounds.x);

    float vScale = totalHeight / actualHeight;
    float hScale = totalWidth / actualWidth;

    this.userScale = Math.min(hScale, vScale);

    PageMargins margins = adjustMarginsToScale(PageInfoHelper.getPageMargins(fPreferences, getMapMode()));

    translated = new Point((int) (-figureBounds.x * userScale), (int) (-figureBounds.y * userScale));

    FontData fontData = JFaceResources.getDefaultFont().getFontData()[0];

    int row = 1, col = 1, finalRow = 0, finalColumn = 0;
    List<PageData> pageList = new java.util.ArrayList<PageData>();

    if (this.printRangePageSelection) {
        //
        // Print only the pages specified in the page range
        // this corresponds to the physical pages, not the print range of
        // pages on one physical page.
        //
        row = calculateRowFromPage(this.pageFrom, this.columns);
        col = calculateColumnFromPage(this.pageFrom, this.columns, row);

        finalRow = calculateRowFromPage(this.pageTo, this.columns);
        finalColumn = calculateColumnFromPage(this.pageTo, this.columns, finalRow);
    }

    for (; row <= rows; row++) {
        for (; col <= columns; col++) {

            pageList.add(new PageData(pageList.size(), row, col, dgrmEP, figureBounds, margins, fontData,
                    fPreferences));

            if (row == finalRow && col == finalColumn && this.printRangePageSelection == true) {
                break;
            }
        }
        if (row == finalRow && col == finalColumn && this.printRangePageSelection == true) {
            break;
        }
        col = 1;
    }
    pages = pageList.toArray(new PageData[pageList.size()]);
}

From source file:org.eclipse.gyrex.admin.ui.internal.helper.SwtUtil.java

License:Open Source License

public static int getTableHeightHint(final Table table, final int rows) {
    if (table.getFont().equals(JFaceResources.getDefaultFont())) {
        table.setFont(JFaceResources.getDialogFont());
    }/*from   w  w w.j ava 2  s . c  o m*/
    int result = table.getItemHeight() * rows + table.getHeaderHeight();
    if (table.getLinesVisible()) {
        result += table.getGridLineWidth() * (rows - 1);
    }
    return result;
}

From source file:org.eclipse.help.ui.internal.views.SeeAlsoPart.java

License:Open Source License

private void updateLinks(String href) {
    Control[] children = linkContainer.getChildren();
    for (int i = 0; i < children.length; i++) {
        ImageHyperlink link = (ImageHyperlink) children[i];
        RowData data = (RowData) link.getLayoutData();
        boolean isCurrentPage = link.getHref().equals(href);
        if (isCurrentPage) {
            link.setFont(JFaceResources.getBannerFont());
        } else {//  ww  w.  j  a v  a 2 s.c  om
            link.setFont(JFaceResources.getDefaultFont());
        }
        data.exclude = false;
        link.setVisible(!data.exclude);
    }
    linkContainer.layout();
    helpPart.reflow();
}

From source file:org.eclipse.jface.snippets.window.Snippet020CustomizedControlTooltips.java

License:Open Source License

public Snippet020CustomizedControlTooltips(final Shell parent) {
    JFaceResources.getColorRegistry().put(MyToolTip.HEADER_BG_COLOR, new RGB(255, 255, 255));
    JFaceResources.getFontRegistry().put(MyToolTip.HEADER_FONT, JFaceResources.getFontRegistry()
            .getBold(JFaceResources.getDefaultFont().getFontData()[0].getName()).getFontData());

    JFaceResources.getImageRegistry().put(MyToolTip.HEADER_CLOSE_ICON,
            ImageDescriptor.createFromFile(Snippet020CustomizedControlTooltips.class, "showerr_tsk.gif"));
    JFaceResources.getImageRegistry().put(MyToolTip.HEADER_HELP_ICON,
            ImageDescriptor.createFromFile(Snippet020CustomizedControlTooltips.class, "linkto_help.gif"));

    Text text = new Text(parent, SWT.BORDER);
    text.setText("Hello World");

    MyToolTip myTooltipLabel = new MyToolTip(text) {

        @Override/*from w  ww .  j  av a 2  s. c  o  m*/
        protected Composite createContentArea(Composite parent) {
            Composite comp = super.createContentArea(parent);
            comp.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
            FillLayout layout = new FillLayout();
            layout.marginWidth = 5;
            comp.setLayout(layout);
            Link l = new Link(comp, SWT.NONE);
            l.setText(
                    "This a custom tooltip you can: \n- pop up any control you want\n- define delays\n - ... \nGo and get Eclipse from <a>http://www.eclipse.org</a>");
            l.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
            l.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    openURL();
                }
            });
            return comp;
        }

        protected void openURL() {
            MessageBox box = new MessageBox(parent, SWT.ICON_INFORMATION);
            box.setText("Eclipse.org");
            box.setMessage("Here is where we'd open the URL.");
            box.open();
        }

        @Override
        protected void openHelp() {
            MessageBox box = new MessageBox(parent, SWT.ICON_INFORMATION);
            box.setText("Info");
            box.setMessage("Here is where we'd show some information.");
            box.open();
        }

    };
    myTooltipLabel.setShift(new Point(-5, -5));
    myTooltipLabel.setHideOnMouseDown(false);
    myTooltipLabel.activate();

    text = new Text(parent, SWT.BORDER);
    text.setText("Hello World");
    DefaultToolTip toolTip = new DefaultToolTip(text);
    toolTip.setText("Hello World\nHello World");
    toolTip.setBackgroundColor(parent.getDisplay().getSystemColor(SWT.COLOR_RED));

    Button b = new Button(parent, SWT.PUSH);
    b.setText("Popup on press");

    final DefaultToolTip toolTipDelayed = new DefaultToolTip(b, ToolTip.RECREATE, true);
    toolTipDelayed.setText("Hello World\nHello World");
    toolTipDelayed.setBackgroundColor(parent.getDisplay().getSystemColor(SWT.COLOR_RED));
    toolTipDelayed.setHideDelay(2000);

    b.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            toolTipDelayed.show(new Point(0, 0));
        }
    });

}