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.
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.