Search in sources :

Example 1 with DelayedListenerMultiCombiner

use of com.biglybt.ui.swt.DelayedListenerMultiCombiner in project BiglyBT by BiglySoftware.

the class MyTorrentsSuperView method initialize.

public void initialize(final Composite parent) {
    if (form != null) {
        return;
    }
    form = new Composite(parent, SWT.NONE);
    FormLayout flayout = new FormLayout();
    flayout.marginHeight = 0;
    flayout.marginWidth = 0;
    form.setLayout(flayout);
    GridData gridData;
    gridData = new GridData(GridData.FILL_BOTH);
    form.setLayoutData(gridData);
    GridLayout layout;
    child1 = new Composite(form, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 1;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    child1.setLayout(layout);
    final Sash sash = Utils.createSash(form, SASH_WIDTH);
    child2 = new Composite(form, SWT.NULL);
    layout = new GridLayout();
    layout.numColumns = 1;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    child2.setLayout(layout);
    FormData formData;
    // More precision, times by 100
    int weight = (int) (COConfigurationManager.getFloatParameter("MyTorrents.SplitAt"));
    if (weight > 10000) {
        weight = 10000;
    } else if (weight < 100) {
        weight *= 100;
    }
    // Min/max of 5%/95%
    if (weight < 500) {
        weight = 500;
    } else if (weight > 9000) {
        weight = 9000;
    }
    double pct = (float) weight / 10000;
    sash.setData("PCT", new Double(pct));
    // FormData for table child1
    formData = new FormData();
    formData.left = new FormAttachment(0, 0);
    formData.right = new FormAttachment(100, 0);
    formData.top = new FormAttachment(0, 0);
    formData.bottom = new FormAttachment((int) (pct * 100), 0);
    child1.setLayoutData(formData);
    final FormData child1Data = formData;
    // sash
    formData = new FormData();
    formData.left = new FormAttachment(0, 0);
    formData.right = new FormAttachment(100, 0);
    formData.top = new FormAttachment(child1);
    formData.height = SASH_WIDTH;
    sash.setLayoutData(formData);
    // child2
    formData = new FormData();
    formData.left = new FormAttachment(0, 0);
    formData.right = new FormAttachment(100, 0);
    formData.bottom = new FormAttachment(100, 0);
    formData.top = new FormAttachment(sash);
    child2.setLayoutData(formData);
    // Listeners to size the folder
    sash.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            final boolean FASTDRAG = true;
            if (FASTDRAG && e.detail == SWT.DRAG)
                return;
            child1Data.height = e.y + e.height - SASH_WIDTH;
            form.layout();
            Double l = new Double((double) child1.getBounds().height / form.getBounds().height);
            sash.setData("PCT", l);
            if (e.detail != SWT.DRAG) {
                int i = (int) (l.doubleValue() * 10000);
                COConfigurationManager.setParameter("MyTorrents.SplitAt", i);
            }
        }
    });
    form.addListener(SWT.Resize, new DelayedListenerMultiCombiner() {

        @Override
        public void handleDelayedEvent(Event e) {
            if (sash.isDisposed()) {
                return;
            }
            Double l = (Double) sash.getData("PCT");
            if (l == null) {
                return;
            }
            int newHeight = (int) (form.getBounds().height * l.doubleValue());
            if (child1Data.height != newHeight || child1Data.bottom != null) {
                child1Data.bottom = null;
                child1Data.height = newHeight;
                form.layout();
            }
        }
    });
    CoreFactory.addCoreRunningListener(new CoreRunningListener() {

        @Override
        public void coreRunning(final Core core) {
            Utils.execSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    initializeWithCore(core, parent);
                }
            });
        }
    });
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DelayedListenerMultiCombiner(com.biglybt.ui.swt.DelayedListenerMultiCombiner) SelectionEvent(org.eclipse.swt.events.SelectionEvent) CoreRunningListener(com.biglybt.core.CoreRunningListener) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Core(com.biglybt.core.Core) TableColumnCore(com.biglybt.ui.common.table.TableColumnCore)

Aggregations

Core (com.biglybt.core.Core)1 CoreRunningListener (com.biglybt.core.CoreRunningListener)1 AERunnable (com.biglybt.core.util.AERunnable)1 TableColumnCore (com.biglybt.ui.common.table.TableColumnCore)1 DelayedListenerMultiCombiner (com.biglybt.ui.swt.DelayedListenerMultiCombiner)1 UISWTViewEvent (com.biglybt.ui.swt.pif.UISWTViewEvent)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1