Search in sources :

Example 41 with AERunnable

use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.

the class ProgressWindow method showDialog.

protected void showDialog(Shell _shell, CoreOperation _core_op) {
    shell = _shell;
    if (shell == null || shell.isDisposed()) {
        return;
    }
    boolean closeable = (shell.getStyle() & SWT.CLOSE) != 0;
    shell.setText(MessageText.getString("progress.window.title"));
    CoreOperationTask task = _core_op == null ? null : _core_op.getTask();
    ProgressCallback progress = task == null ? null : task.getProgressCallback();
    boolean alreadyPositioned = Utils.linkShellMetricsToConfig(shell, "com.biglybt.ui.swt.progress.ProgressWindow" + "." + _core_op.getOperationType());
    Utils.setShellIcon(shell);
    if (!closeable) {
        shell.addListener(SWT.Close, (ev) -> {
            ev.doit = false;
        });
    }
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    shell.setLayout(layout);
    Color bg = (Utils.isDarkAppearanceNative() || Utils.isDarkAppearancePartial()) ? null : Colors.white;
    shell.setBackground(bg);
    if (task != null) {
        String name = task.getName();
        if (name != null) {
            Label lName = new Label(shell, SWT.NONE);
            FontData fontData = lName.getFont().getFontData()[0];
            Font bold_font = new Font(shell.getDisplay(), new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
            lName.setText(name);
            GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
            gridData.horizontalSpan = 2;
            lName.setLayoutData(gridData);
            lName.setBackground(bg);
            lName.setFont(bold_font);
            lName.addDisposeListener(new DisposeListener() {

                @Override
                public void widgetDisposed(DisposeEvent arg0) {
                    bold_font.dispose();
                }
            });
            if (progress != null && (progress.getSupportedTaskStates() & ProgressCallback.ST_SUBTASKS) != 0) {
                subtask_label = new Label(shell, SWT.NONE);
                gridData = new GridData(GridData.FILL_HORIZONTAL);
                gridData.horizontalSpan = 2;
                gridData.horizontalIndent = 25;
                subtask_label.setLayoutData(gridData);
                subtask_label.setBackground(bg);
            }
        }
    }
    spinImages = ImageLoader.getInstance().getImages("working");
    if (spinImages == null || spinImages.length == 0) {
        new Label(shell, SWT.NULL);
    } else {
        final Rectangle spinBounds = spinImages[0].getBounds();
        final Canvas canvas = new Canvas(shell, SWT.DOUBLE_BUFFERED) {

            @Override
            public Point computeSize(int wHint, int hHint, boolean changed) {
                return (new Point(spinBounds.width, spinBounds.height));
            }
        };
        canvas.addPaintListener(new PaintListener() {

            @Override
            public void paintControl(PaintEvent e) {
                e.gc.drawImage(spinImages[curSpinIndex], 0, 0);
            }
        });
        Utils.execSWTThreadLater(100, new AERunnable() {

            @Override
            public void runSupport() {
                if (canvas == null || canvas.isDisposed()) {
                    return;
                }
                canvas.redraw();
                if (curSpinIndex == spinImages.length - 1) {
                    curSpinIndex = 0;
                } else {
                    curSpinIndex++;
                }
                if (progress != null && progress_bar != null) {
                    if (progress_bar.isDisposed()) {
                        return;
                    }
                    int p = progress.getProgress();
                    progress_bar.setSelection(p);
                    if (subtask_label != null) {
                        String st = progress.getSubTaskName();
                        if (st == null) {
                            st = "";
                        }
                        subtask_label.setText(st);
                    }
                }
                Utils.execSWTThreadLater(100, this);
            }
        });
        canvas.setBackground(bg);
    }
    Label label = new Label(shell, SWT.NONE);
    label.setText(MessageText.getString(resource));
    GridData gridData = new GridData();
    label.setLayoutData(gridData);
    label.setBackground(bg);
    if (progress != null) {
        Composite compProg = new Composite(shell, SWT.BORDER);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.grabExcessHorizontalSpace = true;
        gridData.horizontalSpan = 2;
        compProg.setLayoutData(gridData);
        GridLayout layoutProgress = new GridLayout();
        layoutProgress.numColumns = 1;
        layoutProgress.marginWidth = layoutProgress.marginHeight = 0;
        compProg.setLayout(layoutProgress);
        compProg.setBackground(bg);
        progress_bar = new ProgressBar(compProg, SWT.HORIZONTAL);
        progress_bar.setMinimum(0);
        progress_bar.setMaximum(1000);
        progress_bar.setBackground(bg);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.widthHint = 400;
        progress_bar.setLayoutData(gridData);
        int states = progress.getSupportedTaskStates();
        if ((states & ProgressCallback.ST_BUTTONS) != 0) {
            Label labelSeparator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
            gridData = new GridData(GridData.FILL_HORIZONTAL);
            gridData.horizontalSpan = 2;
            labelSeparator.setLayoutData(gridData);
            // buttons
            boolean has_pause_resume = (states & (ProgressCallback.ST_PAUSE | ProgressCallback.ST_RESUME)) != 0;
            boolean has_cancel = (states & ProgressCallback.ST_CANCEL) != 0;
            if (!has_pause_resume) {
                has_cancel = true;
            }
            int num_buttons = 0;
            if (has_pause_resume)
                num_buttons += 2;
            if (has_cancel)
                num_buttons++;
            Composite comp = new Composite(shell, SWT.NULL);
            gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END | GridData.HORIZONTAL_ALIGN_FILL);
            gridData.grabExcessHorizontalSpace = true;
            gridData.horizontalSpan = 2;
            comp.setLayoutData(gridData);
            GridLayout layoutButtons = new GridLayout();
            layoutButtons.numColumns = num_buttons;
            comp.setLayout(layoutButtons);
            comp.setBackground(bg);
            List<Button> buttons = new ArrayList<>();
            Button bPause;
            Button bResume;
            Button bCancel;
            if (has_pause_resume) {
                bPause = new Button(comp, SWT.PUSH);
                bPause.setText(MessageText.getString("v3.MainWindow.button.pause"));
                gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END | GridData.HORIZONTAL_ALIGN_FILL);
                gridData.grabExcessHorizontalSpace = true;
                // gridData.widthHint = 70;
                bPause.setLayoutData(gridData);
                buttons.add(bPause);
                bResume = new Button(comp, SWT.PUSH);
                bResume.setText(MessageText.getString("v3.MainWindow.button.resume"));
                gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END | GridData.HORIZONTAL_ALIGN_FILL);
                gridData.grabExcessHorizontalSpace = false;
                // gridData.widthHint = 70;
                bResume.setLayoutData(gridData);
                buttons.add(bResume);
            } else {
                bPause = null;
                bResume = null;
            }
            if (has_cancel) {
                bCancel = new Button(comp, SWT.PUSH);
                bCancel.setText(MessageText.getString("UpdateWindow.cancel"));
                gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
                gridData.grabExcessHorizontalSpace = false;
                // gridData.widthHint = 70;
                bCancel.setLayoutData(gridData);
                buttons.add(bCancel);
            } else {
                bCancel = null;
            }
            Utils.makeButtonsEqualWidth(buttons);
            if (has_pause_resume) {
                // if we have resume then we have pause
                bResume.setEnabled(false);
                bPause.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event e) {
                        task_paused = true;
                        bPause.setEnabled(false);
                        bResume.setEnabled(true);
                        shell.setDefaultButton(bResume);
                        progress.setTaskState(ProgressCallback.ST_PAUSE);
                    }
                });
                bResume.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event e) {
                        task_paused = false;
                        bPause.setEnabled(true);
                        bResume.setEnabled(false);
                        shell.setDefaultButton(bPause);
                        progress.setTaskState(ProgressCallback.ST_RESUME);
                    }
                });
            }
            if (bCancel != null) {
                bCancel.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event e) {
                        if (has_pause_resume) {
                            bPause.setEnabled(false);
                            bResume.setEnabled(false);
                        }
                        bCancel.setEnabled(false);
                        progress.setTaskState(ProgressCallback.ST_CANCEL);
                    }
                });
            }
            Utils.execSWTThreadLater(250, new Runnable() {

                @Override
                public void run() {
                    if (comp.isDisposed()) {
                        return;
                    }
                    int state = progress.getTaskState();
                    if (state == ProgressCallback.ST_CANCEL) {
                        shell.dispose();
                    } else {
                        if (has_pause_resume) {
                            if (state == ProgressCallback.ST_PAUSE) {
                                bPause.setEnabled(false);
                                bResume.setEnabled(true);
                            } else {
                                bPause.setEnabled(true);
                                bResume.setEnabled(false);
                            }
                        }
                        Utils.execSWTThreadLater(250, this);
                    }
                }
            });
            shell.setDefaultButton(has_pause_resume ? bPause : bCancel);
            shell.addDisposeListener(new DisposeListener() {

                @Override
                public void widgetDisposed(DisposeEvent arg0) {
                    if (task_paused) {
                        progress.setTaskState(ProgressCallback.ST_RESUME);
                    }
                }
            });
        }
    }
    shell.pack();
    if (!alreadyPositioned) {
        Composite parent = shell.getParent();
        if (parent != null) {
            Utils.centerWindowRelativeTo(shell, parent);
        } else {
            Utils.centreWindow(shell);
        }
    }
    shell.open();
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) DisposeListener(org.eclipse.swt.events.DisposeListener) PaintListener(org.eclipse.swt.events.PaintListener) DisposeListener(org.eclipse.swt.events.DisposeListener) UIExitUtilsSWT.canCloseListener(com.biglybt.ui.swt.UIExitUtilsSWT.canCloseListener) CoreOperationListener(com.biglybt.core.CoreOperationListener) ArrayList(java.util.ArrayList) CoreOperationTask(com.biglybt.core.CoreOperationTask) DisposeEvent(org.eclipse.swt.events.DisposeEvent) GridLayout(org.eclipse.swt.layout.GridLayout) PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) ProgressCallback(com.biglybt.core.CoreOperationTask.ProgressCallback) AERunnable(com.biglybt.core.util.AERunnable) GridData(org.eclipse.swt.layout.GridData) DisposeEvent(org.eclipse.swt.events.DisposeEvent) DelayedEvent(com.biglybt.core.util.DelayedEvent) PaintEvent(org.eclipse.swt.events.PaintEvent)

Example 42 with AERunnable

use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.

the class SWTSkinObjectButton method switchSuffix.

// @see SWTSkinObjectBasic#switchSuffix(java.lang.String, int, boolean)
@Override
public String switchSuffix(String suffix, int level, boolean walkUp, boolean walkDown) {
    suffix = super.switchSuffix(suffix, level, walkUp, walkDown);
    if (suffix == null) {
        return null;
    }
    String sPrefix = sConfigID + ".text";
    String text = properties.getStringValue(sPrefix + suffix);
    if (text != null) {
        setText(text, true);
    }
    final String fSuffix = suffix;
    String oldImageID = imageID;
    imageID = sConfigID + ".image" + fSuffix;
    final String imageVal = properties.getStringValue(imageID);
    if (imageVal != null) {
        if (oldImageID != null) {
            final ImageLoader imageLoader = skin.getImageLoader(properties);
            imageLoader.releaseImage(oldImageID);
        }
        Utils.execSWTThread(new AERunnable() {

            @Override
            public void runSupport() {
                if (button != null && !button.isDisposed() && imageID != null) {
                    final ImageLoader imageLoader = skin.getImageLoader(properties);
                    Image image = imageLoader.getImage(imageID);
                    if (ImageLoader.isRealImage(image)) {
                        button.setImage(image);
                    } else {
                        button.setImage(null);
                    }
                }
            }
        });
    }
    return suffix;
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) Image(org.eclipse.swt.graphics.Image)

Example 43 with AERunnable

use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.

the class SWTSkinObjectContainer method setIsVisible.

// @see SWTSkinObjectBasic#setIsVisible(boolean)
@Override
protected boolean setIsVisible(boolean visible, boolean walkup) {
    if (Utils.isThisThreadSWT() && !control.isDisposed() && !control.getShell().isVisible()) {
        return false;
    }
    boolean changed = super.setIsVisible(visible, walkup && visible);
    if (!changed) {
        return false;
    }
    // Currently we ignore "changed" and set visibility on children to ensure
    // things display
    Utils.execSWTThreadLater(0, new AERunnable() {

        @Override
        public void runSupport() {
            SWTSkinObject[] children = getChildren();
            if (children.length == 0) {
                return;
            }
            if (SWTSkin.DEBUG_VISIBILITIES) {
                System.out.println(">> setIsVisible for " + children.length + " children of " + SWTSkinObjectContainer.this);
            }
            for (int i = 0; i < children.length; i++) {
                if (children[i] instanceof SWTSkinObjectBasic) {
                    SWTSkinObjectBasic child = ((SWTSkinObjectBasic) children[i]);
                    Control childControl = child.getControl();
                    if (childControl != null && !childControl.isDisposed()) {
                        // child.setIsVisible(visible, false);
                        // System.out.println("child control " + child + " is " + (childControl.isVisible() ? "visible" : "invisible"));
                        child.setIsVisible(childControl.isVisible(), false);
                    }
                }
            }
            getComposite().layout();
            if (SWTSkin.DEBUG_VISIBILITIES) {
                System.out.println("<< setIsVisible for " + children.length + " children");
            }
        }
    });
    return changed;
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) Control(org.eclipse.swt.widgets.Control)

Example 44 with AERunnable

use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.

the class SWTSkinObjectText2 method setTextID.

private void setTextID(String key, boolean forceRefresh) {
    if (key == null) {
        setText("");
    } else if (!forceRefresh && key.equals(sKey)) {
        return;
    }
    this.sText = MessageText.getString(key);
    this.sDisplayText = isAllcaps && sText != null ? sText.toUpperCase() : sText;
    this.sKey = key;
    bIsTextDefault = false;
    Utils.execSWTThreadLater(0, new AERunnable() {

        @Override
        public void runSupport() {
            if (canvas == null || canvas.isDisposed()) {
                return;
            }
            canvas.redraw();
            if (relayoutOnTextChange) {
                canvas.layout(true);
                Utils.relayout(canvas);
            }
        }
    });
}
Also used : AERunnable(com.biglybt.core.util.AERunnable)

Example 45 with AERunnable

use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.

the class SWTSkinObjectSash method initialize.

/**
 * @since 3.1.0.1
 */
protected void initialize() {
    SWTSkinObject skinObject;
    skinObject = skin.getSkinObjectByID(sControlBefore);
    if (skinObject != null) {
        soAbove = skinObject;
        above = (Composite) skinObject.getControl();
        aboveMin = skinObject.getProperties().getIntValue(getConfigID() + ".above" + (isVertical ? ".minwidth" : ".minheight"), 0);
        boolean aboveVisible = COConfigurationManager.getBooleanParameter("v3." + sID + ".aboveVisible", true);
        soAbove.setVisible(aboveVisible);
    }
    skinObject = skin.getSkinObjectByID(sControlAfter);
    if (skinObject != null) {
        soBelow = skinObject;
        below = (Composite) skinObject.getControl();
    }
    if (below == null) {
        return;
    }
    belowMin = skinObject == null ? 0 : skinObject.getProperties().getIntValue(getConfigID() + ".below" + (isVertical ? ".minwidth" : ".minheight"), 0);
    Listener l = new Listener() {

        @Override
        public void handleEvent(Event e) {
            if (e.type == SWT.MouseUp) {
                if (e.button == 3 || (e.button == 1 && (e.stateMask & SWT.MOD1) > 0)) {
                    String sPos = properties.getStringValue(sConfigID + ".startpos");
                    if (sPos == null) {
                        return;
                    }
                    try {
                        int l = NumberFormat.getInstance().parse(sPos).intValue();
                        sash.setData("PX", new Long(l));
                        // FALL THROUGH
                        e.type = SWT.Show;
                    } catch (Exception ex) {
                        Debug.out(ex);
                        return;
                    }
                } else {
                    return;
                }
            }
            if (e.type == SWT.Show) {
                // delay so soAbove's show gets triggered
                Utils.execSWTThreadLater(0, new AERunnable() {

                    @Override
                    public void runSupport() {
                        handleShow();
                    }
                });
            } else if (e.type == SWT.Selection) {
                if (FASTDRAG && e.detail == SWT.DRAG) {
                    return;
                }
                Rectangle area = parentComposite.getBounds();
                FormData aboveData = (FormData) above.getLayoutData();
                // FormData belowData = (FormData) below.getLayoutData();
                if (isVertical) {
                    // Need to figure out if we have to use border width elsewhere
                    // in calculations (probably)
                    aboveData.width = e.x - above.getBorderWidth();
                    if (aboveData.width < aboveMin) {
                        aboveData.width = aboveMin;
                        e.x = aboveMin;
                    } else {
                        int excess = area.width - (above.getBorderWidth() * 2) - sash.getSize().x;
                        if (excess - aboveData.width < belowMin) {
                            aboveData.width = excess - belowMin;
                            e.doit = false;
                        }
                    }
                } else {
                    aboveData.height = e.y - above.getBorderWidth();
                    if (aboveData.height < aboveMin) {
                        aboveData.height = aboveMin;
                        e.y = aboveMin;
                    } else {
                        int excess = area.height - (above.getBorderWidth() * 2) - sash.getSize().y;
                        if (excess - aboveData.height < belowMin) {
                            aboveData.height = excess - belowMin;
                            e.doit = false;
                        }
                    }
                }
                parentComposite.layout(true);
                double aboveNewSize;
                if (isVertical) {
                    aboveNewSize = above.getBounds().width + (sash.getSize().x / 2.0);
                } else {
                    aboveNewSize = above.getBounds().height + (sash.getSize().y / 2.0);
                }
                sash.setData("PX", new Long((long) aboveNewSize));
            }
        }
    };
    sash.addListener(SWT.Selection, l);
    sash.addListener(SWT.MouseUp, l);
    sash.getShell().addListener(SWT.Show, l);
    handleShow();
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) FormData(org.eclipse.swt.layout.FormData) PaintListener(org.eclipse.swt.events.PaintListener) Rectangle(org.eclipse.swt.graphics.Rectangle) PaintEvent(org.eclipse.swt.events.PaintEvent) Point(org.eclipse.swt.graphics.Point)

Aggregations

AERunnable (com.biglybt.core.util.AERunnable)92 GridLayout (org.eclipse.swt.layout.GridLayout)12 DownloadManager (com.biglybt.core.download.DownloadManager)11 Image (org.eclipse.swt.graphics.Image)10 ArrayList (java.util.ArrayList)9 GridData (org.eclipse.swt.layout.GridData)9 CoreRunningListener (com.biglybt.core.CoreRunningListener)7 File (java.io.File)7 PEPeer (com.biglybt.core.peer.PEPeer)6 Shell (org.eclipse.swt.widgets.Shell)6 Core (com.biglybt.core.Core)5 ImageLoader (com.biglybt.ui.swt.imageloader.ImageLoader)5 Point (org.eclipse.swt.graphics.Point)5 PEPeerManager (com.biglybt.core.peer.PEPeerManager)4 Subscription (com.biglybt.core.subs.Subscription)3 TableColumnCore (com.biglybt.ui.common.table.TableColumnCore)3 UISWTViewEvent (com.biglybt.ui.swt.pif.UISWTViewEvent)3 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)3 MouseAdapter (org.eclipse.swt.events.MouseAdapter)3 MouseEvent (org.eclipse.swt.events.MouseEvent)3