Search in sources :

Example 1 with Rectangle

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

the class DesignEditorFrame method resetFrameSize.

protected void resetFrameSize() {
    // Update the size with the preferred size of the contents.
    DoubleSize size = computeFrameSize(getScale());
    int width = PrecisionUtilities.round(size.width);
    int height = PrecisionUtilities.round(size.height);
    // Set the initial size to force a repaint call.
    // Call super, since we actually want to set the Size.. vs the current
    // which will try and resize to the "current size"
    // while this is actually a flag to force a paint.
    super.setSize(width, height);
    super.setPreferredSize(width, height);
    // Force this to always take the extra space up by frameWidget Box
    if (usesSpeaker) {
        height -= speakerBox.getPreferredSize().height;
    }
    height -= (inputDeviceBox.getPreferredSize().height + inputDeviceBox.getInsets().getHeight());
    height -= nameLabel.getPreferredSize().height;
    frameWidgetBox.setSize(width, height);
    frameWidgetBox.setPreferredSize(width, height);
    if (usesSpeaker) {
        int insetsWidth = getInsets().getWidth();
        int speakerTextWidth = width - insetsWidth - (4 * SPEAKER_DIVIDER_WIDTH) - speakerImgWidth - LISTEN_TIME_WIDTH - 1;
        Rectangle layoutConstraint = new Rectangle(speakerImgWidth + SPEAKER_DIVIDER_WIDTH, 0, speakerTextWidth, speakerImgHeight);
        speakerLayout.setConstraint(speakerText, layoutConstraint);
        layoutConstraint = new Rectangle(speakerImgWidth + SPEAKER_DIVIDER_WIDTH + speakerTextWidth, 0, SPEAKER_DIVIDER_WIDTH, speakerImgHeight);
        speakerLayout.setConstraint(divider, layoutConstraint);
        layoutConstraint = new Rectangle(speakerImgWidth + (2 * SPEAKER_DIVIDER_WIDTH) + speakerTextWidth, 0, LISTEN_TIME_WIDTH, speakerImgHeight);
        speakerLayout.setConstraint(listenTime, layoutConstraint);
        layoutConstraint = new Rectangle(speakerImgWidth + (3 * SPEAKER_DIVIDER_WIDTH) + speakerTextWidth + LISTEN_TIME_WIDTH, 0, SPEAKER_DIVIDER_WIDTH, speakerImgHeight);
        speakerLayout.setConstraint(timeWestBorder, layoutConstraint);
    }
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) DoubleSize(edu.cmu.cs.hcii.cogtool.model.DoubleSize) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 2 with Rectangle

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

the class FrameUIModel method setGraphicalWidgetMove.

/**
     * Set the origin of the graphical widget to be displaced by the differences.
     * Generally this is a temporary move; since it does not affect the model
     * it is here for performance reasons.
     */
public void setGraphicalWidgetMove(double diffX, double diffY, GraphicalWidget<?> gw) {
    Rectangle r = gw.getBounds();
    setGraphicalWidgetOrigin(r.x + diffX, r.y + diffY, gw);
}
Also used : DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) Rectangle(org.eclipse.draw2d.geometry.Rectangle)

Example 3 with Rectangle

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

the class FrameUIModel method drawWidgets.

// addFrameChangeListeners
/**
     * Loop through each element in the widgets & figures list and then
     * draw them.
     *
     * By default the contents Figure would already have these added...
     * Check to see if they are already there.. or remove all and insert all.
     */
public void drawWidgets() {
    // Sort the items to be drawn into an order based on the level.
    // Highest numbers go first, i.e. render widgets from back to front.
    Collection<GraphicalWidget<?>> figures = figureList.values();
    GraphicalWidget<?>[] figureArray = new GraphicalWidget[figures.size()];
    figureArray = figures.toArray(figureArray);
    Arrays.sort(figureArray, GraphicalWidgetBase.GraphicalWidgetLevelComparator.ONLY);
    // Add the background
    if (backgroundImage != null) {
        // Add the background to the lowest layer 0
        contents.add(backgroundImage, new Rectangle(backgroundImage.getBounds()), 0);
    }
    // Add each graphical widget from the array to the scalable figure
    for (GraphicalWidget<?> figureItem : figureArray) {
        // Add the figure to the contents
        // Specify the bounds of the figure in the XY layout of the content
        // Theoretically this could be removed...
        // but doing so causes lots of rendering bugs
        DoubleRectangle shapeBounds = figureItem.getModel().getEltBounds();
        contents.add(figureItem, PrecisionUtilities.getDraw2DRectangle(shapeBounds), -1);
    }
}
Also used : DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) Rectangle(org.eclipse.draw2d.geometry.Rectangle) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)

Example 4 with Rectangle

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

the class FrameUIModel method setGraphicalWidgetBounds.

/**
     * Set the bounds of the graphical widget to the new coordinates.
     * Generally this is a temporary move; since it does not affect the model
     * it is here for performance reasons.
     */
public void setGraphicalWidgetBounds(double tempOriginX, double tempOriginY, double tempWidth, double tempHeight, GraphicalWidget<?> gw) {
    Rectangle newBds = PrecisionUtilities.getDraw2DRectangle(tempOriginX, tempOriginY, tempWidth, tempHeight);
    gw.setBounds(newBds);
    // For some idiot reason, the setBounds call doesn't refresh the size
    // during dynamics, so do the setSize to force it (sigh)
    gw.setSize((newBds.width > 0) ? newBds.width : 1, (newBds.height > 0) ? newBds.height : 1);
}
Also used : DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) Rectangle(org.eclipse.draw2d.geometry.Rectangle)

Example 5 with Rectangle

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

the class FrameEditorUI method confirmRenameFigure.

protected void confirmRenameFigure() {
    if ((editor != null) && editor.inUse()) {
        String newTitle = editor.getText();
        editor.cleanup();
        // figure whose title is currently being edited
        IFigure figure = (IFigure) editor.getData();
        if (figure instanceof PotentialFigure) {
            if ("".equals(newTitle)) {
                // nothing to do if empty string on potential item!
                return;
            }
            GraphicalTraversableWidget<?> parent = potentialUIFig.getFigureOwner();
            TraversableWidget parentModel = (TraversableWidget) parent.getModel();
            boolean isRightPotentialFigure = (figure == potentialUIFig.getRightFigure());
            WidgetType type = null;
            AParentWidget header = null;
            SimpleWidgetGroup group = null;
            boolean isSeparator = false;
            if (parentModel instanceof MenuItem) {
                type = WidgetType.MenuItem;
                MenuItem parentItem = (MenuItem) parentModel;
                if (isRightPotentialFigure) {
                    // position of selected figure is on the right
                    // parent menuitem becomes a submenu; figure to be
                    // created becomes a child of the submenu
                    parentItem.setSubmenu(true);
                    header = parentItem;
                } else {
                    // if position is on the bottom and the parent is not a
                    // header, put the new widget in the same menu as the
                    // parent item
                    header = parentItem.getParent();
                    // previous item should hide children if it's a submenu
                    ((GraphicalParentWidget<?, ?>) parent).closeChildren();
                }
                if (parentModel.getWidgetType() != WidgetType.Submenu) {
                    isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
                }
            } else if (parentModel instanceof ContextMenu) {
                header = (ContextMenu) parentModel;
                type = WidgetType.MenuItem;
                isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
            } else if (parentModel instanceof MenuHeader) {
                // and hide children of the previous header
                if (isRightPotentialFigure) {
                    type = WidgetType.Menu;
                    ((GraphicalParentWidget<?, ?>) parent).closeChildren();
                    group = parentModel.getParentGroup();
                } else {
                    header = (MenuHeader) parentModel;
                    type = WidgetType.MenuItem;
                    isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
                }
            } else if (parentModel instanceof PullDownItem) {
                type = WidgetType.PullDownItem;
                if (!isRightPotentialFigure) {
                    PullDownItem parentItem = (PullDownItem) parentModel;
                    header = parentItem.getParent();
                    isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
                }
            } else if (parentModel instanceof PullDownHeader) {
                type = WidgetType.PullDownItem;
                if (!isRightPotentialFigure) {
                    header = (PullDownHeader) parentModel;
                    isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
                }
            } else if (parentModel instanceof ListItem) {
                type = WidgetType.ListBoxItem;
                group = parentModel.getParentGroup();
                isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
            } else if (parentModel instanceof GridButton) {
                type = parentModel.getWidgetType();
                group = parentModel.getParentGroup();
            }
            Rectangle r = ((PotentialFigure) figure).getUnscaledBounds();
            DoubleRectangle bounds = new DoubleRectangle(r.x, r.y, r.width, r.height);
            performAction(CogToolLID.NewWidget, new FrameEditorUI.NewWidgetParameters(bounds, header, type, view.isAutomaticCreation(), newTitle, group, isSeparator));
        } else {
            boolean isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
            performAction(FrameEditorLID.ChangeTitleProperty, new FrameEditorUI.ActionStringParameters(newTitle, selection, isSeparator), true);
        }
    }
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) MenuHeader(edu.cmu.cs.hcii.cogtool.model.MenuHeader) GraphicalMenuHeader(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalMenuHeader) Rectangle(org.eclipse.draw2d.geometry.Rectangle) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) MenuItem(edu.cmu.cs.hcii.cogtool.model.MenuItem) ContextMenu(edu.cmu.cs.hcii.cogtool.model.ContextMenu) GraphicalContextMenu(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalContextMenu) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) PullDownHeader(edu.cmu.cs.hcii.cogtool.model.PullDownHeader) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) PotentialFigure(edu.cmu.cs.hcii.cogtool.view.PotentialFigure) TraversableWidget(edu.cmu.cs.hcii.cogtool.model.TraversableWidget) GraphicalTraversableWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget) GraphicalGridButton(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalGridButton) GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) PullDownItem(edu.cmu.cs.hcii.cogtool.model.PullDownItem) GraphicalListItem(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalListItem) ListItem(edu.cmu.cs.hcii.cogtool.model.ListItem) WidgetType(edu.cmu.cs.hcii.cogtool.model.WidgetType) GraphicalParentWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalParentWidget) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

Rectangle (org.eclipse.draw2d.geometry.Rectangle)197 Point (org.eclipse.draw2d.geometry.Point)59 Dimension (org.eclipse.draw2d.geometry.Dimension)43 IFigure (org.eclipse.draw2d.IFigure)31 List (java.util.List)21 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)17 Iterator (java.util.Iterator)11 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)11 NodeContainer (org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)11 AbstractGraphicalEditPart (org.eclipse.gef.editparts.AbstractGraphicalEditPart)9 TableFigure (com.cubrid.common.ui.er.figures.TableFigure)8 ArrayList (java.util.ArrayList)8 Node (org.talend.designer.core.ui.editor.nodes.Node)8 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)7 Figure (org.eclipse.draw2d.Figure)6 Color (org.eclipse.swt.graphics.Color)6 ERTable (com.cubrid.common.ui.er.model.ERTable)5 DesignEditorFrame (edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorFrame)5 Label (org.eclipse.draw2d.Label)5 Image (org.eclipse.swt.graphics.Image)5