PDA

View Full Version : Implementing Rex ToolKit Tray with your server



Emily
June 13th, 2011, 06:24
What you are adding:
Rex ToolKit Tray, created by Emily. It's a tool bar item that allows you check how many players are online when browsing elsewhere. Also has the option to open up to runelocus without typing out the url. More of a convenience factor then anything.

Images:
Only the registered members can see the link.

Step 1:
Create a package in your source called
com.servername.tray
(basically anything you want)

Step 2.
Create a new class called RexTray.java

Step 3:
Paste this:


package com.ember.tray;

import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import javax.swing.*;

import com.ember.model.World;

/**
* Rex Toolkit Tray
* @author Emily & Oracle
* @version 1.0
* @since June 13, 2011 1:07 A.M. Eastern
*/
public class RexTray {

public static void main(String[] args) {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
} catch (IllegalAccessException ex) {
ex.printStackTrace();
} catch (InstantiationException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
UIManager.put("swing.boldMetal", Boolean.FALSE);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
final static TrayIcon trayIcon = new TrayIcon(createImage("icon.png", "tray icon"));

private static void createAndShowGUI() {
if (!SystemTray.isSupported()) {
System.out.println("SystemTray is not supported");
return;
}
final PopupMenu popup = new PopupMenu();
final SystemTray tray = SystemTray.getSystemTray();
MenuItem aboutItem = new MenuItem("About");
CheckboxMenuItem checkB = new CheckboxMenuItem("Set auto size");
CheckboxMenuItem checkC = new CheckboxMenuItem("Set tooltip");
Menu displayMenu = new Menu("Display");
MenuItem redirectItem = new MenuItem("Runelocus");
MenuItem playerItem = new MenuItem("Players");
MenuItem creatorItem = new MenuItem("Creator");
MenuItem exitItem = new MenuItem("Exit");
popup.add(aboutItem);
popup.addSeparator();
popup.add(checkB);
popup.add(checkC);
popup.addSeparator();
popup.add(displayMenu);
displayMenu.add(redirectItem);
displayMenu.add(playerItem);
displayMenu.add(creatorItem);
popup.add(exitItem);
trayIcon.setPopupMenu(popup);
try {
tray.add(trayIcon);
} catch (AWTException e) {
System.out.println("TrayIcon could not be added.");
return;
}
trayIcon.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "This dialog box is run from System Tray");
}
});
aboutItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "The Rex server toolkit.");
}
});
checkB.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
int cb1Id = e.getStateChange();
if (cb1Id == ItemEvent.SELECTED){
trayIcon.setImageAutoSize(true);
} else {
trayIcon.setImageAutoSize(false);
}
}
});
checkC.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
int cb2Id = e.getStateChange();
if (cb2Id == ItemEvent.SELECTED){
trayIcon.setToolTip("Rex TrayIcon");
} else {
trayIcon.setToolTip(null);
}
}
});
ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
MenuItem item = (MenuItem)e.getSource();
System.out.println(item.getLabel());
if ("Runelocus".equals(item.getLabel())) {
trayIcon.displayMessage("Rex", "Redirecting to Runelocus.com", TrayIcon.MessageType.INFO);
if(!java.awt.Desktop.isDesktopSupported()) {
trayIcon.displayMessage("Rex", "Desktop is not supported (fatal)", TrayIcon.MessageType.WARNING);
System.exit(1);
}
java.awt.Desktop desktop = java.awt.Desktop.getDesktop();
if( !desktop.isSupported(java.awt.Desktop.Action.BROWS E)) {
trayIcon.displayMessage("Rex", "Desktop doesn't support the browse action (fatal)", TrayIcon.MessageType.WARNING);
System.exit(1);
}
String[] args = {"Only the registered members can see the link."};
for (String arg : args) {
try {
java.net.URI url = new java.net.URI(arg);
desktop.browse(url);
}
catch (Exception er) {
trayIcon.displayMessage("Rex", "Error:"+er, TrayIcon.MessageType.WARNING);
}
}
} else if ("Players".equals(item.getLabel())) {
trayIcon.displayMessage("Rex", "They're "+World.getWorld().getPlayers().size()+" players online.", TrayIcon.MessageType.INFO);

} else if ("Creator".equals(item.getLabel())) {
trayIcon.displayMessage("Rex", "Rex was created by Emily.", TrayIcon.MessageType.NONE);
}
}
};
redirectItem.addActionListener(listener);
playerItem.addActionListener(listener);
creatorItem.addActionListener(listener);
exitItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tray.remove(trayIcon);
System.exit(0);
}
});
}

protected static Image createImage(String path, String description) {
URL imageURL = RexTray.class.getResource(path);
if (imageURL == null) {
System.err.println("Resource not found: " + path);
return null;
} else {
return (new ImageIcon(imageURL, description)).getImage();
}
}

}


Step 4:
Change Package name from com.ember.tray (to yours)
Change Import name from com.ember.model.world (to yours)

Step 5:
Download this image, call it "icon.png". Place it in the same package as the RexTray.java file

Only the registered members can see the link.

Download link if to lazy to right click and save image: Only the registered members can see the link.

Using Rex Toolkit Tray:
Run your source and then run the file separate. (If using eclipse).

Modify it to your needs, make it better if you want.

Marcus01
June 13th, 2011, 06:29
Awesome release Emily!

Drain
June 13th, 2011, 07:24
Sexy tut there. Didnt know Java was capable of this and needed native code but thanks anyway for this. :D

The Only Cj
June 13th, 2011, 12:53
Nice one Emily :)

SkrilleX
June 13th, 2011, 13:31
0.o Awesome, didn't even think of this,good job!

Emily
June 13th, 2011, 17:14
Thanks anyone, if you have any suggestions on possible add ons or different tools that would be useful just comment.

tedhead2
June 13th, 2011, 18:14
This is actually really epic...

I hope someone expands on this, there is so much you could do with this!

The first thing that comes to find is a rightclick option that brings up a textbox and a "broadcast" button, to broadcast something to everyone without even logging in.

Cart
June 13th, 2011, 18:18
This is actually really epic...

I hope someone expands on this, there is so much you could do with this!

The first thing that comes to find is a rightclick option that brings up a textbox and a "broadcast" button, to broadcast something to everyone without even logging in.


Pretty sure someone released a tool like this on R-S, which would allow you to speak like "[Server] Hello guys" without logging in etc.

I'll check.

Emily
June 13th, 2011, 18:20
This is actually really epic...

I hope someone expands on this, there is so much you could do with this!

The first thing that comes to find is a rightclick option that brings up a textbox and a "broadcast" button, to broadcast something to everyone without even logging in.

Not that hard, just add a pop JDialogbox and submit it through the files.


Pretty sure someone released a tool like this on R-S, which would allow you to speak like "[Server] Hello guys" without logging in etc.

I'll check.

People have done Gui implementations with announcements, but nothing like this before.

David
June 13th, 2011, 18:29
Pretty sure someone released a tool like this on R-S, which would allow you to speak like "[Server] Hello guys" without logging in etc.

I'll check.

What your speaking off is a GUI lol

Lukedawesome
June 13th, 2011, 18:29
Wow, pretty cool, but I really can't think of much more that you can do with this.

Good release.

Faab234
June 13th, 2011, 18:33
I would recommend the Standard Widget toolkit. Anyway, nice job.

Emily
June 13th, 2011, 22:48
Standard widget toolkit: Only the registered members can see the link.

if interested in that.

SkrilleX
June 14th, 2011, 00:15
I think you should add all of the Admin features so you can be browsing and do something,or make it so you can use hotkeys that'd be cool like you do SHIFT+H and then it opens a admin console type thing

davidpaceway
June 14th, 2011, 20:44
Icon didn't pop up even after I imported world.java, and fixed the errors (Using caelums)

Emily
June 16th, 2011, 00:11
Icon didn't pop up even after I imported world.java, and fixed the errors (Using caelums)

You have to run the file separately apart from the server, also the image file must be in the same folder/package as the class file.

davidpaceway
June 16th, 2011, 09:09
You have to run the file separately apart from the server, also the image file must be in the same folder/package as the class file.

Its in the same file, And I have no idea how to run it separately.

SkrilleX
June 16th, 2011, 09:46
Its in the same file, And I have no idea how to run it separately.

She told me to have it like your runeserver.bat info but change the path but it doesnt work for me so idk it wont compile the class for me but idc lol

David
June 16th, 2011, 13:04
A bat that contains
java RexTray would be simply enough

davidpaceway
June 17th, 2011, 00:50
A bat that contains
java RexTray would be simply enough

Didn't work.

Divine-X
July 12th, 2011, 23:32
Naice I guess :i But you just took everything from Oracle and edited it and added website and player thing..