Example usage for org.eclipse.jface.util Geometry isHorizontal

List of usage examples for org.eclipse.jface.util Geometry isHorizontal

Introduction

In this page you can find the example usage for org.eclipse.jface.util Geometry isHorizontal.

Prototype

public static boolean isHorizontal(int swtSideConstant) 

Source Link

Document

Returns true iff the given SWT side constant corresponds to a horizontal side of a rectangle.

Usage

From source file:org.eclipse.ui.internal.FastViewBar.java

License:Open Source License

/**
 * Creates the underlying SWT fvbComposite for the fast view bar. Will add exactly
 * one new fvbComposite to the given composite. Makes no assumptions about the layout
 * being used in the parent composite./*  w  w  w . j  a  v a  2 s .c  o m*/
 * 
 * @param parent enclosing SWT composite
 */
public void createControl(Composite parent) {
    fvbComposite = new Composite(parent, SWT.NONE) {
        public Point computeSize(int wHint, int hHint, boolean changed) {
            Point size = super.computeSize(wHint, hHint, changed);
            if (Geometry.isHorizontal(getSide())) {
                if (size.y < TrimUtil.TRIM_DEFAULT_HEIGHT) {
                    size.y = TrimUtil.TRIM_DEFAULT_HEIGHT;
                }
            } else {
                if (size.x < TrimUtil.TRIM_DEFAULT_HEIGHT) {
                    size.x = TrimUtil.TRIM_DEFAULT_HEIGHT;
                }
            }
            return size;
        }
    };
    String tip = WorkbenchMessages.get().FastViewBar_0;
    fvbComposite.setToolTipText(tip);

    fvbComposite.addListener(SWT.MenuDetect, menuListener);

    // RAP [bm]: DnD
    //        PresentationUtil.addDragListener(fvbComposite, dragListener);
    // RAPEND: [bm] 

    createChildControls();
}

From source file:org.eclipse.ui.internal.FastViewBar.java

License:Open Source License

/**
 * Create the contents of the fast view bar. The top-level fvbComposite (created by createControl) is a 
 * composite that is created once over the lifetime of the fast view bar. This method creates the 
 * rest of the widgetry inside that composite. The controls created by this method will be 
 * destroyed and recreated if the fast view bar is docked to a different side of the window.
 *///from  w w  w.ja v  a 2  s  . c o  m
protected void createChildControls() {
    int newSide = getSide();
    int orientation = Geometry.isHorizontal(newSide) ? SWT.HORIZONTAL : SWT.VERTICAL;

    // Create a ControlLayout apropriate for the new orientation
    CellLayout controlLayout;
    if (Geometry.isHorizontal(newSide)) {
        controlLayout = new CellLayout(0).setMargins(0, 0).setDefaultRow(Row.growing())
                .setDefaultColumn(Row.fixed()).setColumn(1, Row.growing());
    } else {
        controlLayout = new CellLayout(1).setMargins(0, 3).setDefaultColumn(Row.growing())
                .setDefaultRow(Row.fixed()).setRow(1, Row.growing());
    }

    // Set up the composite for the new orientation
    fvbComposite.setLayout(controlLayout);

    if (!hasNewFastViewDisabled) {
        // Create a toolbar to show an 'Add FastView' menu 'button'
        menuTB = new ToolBar(fvbComposite, SWT.FLAT | orientation);

        // Construct an item to act as a 'menu button' (a la the PerspectiveSwitcher)
        menuItem = new ToolItem(menuTB, SWT.PUSH, 0);

        Image tbImage = WorkbenchImages.getImage(IWorkbenchGraphicConstants.IMG_ETOOL_NEW_FASTVIEW);
        menuItem.setImage(tbImage);

        final String menuTip = WorkbenchMessages.get().FastViewBar_0;
        menuItem.setToolTipText(menuTip);
        //new ToolItem(menuTB, SWT.SEPARATOR, 1);

        // RAP [bm]: Accessibility
        //           menuTB.getAccessible().addAccessibleListener(new AccessibleAdapter() {
        //               public void getName(AccessibleEvent e) {
        //                  e.result = menuTip;
        //               }
        //            });
        // RAPEND: [bm] 

        // Now that the ToolBar is populated calculate its size...
        Point size = menuTB.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
        menuTB.setBounds(0, 0, size.x, size.y);

        // Bring up the 'Add Fast View' menu on a left -or- right button click
        // Right click (context menu)
        menuItem.addListener(SWT.MenuDetect, addMenuListener);
        menuTB.addListener(SWT.MenuDetect, addMenuListener);
        menuItem.addListener(SWT.MouseUp, addMenuListener);
        menuTB.addListener(SWT.MouseUp, addMenuListener);
        // RAPEND: [bm] 

        // Left Click...
        menuItem.addSelectionListener(new SelectionListener() {
            public void widgetSelected(SelectionEvent e) {
                Rectangle bb = DragUtil.getDisplayBounds(menuTB);
                showAddFastViewPopup(new Point(bb.x, bb.y + bb.height));
            }

            public void widgetDefaultSelected(SelectionEvent e) {
            }

        });

        // try to get the layout correct...
        toolBarData = new CellData();
        toolBarData.align(SWT.FILL, SWT.FILL);
        menuTB.setLayoutData(toolBarData);
    }

    // Construct the ToolBar containing the 'Fast' views
    fastViewBar = new ToolBarManager(SWT.FLAT | SWT.WRAP | orientation);
    fastViewBar.add(new ShowFastViewContribution(window));

    fastViewBar.createControl(fvbComposite);

    getToolBar().addListener(SWT.MenuDetect, menuListener);

    // RAP [bm]: DnD
    //        IDragOverListener fastViewDragTarget = new IDragOverListener() {
    //
    //            public IDropTarget drag(Control currentControl,
    //                    Object draggedObject, Point position,
    //                    Rectangle dragRectangle) {
    //                ToolItem targetItem = getToolItem(position);
    //                if (draggedObject instanceof ViewPane) {
    //                    ViewPane pane = (ViewPane) draggedObject;
    //
    //                    // Can't drag views between windows
    //                    if (pane.getWorkbenchWindow() != window) {
    //                        return null;
    //                    }
    //
    //                    List newList = new ArrayList(1);
    //                    newList.add(draggedObject);
    //
    //                    return createDropTarget(newList, targetItem);
    //                }
    //                if (draggedObject instanceof ViewStack) {
    //                    ViewStack folder = (ViewStack) draggedObject;
    //
    //                    if (folder.getWorkbenchWindow() != window) {
    //                        return null;
    //                    }
    //
    //                    List viewList = new ArrayList(folder.getItemCount());
    //                    LayoutPart[] children = folder.getChildren();
    //
    //                    for (int idx = 0; idx < children.length; idx++) {
    //                        if (!(children[idx] instanceof PartPlaceholder)) {
    //                            viewList.add(children[idx]);
    //                        }
    //                    }
    //
    //                    return createDropTarget(viewList, targetItem);
    //                }
    //
    //                return null;
    //            }
    //
    //        };

    toolBarData = new CellData();
    toolBarData.align(SWT.FILL, SWT.FILL);

    getToolBar().setLayoutData(toolBarData);
    // RAP [bm]: Dnd
    //        PresentationUtil.addDragListener(getToolBar(), dragListener);
    //        DragUtil.addDragTarget(getControl(), fastViewDragTarget);
    // RAPEND: [bm] 

    update(true);
}

From source file:org.eclipse.ui.internal.FastViewBar.java

License:Open Source License

private void updateLayoutData() {
    ToolItem[] items = fastViewBar.getControl().getItems();
    boolean isHorizontal = Geometry.isHorizontal(getSide());
    boolean shouldExpand = items.length > 0;

    Point hint = new Point(32, shouldExpand ? SWT.DEFAULT : HIDDEN_WIDTH);

    if (!isHorizontal) {
        Geometry.flipXY(hint);//  w ww. j a  v a 2  s .c  o m
    }

    if (shouldExpand) {
        toolBarData.setHint(CellData.MINIMUM, hint);
    } else {
        toolBarData.setHint(CellData.OVERRIDE, hint);
    }

    if (items.length != oldLength) {
        LayoutUtil.resize(fvbComposite);
        oldLength = items.length;
    }
}

From source file:org.eclipse.ui.internal.FastViewBar.java

License:Open Source License

private boolean isHorizontal(IViewReference ref) {
    Integer orientation = (Integer) viewOrientation.get(ref.getId());
    boolean horizontalBar = Geometry.isHorizontal(getSide());
    boolean horizontal = horizontalBar;
    if (orientation != null) {
        horizontal = orientation.intValue() == SWT.HORIZONTAL;
    } else {/*from  w ww  .j  av  a2s .co m*/
        horizontal = false;
    }

    return horizontal;
}

From source file:org.eclipse.ui.internal.FastViewBar.java

License:Open Source License

/**
 * Returns the approximate location where the next fastview icon
 * will be drawn (display coordinates)// w w w  .  j  ava2s.  com
 */
public Rectangle getLocationOfNextIcon() {
    ToolBar control = getToolBar();

    Rectangle result = control.getBounds();
    Point size = control.computeSize(SWT.DEFAULT, SWT.DEFAULT, false);
    result.height = size.y;
    result.width = size.x;

    boolean horizontal = Geometry.isHorizontal(getSide());
    if (control.getItemCount() == 0) {
        Geometry.setDimension(result, horizontal, 0);
    }

    int hoverSide = horizontal ? SWT.RIGHT : SWT.BOTTOM;

    result = Geometry.getExtrudedEdge(result, -Geometry.getDimension(result, !horizontal), hoverSide);

    return Geometry.toDisplay(control.getParent(), result);
}

From source file:org.eclipse.ui.internal.FastViewPane.java

License:Open Source License

/**
 * Returns the current fastview size ratio. Returns 0.0 if there is no fastview visible.
 *///from  ww w.j  a  v a2  s.c o  m
public float getCurrentRatio() {
    if (currentPane == null) {
        return 0.0f;
    }

    boolean isVertical = !Geometry.isHorizontal(side);
    Rectangle clientArea = clientComposite.getClientArea();

    int clientSize = Geometry.getDimension(clientArea, isVertical);

    return (float) size / (float) clientSize;
}

From source file:org.eclipse.ui.internal.FastViewPane.java

License:Open Source License

private Rectangle getBounds() {
    Rectangle bounds = getClientArea();

    if (site.getState() == IStackPresentationSite.STATE_MAXIMIZED) {
        return bounds;
    }//from   w  w w. j  a  v  a2 s  .  co  m

    boolean horizontal = Geometry.isHorizontal(side);

    int available = Geometry.getDimension(bounds, !horizontal);

    return Geometry.getExtrudedEdge(bounds, Math.min(FastViewPane.this.size, available), side);
}

From source file:org.eclipse.ui.internal.FastViewPane.java

License:Open Source License

/**
 * Displays the given view as a fastview. The view will be docked to the edge of the
 * given composite until it is subsequently hidden by a call to hideFastView. 
 * /*from w ww  . j ava 2 s .  com*/
 * @param newClientComposite
 * @param pane
 * @param newSide
 */
public void showView(Composite newClientComposite, ViewPane pane, int newSide, float sizeRatio) {
    side = newSide;

    if (currentPane != null) {
        hideView();
    }

    currentPane = new PresentablePart(pane, newClientComposite);

    fastViewAction.setPane(currentPane);
    clientComposite = newClientComposite;

    clientComposite.addListener(SWT.Resize, resizeListener);

    // Create the control first
    Control ctrl = pane.getControl();
    if (ctrl == null) {
        pane.createControl(clientComposite);
        ctrl = pane.getControl();
    }

    // RAP [bm]: 
    //        ctrl.addListener(SWT.Traverse, escapeListener);

    // Temporarily use the same appearance as docked views .. eventually, fastviews will
    // be independently pluggable.
    AbstractPresentationFactory factory = getPresentationFactory();
    StackPresentation presentation = factory.createViewPresentation(newClientComposite, site);

    site.setPresentation(presentation);
    site.setPresentationState(IStackPresentationSite.STATE_RESTORED);
    presentation.addPart(currentPane, null);
    presentation.selectPart(currentPane);
    presentation.setActive(StackPresentation.AS_ACTIVE_FOCUS);
    presentation.setVisible(true);

    boolean horizontalResize = Geometry.isHorizontal(side);

    minSize = presentation.computePreferredSize(horizontalResize, ISizeProvider.INFINITE,
            Geometry.getDimension(getClientArea(), horizontalResize), 0);

    // Show pane fast.
    ctrl.setEnabled(true); // Add focus support.
    Composite parent = ctrl.getParent();

    boolean horizontal = Geometry.isHorizontal(side);

    // Create a sash of the correct style using the factory
    int style = AbstractPresentationFactory.SASHTYPE_FLOATING;
    if (horizontal)
        style |= AbstractPresentationFactory.SASHORIENTATION_HORIZONTAL;
    else
        style |= AbstractPresentationFactory.SASHORIENTATION_VERTICAL;
    sash = factory.createSash(parent, style);

    sash.addSelectionListener(selectionListener);

    Rectangle clientArea = newClientComposite.getClientArea();

    getPresentation().getControl().moveAbove(null);
    currentPane.getPane().moveAbove(null);
    sash.moveAbove(null);

    setSize((int) (Geometry.getDimension(clientArea, !horizontal) * sizeRatio));

    Display display = sash.getDisplay();

    display.addFilter(SWT.MouseDown, mouseDownListener);

    pane.setFocus();
}

From source file:org.eclipse.ui.internal.FastViewPane.java

License:Open Source License

private int getSashSize() {
    AbstractPresentationFactory factory = getPresentationFactory();

    // Set up the correct 'style' bits
    int style = AbstractPresentationFactory.SASHTYPE_FLOATING;
    if (Geometry.isHorizontal(side))
        style |= AbstractPresentationFactory.SASHORIENTATION_HORIZONTAL;
    else/*from  www .ja  va2  s . c om*/
        style |= AbstractPresentationFactory.SASHORIENTATION_VERTICAL;

    int size = factory.getSashSize(style);

    return size;
}