Search in sources :

Example 36 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.

the class TableCombo method dropDown.

/**
	 * handle DropDown request
	 * @param drop
	 */
void dropDown(boolean drop) {
    // if already dropped then return
    if (drop == isDropped())
        return;
    // closing the dropDown
    if (!drop) {
        popup.setVisible(false);
        if (!isDisposed() && isFocusControl()) {
            text.setFocus();
        }
        return;
    }
    // if not visible then return
    if (!isVisible())
        return;
    // create a new popup if needed.
    if (getShell() != popup.getParent()) {
        int selectionIndex = table.getSelectionIndex();
        table.removeListener(SWT.Dispose, listener);
        popup.dispose();
        popup = null;
        table = null;
        createPopup(selectionIndex);
    }
    // get the size of the TableCombo.
    Point tableComboSize = getSize();
    // calculate the table height.
    int itemCount = table.getItemCount();
    itemCount = (itemCount == 0) ? visibleItemCount : Math.min(visibleItemCount, itemCount);
    int itemHeight = (table.getItemHeight() * itemCount);
    // visible item count.
    if (table.getItemCount() <= visibleItemCount) {
        itemHeight += 1;
    }
    // add height of header if the header is being displayed.
    if (table.getHeaderVisible()) {
        itemHeight += table.getHeaderHeight();
    }
    // get table column references
    TableColumn[] tableColumns = table.getColumns();
    int totalColumns = (tableColumns == null ? 0 : tableColumns.length);
    // then just create a blank one.
    if (table.getColumnCount() == 0) {
        new TableColumn(table, SWT.NONE);
        totalColumns = 1;
        tableColumns = table.getColumns();
    }
    int totalColumnWidth = 0;
    // now pack any columns that do not have a explicit value set for them.
    for (int colIndex = 0; colIndex < totalColumns; colIndex++) {
        if (!wasColumnWidthSpecified(colIndex)) {
            tableColumns[colIndex].pack();
        }
        totalColumnWidth += tableColumns[colIndex].getWidth();
    }
    // reset the last column's width to the preferred size if it has a
    // explicit value.
    int lastColIndex = totalColumns - 1;
    if (wasColumnWidthSpecified(lastColIndex)) {
        tableColumns[lastColIndex].setWidth(columnWidths[lastColIndex]);
    }
    // calculate the table size after making adjustments.
    Point tableSize = table.computeSize(SWT.DEFAULT, itemHeight, false);
    // calculate the table width and table height.
    double pct = tableWidthPercentage / 100d;
    int tableWidth = (int) (Math.max(tableComboSize.x - 2, tableSize.x) * pct);
    int tableHeight = tableSize.y;
    // not viewing the full table.
    if (tableWidthPercentage < 100) {
        tableHeight += table.getHorizontalBar().getSize().y;
    }
    // set the bounds on the table.
    table.setBounds(1, 1, tableWidth, tableHeight);
    // it is needed or not.
    if (!table.getVerticalBar().getVisible() && tableSize.x - table.getVerticalBar().getSize().x >= tableComboSize.x - 2) {
        tableWidth = tableWidth - table.getVerticalBar().getSize().x;
        // reset the bounds on the table.
        table.setBounds(1, 1, tableWidth, tableHeight);
    }
    table.getHorizontalBar().setVisible(false);
    // adjust the last column to make sure that there is no empty space.
    autoAdjustColumnWidthsIfNeeded(tableColumns, tableWidth, totalColumnWidth);
    // set the table top index if there is a valid selection.
    String indexStr = (String) text.getData();
    if (indexStr != null && !indexStr.equals("")) {
        int index = Integer.parseInt(indexStr);
        table.setSelection(index);
        table.setTopIndex(index);
    }
    // calculate popup dimensions.
    Display display = getDisplay();
    Rectangle tableRect = table.getBounds();
    Rectangle parentRect = display.map(getParent(), null, getBounds());
    Point comboSize = getSize();
    Rectangle displayRect = getMonitor().getClientArea();
    int overallWidth = 0;
    // now set what the overall width should be.
    if (tableWidthPercentage < 100) {
        overallWidth = tableRect.width + 2;
    } else {
        overallWidth = Math.max(comboSize.x, tableRect.width + 2);
    }
    int overallHeight = tableRect.height + 2;
    int x = parentRect.x;
    int y = parentRect.y + comboSize.y;
    if (y + overallHeight > displayRect.y + displayRect.height)
        y = parentRect.y - overallHeight;
    if (x + overallWidth > displayRect.x + displayRect.width)
        x = displayRect.x + displayRect.width - tableRect.width;
    // set the bounds of the popup
    popup.setBounds(x, y, overallWidth, overallHeight);
    // set the popup visible
    popup.setVisible(true);
    // set focus on the table.
    table.setFocus();
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) TableColumn(org.eclipse.swt.widgets.TableColumn) Point(org.eclipse.swt.graphics.Point) Display(org.eclipse.swt.widgets.Display)

Example 37 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.

the class TableCombo method popupEvent.

/**
	 * Handles Popup Events
	 * @param event
	 */
private void popupEvent(Event event) {
    switch(event.type) {
        case SWT.Paint:
            // draw rectangle around table
            Rectangle tableRect = table.getBounds();
            event.gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION));
            event.gc.drawRectangle(0, 0, tableRect.width + 1, tableRect.height + 1);
            break;
        case SWT.Close:
            event.doit = false;
            dropDown(false);
            break;
        case SWT.Deactivate:
            /*
			 * Bug in GTK. When the arrow button is pressed the popup control receives a deactivate event and then the
			 * arrow button receives a selection event. If we hide the popup in the deactivate event, the selection
			 * event will show it again. To prevent the popup from showing again, we will let the selection event of the
			 * arrow button hide the popup. In Windows, hiding the popup during the deactivate causes the deactivate to
			 * be called twice and the selection event to be disappear.
			 */
            if (!"carbon".equals(SWT.getPlatform())) {
                Point point = arrow.toControl(getDisplay().getCursorLocation());
                Point size = arrow.getSize();
                Rectangle rect = new Rectangle(0, 0, size.x, size.y);
                if (!rect.contains(point))
                    dropDown(false);
            } else {
                dropDown(false);
            }
            break;
        case SWT.Help:
            if (isDropped()) {
                dropDown(false);
            }
            Composite comp = TableCombo.this;
            do {
                if (comp.getListeners(event.type) != null && comp.getListeners(event.type).length > 0) {
                    comp.notifyListeners(event.type, event);
                    break;
                }
                comp = comp.getParent();
            } while (null != comp);
            break;
    }
}
Also used : Composite(org.eclipse.swt.widgets.Composite) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point)

Example 38 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.

the class GridColumnGroup method getBounds.

Rectangle getBounds() {
    Rectangle bounds = new Rectangle(0, 0, 0, 0);
    bounds.height = parent.getGroupHeaderHeight();
    boolean foundFirstColumnInGroup = false;
    GridColumn[] cols = parent.getColumnsInOrder();
    for (int i = 0; i < cols.length; i++) {
        if (cols[i].getColumnGroup() == this) {
            if (cols[i].isVisible()) {
                if (!foundFirstColumnInGroup) {
                    bounds.x = parent.getOrigin(cols[i], null).x;
                    foundFirstColumnInGroup = true;
                }
                bounds.width += cols[i].getWidth();
            }
        } else {
            if (foundFirstColumnInGroup) {
                break;
            }
        }
    }
    return bounds;
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point)

Example 39 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.

the class GridDragSourceEffect method getDragSourceImage.

Image getDragSourceImage(DragSourceEvent event) {
    if (dragSourceImage != null)
        dragSourceImage.dispose();
    dragSourceImage = null;
    Grid grid = (Grid) getControl();
    Display display = grid.getDisplay();
    Rectangle empty = new Rectangle(0, 0, 0, 0);
    // Collect the currently selected items. 
    Point[] selection;
    if (grid.getCellSelectionEnabled()) {
        selection = grid.getCellSelection();
    } else {
        List l = new ArrayList();
        GridItem[] selItems = grid.getSelection();
        for (int i = 0; i < selItems.length; i++) {
            for (int j = 0; j < grid.getColumnCount(); j++) {
                if (grid.getColumn(j).isVisible()) {
                    l.add(new Point(j, grid.indexOf(selItems[i])));
                }
            }
        }
        selection = (Point[]) l.toArray(new Point[l.size()]);
    }
    if (selection.length == 0)
        return null;
    Rectangle bounds = null;
    for (int i = 0; i < selection.length; i++) {
        GridItem item = grid.getItem(selection[i].y);
        Rectangle currBounds = item.getBounds(selection[i].x);
        if (empty.equals(currBounds)) {
            selection[i] = null;
        } else {
            if (bounds == null) {
                bounds = currBounds;
            } else {
                bounds = bounds.union(currBounds);
            }
        }
    }
    if (bounds == null)
        return null;
    if (bounds.width <= 0 || bounds.height <= 0)
        return null;
    dragSourceImage = new Image(display, bounds.width, bounds.height);
    GC gc = new GC(dragSourceImage);
    for (int i = 0; i < selection.length; i++) {
        if (selection[i] == null)
            continue;
        GridItem item = grid.getItem(selection[i].y);
        GridColumn column = grid.getColumn(selection[i].x);
        Rectangle currBounds = item.getBounds(selection[i].x);
        GridCellRenderer r = column.getCellRenderer();
        r.setBounds(currBounds.x - bounds.x, currBounds.y - bounds.y, currBounds.width, currBounds.height);
        gc.setClipping(currBounds.x - bounds.x - 1, currBounds.y - bounds.y - 1, currBounds.width + 2, currBounds.height + 2);
        r.setColumn(selection[i].x);
        r.setSelected(false);
        r.setFocus(false);
        r.setRowFocus(false);
        r.setCellFocus(false);
        r.setRowHover(false);
        r.setColumnHover(false);
        r.setCellSelected(false);
        r.setHoverDetail("");
        r.setDragging(true);
        r.paint(gc, item);
        gc.setClipping((Rectangle) null);
    }
    gc.dispose();
    return dragSourceImage;
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) ArrayList(java.util.ArrayList) Point(org.eclipse.swt.graphics.Point) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) List(java.util.List) ArrayList(java.util.ArrayList) GC(org.eclipse.swt.graphics.GC) Display(org.eclipse.swt.widgets.Display)

Example 40 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.

the class GridEditor method computeBounds.

/**
     * Returns the bounds of the editor.
     * 
     * @return bounds of the editor.
     */
protected Rectangle computeBounds() {
    if (item == null || column == -1 || item.isDisposed())
        return new Rectangle(0, 0, 0, 0);
    Rectangle cell = item.getBounds(column);
    Rectangle area = table.getClientArea();
    if (cell.x < area.x + area.width) {
        if (cell.x + cell.width > area.x + area.width) {
            cell.width = area.x + area.width - cell.x;
        }
    }
    Rectangle editorRect = new Rectangle(cell.x, cell.y, minimumWidth, minimumHeight);
    if (grabHorizontal) {
        editorRect.width = Math.max(cell.width, minimumWidth);
    }
    if (grabVertical) {
        editorRect.height = Math.max(cell.height, minimumHeight);
    }
    if (horizontalAlignment == SWT.RIGHT) {
        editorRect.x += cell.width - editorRect.width;
    } else if (horizontalAlignment == SWT.LEFT) {
    // do nothing - cell.x is the right answer
    } else {
        // default is CENTER
        editorRect.x += (cell.width - editorRect.width) / 2;
    }
    if (verticalAlignment == SWT.BOTTOM) {
        editorRect.y += cell.height - editorRect.height;
    } else if (verticalAlignment == SWT.TOP) {
    // do nothing - cell.y is the right answer
    } else {
        // default is CENTER
        editorRect.y += (cell.height - editorRect.height) / 2;
    }
    GridColumn c = table.getColumn(column);
    if (c != null && c.isTree()) {
        int x = c.getCellRenderer().getTextBounds(item, false).x;
        editorRect.x += x;
        editorRect.width -= x;
    }
    return editorRect;
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle)

Aggregations

Rectangle (org.eclipse.swt.graphics.Rectangle)651 Point (org.eclipse.swt.graphics.Point)370 Image (org.eclipse.swt.graphics.Image)114 GC (org.eclipse.swt.graphics.GC)104 Test (org.junit.Test)80 Color (org.eclipse.swt.graphics.Color)61 Shell (org.eclipse.swt.widgets.Shell)54 Composite (org.eclipse.swt.widgets.Composite)53 SelectionEvent (org.eclipse.swt.events.SelectionEvent)51 TableItem (org.eclipse.swt.widgets.TableItem)47 GridLayout (org.eclipse.swt.layout.GridLayout)44 Display (org.eclipse.swt.widgets.Display)44 Button (org.eclipse.swt.widgets.Button)42 Menu (org.eclipse.swt.widgets.Menu)40 GridData (org.eclipse.swt.layout.GridData)38 Label (org.eclipse.swt.widgets.Label)37 SWT (org.eclipse.swt.SWT)34 Event (org.eclipse.swt.widgets.Event)34 Font (org.eclipse.swt.graphics.Font)30 Listener (org.eclipse.swt.widgets.Listener)29