Search in sources :

Example 46 with Rectangle

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

the class TableContainerLayout method layout.

@Override
public void layout(IFigure parent) {
    List children = parent.getChildren();
    int numChildren = children.size();
    Rectangle clientArea = transposer.t(parent.getClientArea());
    int x = clientArea.x;
    int y = clientArea.y;
    int availableHeight = clientArea.height;
    Dimension[] prefSizes = new Dimension[numChildren];
    Dimension[] minSizes = new Dimension[numChildren];
    int wHint = -1;
    int hHint = -1;
    if (isHorizontal()) {
        hHint = parent.getClientArea(Rectangle.SINGLETON).height;
    } else {
        wHint = parent.getClientArea(Rectangle.SINGLETON).width;
    }
    IFigure child;
    int totalHeight = 0;
    int totalMinHeight = 0;
    int prefMinSumHeight = 0;
    for (int i = 0; i < numChildren; i++) {
        child = (IFigure) children.get(i);
        prefSizes[i] = transposer.t(getChildPreferredSize(child, wHint, hHint));
        minSizes[i] = transposer.t(getChildMinimumSize(child, wHint, hHint));
        totalHeight += prefSizes[i].height;
        totalMinHeight += minSizes[i].height;
    }
    totalHeight += (numChildren - 1) * spacing;
    totalMinHeight += (numChildren - 1) * spacing;
    prefMinSumHeight = totalHeight - totalMinHeight;
    int amntShrinkHeight = totalHeight - Math.max(availableHeight, totalMinHeight);
    if (amntShrinkHeight < 0) {
        amntShrinkHeight = 0;
    }
    for (int i = 0; i < numChildren; i++) {
        int amntShrinkCurrentHeight = 0;
        int prefHeight = prefSizes[i].height;
        int minHeight = minSizes[i].height;
        int prefWidth = prefSizes[i].width;
        int minWidth = minSizes[i].width;
        Rectangle newBounds = new Rectangle(x, y, prefWidth, prefHeight);
        child = (IFigure) children.get(i);
        if (child instanceof AbstractTreeSettingContainer) {
            if (!tableMananger.isActivateCondensedTool()) {
                child.setBounds(new Rectangle(x, y, 0, 0));
                continue;
            }
        }
        if (child instanceof FilterContainer) {
            if (!tableMananger.isActivateExpressionFilter()) {
                child.setBounds(new Rectangle(x, y, 0, 0));
                continue;
            }
        }
        if (child instanceof AbstractGlobalMapContainer) {
            if (!tableMananger.isActivateGlobalMap()) {
                child.setBounds(new Rectangle(x, y, 0, 0));
                continue;
            }
        }
        int width = Math.min(prefWidth, transposer.t(child.getMaximumSize()).width);
        if (matchWidth) {
            width = transposer.t(child.getMaximumSize()).width;
        }
        width = Math.max(minWidth, Math.min(clientArea.width, width));
        newBounds.width = width;
        child.setBounds(transposer.t(newBounds));
        amntShrinkHeight -= amntShrinkCurrentHeight;
        prefMinSumHeight -= (prefHeight - minHeight);
        y += newBounds.height + spacing;
        if (child instanceof ScrollPane) {
            IFigure contents = ((ScrollPane) child).getViewport().getContents();
            if (contents instanceof AbstractTable) {
            // ((AbstractTable) contents).setDefautTableWidth(newBounds.width);
            }
        }
    }
}
Also used : AbstractTable(org.talend.designer.gefabstractmap.figures.table.AbstractTable) ScrollPane(org.eclipse.draw2d.ScrollPane) FilterContainer(org.talend.designer.gefabstractmap.figures.treesettings.FilterContainer) AbstractGlobalMapContainer(org.talend.designer.gefabstractmap.figures.table.AbstractGlobalMapContainer) Rectangle(org.eclipse.draw2d.geometry.Rectangle) List(java.util.List) Dimension(org.eclipse.draw2d.geometry.Dimension) AbstractTreeSettingContainer(org.talend.designer.gefabstractmap.figures.treesettings.AbstractTreeSettingContainer) IFigure(org.eclipse.draw2d.IFigure)

Example 47 with Rectangle

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

the class TableItemLayout method layout.

@Override
public void layout(IFigure parent) {
    if (parent.getParent() == null || !(parent.getParent().getParent() instanceof Table)) {
        throw new RuntimeException("Can't find table");
    }
    Table table = (Table) parent.getParent().getParent();
    Rectangle clientArea = parent.getClientArea();
    int X = clientArea.x;
    int Y = clientArea.y;
    List<TableColumn> columns = table.getColumns();
    List children = parent.getChildren();
    if (columns.size() != children.size()) {
        throw new RuntimeException("Table items size don't match column size");
    }
    int rowheight = 0;
    for (int i = 0; i < children.size(); i++) {
        Figure figure = (Figure) children.get(i);
        Dimension size = figure.getPreferredSize();
        rowheight = Math.max(rowheight, size.height);
    }
    for (int i = 0; i < columns.size(); i++) {
        TableColumn tableColumn = columns.get(i);
        Figure figure = (Figure) children.get(i);
        int columnWidth = table.getColumnWidth(tableColumn.getColumnKey());
        Rectangle newBounds = new Rectangle(X, Y, columnWidth, rowheight);
        figure.setBounds(newBounds);
        X += columnWidth;
    }
}
Also used : Table(org.talend.designer.gefabstractmap.figures.table.Table) Rectangle(org.eclipse.draw2d.geometry.Rectangle) List(java.util.List) Dimension(org.eclipse.draw2d.geometry.Dimension) TableColumn(org.talend.designer.gefabstractmap.figures.table.TableColumn) Figure(org.eclipse.draw2d.Figure) IFigure(org.eclipse.draw2d.IFigure)

Example 48 with Rectangle

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

the class TableLayout method layout.

@Override
public void layout(IFigure container) {
    Rectangle clientArea = container.getClientArea();
    IFigure tableContainer = getTableContainer(container);
    int containerWidth = tableContainer.getBounds().width;
    int clientWidth = clientArea.width;
    if (ajustToDefaultWidth) {
        clientWidth = containerWidth;
    }
    initColumnPercentage(clientWidth, containerWidth);
    int columnNum = columns.size();
    int toltalWidth = 0;
    Dimension[] prefSizes = new Dimension[columnNum];
    int titleHeight = 0;
    for (int i = 0; i < columnNum; i++) {
        TableColumn column = columns.get(i);
        prefSizes[i] = column.getPreferredSize();
        titleHeight = Math.max(titleHeight, prefSizes[i].height);
    }
    int X = clientArea.x;
    int Y = clientArea.y;
    int previousSashOccupied = 0;
    for (int i = 0; i < columns.size(); i++) {
        TableColumn currentColumn = columns.get(i);
        ColumnSash sash = null;
        if (i < columns.size() - 1) {
            sash = separators.get(i);
        }
        Double percent = keyAndPercentage.get(currentColumn.getColumnKey());
        int width = (int) Math.round(clientWidth * percent);
        if (sash != null) {
            int halfSashWidth = sash.getSashWidth() / 2;
            toltalWidth += width;
            Rectangle newBounds = new Rectangle(X, Y, width - halfSashWidth - previousSashOccupied, titleHeight);
            currentColumn.setBounds(newBounds);
            keyAndLength.put(currentColumn.getColumnKey(), width);
            X += newBounds.width;
            // don't add sash width to total width
            newBounds = new Rectangle(X, Y, sash.getSashWidth(), titleHeight);
            sash.setBounds(newBounds);
            X += newBounds.width;
            previousSashOccupied = halfSashWidth;
        } else {
            Rectangle newBounds = new Rectangle(X, Y, width - previousSashOccupied, titleHeight);
            currentColumn.setBounds(newBounds);
            keyAndLength.put(currentColumn.getColumnKey(), width);
            toltalWidth += width;
        }
    }
    // in case some blank width
    if (toltalWidth != 0) {
        int diff = clientWidth - toltalWidth;
        if (diff < 0) {
            diff = 0;
        }
        int avg = diff / columnNum;
        int remainder = diff % columnNum;
        if (avg != 0) {
            for (int i = 0; i < columnNum; i++) {
                TableColumn tableColumn = columns.get(i);
                Rectangle copy = tableColumn.getBounds().getCopy();
                if (i > 0) {
                    copy.x += avg * i;
                }
                copy.width += avg;
                tableColumn.setBounds(copy);
                keyAndLength.put(tableColumn.getColumnKey(), keyAndLength.get(tableColumn.getColumnKey()) + avg);
                if (i < separators.size()) {
                    ColumnSash separator = separators.get(i);
                    copy = separator.getBounds().getCopy();
                    copy.x += avg * (i + 1);
                    separator.setBounds(copy);
                }
            }
        }
        if (remainder != 0) {
            TableColumn lastChild = columns.get(columns.size() - 1);
            final Rectangle bounds = lastChild.getBounds();
            bounds.width = bounds.width + remainder;
            lastChild.setBounds(bounds);
            keyAndLength.put(lastChild.getColumnKey(), keyAndLength.get(lastChild.getColumnKey()) + remainder);
        }
    }
    Dimension itemContainerSize = tableItemContainer.getPreferredSize();
    Rectangle newBounds = new Rectangle(clientArea.x, clientArea.y + titleHeight, clientWidth, itemContainerSize.height);
    tableItemContainer.setBounds(newBounds);
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) Dimension(org.eclipse.draw2d.geometry.Dimension) ColumnSash(org.talend.designer.gefabstractmap.figures.table.ColumnSash) TableColumn(org.talend.designer.gefabstractmap.figures.table.TableColumn) IFigure(org.eclipse.draw2d.IFigure)

Example 49 with Rectangle

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

the class TableLayout method getColumnBounds.

public Rectangle getColumnBounds(int index) {
    Rectangle copy = columns.get(index).getBounds().getCopy();
    int ajustSashWidth = 0;
    if (index == 0 && separators.size() > 0) {
        ajustSashWidth = (int) (separators.get(0).getSashWidth() / (double) 2);
    } else if (index > 0 && index == separators.size()) {
        ajustSashWidth = (int) (separators.get(index - 1).getSashWidth() / (double) 2);
    } else if (index > 0 && index < separators.size()) {
        ajustSashWidth = (int) (separators.get(index - 1).getSashWidth() / (double) 2 + separators.get(index).getSashWidth() / (double) 2);
    }
    copy.width += ajustSashWidth;
    return copy;
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle)

Example 50 with Rectangle

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

the class TreeBranchLayout method paintLines.

public void paintLines(Graphics g) {
    int gap = treeBranch.getGaps();
    g.setLineStyle(getBranchLineStyle());
    IFigure startFig = treeBranch.getTitle();
    int x = startFig.getBounds().x + gap;
    int y = startFig.getBounds().bottom() - 2;
    if (getTreeNodeFigure() != null) {
        List children = getTreeNodeFigure().getContents().getChildren();
        if (children.size() == 0) {
            return;
        }
        int bottom = y;
        for (int i = 0; i < children.size(); i++) {
            TableTreeEntityFigure treeNode = (TableTreeEntityFigure) children.get(i);
            Rectangle childStartBounds = treeNode.getTreeBranch().getTitle().getBounds();
            Point pt = childStartBounds.getLeft();
            g.drawLine(x, pt.y, pt.x, pt.y);
            bottom = Math.max(bottom, pt.y);
        }
        g.drawLine(x, y, x, bottom);
    }
}
Also used : TableTreeEntityFigure(org.talend.designer.gefabstractmap.figures.table.entity.TableTreeEntityFigure) Rectangle(org.eclipse.draw2d.geometry.Rectangle) List(java.util.List) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

Rectangle (org.eclipse.draw2d.geometry.Rectangle)347 Point (org.eclipse.draw2d.geometry.Point)107 Dimension (org.eclipse.draw2d.geometry.Dimension)80 IFigure (org.eclipse.draw2d.IFigure)43 List (java.util.List)24 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)18 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)17 PointList (org.eclipse.draw2d.geometry.PointList)16 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)15 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)14 ArrayList (java.util.ArrayList)11 Iterator (java.util.Iterator)11 PrecisionRectangle (org.eclipse.draw2d.geometry.PrecisionRectangle)11 NodeContainer (org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)11 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)10 AbstractGraphicalEditPart (org.eclipse.gef.editparts.AbstractGraphicalEditPart)10 TableFigure (com.cubrid.common.ui.er.figures.TableFigure)8 Viewport (org.eclipse.draw2d.Viewport)8 Node (org.talend.designer.core.ui.editor.nodes.Node)8 Image (org.eclipse.swt.graphics.Image)7