Search in sources :

Example 61 with FontData

use of org.eclipse.swt.graphics.FontData in project yamcs-studio by yamcs.

the class FontProperty method readValueFromXML.

@Override
public Object readValueFromXML(Element propElement) {
    Element fontElement = propElement.getChild(XML_ELEMENT_FONT);
    if (fontElement != null) {
        // Create the OPIFont with the raw font data from the XML.
        OPIFont font = new OPIFont(new FontData(fontElement.getAttributeValue(XML_ATTRIBUTE_FONT_NAME), (int) Double.parseDouble(fontElement.getAttributeValue(XML_ATTRIBUTE_FONT_HEIGHT)), Integer.parseInt(fontElement.getAttributeValue(XML_ATTRIBUTE_FONT_STYLE))));
        font.setSizeInPixels(Boolean.parseBoolean(fontElement.getAttributeValue(XML_ATTRIBUTE_FONT_PIXELS)));
        return font;
    } else {
        fontElement = propElement.getChild(XML_ELEMENT_FONTNAME);
        if (fontElement != null) {
            OPIFont font = null;
            String fontName = fontElement.getAttributeValue(XML_ATTRIBUTE_FONT_NAME);
            String fontHeight = fontElement.getAttributeValue(XML_ATTRIBUTE_FONT_HEIGHT);
            String fontStyle = fontElement.getAttributeValue(XML_ATTRIBUTE_FONT_STYLE);
            String heightInPixels = fontElement.getAttributeValue(XML_ATTRIBUTE_FONT_PIXELS);
            if (fontName != null && fontHeight != null && fontStyle != null) {
                FontData fd = new FontData(fontName, (int) Double.parseDouble(fontHeight), Integer.parseInt(fontStyle));
                font = MediaService.getInstance().getOPIFont(fontElement.getText(), fd);
            } else {
                font = MediaService.getInstance().getOPIFont(fontElement.getText());
            }
            if (!font.isPreDefined()) {
                // changed when re-saved, make this explicit.
                if (heightInPixels != null) {
                    boolean inPixels = Boolean.parseBoolean(heightInPixels);
                    font.setSizeInPixels(inPixels);
                } else {
                    font.setSizeInPixels(false);
                }
            }
            return font;
        } else
            return null;
    }
}
Also used : OPIFont(org.csstudio.opibuilder.util.OPIFont) Element(org.jdom.Element) FontData(org.eclipse.swt.graphics.FontData)

Example 62 with FontData

use of org.eclipse.swt.graphics.FontData in project yamcs-studio by yamcs.

the class ThumbWheelEditPart method doCreateFigure.

/**
 * {@inheritDoc}
 */
@Override
protected IFigure doCreateFigure() {
    model = (ThumbWheelModel) getWidgetModel();
    logic = new ThumbWheelLogic(0, model.getWholePartDigits(), model.getDecimalPartDigits());
    logic.setMax(model.getMaximum());
    logic.setMin(model.getMinimum());
    figure = new ThumbWheelFigure(logic.getIntegerWheels(), logic.getDecimalWheels(), this.getExecutionMode() == ExecutionMode.RUN_MODE);
    model.setWholePartDigits(logic.getIntegerWheels());
    model.setDecimalPartDigits(logic.getDecimalWheels());
    FontData fontData = model.getFont().getFontData();
    figure.setWheelFont(CustomMediaFactory.getInstance().getFont(fontData.getName(), fontData.getHeight(), fontData.getStyle()));
    figure.setInternalBorderColor(model.getInternalBorderColor());
    figure.setInternalFocusedBorderColor(model.getInternalFocusedBorderColor());
    figure.setInternalBorderThickness(model.getInternalBorderWidth());
    figure.setButtonVisibility(model.isButtonVisible());
    markAsControlPV(AbstractPVWidgetModel.PROP_PVNAME, AbstractPVWidgetModel.PROP_PVVALUE);
    figure.addWheelListener(new WheelListener() {

        @Override
        public void decrementDecimalPart(int index) {
            if (getExecutionMode() == ExecutionMode.RUN_MODE) {
                logic.decrementDecimalDigitAt(index);
                updateWheelValues();
                // write value to pv if pv name is not empty
                if (getWidgetModel().getPVName().trim().length() > 0) {
                    double doubleValue = logic.getValue();
                    setPVValue(AbstractPVWidgetModel.PROP_PVNAME, doubleValue);
                }
            }
        }

        @Override
        public void incrementDecimalPart(int index) {
            if (getExecutionMode() == ExecutionMode.RUN_MODE) {
                logic.incrementDecimalDigitAt(index);
                updateWheelValues();
                // write value to pv if pv name is not empty
                if (getWidgetModel().getPVName().trim().length() > 0) {
                    double doubleValue = logic.getValue();
                    setPVValue(AbstractPVWidgetModel.PROP_PVNAME, doubleValue);
                }
            }
        }

        @Override
        public void decrementIntegerPart(int index) {
            if (getExecutionMode() == ExecutionMode.RUN_MODE) {
                logic.decrementIntigerDigitAt(index);
                updateWheelValues();
                // write value to pv if pv name is not empty
                if (getWidgetModel().getPVName().trim().length() > 0) {
                    double doubleValue = logic.getValue();
                    setPVValue(AbstractPVWidgetModel.PROP_PVNAME, doubleValue);
                }
            }
        }

        @Override
        public void incrementIntegerPart(int index) {
            if (getExecutionMode() == ExecutionMode.RUN_MODE) {
                logic.incrementIntigerWheel(index);
                updateWheelValues();
                // write value to pv if pv name is not empty
                if (getWidgetModel().getPVName().trim().length() > 0) {
                    double doubleValue = logic.getValue();
                    setPVValue(AbstractPVWidgetModel.PROP_PVNAME, doubleValue);
                }
            }
        }
    });
    updateWheelValues();
    return figure;
}
Also used : ThumbWheelFigure(org.csstudio.swt.widgets.figures.ThumbWheelFigure) WheelListener(org.csstudio.swt.widgets.figures.ThumbWheelFigure.WheelListener) FontData(org.eclipse.swt.graphics.FontData)

Example 63 with FontData

use of org.eclipse.swt.graphics.FontData in project yamcs-studio by yamcs.

the class OPIFontDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    final Composite parent_Composite = (Composite) super.createDialogArea(parent);
    final Composite mainComposite = new Composite(parent_Composite, SWT.None);
    mainComposite.setLayout(new GridLayout(2, false));
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData.heightHint = 300;
    mainComposite.setLayoutData(gridData);
    final Composite leftComposite = new Composite(mainComposite, SWT.None);
    leftComposite.setLayout(new GridLayout(1, false));
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.widthHint = 250;
    leftComposite.setLayoutData(gd);
    createLabel(leftComposite, "Choose from Predefined Fonts:");
    preDefinedFontsViewer = createPredefinedFontsTableViewer(leftComposite);
    preDefinedFontsViewer.setInput(MediaService.getInstance().getAllPredefinedFonts());
    Composite rightComposite = new Composite(mainComposite, SWT.None);
    rightComposite.setLayout(new GridLayout(1, false));
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.widthHint = 250;
    rightComposite.setLayoutData(gd);
    // This label doesn't need to do anything but exist.
    @SuppressWarnings("unused") Label spacer = new Label(rightComposite, SWT.NONE);
    Button fontDialogButton = new Button(rightComposite, SWT.PUSH);
    // Push radioButtons to bottom of rightComposite.
    Label spacer2 = new Label(rightComposite, SWT.NONE);
    GridData gd2 = new GridData();
    gd2.grabExcessVerticalSpace = true;
    spacer2.setLayoutData(gd2);
    pixelsOrPointsBox = new PixelsOrPointsBox(rightComposite, SWT.NONE);
    pixelsOrPointsBox.setSizeInPixels(opiFont.isSizeInPixels());
    fontDialogButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    fontDialogButton.setText("Choose from Font Dialog");
    fontDialogButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            FontDialog dialog = new FontDialog(Display.getCurrent().getActiveShell());
            dialog.setFontList(new FontData[] { opiFont.getRawFontData() });
            FontData fontdata = dialog.open();
            pixelsOrPointsBox.setEnabled(true);
            if (fontdata != null) {
                opiFont = new OPIFont(fontdata);
                opiFont.setSizeInPixels(pixelsOrPointsBox.isSizeInPixels());
                preDefinedFontsViewer.setSelection(null);
                outputTextLabel.setText(opiFont.getFontMacroName());
                outputTextLabel.setFont(CustomMediaFactory.getInstance().getFont(opiFont.getFontData()));
                getShell().layout(true, true);
            }
        }
    });
    SelectionListener radioSelectionListener = new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            opiFont.setSizeInPixels(pixelsOrPointsBox.isSizeInPixels());
            outputTextLabel.setText(opiFont.getFontMacroName());
            outputTextLabel.setFont(CustomMediaFactory.getInstance().getFont(opiFont.getFontData()));
            getShell().layout(true, true);
        }
    };
    pixelsOrPointsBox.addSelectionListener(radioSelectionListener);
    Group group = new Group(mainComposite, SWT.None);
    gd = new GridData(SWT.FILL, SWT.END, true, true, 2, 1);
    gd.heightHint = 100;
    group.setLayoutData(gd);
    group.setLayout(new GridLayout(1, false));
    group.setText("Output");
    outputTextLabel = new Label(group, SWT.None);
    outputTextLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    outputTextLabel.setText(opiFont.getFontMacroName());
    outputTextLabel.setFont(opiFont.getSWTFont());
    if (opiFont.isPreDefined())
        preDefinedFontsViewer.setSelection(new StructuredSelection(opiFont));
    else
        preDefinedFontsViewer.setSelection(null);
    return parent_Composite;
}
Also used : OPIFont(org.csstudio.opibuilder.util.OPIFont) Group(org.eclipse.swt.widgets.Group) FontDialog(org.eclipse.swt.widgets.FontDialog) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FontData(org.eclipse.swt.graphics.FontData) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 64 with FontData

use of org.eclipse.swt.graphics.FontData in project yamcs-studio by yamcs.

the class MediaService method loadPredefinedFonts.

private void loadPredefinedFonts() {
    FontData defaultFont = Display.getDefault().getSystemFont().getFontData()[0];
    fontMap.put(DEFAULT_FONT, new OPIFont(DEFAULT_FONT, defaultFont));
    int height = defaultFont.getHeight();
    FontData defaultBoldFont = new FontData(defaultFont.getName(), height, SWT.BOLD);
    fontMap.put(DEFAULT_BOLD_FONT, new OPIFont(DEFAULT_BOLD_FONT, defaultBoldFont));
    FontData header1 = new FontData(defaultFont.getName(), height + 8, SWT.BOLD);
    fontMap.put(HEADER1, new OPIFont(HEADER1, header1));
    FontData header2 = new FontData(defaultFont.getName(), height + 4, SWT.BOLD);
    fontMap.put(HEADER2, new OPIFont(HEADER2, header2));
    FontData header3 = new FontData(defaultFont.getName(), height + 2, SWT.BOLD);
    fontMap.put(HEADER3, new OPIFont(HEADER3, header3));
    FontData finePrint = new FontData(defaultFont.getName(), height - 2, SWT.NORMAL);
    fontMap.put(FINE_PRINT, new OPIFont(FINE_PRINT, finePrint));
}
Also used : FontData(org.eclipse.swt.graphics.FontData)

Example 65 with FontData

use of org.eclipse.swt.graphics.FontData in project translationstudio8 by heartsome.

the class JaretTablePrinter method print.

public void print(JaretTablePrintConfiguration configuration) {
    _printingRect = new Rectangle(pixelForCmX(_borderLeft), pixelForCmY(_borderTop), _pageWidth, _pageHeight);
    _headerRenderer = _table.getHeaderRenderer().getPrintRenderer(_printer);
    Point pages = calculatePageCount(configuration);
    int pagesx = pages.x;
    int pagesy = pages.y;
    _printer.startJob(configuration.getName() != null ? configuration.getName() : "jarettable");
    GC gc = new GC(_printer);
    Font oldfont = gc.getFont();
    FontData fontdata = new FontData("Arial", (int) (8.0 * _scale), SWT.NULL);
    Font printerFont = new Font(_printer, fontdata);
    gc.setFont(printerFont);
    for (int px = 0; px < pagesx; px++) {
        int startx = (int) ((px * _pageWidth) / (_scaleX * _scale));
        IColumn column = _table.getColumnForAbsX(startx);
        int offx = startx - _table.getAbsBeginXForColumn(column);
        int beginColIdx = _table.getColIdxForAbsX(startx);
        // System.out.println("PX "+px+" startx "+startx+" offx "+offx+" beginColIdx "+beginColIdx);
        int rIdx = 0;
        for (int py = 0; py < pagesy; py++) {
            int y = 0;
            String footerText = configuration.getFooterText() != null ? configuration.getFooterText() : "";
            footerText += "(" + (px + 1) + "/" + pagesx + "," + (py + 1) + "/" + pagesy + ")";
            _printer.startPage();
            int starty = (int) (py * ((_pageHeight - _footerHeight - (configuration.getRepeatHeader() ? scaleY(_table.getHeaderHeight()) : 0)) / (_scaleY * _scale)));
            // _table.getRowIdxForAbsY(starty);
            rIdx = py == 0 ? 0 : rIdx;
            Rectangle clipSave = gc.getClipping();
            if (starty == 0 || configuration.getRepeatHeader()) {
                // draw header
                // draw headers table area
                int x = -offx;
                int cIdx = beginColIdx;
                while (scaleX(x) < _pageWidth && cIdx < _table.getColumnCount() && (configuration.getColLimit() == -1 || cIdx <= configuration.getColLimit())) {
                    IColumn col = _table.getColumn(cIdx);
                    int colwidth = _table.getTableViewState().getColumnWidth(col);
                    int xx = x > 0 ? x : 0;
                    int clipWidth = x > 0 ? colwidth : colwidth - offx;
                    if (!_headerRenderer.disableClipping()) {
                        gc.setClipping(scaleX(xx) + pixelForCmX(_borderLeft), pixelForCmY(_borderTop), scaleX(clipWidth), scaleY(_table.getHeaderHeight()));
                        gc.setClipping(gc.getClipping().intersection(_printingRect));
                    }
                    drawHeader(gc, scaleX(x) + pixelForCmX(_borderLeft), scaleX(colwidth), col);
                    x += colwidth;
                    cIdx++;
                }
                y += _table.getHeaderHeight();
                gc.setClipping(clipSave);
            }
            // normal table area
            gc.setClipping(_printingRect);
            while (scaleY(y) < _pageHeight && rIdx < _table.getRowCount() && (configuration.getRowLimit() == -1 || rIdx <= configuration.getRowLimit())) {
                IRow row = _table.getRow(rIdx);
                int rHeight = _table.getTableViewState().getRowHeight(row);
                // do not draw a row that does not fit on th page
                if (scaleY(y) + scaleY(rHeight) > _pageHeight) {
                    break;
                }
                int x = -offx;
                int cIdx = beginColIdx;
                while (scaleX(x) < _pageWidth && cIdx < _table.getColumnCount() && (configuration.getColLimit() == -1 || cIdx <= configuration.getColLimit())) {
                    IColumn col = _table.getColumn(cIdx);
                    int colwidth = _table.getTableViewState().getColumnWidth(col);
                    Rectangle area = new Rectangle(scaleX(x) + pixelForCmX(_borderLeft), scaleY(y) + pixelForCmY(_borderTop), scaleX(colwidth), scaleY(rHeight));
                    drawCell(gc, area, row, col);
                    x += colwidth;
                    cIdx++;
                }
                y += rHeight;
                rIdx++;
            }
            gc.setClipping(clipSave);
            drawFooter(gc, footerText);
            _printer.endPage();
        }
    }
    _printer.endJob();
    printerFont.dispose();
    gc.setFont(oldfont);
    gc.dispose();
}
Also used : IRow(de.jaret.util.ui.table.model.IRow) IColumn(de.jaret.util.ui.table.model.IColumn) FontData(org.eclipse.swt.graphics.FontData) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font)

Aggregations

FontData (org.eclipse.swt.graphics.FontData)147 Font (org.eclipse.swt.graphics.Font)89 GridData (org.eclipse.swt.layout.GridData)30 Label (org.eclipse.swt.widgets.Label)26 GridLayout (org.eclipse.swt.layout.GridLayout)25 Composite (org.eclipse.swt.widgets.Composite)25 Point (org.eclipse.swt.graphics.Point)23 Test (org.junit.Test)21 Color (org.eclipse.swt.graphics.Color)15 FontStyle (org.eclipse.gmf.runtime.notation.FontStyle)14 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)11 Button (org.eclipse.swt.widgets.Button)10 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)9 SelectionEvent (org.eclipse.swt.events.SelectionEvent)9 Display (org.eclipse.swt.widgets.Display)9 Text (org.eclipse.swt.widgets.Text)9 GC (org.eclipse.swt.graphics.GC)8 StyleRange (org.eclipse.swt.custom.StyleRange)7 Image (org.eclipse.swt.graphics.Image)7 IOException (java.io.IOException)6