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:ca.usask.cs.srlab.simclipse.ui.SWTUtil.java

License:Open Source License

public static int getTableHeightHint(Table table, int rows) {
    if (table.getFont().equals(JFaceResources.getDefaultFont()))
        table.setFont(JFaceResources.getDialogFont());
    int result = table.getItemHeight() * rows + table.getHeaderHeight();
    if (table.getLinesVisible())
        result += table.getGridLineWidth() * (rows - 1);
    return result;
}

From source file:cc.warlock.rcp.configuration.GameViewConfiguration.java

License:Open Source License

private GameViewConfiguration(IWarlockSetting parent) {
    super(parent, ID);

    String bgString = getNode().get("background", null);
    if (bgString != null)
        defaultBackground = new WarlockColor(bgString);
    String fgString = getNode().get("foreground", null);
    if (fgString != null)
        defaultForeground = new WarlockColor(fgString);

    defaultFontFace = getNode().get("face", JFaceResources.getDefaultFont().getFontData()[0].getName());
    defaultFontSize = getNode().getInt("size", JFaceResources.getDefaultFont().getFontData()[0].getHeight());

    bufferLines = getNode().getInt("buffer", 5000);
    suppressPrompt = getNode().getBoolean("suppress-prompt", false);

    // WarlockConfiguration.getMainConfiguration().addConfigurationProvider(this);
}

From source file:cc.warlock.rcp.stormfront.ui.StormFrontDialogControl.java

License:Open Source License

public StormFrontDialogControl(Composite composite, int style) {
    super(composite, style);
    Display display = this.getDisplay();

    // defaults/*from   ww w  .j a  va  2s .  c  om*/
    width = 100;
    height = 15;

    Font textFont = JFaceResources.getDefaultFont();
    FontData textData = textFont.getFontData()[0];
    int minHeight = 8;

    healthBG = new Color(display, 0x80, 0, 0);
    healthFG = new Color(display, 255, 255, 255);
    healthBorder = new Color(display, 0x79, 0x6a, 0x6a);

    manaBG = new Color(display, 0, 0, 0xff);
    manaFG = new Color(display, 255, 255, 255);
    manaBorder = new Color(display, 0x72, 0x72, 0xff);

    fatigueBG = new Color(display, 0xd0, 0x98, 0x2f);
    fatigueFG = new Color(display, 0, 0, 0);
    fatigueBorder = new Color(display, 0xde, 0xcc, 0xaa);

    spiritBG = new Color(display, 150, 150, 150);
    spiritFG = new Color(display, 0, 0, 0);
    spiritBorder = new Color(display, 225, 225, 225);

    concentrationBG = new Color(display, 0, 255, 0);
    concentrationFG = new Color(display, 0, 0, 0);
    concentrationBorder = new Color(display, 225, 225, 225);

    defaultBG = new Color(display, 150, 150, 150);
    defaultFG = new Color(display, 0, 0, 0);
    defaultBorder = new Color(display, 225, 225, 225);

    progressFont = new Font(getShell().getDisplay(), textData.getName(),
            (int) Math.max(minHeight, textData.getHeight()), textData.getStyle());

    borderWidth = 1;

    addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            Rectangle bounds = getBounds();

            e.gc.setFont(progressFont);

            for (StormFrontProgressBar progressBar : progressBars.values()) {
                int pbWidth = progressBar.getWidth();
                int pbLeft = progressBar.getLeft();
                int pbValue = progressBar.getValue();

                // This should probably all be abstracted out
                int fullBarWidth = pbWidth * bounds.width / 100;
                int barWidth = fullBarWidth - 2 * borderWidth;
                int barHeight = bounds.height - 2 * borderWidth;
                int filledWidth = pbValue * barWidth / 100;
                int left = pbLeft * bounds.width / 100;

                // Draw the border
                Color borderColor = getBorderColor(progressBar.id);
                e.gc.setForeground(borderColor);
                e.gc.setLineWidth(borderWidth);
                e.gc.drawRectangle(left, 0, fullBarWidth, bounds.height);

                Color bgColor = getBgColor(progressBar.id);

                // draw the filled part of the rectangle
                Color gradientColor = getGradientColor(25, true, bgColor);
                e.gc.setBackground(gradientColor);
                e.gc.setForeground(bgColor);
                e.gc.fillGradientRectangle(borderWidth + left, borderWidth, filledWidth, barHeight, false);

                // draw the background
                e.gc.setBackground(borderColor);
                e.gc.fillRectangle(borderWidth + left + filledWidth, borderWidth, barWidth - filledWidth,
                        barHeight);

                Color textColor = getTextColor(progressBar.id);
                e.gc.setForeground(textColor);

                String text = progressBar.text;
                Point extent = e.gc.textExtent(text);

                int text_left = left + (barWidth - extent.x) / 2;
                int text_top = (bounds.height - 2 * borderWidth - e.gc.getFontMetrics().getHeight()) / 2;
                e.gc.drawText(text, text_left, text_top, true);
            }
        }
    });
}

From source file:cc.warlock.rcp.ui.WarlockPopupAction.java

License:Open Source License

public WarlockPopupAction(Composite parent, int style) {
    super(parent, style);

    this.parent = parent;
    parent.addPaintListener(this);
    addPaintListener(this);

    this.background = new Color(getDisplay(), 239, 243, 193);
    setBackground(background);/*ww w .j  a v  a 2  s  .co m*/
    setCursor(getDisplay().getSystemCursor(SWT.CURSOR_ARROW));

    FontData defaultFontData = JFaceResources.getDefaultFont().getFontData()[0];
    int height = Math.max(8, defaultFontData.getHeight() - 1);

    smallFont = new Font(getDisplay(), defaultFontData.getName(), height, defaultFontData.getStyle());
    setFont(smallFont);
}

From source file:cc.warlock.rcp.ui.WarlockProgressBar.java

License:Open Source License

public WarlockProgressBar(Composite composite, int style) {
    super(composite, style);

    // defaults/*from  w  w w . jav a  2s. c om*/
    width = 100;
    height = 15;
    showText = true;

    Font textFont = JFaceResources.getDefaultFont();
    FontData textData = textFont.getFontData()[0];
    int minHeight = 8;

    progressFont = new Font(getShell().getDisplay(), textData.getName(),
            (int) Math.max(minHeight, textData.getHeight()), textData.getStyle());
    foreground = new Color(getShell().getDisplay(), 255, 255, 255);
    background = new Color(getShell().getDisplay(), 0, 0, 0);
    borderColor = new Color(getShell().getDisplay(), 25, 25, 25);

    borderWidth = 1;

    addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            Rectangle bounds = getBounds();

            int barWidth = 0;
            int fullBarWidth = bounds.width - 2 * borderWidth;
            int fullBarHeight = bounds.height - 2 * borderWidth;

            if (max > min) {
                double decimal = (selection / ((double) (max - min)));
                barWidth = (int) Math.floor(decimal * fullBarWidth - 1);
            }

            Color gradientColor = getGradientColor(25, true);
            e.gc.setBackground(gradientColor);
            e.gc.setForeground(background);
            e.gc.fillGradientRectangle(borderWidth, borderWidth, barWidth, fullBarHeight, false);

            e.gc.setBackground(borderColor);
            e.gc.fillRectangle(borderWidth + barWidth, borderWidth, fullBarWidth, fullBarHeight);

            e.gc.setForeground(borderColor);
            e.gc.setLineWidth(borderWidth);
            e.gc.drawRectangle(0, 0, bounds.width, bounds.height);

            if (showText && label != null) {

                e.gc.setFont(progressFont);

                Point extent = e.gc.textExtent(label);

                int left = (bounds.width - 2 * borderWidth - extent.x) / 2;
                int top = (bounds.height - 2 * borderWidth - e.gc.getFontMetrics().getHeight()) / 2;

                e.gc.setForeground(foreground);
                e.gc.drawText(label, left, top, true);

            }
        }
    });
}

From source file:cc.warlock.rcp.util.RCPUtil.java

License:Open Source License

static public FontData[] getFontList(Shell shell, IWarlockFont font) {

    if (font.isDefaultFont()) {
        return JFaceResources.getDefaultFont().getFontData();
    }//from  ww  w .  j a va  2  s .  c  o  m

    FontData datas[] = new FontData[0];

    if (font.getFamilyName() != null)
        datas = shell.getDisplay().getFontList(font.getFamilyName(), true);

    FontData data = new FontData();
    if (datas.length == 0) {
        return JFaceResources.getDefaultFont().getFontData();
    } else {
        data.setName(font.getFamilyName());
        data.setHeight(font.getSize());

        return new FontData[] { data };
    }
}

From source file:com.aptana.editor.common.contentassist.CompletionProposalPopup.java

License:Open Source License

/**
 * Creates the proposal selector.// w ww.j  a v  a2 s  .  co m
 */
private void createProposalSelector() {
    Control control = fContentAssistSubjectControlAdapter.getControl();
    if (Helper.okToUse(fProposalShell)) {
        // Custom code to force colors again in case theme changed...
        // Not sure why we don't set background for all WS here
        if (!"carbon".equals(SWT.getPlatform())) //$NON-NLS-1$
        {
            fProposalShell.setBackground(getForegroundColor(control));
        }

        Color c = getBackgroundColor(control);
        fProposalTable.setBackground(c);

        c = getForegroundColor(control);
        fProposalTable.setForeground(c);
        return;
    }

    fProposalShell = new Shell(control.getShell(), SWT.ON_TOP | SWT.RESIZE);
    fProposalShell.setFont(JFaceResources.getDefaultFont());
    if (USE_VIRTUAL) {
        fProposalTable = new Table(fProposalShell, SWT.H_SCROLL | SWT.V_SCROLL | SWT.VIRTUAL);

        Listener listener = new Listener() {
            public void handleEvent(Event event) {
                handleSetData(event);
            }
        };
        fProposalTable.addListener(SWT.SetData, listener);
    } else {
        fProposalTable = new Table(fProposalShell, SWT.H_SCROLL | SWT.V_SCROLL);
    }

    fProposalShell.addControlListener(new ControlAdapter() {
        public void controlResized(ControlEvent e) {
            TableColumn[] columns = fProposalTable.getColumns();
            int currentSize = 0;
            for (int i = 1; i < columns.length; i++) {
                currentSize += columns[i].getWidth();
            }

            Rectangle area = fProposalShell.getClientArea();
            int width = getTableWidth();
            TableColumn column1 = fProposalTable.getColumn(0);

            // take up any remaining space for first column
            fProposalTable.setSize(area.width, area.height);

            int col1Width = width - currentSize;

            // 1st column can't be smaller than a default size;
            col1Width = Math.max(col1Width, MIN_PROPOSAL_COLUMN_WIDTH);
            column1.setWidth(col1Width);
        }
    });

    _insertOnTab = true; // store.getBoolean(IPreferenceConstants.INSERT_ON_TAB);

    // Here we add custom columns
    new TableColumn(fProposalTable, SWT.LEFT);

    for (int i = 0; i < fContentAssistant.getUserAgentColumnCount(); i++) {
        TableColumn tc = new TableColumn(fProposalTable, SWT.LEFT);
        tc.setWidth(20);
    }

    new TableColumn(fProposalTable, SWT.LEFT);
    // end custom columns

    fProposalTable.setLocation(0, 0);
    if (fAdditionalInfoController != null) {
        fAdditionalInfoController.setSizeConstraints(40, 20, true, false);
    }

    // Custom code: We set margins to 1 so we get a border
    GridLayout layout = new GridLayout();
    layout.marginWidth = 1;
    layout.marginHeight = 1;
    fProposalShell.setLayout(layout);

    GridData data = new GridData(GridData.FILL_BOTH);

    Point size = fContentAssistant.restoreCompletionProposalPopupSize();
    if (size != null) {
        fProposalTable.setLayoutData(data);
        fProposalShell.setSize(size);
    } else {
        int height = fProposalTable.getItemHeight() * CompletionProposalPopup.PROPOSAL_ITEMS_VISIBLE;
        // use golden ratio as default aspect ratio
        final double aspectRatio = (1 + Math.sqrt(5)) / 2;
        int width = (int) (height * aspectRatio);
        Rectangle trim = fProposalTable.computeTrim(0, 0, width, height);
        data.heightHint = trim.height;
        data.widthHint = trim.width;
        fProposalTable.setLayoutData(data);
        fProposalShell.pack();
    }

    fProposalShell.addControlListener(new ControlListener() {

        public void controlMoved(ControlEvent e) {
        }

        public void controlResized(ControlEvent e) {
            if (fAdditionalInfoController != null) {
                // reset the cached resize constraints
                fAdditionalInfoController.setSizeConstraints(40, 20, true, false);
                fAdditionalInfoController.hideInformationControl();
                fAdditionalInfoController.handleTableSelectionChanged();
            }

            fSize = fProposalShell.getSize();
        }
    });

    // Custom code: not sure why we don't set background for all WS here
    if (!"carbon".equals(SWT.getPlatform())) //$NON-NLS-1$
    {
        fProposalShell.setBackground(getForegroundColor(control));
    }

    Color c = getBackgroundColor(control);
    fProposalTable.setBackground(c);

    c = getForegroundColor(control);
    fProposalTable.setForeground(c);

    // Custom code for overriding selection color
    Listener selectionOverride = new Listener() {
        public void handleEvent(Event event) {
            if ((event.detail & SWT.SELECTED) != 0) {
                GC gc = event.gc;
                Color oldBackground = gc.getBackground();

                Color sc = fContentAssistant.getProposalSelectorSelectionColor();
                if (sc == null)
                    return;
                gc.setBackground(sc);
                gc.fillRectangle(event.x, event.y, event.width, event.height);
                gc.setBackground(oldBackground);

                event.detail &= ~SWT.SELECTED;
                event.detail &= ~SWT.BACKGROUND;

                gc.setForeground(getForegroundColor(fContentAssistSubjectControlAdapter.getControl()));
            }
        }
    };
    fProposalTable.addListener(SWT.EraseItem, selectionOverride);

    fProposalTable.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            selectProposalWithMask(e.stateMask);
            // This disposal on windows it because of focus issue when a select is manually select and the next time
            // the popup is show it has focus and so editor typing focus is lost
            if (Platform.OS_WIN32.equals(Platform.getOS())) {
                disposePopup();
            }
        }
    });
    fPopupCloser.install(fContentAssistant, fProposalTable, fAdditionalInfoController);
    // TISTUD-913: changed to the line above from 'fPopupCloser.install(fContentAssistant, fProposalTable);'

    installPreferenceListener();

    fProposalShell.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            unregister(); // but don't dispose the shell, since we're being called from its disposal event!
        }
    });

    fProposalTable.setHeaderVisible(false);

    // addCommandSupport(fProposalTable);
}

From source file:com.aptana.ide.core.ui.SWTUtils.java

License:Open Source License

/**
 * Gets the default small font from the JFace font registry
 * /*from  w  w w.jav  a2  s.  c  o  m*/
 * @return - default small font
 */
public static Font getDefaultSmallFont() {
    Font small = JFaceResources.getFontRegistry().get(SMALL_FONT);
    if (small != null) {
        return small;
    }

    Font f = JFaceResources.getDefaultFont();
    FontData[] smaller = resizeFont(f, -2);
    JFaceResources.getFontRegistry().put(SMALL_FONT, smaller);
    return JFaceResources.getFontRegistry().get(SMALL_FONT);
}

From source file:com.aptana.ide.core.ui.SWTUtils.java

License:Open Source License

/**
 * Gets the default large font from the JFace font registry
 * //from www . jav  a2s. c om
 * @return - default large font
 */
public static Font getDefaultLargeFont() {
    Font small = JFaceResources.getFontRegistry().get(LARGE_FONT);
    if (small != null) {
        return small;
    }

    Font f = JFaceResources.getDefaultFont();
    FontData[] smaller = resizeFont(f, -2);
    JFaceResources.getFontRegistry().put(LARGE_FONT, smaller);
    return JFaceResources.getFontRegistry().get(LARGE_FONT);
}

From source file:com.aptana.ide.internal.ui.dialogs.SWTUtil.java

License:Open Source License

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