Search in sources :

Example 1 with TextFlow

use of org.eclipse.draw2d.text.TextFlow in project archi by archimatetool.

the class AbstractTextControlContainerFigure method createTextFlowControl.

protected TextFlow createTextFlowControl(Locator textLocator) {
    TextFlow textFlow = new TextFlow();
    int wordWrapStyle = Preferences.STORE.getInt(IPreferenceConstants.ARCHIMATE_FIGURE_WORD_WRAP_STYLE);
    textFlow.setLayoutManager(new ParagraphTextLayout(textFlow, wordWrapStyle));
    BlockFlow block = new BlockFlow();
    block.add(textFlow);
    FlowPage page = new FlowPage();
    page.add(block);
    Figure textWrapperFigure = new Figure();
    GridLayout layout = new GridLayout();
    layout.marginWidth = getTextControlMarginWidth();
    layout.marginHeight = 5;
    textWrapperFigure.setLayoutManager(layout);
    GridData gd = new GridData(SWT.CENTER, SWT.TOP, true, true);
    textWrapperFigure.add(page, gd);
    if (getDiagramModelObject() instanceof ITextPosition) {
        fTextPositionDelegate = new TextPositionDelegate(textWrapperFigure, page, (ITextPosition) getDiagramModelObject());
    }
    add(textWrapperFigure, textLocator);
    return textFlow;
}
Also used : FlowPage(org.eclipse.draw2d.text.FlowPage) GridLayout(org.eclipse.draw2d.GridLayout) ITextPosition(com.archimatetool.model.ITextPosition) BlockFlow(org.eclipse.draw2d.text.BlockFlow) GridData(org.eclipse.draw2d.GridData) TextFlow(org.eclipse.draw2d.text.TextFlow) ParagraphTextLayout(org.eclipse.draw2d.text.ParagraphTextLayout) IFigure(org.eclipse.draw2d.IFigure) Figure(org.eclipse.draw2d.Figure)

Example 2 with TextFlow

use of org.eclipse.draw2d.text.TextFlow in project archi by archimatetool.

the class NoteFigure method setUI.

@Override
protected void setUI() {
    setLayoutManager(new GridLayout());
    FlowPage page = new FlowPage();
    BlockFlow block = new BlockFlow();
    fTextFlow = new TextFlow();
    fTextFlow.setLayoutManager(new ParagraphTextLayout(fTextFlow, ParagraphTextLayout.WORD_WRAP_SOFT));
    block.add(fTextFlow);
    page.add(block);
    setOpaque(true);
    GridData gd = new GridData(SWT.LEFT, SWT.TOP, true, true);
    add(page, gd);
    fTextPositionDelegate = new TextPositionDelegate(this, page, getDiagramModelObject());
}
Also used : GridLayout(org.eclipse.draw2d.GridLayout) FlowPage(org.eclipse.draw2d.text.FlowPage) BlockFlow(org.eclipse.draw2d.text.BlockFlow) GridData(org.eclipse.draw2d.GridData) TextFlow(org.eclipse.draw2d.text.TextFlow) TextPositionDelegate(com.archimatetool.editor.diagram.figures.TextPositionDelegate) ParagraphTextLayout(org.eclipse.draw2d.text.ParagraphTextLayout)

Example 3 with TextFlow

use of org.eclipse.draw2d.text.TextFlow in project archi by archimatetool.

the class CanvasBlockFigure method setUI.

@Override
protected void setUI() {
    setLayoutManager(new DelegatingLayout());
    Locator mainLocator = new Locator() {

        public void relocate(IFigure target) {
            Rectangle bounds = getBounds().getCopy();
            translateFromParent(bounds);
            target.setBounds(bounds);
        }
    };
    FlowPage flowPage = new FlowPage();
    BlockFlow block = new BlockFlow();
    fTextFlow = new TextFlow();
    fTextFlow.setLayoutManager(new ParagraphTextLayout(fTextFlow, ParagraphTextLayout.WORD_WRAP_HARD));
    block.add(fTextFlow);
    flowPage.add(block);
    Figure textWrapperFigure = new Figure();
    textWrapperFigure.setLayoutManager(new GridLayout());
    textWrapperFigure.add(flowPage, new GridData(SWT.CENTER, SWT.CENTER, true, true));
    add(textWrapperFigure, mainLocator);
    fTextPositionDelegate = new TextPositionDelegate(textWrapperFigure, flowPage, getDiagramModelObject());
    // This last
    add(getMainFigure(), mainLocator);
    // Have to add this if we want Animation to work on figures!
    AnimationUtil.addFigureForAnimation(getMainFigure());
    fIconicDelegate = new IconicDelegate(getDiagramModelObject());
    fIconicDelegate.updateImage();
}
Also used : DelegatingLayout(org.eclipse.draw2d.DelegatingLayout) Rectangle(org.eclipse.draw2d.geometry.Rectangle) IFigure(org.eclipse.draw2d.IFigure) AbstractContainerFigure(com.archimatetool.editor.diagram.figures.AbstractContainerFigure) Figure(org.eclipse.draw2d.Figure) Locator(org.eclipse.draw2d.Locator) FlowPage(org.eclipse.draw2d.text.FlowPage) GridLayout(org.eclipse.draw2d.GridLayout) BlockFlow(org.eclipse.draw2d.text.BlockFlow) GridData(org.eclipse.draw2d.GridData) TextFlow(org.eclipse.draw2d.text.TextFlow) TextPositionDelegate(com.archimatetool.editor.diagram.figures.TextPositionDelegate) ParagraphTextLayout(org.eclipse.draw2d.text.ParagraphTextLayout) IFigure(org.eclipse.draw2d.IFigure)

Example 4 with TextFlow

use of org.eclipse.draw2d.text.TextFlow in project knime-core by knime.

the class NodeAnnotationFigure method newContent.

/**
 * @param annotation the new annotation content
 */
public void newContent(final Annotation annotation) {
    boolean isNodeAnnotation = (annotation instanceof NodeAnnotation);
    String text;
    AnnotationData.StyleRange[] sr;
    if (AnnotationEditPart.isDefaultNodeAnnotation(annotation)) {
        text = AnnotationEditPart.getAnnotationText(annotation);
        sr = new AnnotationData.StyleRange[0];
    } else {
        text = annotation.getText();
        if (annotation.getStyleRanges() != null) {
            sr = Arrays.copyOf(annotation.getStyleRanges(), annotation.getStyleRanges().length);
        } else {
            sr = new AnnotationData.StyleRange[0];
        }
    }
    Arrays.sort(sr, new Comparator<AnnotationData.StyleRange>() {

        /**
         * {@inheritDoc}
         */
        @Override
        public int compare(final AnnotationData.StyleRange o1, final AnnotationData.StyleRange o2) {
            if (o1.getStart() == o2.getStart()) {
                NodeLogger.getLogger(NodeAnnotationFigure.class).error("Ranges overlap");
                return 0;
            } else {
                return o1.getStart() < o2.getStart() ? -1 : 1;
            }
        }
    });
    Color bg = AnnotationEditPart.RGBintToColor(annotation.getBgColor());
    setBackgroundColor(bg);
    m_page.setBackgroundColor(bg);
    if (isNodeAnnotation && AnnotationEditPart.DEFAULT_BG_NODE.equals(bg)) {
        // node annotation are white if
        setOpaque(false);
    } else {
        setOpaque(true);
    }
    int i = 0;
    List<TextFlow> segments = new ArrayList<TextFlow>(sr.length);
    // in old flow annotations didn't store the font if system default was used. New annotations always store font
    // info. For backward compatibility use the system font if no font is specified here.
    final Font defaultFont;
    if (isNodeAnnotation) {
        defaultFont = AnnotationEditPart.getNodeAnnotationDefaultFont();
    } else if (annotation.getVersion() < AnnotationData.VERSION_20151012) {
        defaultFont = FontStore.INSTANCE.getSystemDefaultFont();
    } else if (annotation.getVersion() < AnnotationData.VERSION_20151123) {
        defaultFont = AnnotationEditPart.getWorkflowAnnotationDefaultFont();
    } else {
        if (annotation.getDefaultFontSize() < 0) {
            defaultFont = AnnotationEditPart.getWorkflowAnnotationDefaultFont();
        } else {
            defaultFont = AnnotationEditPart.getWorkflowAnnotationDefaultFont(annotation.getDefaultFontSize());
        }
    }
    for (AnnotationData.StyleRange r : sr) {
        // create text from last range to beginning of this range
        if (i < r.getStart()) {
            String noStyle = text.substring(i, r.getStart());
            if (isNodeAnnotation) {
                segments.add(getNodeAnnotationSystemDefaultStyled(noStyle, defaultFont, bg));
            } else {
                segments.add(getWorkflowAnnotationSystemDefaultStyled(noStyle, defaultFont, bg));
            }
            i = r.getStart();
        }
        String styled = text.substring(i, r.getStart() + r.getLength());
        segments.add(getStyled(styled, r, bg, defaultFont));
        i = r.getStart() + r.getLength();
    }
    if (i < text.length()) {
        String noStyle = text.substring(i, text.length());
        if (isNodeAnnotation) {
            segments.add(getNodeAnnotationSystemDefaultStyled(noStyle, defaultFont, bg));
        } else {
            segments.add(getWorkflowAnnotationSystemDefaultStyled(noStyle, defaultFont, bg));
        }
    }
    BlockFlow bf = new BlockFlow();
    BlockFlowLayout bfl = new BlockFlowLayout(bf);
    bfl.setContinueOnSameLine(true);
    bf.setLayoutManager(bfl);
    int position;
    switch(annotation.getAlignment()) {
        case CENTER:
            position = PositionConstants.CENTER;
            break;
        case RIGHT:
            position = PositionConstants.RIGHT;
            break;
        default:
            position = PositionConstants.LEFT;
    }
    bf.setHorizontalAligment(position);
    bf.setOrientation(SWT.LEFT_TO_RIGHT);
    bf.setBackgroundColor(bg);
    for (TextFlow tf : segments) {
        bf.add(tf);
    }
    m_page.removeAll();
    m_page.add(bf);
    m_page.setVisible(true);
    revalidate();
}
Also used : AnnotationData(org.knime.core.node.workflow.AnnotationData) Color(org.eclipse.swt.graphics.Color) ArrayList(java.util.ArrayList) Font(org.eclipse.swt.graphics.Font) BlockFlowLayout(org.eclipse.draw2d.text.BlockFlowLayout) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) BlockFlow(org.eclipse.draw2d.text.BlockFlow) TextFlow(org.eclipse.draw2d.text.TextFlow)

Example 5 with TextFlow

use of org.eclipse.draw2d.text.TextFlow in project archi by archimatetool.

the class CanvasStickyFigure method setUI.

@Override
protected void setUI() {
    setLayoutManager(new GridLayout());
    FlowPage flowPage = new FlowPage();
    BlockFlow block = new BlockFlow();
    fTextFlow = new TextFlow();
    fTextFlow.setLayoutManager(new ParagraphTextLayout(fTextFlow, ParagraphTextLayout.WORD_WRAP_HARD));
    block.add(fTextFlow);
    flowPage.add(block);
    add(flowPage, new GridData(SWT.CENTER, SWT.CENTER, true, true));
    fTextPositionDelegate = new TextPositionDelegate(this, flowPage, getDiagramModelObject());
    fIconicDelegate = new IconicDelegate(getDiagramModelObject());
    fIconicDelegate.updateImage();
}
Also used : GridLayout(org.eclipse.draw2d.GridLayout) FlowPage(org.eclipse.draw2d.text.FlowPage) BlockFlow(org.eclipse.draw2d.text.BlockFlow) GridData(org.eclipse.draw2d.GridData) TextFlow(org.eclipse.draw2d.text.TextFlow) TextPositionDelegate(com.archimatetool.editor.diagram.figures.TextPositionDelegate) ParagraphTextLayout(org.eclipse.draw2d.text.ParagraphTextLayout)

Aggregations

BlockFlow (org.eclipse.draw2d.text.BlockFlow)5 TextFlow (org.eclipse.draw2d.text.TextFlow)5 GridData (org.eclipse.draw2d.GridData)4 GridLayout (org.eclipse.draw2d.GridLayout)4 FlowPage (org.eclipse.draw2d.text.FlowPage)4 ParagraphTextLayout (org.eclipse.draw2d.text.ParagraphTextLayout)4 TextPositionDelegate (com.archimatetool.editor.diagram.figures.TextPositionDelegate)3 Figure (org.eclipse.draw2d.Figure)2 IFigure (org.eclipse.draw2d.IFigure)2 AbstractContainerFigure (com.archimatetool.editor.diagram.figures.AbstractContainerFigure)1 ITextPosition (com.archimatetool.model.ITextPosition)1 ArrayList (java.util.ArrayList)1 DelegatingLayout (org.eclipse.draw2d.DelegatingLayout)1 Locator (org.eclipse.draw2d.Locator)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 BlockFlowLayout (org.eclipse.draw2d.text.BlockFlowLayout)1 Color (org.eclipse.swt.graphics.Color)1 Font (org.eclipse.swt.graphics.Font)1 AnnotationData (org.knime.core.node.workflow.AnnotationData)1 NodeAnnotation (org.knime.core.node.workflow.NodeAnnotation)1