Search in sources :

Example 1 with Dimension

use of org.eclipse.draw2d.geometry.Dimension in project cogtool by cogtool.

the class InteractionDrawingEditor method resizeContents.

public void resizeContents(int width, int height, boolean resizeMin) {
    // Get the size of the view in unscaled coordinates
    Rectangle viewSize = contents.getChildrenUtilizedAreaScaled();
    // We need the TOTAL size starting from 0,0. Not just the actual size.
    int viewUIWidth = viewSize.width + viewSize.x;
    int viewUIHeight = viewSize.height + viewSize.y;
    // If the area grows, then we want to use the LARGER area
    if (viewUIWidth > width) {
        width = viewUIWidth;
    }
    if (viewUIHeight > height) {
        height = viewUIHeight;
    }
    Dimension prefSize = new Dimension(width, height);
    contents.setPreferredSize(prefSize);
    contents.setSize(width, height);
    interactionLayer.setPreferredSize(prefSize);
    interactionLayer.setSize(width, height);
    backgroundColorFigure.setPreferredSize(prefSize);
    backgroundColorFigure.setSize(width, height);
    if (resizeMin) {
        setMinVisibleArea(width, height, false);
        // Check to see if the area was enlarged if so grow to match
        int editorWidth = editorComposite.getSize().x;
        int editorHeight = editorComposite.getSize().y;
        if (editorWidth > width) {
            width = editorWidth;
        }
        if (editorHeight > height) {
            height = editorHeight;
        }
        contents.setSize(width, height);
        interactionLayer.setSize(width, height);
        backgroundColorFigure.setSize(width, height);
    }
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) Dimension(org.eclipse.draw2d.geometry.Dimension) Point(org.eclipse.draw2d.geometry.Point)

Example 2 with Dimension

use of org.eclipse.draw2d.geometry.Dimension in project cogtool by cogtool.

the class GraphicalWidgetBase method regenerateCaches.

// paint
/**
     * Regenerates the dirty caches in a background thread.
     */
protected void regenerateCaches() {
    Dimension size = getSize();
    regenerateCaches(size.width, size.height);
}
Also used : Dimension(org.eclipse.draw2d.geometry.Dimension)

Example 3 with Dimension

use of org.eclipse.draw2d.geometry.Dimension in project cogtool by cogtool.

the class GraphicalWidgetBase method updateShape.

public synchronized void updateShape() {
    // Mark the caches as dirty so that no one will use them
    synchronized (this.flagLock) {
        this.cachedMidgroundDirty = true;
        this.cachedBackgroundDirty = true;
    }
    // Keep track of some properties that we need later
    Dimension oldSize = getSize();
    GraphicalWidgetClipper oldClipper = this.clipper;
    AShape s = model.getShape();
    DoubleRectangle shapeBds = s.getBounds();
    Rectangle figBds = PrecisionUtilities.getDraw2DRectangle(shapeBds);
    // Inherit properties from our model's shape
    setBounds(figBds);
    if ((figBds.width == 0) || (figBds.height == 0)) {
        if (figBds.width == 0) {
            figBds.width = 1;
        }
        if (figBds.height == 0) {
            figBds.height = 1;
        }
        super.setSize(figBds.width, figBds.height);
    }
    this.renderer.setSize(figBds.width, figBds.height);
    setPreferredSize(figBds.width, figBds.height);
    this.clipper = getClipperForShape(s);
    // Decide whether the caches are really dirty
    if (this.clipper.equals(oldClipper) && getSize().equals(oldSize)) {
        synchronized (this.flagLock) {
            this.cachedMidgroundDirty = false;
            this.cachedBackgroundDirty = false;
        }
    }
    regenerateCaches(figBds.width, figBds.height);
}
Also used : ShapeRoundedRectangle(edu.cmu.cs.hcii.cogtool.model.ShapeRoundedRectangle) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Dimension(org.eclipse.draw2d.geometry.Dimension) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) AShape(edu.cmu.cs.hcii.cogtool.model.AShape)

Example 4 with Dimension

use of org.eclipse.draw2d.geometry.Dimension in project cogtool by cogtool.

the class PERTChartOperatorBar method paint.

//  ----------- UI METHODS _------------------------------------------------
@Override
public void paint(Graphics g) {
    g.pushState();
    try {
        Color drawColor = (selected) ? selectedColor : color;
        Rectangle bds = getBounds();
        g.setBackgroundColor(drawColor);
        g.setForegroundColor(ColorConstants.black);
        g.fillRectangle(bds);
        if (!selected) {
            g.setForegroundColor(ColorConstants.white);
        }
        // don't display it.  This avoids unnecessary (& illegible) visual clutter
        if (name != null) {
            String minVisibleName = name;
            if (name.length() > 3) {
                minVisibleName = name.substring(0, 3);
            }
            Dimension textDim = FigureUtilities.getTextExtents(minVisibleName, g.getFont());
            if (textDim.width < (bds.width - 5)) {
                if (textDim.height < (bds.height - 5)) {
                    g.drawText(name, bds.x + 2, bds.y + 2);
                }
            }
        }
        g.setForegroundColor(ColorConstants.black);
        if (!isCascade()) {
            g.drawRectangle(new Rectangle(bds.x, bds.y, bds.width - 1, bds.height - 1));
        }
    } finally {
        g.popState();
    }
}
Also used : Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Dimension(org.eclipse.draw2d.geometry.Dimension)

Example 5 with Dimension

use of org.eclipse.draw2d.geometry.Dimension in project tdi-studio-se by Talend.

the class ConnectionTraceFigure method setTraceData.

public void setTraceData(TraceData data, boolean flag, boolean traceFlag) {
    if (data != null) {
        List childrens = this.getChildren();
        childrens.clear();
        boolean noVarNameDefined = false;
        Figure outlineFigure = new Figure();
        outlineFigure.setLayoutManager(new ToolbarLayout(true));
        int title1With = 0;
        int title2With = 0;
        if (tooltip != null) {
            collapseButton = new CollapseFigure();
            collapseButton.setCollapsed(connection.getConnectionTrace().isCollapse());
            collapseButton.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent event) {
                    connection.getConnectionTrace().setCollapse(!connection.getConnectionTrace().isCollapse());
                    collapseButton.setCollapsed(connection.getConnectionTrace().isCollapse());
                    refreshCollapseStatus();
                }
            });
            if (flag == true) {
                outlineFigure.add(collapseButton);
            }
        }
        // int sepIndex = data.indexOf(FIELD_SEP); // index separator for row name
        //
        // String dataWithoutRowName = data.substring(sepIndex + 1);
        // sepIndex = dataWithoutRowName.indexOf(FIELD_SEP);
        int lineNumber = data.getNbLine();
        SimpleHtmlFigure titleFigure = new SimpleHtmlFigure();
        //$NON-NLS-1$
        titleFigure.setText("");
        titleFigure.setText(//$NON-NLS-1$
        "<font color='#0000FF'> <b> " + connection.getConnectionLabel().getLabelText() + //$NON-NLS-1$ 
        "</b></font>");
        if (tooltip != null) {
            titleFigure.setBackgroundColor(ColorConstants.white);
            titleFigure.setOpaque(false);
        }
        titleFigure.getPreferredSize().expand(20, 2);
        title1With = titleFigure.getPreferredSize().width;
        SimpleHtmlFigure titleFigureSe = new SimpleHtmlFigure();
        //$NON-NLS-1$ //$NON-NLS-2$
        titleFigureSe.setText(" <font color='#808080'>Current row : " + lineNumber + "</font>");
        if (tooltip != null) {
            titleFigureSe.setBackgroundColor(ColorConstants.white);
            titleFigureSe.setOpaque(false);
        }
        titleFigureSe.getPreferredSize().expand(20, 2);
        title2With = titleFigureSe.getPreferredSize().width;
        if (flag == true) {
            outlineFigure.add(titleFigure);
        }
        ImageFigure figure = new ImageFigure(getTraceConnectionImage(flag));
        outlineFigure.add(figure);
        if (flag == true) {
            outlineFigure.add(titleFigureSe);
        }
        outlineFigure.setBorder(new LineBorder(ColorConstants.darkGray, SWT.LEFT | SWT.RIGHT | SWT.TOP | SWT.BOTTOM));
        outlineFigure.setOpaque(true);
        add(outlineFigure);
        Dimension size = titleFigure.getPreferredSize().getCopy();
        int variableWidth = 0;
        int valueWidth = 0;
        // String lineInfo = dataWithoutRowName.substring(sepIndex + 1);
        // ArrayList columnValueList = new ArrayList();
        // int lastLocation = 0;
        // int endLocation = lineInfo.indexOf(FIELD_SEP, lastLocation);
        // while (endLocation != -1) {
        // columnValueList.add(lineInfo.substring(lastLocation, endLocation + 1));
        // lastLocation = endLocation + 2;
        // endLocation = lineInfo.indexOf(FIELD_SEP, lastLocation);
        // }
        // if (columnValueList.size() > 0 && connection.traceColumn.size() == 0
        // && connection.getPropertyValue(EParameterName.TRACES_CONNECTION_FILTER.getName()) != null) {
        // Object value = connection.getPropertyValue(EParameterName.TRACES_CONNECTION_FILTER.getName());
        // lineInfo = "";
        // for (Object o : columnValueList) {
        // for (Object o1 : (ArrayList) value) {
        // if (o1 instanceof HashMap) {
        // String columnValue = o.toString();
        // if (columnValue.indexOf("=") > 0) {
        // if (((HashMap) o1).get(IConnection.TRACE_SCHEMA_COLUMN).toString()
        // .equals(columnValue.substring(0, columnValue.indexOf("=")).trim())
        // && Boolean.TRUE.toString().equals(
        // ((HashMap) o1).get(IConnection.TRACE_SCHEMA_COLUMN_CHECKED).toString())) {
        // lineInfo += columnValue;
        // break;
        // }
        // }
        // }
        // }
        // }
        // }
        // if (columnValueList.size() > 0 && (connection.traceColumn.size() > 0 || connection.setNullColumn ==
        // true)) {
        // lineInfo = "";
        // Object value = connection.getPropertyValue(EParameterName.TRACES_CONNECTION_FILTER.getName());
        // int columnNum = 0;
        // for (Object o : columnValueList) {
        // if (connection.traceColumn != null && connection.traceColumn.contains(columnNum)) {
        // lineInfo += o.toString();
        // } else {
        // for (Object o1 : (ArrayList) value) {
        // if (((HashMap) o1).get(IConnection.TRACE_SCHEMA_COLUMN).toString()
        // .equals(o.toString().substring(0, o.toString().indexOf("=")).trim())
        // && Boolean.TRUE.toString().equals(
        // ((HashMap) o1).get(IConnection.TRACE_SCHEMA_COLUMN_CHECKED).toString())) {
        // lineInfo += o.toString();
        // break;
        // }
        // }
        // }
        // columnNum++;
        // }
        // }
        // StringTokenizer st = new StringTokenizer(lineInfo, FIELD_SEP);
        List<Map<String, Object>> columnsCheckInfo = null;
        if (data.getData() != null) {
            columnsCheckInfo = TracesConnectionUtils.getTraceConnectionFilterValues(connection);
            Iterator<String> iterator = data.getData().keySet().iterator();
            while (iterator.hasNext()) {
                String columnLabel = iterator.next();
                if (columnsCheckInfo != null && !isColumnChecked(columnsCheckInfo, columnLabel)) {
                    continue;
                }
                // String str = st.nextToken();
                // int valueStart = str.indexOf(FIELD_EQUAL);
                // if (valueStart != -1) {
                String formatedVariable = //$NON-NLS-1$
                "<font color='#000000'>  <b>" + columnLabel + //$NON-NLS-1$
                "</b></font>";
                //$NON-NLS-1$ //$NON-NLS-2$
                String formatedValue = "<font color='#FF8040'> <b>" + data.getData().get(columnLabel) + "</b></font>";
                SimpleHtmlFigure var = new SimpleHtmlFigure();
                var.setText(formatedVariable);
                SimpleHtmlFigure value = new SimpleHtmlFigure();
                value.setText(formatedValue);
                Dimension varSize = var.getPreferredSize();
                varSize.expand(0, 3);
                var.setPreferredSize(varSize);
                if (varSize.width > variableWidth) {
                    variableWidth = varSize.width;
                }
                Dimension valueSize = value.getPreferredSize();
                valueSize.expand(0, 3);
                value.setPreferredSize(valueSize);
                if (valueSize.width > valueWidth) {
                    valueWidth = valueSize.width;
                }
                size.expand(0, varSize.height);
            // } else {
            // noVarNameDefined = true;
            //                    String formatedValue = "<font color='#FF8040'> <b>" + str + "</b></font>"; //$NON-NLS-1$ //$NON-NLS-2$
            // SimpleHtmlFigure value = new SimpleHtmlFigure();
            // value.setText(formatedValue);
            // Dimension valueSize = value.getPreferredSize();
            // if (valueSize.width > valueWidth) {
            // valueWidth = valueSize.width;
            // }
            // size.expand(0, valueSize.height);
            // }
            }
        }
        variableWidth += 10;
        valueWidth += 10;
        if (variableWidth < title1With) {
            variableWidth = title1With;
        }
        if (valueWidth < title2With) {
            valueWidth = title2With;
        }
        // if (maximized) {
        if (variableWidth < MAX_VARIABLE_WIDTH) {
            variableWidth = MAX_VARIABLE_WIDTH;
        }
        if (valueWidth < MAX_VALUE_WIDTH) {
            valueWidth = MAX_VALUE_WIDTH;
        }
        if ((variableWidth + valueWidth) < titleFigure.getPreferredSize().width) {
            valueWidth = titleFigure.getPreferredSize().width - variableWidth;
        }
        if (noVarNameDefined) {
            if (titleFigure.getPreferredSize().width > valueWidth) {
                valueWidth = titleFigure.getPreferredSize().width;
            }
        }
        // st = new StringTokenizer(lineInfo, FIELD_SEP);
        int nbVar = 0;
        if (data.getData() != null) {
            Iterator<String> iterator = data.getData().keySet().iterator();
            while (iterator.hasNext()) {
                String columnLabel = iterator.next();
                if (columnsCheckInfo != null && !isColumnChecked(columnsCheckInfo, columnLabel)) {
                    continue;
                }
                // int valueStart = str.indexOf(FIELD_EQUAL);
                // if (valueStart != -1) {
                String formatedVariable = //$NON-NLS-1$
                "<font color='#000000'>  <b>" + columnLabel + //$NON-NLS-1$
                "</b></font>";
                //$NON-NLS-1$ //$NON-NLS-2$
                String formatedValue = "<font color='#FF8040'> <b>" + data.getData().get(columnLabel) + "</b></font>";
                SimpleHtmlFigure var = new SimpleHtmlFigure();
                var.setText(formatedVariable);
                SimpleHtmlFigure value = new SimpleHtmlFigure();
                value.setText(formatedValue);
                Dimension valueSize = value.getPreferredSize();
                valueSize.expand(0, 3);
                value.setPreferredSize(valueSize);
                value.setPreferredSize(valueWidth, valueSize.height);
                var.setBorder(new LineBorder(ColorConstants.darkGray, SWT.RIGHT));
                Dimension varSize = var.getPreferredSize();
                varSize.expand(0, 3);
                var.setPreferredSize(varSize);
                var.setPreferredSize(variableWidth, varSize.height);
                ToolbarLayout variableLayout = new ToolbarLayout(true);
                variableFigure = new Figure();
                variableFigure.setLayoutManager(variableLayout);
                variableFigure.add(var);
                variableFigure.add(value);
                if (flag == true) {
                    add(variableFigure);
                }
            // } else {
            //                    String formatedValue = "<font color='#FF8040'> <b> " + str + "</b></font>"; //$NON-NLS-1$ //$NON-NLS-2$
            // SimpleHtmlFigure value = new SimpleHtmlFigure();
            // value.setText(formatedValue);
            //
            // Dimension valueSize = value.getPreferredSize();
            // valueSize.expand(0, 3);
            // value.setPreferredSize(valueSize);
            // value.setPreferredSize(valueWidth, valueSize.height);
            //
            // ToolbarLayout variableLayout = new ToolbarLayout(true);
            // variableFigure = new Figure();
            // variableFigure.setLayoutManager(variableLayout);
            // variableFigure.add(value);
            // if (flag == true) {
            // add(variableFigure);
            // }
            // }
            }
            if (tooltip != null) {
                if (variableFigure != null) {
                    variableFigure.setBorder(new LineBorder(ColorConstants.darkGray, SWT.LEFT | SWT.RIGHT));
                }
            }
            if (variableFigure != null) {
                variableFigure.setOpaque(true);
            }
            if ((nbVar % 2) != 0) {
                if (tooltip != null) {
                    if (variableFigure != null) {
                        variableFigure.setBackgroundColor(ColorConstants.white);
                    }
                }
            } else {
                if (variableFigure != null) {
                    variableFigure.setBackgroundColor(BACKGROUND);
                }
            }
            nbVar++;
        }
        if (tooltip != null) {
            if (variableFigure != null) {
                variableFigure.setBorder(new LineBorder(ColorConstants.darkGray, SWT.LEFT | SWT.BOTTOM | SWT.RIGHT));
            }
        }
        if (maximized) {
            this.setVariableFigureBorder();
        }
        if (noVarNameDefined) {
            size.width = valueWidth;
        } else {
            size.width = variableWidth + valueWidth;
        }
        if (size.width < titleFigure.getPreferredSize().width) {
            size.width = titleFigure.getPreferredSize().width;
        }
        // size.width = size.width * 2;
        size.expand(5, 3);
        setPreferredSize(size);
        setVisible(true);
        if (!flag) {
            this.remove(outlineFigure);
            add(figure);
        }
    } else {
        if (traceFlag) {
            Image enableImage = getTraceConnectionImage(flag);
            setPreferredSize(enableImage.getImageData().width, enableImage.getImageData().height);
            this.getChildren().clear();
            ImageFigure figure = new ImageFigure(enableImage);
            add(figure);
            setVisible(true);
        } else {
            setPreferredSize(0, 0);
            setVisible(false);
        }
    }
    if (tooltip != null) {
        if (flag) {
            tooltip.setTraceData(data, flag, traceFlag);
        } else {
            tooltip.setTraceData(data, flag, false);
        }
    }
    contents = new ArrayList(getChildren());
    refreshCollapseStatus();
}
Also used : ActionEvent(org.eclipse.draw2d.ActionEvent) ArrayList(java.util.ArrayList) Dimension(org.eclipse.draw2d.geometry.Dimension) Image(org.eclipse.swt.graphics.Image) EImage(org.talend.commons.ui.runtime.image.EImage) ECoreImage(org.talend.commons.ui.runtime.image.ECoreImage) IFigure(org.eclipse.draw2d.IFigure) ImageFigure(org.eclipse.draw2d.ImageFigure) SimpleHtmlFigure(org.talend.commons.ui.utils.workbench.gef.SimpleHtmlFigure) Figure(org.eclipse.draw2d.Figure) SimpleHtmlFigure(org.talend.commons.ui.utils.workbench.gef.SimpleHtmlFigure) ToolbarLayout(org.eclipse.draw2d.ToolbarLayout) ActionListener(org.eclipse.draw2d.ActionListener) ArrayList(java.util.ArrayList) List(java.util.List) ImageFigure(org.eclipse.draw2d.ImageFigure) Map(java.util.Map)

Aggregations

Dimension (org.eclipse.draw2d.geometry.Dimension)312 Rectangle (org.eclipse.draw2d.geometry.Rectangle)105 Point (org.eclipse.draw2d.geometry.Point)92 IFigure (org.eclipse.draw2d.IFigure)57 List (java.util.List)29 Image (org.eclipse.swt.graphics.Image)15 Insets (org.eclipse.draw2d.geometry.Insets)14 Font (org.eclipse.swt.graphics.Font)13 FontData (org.eclipse.swt.graphics.FontData)11 Point (org.eclipse.swt.graphics.Point)11 Text (org.eclipse.swt.widgets.Text)11 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)10 ArrayList (java.util.ArrayList)10 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)9 GC (org.eclipse.swt.graphics.GC)9 Figure (org.eclipse.draw2d.Figure)7 PointList (org.eclipse.draw2d.geometry.PointList)7 IBounds (com.archimatetool.model.IBounds)6 Test (org.junit.Test)6 NodeContainer (org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)6