Search in sources :

Example 1 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project cogtool by cogtool.

the class ProjectUI method computeColumnArea.

protected Rectangle computeColumnArea(TreeColumn column) {
    if (column != null) {
        Point size = tree.getSize();
        Rectangle treeArea = new Rectangle(0, 0, size.x, size.y);
        int[] columnOrdering = uiModel.getCurrentDesignOrdering();
        int i = 0;
        TreeColumn nextCol = tree.getColumn(i++);
        while (nextCol != column) {
            treeArea.x += nextCol.getWidth();
            //                if (OSUtils.MACOSX) {
            //                    // XXX: dirty hacks around SWT bugs
            //                    treeArea.x += 30;
            //                }
            nextCol = tree.getColumn(columnOrdering[i++]);
        }
        treeArea.width = column.getWidth();
        if (OSUtils.MACOSX) {
            // XXX: dirty hacks around SWT bugs
            int off = ((numExpandedLevels(tree.getItems()) - 1) * 24);
            treeArea.x += off;
            //     treeArea.width += 1;
            treeArea.y += 1;
            treeArea.height -= 16;
            treeArea.x += 4;
        }
        return treeArea;
    }
    return null;
}
Also used : TreeColumn(org.eclipse.swt.widgets.TreeColumn) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 2 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project cogtool by cogtool.

the class ProjectUI method showContextMenu.

// Override to set the correct context menu on the frame
//    item  item-selected column design  where          selection to use
//(a)  ok        n/a        ok     ok    cell           temporary cell
//(b)  ok        yes        ok    null   task           normal selection
//(c)  ok        no         ok    null   task           temporary task
//(d)  ok        n/a       null    n/a   right of cells temporary task
//(e) null       n/a        ok     ok    design         temporary design
//(f) null       n/a        ok    null   bottom-left    no selection
//(g) null       n/a       null    n/a   bottom-right   no selection
// TODO: dfm -- make the code match the above!!!!!
@Override
public void showContextMenu(int x, int y) {
    // Clear any stale state
    contextSelection.deselectAll();
    // Check which region of the frame was hit
    TreeItem item = tree.getItem(new Point(x, y));
    TreeColumn column = findColumn(x);
    // See if the context invocation was made beyond all designs
    if (column == null) {
        if (item == null) {
            // see (g) above
            showContextMenu();
        } else {
            // see (d) above
            selectOverBox(item.getBounds());
            contextSelection.addSelectedTask((AUndertaking) item.getData());
            showContextMenu(contextSelection, View.CONTEXT);
        }
    } else // If not, the invocation occurred somewhere within the table
    {
        Design design = (Design) column.getData();
        // Detect a context invocation in the table header/footer
        if (item == null) {
            // Detect a context invocation under the "tasks" heading
            if (design == null) {
                // see (f) above
                showContextMenu();
            } else // Otherwise the invocation lies under a design heading
            {
                // see (e) above
                // TODO: Really?  What if something else was selected?
                selectOverBox(computeColumnArea(column));
                contextSelection.setSelectedDesign(design);
                showContextMenu(contextSelection, View.CONTEXT);
            }
        } else // Detect a context invocation inside the table body
        {
            AUndertaking undertaking = (AUndertaking) item.getData();
            // Check for context invocation under the "tasks" column
            if (design == null) {
                // Set up the contextual selection state as necessary
                if (selection.isTaskSelected(undertaking)) {
                    // see (b) above
                    showContextMenu();
                } else {
                    // see (c) above
                    selectOverBox(item.getBounds());
                    contextSelection.addSelectedTask(undertaking);
                    showContextMenu(contextSelection, View.CONTEXT);
                }
            } else // Otherwise at the intersection of a task and a design
            {
                // see (a) above
                selection.setSelectedCell(item, column);
                Rectangle bounds = item.getBounds(tree.indexOf(column));
                if (OSUtils.MACOSX) {
                    // XXX: DIRTY HACK TO fix SWT bug.
                    bounds.y -= 1;
                    bounds.height += 1;
                }
                selectOverBox(bounds);
                // TODO: instead of the following, pass undertaking and
                //       design in to showContextMenuForIntersection()
                Menu contextMenu = view.getContextMenuForIntersection(project, undertaking, design);
                // Set up the contextual selection state as necessary
                contextSelection.setSelectedDesign(design);
                contextSelection.addSelectedTask(undertaking);
                setViewEnabledState(contextSelection, ListenerIdentifierMap.CONTEXT);
                contextMenu.setVisible(true);
            }
        }
    }
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeColumn(org.eclipse.swt.widgets.TreeColumn) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Menu(org.eclipse.swt.widgets.Menu)

Example 3 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project cogtool by cogtool.

the class ControllerNexus method checkWindowBounds.

/**
     * Checks that a stored window location is still visible with the current
     * screen layout.
     * (Really, just checks that the top-left corner is on screen somewhere.)
     *
     * @param loc the location info to check
     * @return a corrected rectangle, completely visible with the
     *         current screen layout
     */
protected static Rectangle checkWindowBounds(Rectangle loc) {
    if (loc == null) {
        return loc;
    }
    // Indicates that upper-left overlaps with the client area of the
    // monitor.
    boolean safe = false;
    // Check if the window is fully contained on the client areas of
    //   some set of monitors
    Monitor[] monitors = WindowUtil.GLOBAL_DISPLAY.getMonitors();
    for (int i = 0; !safe && (i < monitors.length); i++) {
        Monitor monitor = monitors[i];
        if (monitor != null) {
            safe = monitor.getClientArea().contains(loc.x, loc.y);
        }
    }
    if (!safe) {
        Monitor prim = WindowUtil.GLOBAL_DISPLAY.getPrimaryMonitor();
        Rectangle r = prim.getClientArea();
        loc.x = r.x;
        loc.y = r.y;
        if (loc.width > r.width) {
            loc.width = r.width;
        }
        if (loc.height > r.height) {
            loc.height = r.height;
        }
    }
    return loc;
}
Also used : Monitor(org.eclipse.swt.widgets.Monitor) Rectangle(org.eclipse.swt.graphics.Rectangle)

Example 4 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project cogtool by cogtool.

the class GraphicsUtil method getImageBounds.

/**
     * A utility to load an image and then dispose it from a byte array.
     * This utility returns the size of the image.
     * This is not a good function to call often. its SLOW.
     *
     * If the image is null, then returns a new rectangle (0,0,0,0);
     * TODO: should this return null
     * @param image
     * @return
     */
public static DoubleRectangle getImageBounds(byte[] image) {
    if (image == null) {
        return new DoubleRectangle(0, 0, 0, 0);
    }
    try {
        Image img = new Image(null, new ByteArrayInputStream(image));
        Rectangle rect = img.getBounds();
        img.dispose();
        return new DoubleRectangle(rect.x, rect.y, rect.width, rect.height);
    } catch (SWTException ex) {
        throw new ImageException("Failed to get image bounds.", ex);
    }
}
Also used : SWTException(org.eclipse.swt.SWTException) ByteArrayInputStream(java.io.ByteArrayInputStream) Rectangle(org.eclipse.swt.graphics.Rectangle) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) Image(org.eclipse.swt.graphics.Image)

Example 5 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project cogtool by cogtool.

the class StandardDrawingEditor method getVisibleBounds.

/**
     * Get the visible area on the window. This is the area exposed by the
     * scroll widgets.
     * @return
     */
public Rectangle getVisibleBounds() {
    Point origin = scrollComposite.getOrigin();
    Point extent = scrollComposite.getSize();
    int verticalBarWidth = scrollComposite.getVerticalBar().getSize().x;
    int horizontalBarHeight = scrollComposite.getHorizontalBar().getSize().y;
    // Remove the height and width of the scroll bar from the visible area.
    return new Rectangle(origin.x, origin.y, extent.x - verticalBarWidth, extent.y - horizontalBarHeight);
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Aggregations

Rectangle (org.eclipse.swt.graphics.Rectangle)315 Point (org.eclipse.swt.graphics.Point)173 Image (org.eclipse.swt.graphics.Image)53 SelectionEvent (org.eclipse.swt.events.SelectionEvent)41 Color (org.eclipse.swt.graphics.Color)31 GC (org.eclipse.swt.graphics.GC)29 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)24 TableItem (org.eclipse.swt.widgets.TableItem)23 Event (org.eclipse.swt.widgets.Event)20 Menu (org.eclipse.swt.widgets.Menu)20 ArrayList (java.util.ArrayList)18 MenuItem (org.eclipse.swt.widgets.MenuItem)18 Listener (org.eclipse.swt.widgets.Listener)17 SelectionListener (org.eclipse.swt.events.SelectionListener)15 FocusEvent (org.eclipse.swt.events.FocusEvent)14 Composite (org.eclipse.swt.widgets.Composite)14 GridData (org.eclipse.swt.layout.GridData)13 Shell (org.eclipse.swt.widgets.Shell)13 MouseEvent (org.eclipse.swt.events.MouseEvent)12 HashMap (java.util.HashMap)10