Search in sources :

Example 1 with Sash

use of org.eclipse.swt.widgets.Sash in project translationstudio8 by heartsome.

the class TermDbManagerDialog method createSash.

/**
	 * Create the sash with right control on the right. Note that this method assumes GridData for the layout data of
	 * the rightControl.
	 * @param composite
	 * @param rightControl
	 * @return Sash
	 */
protected Sash createSash(final Composite composite, final Control rightControl) {
    final Sash sash = new Sash(composite, SWT.VERTICAL);
    sash.setLayoutData(new GridData(GridData.FILL_VERTICAL));
    sash.setBackground(composite.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
    // the following listener resizes the tree control based on sash deltas.
    // If necessary, it will also grow/shrink the dialog.
    sash.addListener(SWT.Selection, new Listener() {

        /*
			 * (non-Javadoc)
			 * 
			 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt. widgets.Event)
			 */
        public void handleEvent(Event event) {
            if (event.detail == SWT.DRAG) {
                return;
            }
            int shift = event.x - sash.getBounds().x;
            GridData data = (GridData) rightControl.getLayoutData();
            int newWidthHint = data.widthHint + shift;
            if (newWidthHint < 20) {
                return;
            }
            Point computedSize = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT);
            Point currentSize = getShell().getSize();
            // if the dialog wasn't of a custom size we know we can shrink
            // it if necessary based on sash movement.
            boolean customSize = !computedSize.equals(currentSize);
            data.widthHint = newWidthHint;
            setLastTreeWidth(newWidthHint);
            composite.layout(true);
            // recompute based on new widget size
            computedSize = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT);
            // necessary.
            if (customSize) {
                computedSize.x = Math.max(computedSize.x, currentSize.x);
            }
            computedSize.y = Math.max(computedSize.y, currentSize.y);
            if (computedSize.equals(currentSize)) {
                return;
            }
            setShellSize(computedSize.x, computedSize.y);
            lastShellSize = getShell().getSize();
        }
    });
    return sash;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Listener(org.eclipse.swt.widgets.Listener) MenuDetectListener(org.eclipse.swt.events.MenuDetectListener) Sash(org.eclipse.swt.widgets.Sash) GridData(org.eclipse.swt.layout.GridData) DisposeEvent(org.eclipse.swt.events.DisposeEvent) MenuDetectEvent(org.eclipse.swt.events.MenuDetectEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Point(org.eclipse.swt.graphics.Point)

Example 2 with Sash

use of org.eclipse.swt.widgets.Sash in project translationstudio8 by heartsome.

the class TmDbManagerDialog method createSash.

/**
	 * Create the sash with right control on the right. Note that this method assumes GridData for the layout data of
	 * the rightControl.
	 * @param composite
	 * @param rightControl
	 * @return Sash
	 */
protected Sash createSash(final Composite composite, final Control rightControl) {
    final Sash sash = new Sash(composite, SWT.VERTICAL);
    sash.setLayoutData(new GridData(GridData.FILL_VERTICAL));
    sash.setBackground(composite.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
    // the following listener resizes the tree control based on sash deltas.
    // If necessary, it will also grow/shrink the dialog.
    sash.addListener(SWT.Selection, new Listener() {

        /*
			 * (non-Javadoc)
			 * 
			 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt. widgets.Event)
			 */
        public void handleEvent(Event event) {
            if (event.detail == SWT.DRAG) {
                return;
            }
            int shift = event.x - sash.getBounds().x;
            GridData data = (GridData) rightControl.getLayoutData();
            int newWidthHint = data.widthHint + shift;
            if (newWidthHint < 20) {
                return;
            }
            Point computedSize = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT);
            Point currentSize = getShell().getSize();
            // if the dialog wasn't of a custom size we know we can shrink
            // it if necessary based on sash movement.
            boolean customSize = !computedSize.equals(currentSize);
            data.widthHint = newWidthHint;
            setLastTreeWidth(newWidthHint);
            composite.layout(true);
            // recompute based on new widget size
            computedSize = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT);
            // necessary.
            if (customSize) {
                computedSize.x = Math.max(computedSize.x, currentSize.x);
            }
            computedSize.y = Math.max(computedSize.y, currentSize.y);
            if (computedSize.equals(currentSize)) {
                return;
            }
            setShellSize(computedSize.x, computedSize.y);
            lastShellSize = getShell().getSize();
        }
    });
    return sash;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Listener(org.eclipse.swt.widgets.Listener) MenuDetectListener(org.eclipse.swt.events.MenuDetectListener) Sash(org.eclipse.swt.widgets.Sash) GridData(org.eclipse.swt.layout.GridData) DisposeEvent(org.eclipse.swt.events.DisposeEvent) MenuDetectEvent(org.eclipse.swt.events.MenuDetectEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Point(org.eclipse.swt.graphics.Point)

Example 3 with Sash

use of org.eclipse.swt.widgets.Sash in project bndtools by bndtools.

the class SashHighlightForm method setSashForeground.

public void setSashForeground(Color color) {
    try {
        Field fgfield = SashForm.class.getDeclaredField("foreground");
        fgfield.setAccessible(true);
        fgfield.set(this, color);
        Field sashesField = SashForm.class.getDeclaredField("sashes");
        sashesField.setAccessible(true);
        Sash[] sashes = (Sash[]) sashesField.get(this);
        for (Sash sash : sashes) {
            sash.setForeground(color);
        }
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : Field(java.lang.reflect.Field) Sash(org.eclipse.swt.widgets.Sash)

Example 4 with Sash

use of org.eclipse.swt.widgets.Sash in project bndtools by bndtools.

the class MDSashForm method hookSashListeners.

private void hookSashListeners() {
    purgeSashes();
    Control[] children = getChildren();
    for (int i = 0; i < children.length; i++) {
        if (children[i] instanceof Sash) {
            Sash sash = (Sash) children[i];
            if (sashes.contains(sash))
                continue;
            sash.addListener(SWT.Paint, listener);
            sash.addListener(SWT.MouseEnter, listener);
            sash.addListener(SWT.MouseExit, listener);
            sashes.add(sash);
        }
    }
}
Also used : Control(org.eclipse.swt.widgets.Control) Sash(org.eclipse.swt.widgets.Sash) Point(org.eclipse.swt.graphics.Point)

Example 5 with Sash

use of org.eclipse.swt.widgets.Sash in project bndtools by bndtools.

the class MDSashForm method onSashPaint.

private void onSashPaint(Event e) {
    Sash sash = (Sash) e.widget;
    boolean vertical = (sash.getStyle() & SWT.VERTICAL) != 0;
    GC gc = e.gc;
    //$NON-NLS-1$
    Boolean hover = (Boolean) sash.getData("hover");
    gc.setBackground(bg);
    gc.setForeground(fg);
    Point size = sash.getSize();
    if (vertical) {
        if (hover != null)
            gc.fillRectangle(0, 0, size.x, size.y);
    // else
    // gc.drawLine(1, 0, 1, size.y-1);
    } else {
        if (hover != null)
            gc.fillRectangle(0, 0, size.x, size.y);
    // else
    // gc.drawLine(0, 1, size.x-1, 1);
    }
}
Also used : Sash(org.eclipse.swt.widgets.Sash) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC)

Aggregations

Sash (org.eclipse.swt.widgets.Sash)7 Point (org.eclipse.swt.graphics.Point)4 Field (java.lang.reflect.Field)2 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)2 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)2 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)2 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)2 DisposeEvent (org.eclipse.swt.events.DisposeEvent)2 DisposeListener (org.eclipse.swt.events.DisposeListener)2 MenuDetectEvent (org.eclipse.swt.events.MenuDetectEvent)2 MenuDetectListener (org.eclipse.swt.events.MenuDetectListener)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 ShellEvent (org.eclipse.swt.events.ShellEvent)2 GridData (org.eclipse.swt.layout.GridData)2 Event (org.eclipse.swt.widgets.Event)2 Listener (org.eclipse.swt.widgets.Listener)2 GC (org.eclipse.swt.graphics.GC)1 FormAttachment (org.eclipse.swt.layout.FormAttachment)1 FormData (org.eclipse.swt.layout.FormData)1 FormLayout (org.eclipse.swt.layout.FormLayout)1