Search in sources :

Example 21 with ImageLoader

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

the class GCStringPrinter method main.

public static void main(String[] args) {
    // String s = "this is $1.00";
    // String s2 = "$1";
    // String s3 = s2.replaceAll("\\$", "\\\\\\$");
    // System.out.println(s3);
    // s.replaceAll("h", s3);
    // System.out.println(s);
    // if (true) {
    // return;
    // }
    final Display display = Display.getDefault();
    final Shell shell = new Shell(display, SWT.SHELL_TRIM);
    ImageLoader imageLoader = ImageLoader.getInstance();
    final Image[] images = { imageLoader.getImage("logo32"), imageLoader.getImage("logo64"), imageLoader.getImage("logo16"), imageLoader.getImage("logo128") };
    // final String text = "Opil Wrir, Na Poys Iysk, Yann Only. test of the string printer averlongwordthisisyesindeed";
    final String text = "Apple <A HREF=\"aa\">Banana</a>, Cow <A HREF=\"ss\">Dug Ergo</a>, Flip Only. test of the string printer averlongwordthisisyesindeed " + Constants.INFINITY_STRING;
    // final String text = "Apple, Cow sfjkhsd %1 f, Flip Only. test of %0 the string printer averlongwordthisisyesindeed";
    shell.setSize(500, 500);
    GridLayout gridLayout = new GridLayout(2, false);
    shell.setLayout(gridLayout);
    int initHeight = 67;
    Composite cButtons = new Composite(shell, SWT.NONE);
    GridData gridData = new GridData(SWT.NONE, SWT.FILL, false, true);
    cButtons.setLayoutData(gridData);
    final Canvas cPaint = new Canvas(shell, SWT.DOUBLE_BUFFERED);
    gridData = new GridData(SWT.FILL, SWT.NONE, true, false);
    gridData.heightHint = initHeight;
    cPaint.setLayoutData(gridData);
    cButtons.setLayout(new RowLayout(SWT.VERTICAL));
    Listener l = new Listener() {

        @Override
        public void handleEvent(Event event) {
            cPaint.redraw();
        }
    };
    final Text txtText = new Text(cButtons, SWT.WRAP | SWT.MULTI | SWT.BORDER);
    txtText.setText(text);
    txtText.addListener(SWT.Modify, l);
    txtText.setLayoutData(new RowData(100, 200));
    txtText.addKeyListener(new KeyListener() {

        @Override
        public void keyReleased(KeyEvent e) {
        }

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == 'a' && e.stateMask == SWT.CONTROL) {
                txtText.selectAll();
            }
        }
    });
    final Button btnSkipClip = new Button(cButtons, SWT.CHECK);
    btnSkipClip.setText("Skip Clip");
    btnSkipClip.setSelection(true);
    btnSkipClip.addListener(SWT.Selection, l);
    final Button btnFullOnly = new Button(cButtons, SWT.CHECK);
    btnFullOnly.setText("Full Lines Only");
    btnFullOnly.setSelection(true);
    btnFullOnly.addListener(SWT.Selection, l);
    final Combo cboVAlign = new Combo(cButtons, SWT.READ_ONLY);
    cboVAlign.add("Top");
    cboVAlign.add("Bottom");
    cboVAlign.add("None");
    cboVAlign.addListener(SWT.Selection, l);
    cboVAlign.select(0);
    final Combo cboHAlign = new Combo(cButtons, SWT.READ_ONLY);
    cboHAlign.add("Left");
    cboHAlign.add("Center");
    cboHAlign.add("Right");
    cboHAlign.add("None");
    cboHAlign.addListener(SWT.Selection, l);
    cboHAlign.select(0);
    final Button btnWrap = new Button(cButtons, SWT.CHECK);
    btnWrap.setText("Wrap");
    btnWrap.setSelection(true);
    btnWrap.addListener(SWT.Selection, l);
    final Button btnGCAdvanced = new Button(cButtons, SWT.CHECK);
    btnGCAdvanced.setText("gc.Advanced");
    btnGCAdvanced.setSelection(true);
    btnGCAdvanced.addListener(SWT.Selection, l);
    final Spinner spinnerHeight = new Spinner(cButtons, SWT.BORDER);
    spinnerHeight.setSelection(initHeight);
    spinnerHeight.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            GridData gridData = (GridData) cPaint.getLayoutData();
            gridData.heightHint = spinnerHeight.getSelection();
            cPaint.setLayoutData(gridData);
            shell.layout();
        }
    });
    final Label lblInfo = new Label(shell, SWT.WRAP);
    lblInfo.setText("Welcome");
    Listener l2 = new Listener() {

        URLInfo lastHitInfo = null;

        @Override
        public void handleEvent(Event event) {
            GC gc = event.gc;
            // System.out.println("HE" + event.type);
            boolean ourGC = gc == null;
            if (ourGC) {
                gc = new GC(cPaint);
            }
            try {
                gc.setAdvanced(btnGCAdvanced.getSelection());
                GCStringPrinter sp = buildSP(gc);
                Color colorURL = gc.getDevice().getSystemColor(SWT.COLOR_RED);
                Color colorURL2 = gc.getDevice().getSystemColor(SWT.COLOR_DARK_MAGENTA);
                if (event.type == SWT.MouseMove) {
                    Point pt = cPaint.toControl(display.getCursorLocation());
                    URLInfo hitUrl = sp.getHitUrl(pt.x, pt.y);
                    String url1 = hitUrl == null || hitUrl.url == null ? "" : hitUrl.url;
                    String url2 = lastHitInfo == null || lastHitInfo.url == null ? "" : lastHitInfo.url;
                    if (url1.equals(url2)) {
                        return;
                    }
                    cPaint.redraw();
                    lastHitInfo = hitUrl;
                    return;
                }
                Rectangle bounds = cPaint.getClientArea();
                Color colorBox = gc.getDevice().getSystemColor(SWT.COLOR_YELLOW);
                Color colorText = gc.getDevice().getSystemColor(SWT.COLOR_BLACK);
                gc.setForeground(colorText);
                Point pt = cPaint.toControl(display.getCursorLocation());
                sp.setUrlColor(colorURL);
                URLInfo hitUrl = sp.getHitUrl(pt.x, pt.y);
                if (hitUrl != null) {
                    shell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
                    hitUrl.urlColor = colorURL2;
                } else {
                    shell.setCursor(null);
                }
                boolean fit = sp.printString();
                lblInfo.setText(fit ? "fit" : "no fit");
                bounds.width--;
                bounds.height--;
                gc.setForeground(colorBox);
                gc.drawRectangle(bounds);
                bounds.height -= 20;
                bounds.y += 10;
                gc.setLineStyle(SWT.LINE_DOT);
                gc.drawRectangle(bounds);
            // System.out.println("-         " + System.currentTimeMillis());
            } catch (Throwable t) {
                t.printStackTrace();
            } finally {
                if (ourGC) {
                    gc.dispose();
                }
            }
        }

        private GCStringPrinter buildSP(GC gc) {
            // gc.setFont(Utils.getFontWithHeight(shell.getFont(), gc, 15));
            // gc.setTextAntialias(SWT.ON);
            Rectangle bounds = cPaint.getClientArea();
            bounds.y += 10;
            bounds.height -= 20;
            int style = btnWrap.getSelection() ? SWT.WRAP : 0;
            if (cboVAlign.getSelectionIndex() == 0) {
                style |= SWT.TOP;
            } else if (cboVAlign.getSelectionIndex() == 1) {
                style |= SWT.BOTTOM;
            }
            if (cboHAlign.getSelectionIndex() == 0) {
                style |= SWT.LEFT;
            } else if (cboHAlign.getSelectionIndex() == 1) {
                style |= SWT.CENTER;
            } else if (cboHAlign.getSelectionIndex() == 2) {
                style |= SWT.RIGHT;
            }
            String text = txtText.getText();
            text = text.replaceAll("\r\n", "\n");
            GCStringPrinter sp = new GCStringPrinter(gc, text, bounds, btnSkipClip.getSelection(), btnFullOnly.getSelection(), style);
            sp.setImages(images);
            sp.calculateMetrics();
            return sp;
        }
    };
    cPaint.addListener(SWT.Paint, l2);
    cPaint.addListener(SWT.MouseMove, l2);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
}
Also used : KeyListener(org.eclipse.swt.events.KeyListener) KeyEvent(org.eclipse.swt.events.KeyEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) KeyListener(org.eclipse.swt.events.KeyListener) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Example 22 with ImageLoader

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

the class SWTSkinObjectBasic method setBackground.

@Override
public void setBackground(String sConfigID, String sSuffix) {
    Image imageBG;
    Image imageBGLeft;
    Image imageBGRight;
    if (sConfigID == null) {
        return;
    }
    ImageLoader imageLoader = skin.getImageLoader(properties);
    String id = null;
    String idLeft = null;
    String idRight = null;
    String s = properties.getStringValue(sConfigID + sSuffix, (String) null);
    if (s != null && s.length() > 0) {
        Image[] images = imageLoader.getImages(sConfigID + sSuffix);
        try {
            if (images.length == 1 && ImageLoader.isRealImage(images[0])) {
                id = sConfigID + sSuffix;
                idLeft = id + "-left";
                idRight = id + "-right";
            } else if (images.length == 3 && ImageLoader.isRealImage(images[2])) {
                id = sConfigID + sSuffix;
                idLeft = id;
                idRight = id;
            } else if (images.length == 2 && ImageLoader.isRealImage(images[1])) {
                id = sConfigID + sSuffix;
                idLeft = id;
                idRight = id + "-right";
            } else {
                id = sConfigID + sSuffix;
                // }
                return;
            }
        } finally {
            imageLoader.releaseImage(sConfigID + sSuffix);
        }
    } else {
        if (s != null && painter != null) {
            painter.dispose();
            painter = null;
        }
        if (s == null) {
        // if (sSuffix.length() > 0) {
        // setBackground(sConfigID, "");
        // }
        }
        return;
    }
    if (painter == null) {
        // control.setBackgroundImage doesn't handle transparency!
        // control.setBackgroundImage(image);
        // Workaround: create our own image with shell's background
        // for "transparent" area.  Doesn't allow control's image to show
        // through.  To do that, we'd have to walk up the tree until we
        // found a composite with an image
        // control.setBackgroundMode(SWT.INHERIT_NONE);
        // control.setBackgroundImage(imageBG);
        String sTileMode = properties.getStringValue(sConfigID + ".drawmode");
        int tileMode = SWTSkinUtils.getTileMode(sTileMode);
        // painter = new SWTBGImagePainter(control, imageBGLeft, imageBGRight,
        // imageBG, tileMode);
        painter = new SWTBGImagePainter(control, imageLoader, idLeft, idRight, id, tileMode);
    } else {
        // System.out.println("setImage " + sConfigID + "  " + sSuffix);
        painter.setImage(imageLoader, idLeft, idRight, id);
    }
// XXX Is this needed?  It causes flicker and slows things down.
// Maybe a redraw instead (if anything at all)?
// control.update();
}
Also used : ObfuscateImage(com.biglybt.ui.swt.debug.ObfuscateImage) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Example 23 with ImageLoader

use of com.biglybt.ui.swt.imageloader.ImageLoader 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 24 with ImageLoader

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

the class SWTSkinObjectImage2 method swt_reallySetImage.

protected void swt_reallySetImage() {
    if (currentImageID == null || customImage) {
        drawAlpha = 255;
        return;
    }
    boolean removedDisabled = false;
    ImageLoader imageLoader = skin.getImageLoader(properties);
    boolean imageExists = imageLoader.imageExists(currentImageID);
    if (!imageExists && imageLoader.imageExists(currentImageID + ".image")) {
        currentImageID = sConfigID + ".image";
        imageExists = true;
    }
    if (!imageExists && suffixes != null) {
        for (int i = suffixes.length - 1; i >= 0; i--) {
            String suffixToRemove = suffixes[i];
            if (suffixToRemove != null) {
                if (suffixToRemove.equals("-disabled")) {
                    removedDisabled = true;
                }
                currentImageID = currentImageID.substring(0, currentImageID.length() - suffixToRemove.length());
                if (imageLoader.imageExists(currentImageID)) {
                    imageExists = true;
                    break;
                }
            }
        }
    }
    if (imageExists) {
        drawAlpha = removedDisabled ? 64 : 255;
        setCanvasImage(currentImageID, null);
    } else {
        drawAlpha = 255;
        Utils.execSWTThread(new AERunnable() {

            @Override
            public void runSupport() {
                FormData fd = (FormData) canvas.getLayoutData();
                if (fd == null) {
                    fd = new FormData(0, 0);
                } else {
                    fd.width = 0;
                    fd.height = 0;
                }
                canvas.setLayoutData(fd);
                if (initialized) {
                    Utils.relayout(canvas);
                }
            }
        });
    }
}
Also used : FormData(org.eclipse.swt.layout.FormData) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Example 25 with ImageLoader

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

the class BuddyPluginView method checkBetaInit.

private void checkBetaInit() {
    if (plugin.isBetaEnabled() && plugin.getBeta().isAvailable()) {
        synchronized (this) {
            if (beta_init_done) {
                return;
            }
            beta_init_done = true;
        }
        MenuManager menu_manager = plugin.getPluginInterface().getUIManager().getMenuManager();
        MenuItem chat_item = menu_manager.addMenuItem(MenuManager.MENU_DOWNLOAD_CONTEXT, "label.chat");
        chat_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        chat_item.setHeaderCategory(MenuItem.HEADER_SOCIAL);
        final MenuItem mi_chat = MenuBuildUtils.addChatMenu(menu_manager, chat_item, new MenuBuildUtils.ChatKeyResolver() {

            @Override
            public String getChatKey(Object object) {
                return (BuddyPluginUtils.getChatKey((Download) object));
            }
        });
        addBetaSubviews(true);
        beta_status = ui_instance.createStatusEntry();
        beta_status.setImageEnabled(true);
        beta_status.setVisible(true);
        updateIdleTT(false);
        Utils.execSWTThread(new AERunnable() {

            @Override
            public void runSupport() {
                ImageLoader imageLoader = ImageLoader.getInstance();
                bs_chat_gray = imageLoader.getImage("dchat_gray");
                bs_chat_gray_text = imageLoader.getImage("dchat_gray_text");
                bs_chat_green = imageLoader.getImage("dchat_green");
                bs_chat_red = imageLoader.getImage("dchat_red");
                setBetaStatus(bs_chat_gray);
                mi_chat.setGraphic(ui_instance.createGraphic(bs_chat_gray));
            }
        });
        beta_status.setListener(new UISWTStatusEntryListener() {

            @Override
            public void entryClicked(UISWTStatusEntry entry) {
                Set<ChatInstance> current_instances = menu_latest_instances;
                for (ChatInstance chat : current_instances) {
                    if (chat.getMessageOutstanding()) {
                        try {
                            openChat(chat.getClone());
                        } catch (Throwable e) {
                            Debug.out(e);
                        }
                    }
                }
            }
        });
        periodicEventMsgCheck = SimpleTimer.addPeriodicEvent("msgcheck", 30 * 1000, new TimerEventPerformer() {

            @Override
            public void perform(TimerEvent event) {
                List<ChatInstance> chats = plugin.getBeta().getChats();
                synchronized (pending_msg_map) {
                    for (ChatInstance chat : chats) {
                        if (chat.isInvisible()) {
                            continue;
                        }
                        if (!chat_uis.containsKey(chat)) {
                            if (chat.isFavourite() || chat.isAutoNotify() || chat.isInteresting()) {
                                if (!chat.isStatistics()) {
                                    ChatMessage last_msg = chat.getLastMessageRequiringAttention();
                                    if (last_msg != null) {
                                        ChatMessage last_handled = (ChatMessage) chat.getUserData(CHAT_LM_KEY);
                                        long last_msg_time = last_msg.getTimeStamp();
                                        if (last_handled == null || last_msg_time > last_handled.getTimeStamp()) {
                                            chat.setUserData(CHAT_LM_KEY, last_msg);
                                            betaMessagePending(chat, null, last_msg);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    updateIdleTT(false);
                }
            }
        });
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ChatInstance(com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance) UISWTStatusEntryListener(com.biglybt.ui.swt.pif.UISWTStatusEntryListener) ChatMessage(com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatMessage) MenuItem(com.biglybt.pif.ui.menus.MenuItem) UISWTStatusEntry(com.biglybt.ui.swt.pif.UISWTStatusEntry) MenuManager(com.biglybt.pif.ui.menus.MenuManager) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) MenuBuildUtils(com.biglybt.ui.swt.MenuBuildUtils)

Aggregations

ImageLoader (com.biglybt.ui.swt.imageloader.ImageLoader)71 Image (org.eclipse.swt.graphics.Image)18 GridData (org.eclipse.swt.layout.GridData)14 GridLayout (org.eclipse.swt.layout.GridLayout)14 CoreRunningListener (com.biglybt.core.CoreRunningListener)5 MessageText (com.biglybt.core.internat.MessageText)5 AERunnable (com.biglybt.core.util.AERunnable)5 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)5 ArrayList (java.util.ArrayList)5 Rectangle (org.eclipse.swt.graphics.Rectangle)5 Core (com.biglybt.core.Core)4 LinkLabel (com.biglybt.ui.swt.components.LinkLabel)4 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)4 File (java.io.File)4 DisposeEvent (org.eclipse.swt.events.DisposeEvent)4 DisposeListener (org.eclipse.swt.events.DisposeListener)4 MouseAdapter (org.eclipse.swt.events.MouseAdapter)4 MouseEvent (org.eclipse.swt.events.MouseEvent)4 FormData (org.eclipse.swt.layout.FormData)4 TableColumnCreationListener (com.biglybt.pif.ui.tables.TableColumnCreationListener)3