Jump to content

Change Title/Icon of OSBot


azn2000

Recommended Posts

I needed a easy way to track which bot is running which account, so yeah.

You can change the Title and the icon with this. Have fun :DPreview_Title.gif.a707d74dfe0e46990651fd3f543d66fc.gif

Spoiler

import sun.swing.SwingAccessor;

import javax.swing.*;
import java.awt.*;
import java.awt.image.*;

public class OSBotBar {
    private static Image iconNormal;
    private static Image iconRed;
    private static Image iconGreen;
    private static JFrame frame;
    private static String title;

    public static void setTitle(String name){
        if(frame == null)
            getFrame();
        if(title == null)
            title = frame.getTitle();

        if (frame != null) {
            frame.setTitle(title + " - " + name);
        }
    }

    public static void setIcon(Icon icon){
        if(iconNormal == null || iconRed == null || iconGreen == null)
            getIcons();

        switch (icon){
            case GREEN:
                frame.setIconImage(iconGreen);
                break;
            case RED:
                frame.setIconImage(iconRed);
                break;
            default:
                frame.setIconImage(iconNormal);
        }
    }

    private static void getIcons(){
        if(frame == null)
            getFrame();

        iconNormal = frame.getIconImage();

        ImageProducer prodRed = new FilteredImageSource( iconNormal.getSource(), new ColorFilter(0xffff0000) );
        ImageProducer prodGreen = new FilteredImageSource( iconNormal.getSource(), new ColorFilter(0xff00ff00) );

        iconRed = frame.createImage(prodRed);
        iconGreen = frame.createImage(prodGreen);
    }

    private static void getFrame(){
        Window[] windows = Window.getWindows();
        for (Window window : windows) {
            if (window instanceof JFrame) {
                JFrame jFrame = (JFrame) window;
                if (jFrame != null && jFrame.getTitle().contains("OSBot ")) {
                    frame = jFrame;
                }
            }
        }
    }

    public enum Icon{
        STANDARD,
        RED,
        GREEN
    }
}

class ColorFilter extends RGBImageFilter
{
    private int filter;
    public ColorFilter(int filter)
    {
        this.filter = filter;
        canFilterIndexColorModel = true;
    }
    public int filterRGB( int x, int y, int rgb )
    {
        return (rgb & filter);
    }
}

 

  • Like 5
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...