Search in sources :

Example 56 with Font

use of org.eclipse.swt.graphics.Font in project linuxtools by eclipse.

the class PieChartPaintListener method adjustTitle.

// Adjust the title with trailing blanks so it centers in the plot area
// rather than for the entire chart view which looks odd when not
// centered above the pie-charts themselves.
private void adjustTitle(PaintEvent pe) {
    ITitle title = chart.getTitle();
    Font font = title.getFont();
    Font oldFont = pe.gc.getFont();
    pe.gc.setFont(font);
    Control legend = (Control) chart.getLegend();
    Rectangle legendBounds = legend.getBounds();
    int adjustment = legendBounds.width - 15;
    // $NON-NLS-1$
    Point blankSize = pe.gc.textExtent(" ");
    int numBlanks = ((adjustment / blankSize.x) >> 1) << 1;
    String text = origTitleText;
    for (int i = 0; i < numBlanks; ++i) // $NON-NLS-1$
    text += " ";
    pe.gc.setFont(oldFont);
    title.setText(text);
}
Also used : Control(org.eclipse.swt.widgets.Control) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) ITitle(org.swtchart.ITitle) Font(org.eclipse.swt.graphics.Font) Point(org.eclipse.swt.graphics.Point)

Example 57 with Font

use of org.eclipse.swt.graphics.Font in project linuxtools by eclipse.

the class PieChartPaintListener method drawPieChart.

private void drawPieChart(PaintEvent e, int chartnum, Rectangle bounds) {
    double[] series = seriesValues[chartnum];
    int nelemSeries = series.length;
    double sumTotal = 0;
    // Don't need first angle; it's always 0
    pieSliceAngles[chartnum] = new int[nelemSeries - 1];
    for (int i = 0; i < nelemSeries; i++) {
        sumTotal += series[i];
    }
    GC gc = e.gc;
    Font oldFont = gc.getFont();
    gc.setLineWidth(1);
    int pieX = bounds.x + (bounds.width - pieWidth) / 2;
    int pieY = bounds.y + (bounds.height - pieWidth) / 2;
    pieCenters[chartnum] = new Point(pieX + pieWidth / 2, pieY + pieWidth / 2);
    if (sumTotal == 0) {
        gc.drawOval(pieX, pieY, pieWidth, pieWidth);
    } else {
        double factor = 100 / sumTotal;
        int sweepAngle = 0;
        int incrementAngle = 0;
        int initialAngle = 90;
        for (int i = 0; i < nelemSeries; i++) {
            // Stored angles increase in clockwise direction from 0 degrees at 12:00
            if (i > 0) {
                pieSliceAngles[chartnum][i - 1] = 90 - initialAngle;
            }
            gc.setBackground(((IBarSeries) chart.getSeriesSet().getSeries()[i]).getBarColor());
            if (i == (nelemSeries - 1)) {
                sweepAngle = 360 - incrementAngle;
            } else {
                double angle = series[i] * factor * 3.6;
                sweepAngle = (int) Math.round(angle);
            }
            gc.fillArc(pieX, pieY, pieWidth, pieWidth, initialAngle, (-sweepAngle));
            gc.drawArc(pieX, pieY, pieWidth, pieWidth, initialAngle, (-sweepAngle));
            incrementAngle += sweepAngle;
            initialAngle += (-sweepAngle);
        }
        gc.drawLine(pieCenters[chartnum].x, pieCenters[chartnum].y, pieCenters[chartnum].x, pieCenters[chartnum].y - pieWidth / 2);
    }
    Font font = new Font(Display.getDefault(), FONT, 12, SWT.BOLD);
    gc.setForeground(BLACK);
    gc.setBackground(WHITE);
    gc.setFont(font);
    String text = seriesNames[chartnum];
    Point textSize = e.gc.textExtent(text);
    gc.drawText(text, pieX + (pieWidth - textSize.x) / 2, pieY + pieWidth + textSize.y);
    gc.setFont(oldFont);
    font.dispose();
}
Also used : Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font)

Example 58 with Font

use of org.eclipse.swt.graphics.Font in project linuxtools by eclipse.

the class ChartEditor method createPartControl.

@Override
public void createPartControl(Composite parent) {
    final ChartEditorInput input = (ChartEditorInput) getEditorInput();
    final HeapChart heapChart = input.getChart();
    control = new Chart(parent, SWT.FILL);
    heapChart.setChartControl(control);
    final Color LIGHTYELLOW = new Color(Display.getDefault(), 255, 255, 225);
    final Color WHITE = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
    final Color BLACK = Display.getDefault().getSystemColor(SWT.COLOR_BLACK);
    final Color RED = Display.getDefault().getSystemColor(SWT.COLOR_RED);
    final Color ORANGE = new Color(Display.getDefault(), 255, 165, 0);
    final Color GREEN = Display.getDefault().getSystemColor(SWT.COLOR_GREEN);
    final Color DARK_BLUE = new Color(Display.getDefault(), 64, 128, 128);
    final int TICK_GAP = 40;
    control.setBackground(WHITE);
    control.setBackgroundInPlotArea(LIGHTYELLOW);
    FontData fd = JFaceResources.getDialogFont().getFontData()[0];
    fd.setStyle(SWT.BOLD);
    Font font = new Font(Display.getDefault(), fd);
    fd.setHeight(fd.getHeight() + 2);
    Font titleFont = new Font(Display.getDefault(), fd);
    ITitle title = control.getTitle();
    title.setFont(titleFont);
    title.setForeground(BLACK);
    title.setText(heapChart.title);
    IAxis xAxis = control.getAxisSet().getXAxis(0);
    xAxis.getGrid().setStyle(LineStyle.NONE);
    xAxis.getTick().setForeground(BLACK);
    ITitle xTitle = xAxis.getTitle();
    xTitle.setFont(font);
    xTitle.setForeground(BLACK);
    xTitle.setText(heapChart.xUnits);
    IAxis yAxis = control.getAxisSet().getYAxis(0);
    yAxis.getGrid().setStyle(LineStyle.SOLID);
    yAxis.getTick().setForeground(BLACK);
    yAxis.getTick().setTickMarkStepHint(TICK_GAP);
    ITitle yTitle = yAxis.getTitle();
    yTitle.setFont(font);
    yTitle.setText(heapChart.yUnits);
    yTitle.setForeground(BLACK);
    control.getLegend().setPosition(SWT.BOTTOM);
    // data
    final ILineSeries lsUseful = (ILineSeries) control.getSeriesSet().createSeries(SeriesType.LINE, // $NON-NLS-1$;
    Messages.getString("HeapChart.Useful_Heap"));
    lsUseful.setXSeries(heapChart.time);
    lsUseful.setYSeries(heapChart.dataUseful);
    lsUseful.setSymbolType(PlotSymbolType.DIAMOND);
    lsUseful.setSymbolColor(RED);
    lsUseful.setLineColor(RED);
    final ILineSeries lsExtra = (ILineSeries) control.getSeriesSet().createSeries(SeriesType.LINE, // $NON-NLS-1$;
    Messages.getString("HeapChart.Extra_Heap"));
    lsExtra.setXSeries(heapChart.time);
    lsExtra.setYSeries(heapChart.dataExtra);
    lsExtra.setSymbolType(PlotSymbolType.DIAMOND);
    lsExtra.setSymbolColor(ORANGE);
    lsExtra.setLineColor(ORANGE);
    if (heapChart.dataStacks != null) {
        final ILineSeries lsStack = (ILineSeries) control.getSeriesSet().createSeries(SeriesType.LINE, // $NON-NLS-1$;
        Messages.getString("HeapChart.Stacks"));
        lsStack.setXSeries(heapChart.time);
        lsStack.setYSeries(heapChart.dataStacks);
        lsStack.setSymbolType(PlotSymbolType.DIAMOND);
        lsStack.setSymbolColor(DARK_BLUE);
        lsStack.setLineColor(DARK_BLUE);
    }
    final ILineSeries lsTotal = (ILineSeries) control.getSeriesSet().createSeries(SeriesType.LINE, // $NON-NLS-1$;
    Messages.getString("HeapChart.Total_Heap"));
    lsTotal.setXSeries(heapChart.time);
    lsTotal.setYSeries(heapChart.dataTotal);
    lsTotal.setSymbolType(PlotSymbolType.DIAMOND);
    lsTotal.setSymbolColor(GREEN);
    lsTotal.setLineColor(GREEN);
    // adjust axes
    control.getAxisSet().adjustRange();
    IAxisSet axisSet = control.getAxisSet();
    Range xRange = axisSet.getXAxis(0).getRange();
    Range yRange = axisSet.getYAxis(0).getRange();
    double xExtra = 0.05 * (xRange.upper - xRange.lower);
    double yExtra = 0.05 * (yRange.upper - yRange.lower);
    axisSet.getXAxis(0).setRange(new Range(xRange.lower, xRange.upper + xExtra));
    axisSet.getYAxis(0).setRange(new Range(yRange.lower, yRange.upper + yExtra));
    // listeners
    control.getPlotArea().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            showView();
            TableViewer viewer = input.getView().getTableViewer();
            input.getView().setTopControl(viewer.getControl());
            Point p = new Point(e.x, e.y);
            int closest = 0;
            double d1, d2, d3, currMin;
            double globalMin = Double.MAX_VALUE;
            for (int i = 0; i < heapChart.time.length; i++) {
                // get distance from click event to data points for the given index
                d1 = distance(lsUseful.getPixelCoordinates(i), p);
                d2 = distance(lsExtra.getPixelCoordinates(i), p);
                d3 = distance(lsTotal.getPixelCoordinates(i), p);
                // find the closest data point to the click event
                currMin = Math.min(Math.min(d1, d2), d3);
                if (currMin < globalMin) {
                    closest = i;
                    globalMin = currMin;
                }
            }
            MassifSnapshot snapshot = (MassifSnapshot) viewer.getElementAt(closest);
            viewer.setSelection(new StructuredSelection(snapshot), true);
            if (e.count == 2 && snapshot.isDetailed()) {
                ChartLocationsDialog dialog = new ChartLocationsDialog(Display.getCurrent().getActiveShell());
                dialog.setInput(snapshot);
                if (dialog.open() == Window.OK) {
                    dialog.openEditorForResult();
                }
            }
        }
    });
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) Color(org.eclipse.swt.graphics.Color) FontData(org.eclipse.swt.graphics.FontData) ILineSeries(org.swtchart.ILineSeries) MouseAdapter(org.eclipse.swt.events.MouseAdapter) MassifSnapshot(org.eclipse.linuxtools.internal.valgrind.massif.MassifSnapshot) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Point(org.eclipse.swt.graphics.Point) Range(org.swtchart.Range) ITitle(org.swtchart.ITitle) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font) IAxis(org.swtchart.IAxis) IAxisSet(org.swtchart.IAxisSet) TableViewer(org.eclipse.jface.viewers.TableViewer) Chart(org.swtchart.Chart)

Example 59 with Font

use of org.eclipse.swt.graphics.Font in project linuxtools by eclipse.

the class SystemTapTextView method createViewer.

private void createViewer(Composite parent) {
    viewer = new StyledText(parent, SWT.READ_ONLY | SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);
    viewer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    // $NON-NLS-1$
    Font font = new Font(parent.getDisplay(), "Monospace", 11, SWT.NORMAL);
    viewer.setFont(font);
    masterComposite = parent;
    display = masterComposite.getDisplay();
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) GridData(org.eclipse.swt.layout.GridData) Font(org.eclipse.swt.graphics.Font)

Example 60 with Font

use of org.eclipse.swt.graphics.Font in project knime-core by knime.

the class ElementRadioSelectionDialog method createRadioList.

/**
 * Creates the radio buttons and labels.
 * @param parent the parent composite.
 * @return returns the composite containing the radio buttons
 */
protected Composite createRadioList(final Composite parent) {
    Composite c = new Composite(parent, SWT.FILL);
    GridData data = new GridData();
    data.widthHint = convertWidthInCharsToPixels(m_width);
    data.heightHint = convertHeightInCharsToPixels(m_height);
    data.grabExcessVerticalSpace = true;
    data.grabExcessHorizontalSpace = true;
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.FILL;
    c.setLayoutData(data);
    GridLayout layout = new GridLayout(1, true);
    layout.marginTop = 10;
    c.setLayout(layout);
    c.setFont(parent.getFont());
    m_radioButtons = new Button[m_selectElements.length];
    for (int i = 0; i < m_selectElements.length; i++) {
        final RadioItem item = m_selectElements[i];
        Button radio = new Button(c, SWT.RADIO);
        radio.setText(item.getTitle());
        if (item.getTooltip() != null) {
            radio.setToolTipText(item.getTooltip());
        }
        radio.addSelectionListener(new SelectionAdapter() {

            /**
             * {@inheritDoc}
             */
            @Override
            public void widgetSelected(final SelectionEvent e) {
                m_selectedElement = item;
            }
        });
        if (item.getDescription() != null) {
            Label description = new Label(c, SWT.WRAP);
            description.setLayoutData(new GridData(data.widthHint, SWT.DEFAULT));
            FontData[] fD = c.getFont().getFontData();
            fD[0].setHeight(Math.max(fD[0].getHeight() - 2, 6));
            description.setFont(new Font(parent.getDisplay(), fD[0]));
            description.setText(item.getDescription());
            if (item.getTooltip() != null) {
                description.setToolTipText(item.getTooltip());
            }
        }
        // spacer
        Label spacer = new Label(c, SWT.CENTER);
        spacer.setLayoutData(new GridData(data.widthHint, 5));
        m_radioButtons[i] = radio;
    }
    return c;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FontData(org.eclipse.swt.graphics.FontData) Label(org.eclipse.swt.widgets.Label) Font(org.eclipse.swt.graphics.Font) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Aggregations

Font (org.eclipse.swt.graphics.Font)235 FontData (org.eclipse.swt.graphics.FontData)93 GridData (org.eclipse.swt.layout.GridData)52 Point (org.eclipse.swt.graphics.Point)51 Composite (org.eclipse.swt.widgets.Composite)50 GridLayout (org.eclipse.swt.layout.GridLayout)47 Color (org.eclipse.swt.graphics.Color)45 Label (org.eclipse.swt.widgets.Label)38 Test (org.junit.Test)26 GC (org.eclipse.swt.graphics.GC)22 Image (org.eclipse.swt.graphics.Image)22 Rectangle (org.eclipse.swt.graphics.Rectangle)22 Button (org.eclipse.swt.widgets.Button)19 Display (org.eclipse.swt.widgets.Display)19 SelectionEvent (org.eclipse.swt.events.SelectionEvent)17 Text (org.eclipse.swt.widgets.Text)16 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)15 StyledText (org.eclipse.swt.custom.StyledText)13 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)12 StyleRange (org.eclipse.swt.custom.StyleRange)11