Search in sources :

Example 1 with OPIFont

use of org.csstudio.opibuilder.util.OPIFont in project yamcs-studio by yamcs.

the class FontProperty method writeToXML.

@Override
public void writeToXML(Element propElement) {
    OPIFont opiFont = (OPIFont) getPropertyValue();
    Element fontElement;
    if (!opiFont.isPreDefined()) {
        fontElement = new Element(XML_ELEMENT_FONT);
    } else {
        fontElement = new Element(XML_ELEMENT_FONTNAME);
        fontElement.setText(opiFont.getFontMacroName());
    }
    FontData fontData = opiFont.getRawFontData();
    fontElement.setAttribute(XML_ATTRIBUTE_FONT_NAME, fontData.getName());
    fontElement.setAttribute(XML_ATTRIBUTE_FONT_HEIGHT, // $NON-NLS-1$
    "" + fontData.getHeight());
    fontElement.setAttribute(XML_ATTRIBUTE_FONT_STYLE, // $NON-NLS-1$
    "" + fontData.getStyle());
    fontElement.setAttribute(XML_ATTRIBUTE_FONT_PIXELS, "" + opiFont.isSizeInPixels());
    propElement.addContent(fontElement);
}
Also used : OPIFont(org.csstudio.opibuilder.util.OPIFont) Element(org.jdom.Element) FontData(org.eclipse.swt.graphics.FontData)

Example 2 with OPIFont

use of org.csstudio.opibuilder.util.OPIFont 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 3 with OPIFont

use of org.csstudio.opibuilder.util.OPIFont in project yamcs-studio by yamcs.

the class SpinnerEditpart method registerPropertyChangeHandlers.

@Override
protected void registerPropertyChangeHandlers() {
    // text
    IWidgetPropertyChangeHandler handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            String text = (String) newValue;
            try {
                // $NON-NLS-1$ //$NON-NLS-2$
                text = text.replace("e", "E");
                double value = new DecimalFormat().parse(text).doubleValue();
                // coerce value in range
                value = Math.max(((SpinnerFigure) figure).getMin(), Math.min(((SpinnerFigure) figure).getMax(), value));
                ((SpinnerFigure) figure).setValue(value);
                if (getExecutionMode() == ExecutionMode.RUN_MODE)
                    setPVValue(AbstractPVWidgetModel.PROP_PVNAME, value);
                getWidgetModel().setText(((SpinnerFigure) figure).getLabelFigure().getText(), false);
                return false;
            } catch (Exception e) {
                return false;
            }
        }
    };
    setPropertyChangeHandler(SpinnerModel.PROP_TEXT, handler);
    IWidgetPropertyChangeHandler pvNameHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            registerLoadLimitsListener();
            return false;
        }
    };
    setPropertyChangeHandler(AbstractPVWidgetModel.PROP_PVNAME, pvNameHandler);
    // pv value
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            if (newValue == null)
                return false;
            double value = VTypeHelper.getDouble((VType) newValue);
            ((SpinnerFigure) figure).setDisplayValue(value);
            getWidgetModel().setText(((SpinnerFigure) figure).getLabelFigure().getText(), false);
            return false;
        }
    };
    setPropertyChangeHandler(SpinnerModel.PROP_PVVALUE, handler);
    // min
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((SpinnerFigure) figure).setMin((Double) newValue);
            return false;
        }
    };
    setPropertyChangeHandler(SpinnerModel.PROP_MIN, handler);
    // max
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((SpinnerFigure) figure).setMax((Double) newValue);
            return false;
        }
    };
    setPropertyChangeHandler(SpinnerModel.PROP_MAX, handler);
    // step increment
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((SpinnerFigure) figure).setStepIncrement((Double) newValue);
            return false;
        }
    };
    setPropertyChangeHandler(SpinnerModel.PROP_STEP_INCREMENT, handler);
    // page increment
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((SpinnerFigure) figure).setPageIncrement((Double) newValue);
            return false;
        }
    };
    setPropertyChangeHandler(SpinnerModel.PROP_PAGE_INCREMENT, handler);
    // font
    IWidgetPropertyChangeHandler fontHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((SpinnerFigure) figure).getLabelFigure().setFont(CustomMediaFactory.getInstance().getFont(((OPIFont) newValue).getFontData()));
            return true;
        }
    };
    setPropertyChangeHandler(LabelModel.PROP_FONT, fontHandler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((SpinnerFigure) figure).getLabelFigure().setHorizontalAlignment(H_ALIGN.values()[(Integer) newValue]);
            return true;
        }
    };
    setPropertyChangeHandler(LabelModel.PROP_ALIGN_H, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((SpinnerFigure) figure).getLabelFigure().setVerticalAlignment(V_ALIGN.values()[(Integer) newValue]);
            return true;
        }
    };
    setPropertyChangeHandler(LabelModel.PROP_ALIGN_V, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((SpinnerFigure) figure).getLabelFigure().setOpaque(!(Boolean) newValue);
            return true;
        }
    };
    setPropertyChangeHandler(LabelModel.PROP_TRANSPARENT, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((SpinnerFigure) figure).setFormatType(NumericFormatType.values()[(Integer) newValue]);
            return false;
        }
    };
    setPropertyChangeHandler(SpinnerModel.PROP_FORMAT, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((SpinnerFigure) figure).setPrecision((Integer) newValue);
            return false;
        }
    };
    setPropertyChangeHandler(SpinnerModel.PROP_PRECISION, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((SpinnerFigure) figure).setArrowButtonsOnLeft((Boolean) newValue);
            return false;
        }
    };
    setPropertyChangeHandler(SpinnerModel.PROP_BUTTONS_ON_LEFT, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((SpinnerFigure) figure).setArrowButtonsHorizontal((Boolean) newValue);
            return false;
        }
    };
    setPropertyChangeHandler(SpinnerModel.PROP_HORIZONTAL_BUTTONS_LAYOUT, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((SpinnerFigure) figure).showText((Boolean) newValue);
            return false;
        }
    };
    setPropertyChangeHandler(SpinnerModel.PROP_SHOW_TEXT, handler);
}
Also used : OPIFont(org.csstudio.opibuilder.util.OPIFont) SpinnerFigure(org.csstudio.swt.widgets.figures.SpinnerFigure) DecimalFormat(java.text.DecimalFormat) VType(org.diirt.vtype.VType) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) IFigure(org.eclipse.draw2d.IFigure)

Example 4 with OPIFont

use of org.csstudio.opibuilder.util.OPIFont 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 5 with OPIFont

use of org.csstudio.opibuilder.util.OPIFont in project yamcs-studio by yamcs.

the class OPIFontDialog method refreshGUIOnSelection.

/**
 * Refreshes the enabled-state of the actions.
 */
private void refreshGUIOnSelection() {
    IStructuredSelection selection = (IStructuredSelection) preDefinedFontsViewer.getSelection();
    if (!selection.isEmpty() && selection.getFirstElement() instanceof OPIFont) {
        opiFont = new OPIFont((OPIFont) selection.getFirstElement());
        outputTextLabel.setText(opiFont.getFontMacroName());
        outputTextLabel.setFont(CustomMediaFactory.getInstance().getFont(opiFont.getFontData()));
        pixelsOrPointsBox.setSizeInPixels(opiFont.isSizeInPixels());
        pixelsOrPointsBox.setEnabled(false);
        getShell().layout(true, true);
    }
}
Also used : OPIFont(org.csstudio.opibuilder.util.OPIFont) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

OPIFont (org.csstudio.opibuilder.util.OPIFont)6 FontData (org.eclipse.swt.graphics.FontData)3 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)2 IFigure (org.eclipse.draw2d.IFigure)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 Element (org.jdom.Element)2 DecimalFormat (java.text.DecimalFormat)1 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)1 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)1 NativeTextFigure (org.csstudio.opibuilder.widgets.figures.NativeTextFigure)1 ITextFigure (org.csstudio.swt.widgets.figures.ITextFigure)1 SpinnerFigure (org.csstudio.swt.widgets.figures.SpinnerFigure)1 TextFigure (org.csstudio.swt.widgets.figures.TextFigure)1 WrappableTextFigure (org.csstudio.swt.widgets.figures.WrappableTextFigure)1 VType (org.diirt.vtype.VType)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 GridData (org.eclipse.swt.layout.GridData)1