/*
* File created by Jimmy
* at 2003-aug-30 14:31:00
*/
package Macbeth.Modules.modPacketSender;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import Macbeth.System.*;
import Macbeth.Utilities.MySystem;
/**
* A Macbeth module that allows the user to write and send
* custom packets from a graphical user interface.
* @author Jimmy
*/
public class modPacketSender extends MbModule implements MbModuleGUI {
private GUI gui;
/**
* Creates a new instance of modPacketSender.
*/
public modPacketSender() {
super();
gui = new GUI();
}
/**
* Gets the name of the component.
* @return The name of the component.
*/
return "PacketSender";
}
/**
* Gets the description of the component.
* @return The description of the component.
*/
return "Allows you to send custom packets";
}
/**
* This method sets default values on all _required_ data
* fields in the data repository.
*/
protected void initDataFields() {
//this module doesn't require any data fields
}
/**
* Starts up this module.
*/
public void startup() throws MbStartupException {
super.startup();
}
/**
* Shuts down this module.
*/
public void shutdown() {
super.shutdown();
}
/**
* Will be called when a packet needs to be handled.
* @param p The packet that needs to be handled.
*/
public void handlePacket(MbPacket p) {
//we don't care about incoming packets
}
/**
* Will be called when our GUI should be shown.
*/
gui.render(drawArea);
}
/**
* A class for our GUI.
*/
private JLabel lblDestinationKernel
;
private JLabel lblDestinationModule
;
lblDestinationKernel =
new JLabel("Destination kernel:");
lblDestinationModule =
new JLabel("Destination module:");
lblContents =
new JLabel("Packet contents (XML):");
txtDestinationKernel.setText("self");
txtDestinationModule.setText("PacketReceiver");
txtContents.setText("<test>" + MySystem.lineBreak + "XML-data only!" + MySystem.lineBreak + "</test>" + MySystem.lineBreak + "<wee attribute=\"value\"/>");
btnSend.setActionCommand("send");
btnSend.addActionListener(this);
c.ipadx = 2;
c.ipady = 2;
c.weightx = 1;
c.weighty = 0;
c.gridy = 0;
drawArea.add(lblDestinationKernel,c);
c.gridy = 1;
drawArea.add(txtDestinationKernel,c);
c.gridy = 2;
drawArea.add(lblDestinationModule,c);
c.gridy = 3;
drawArea.add(txtDestinationModule,c);
c.gridy = 4;
drawArea.add(lblContents,c);
c.gridy = 5;
c.weighty = 1;
drawArea.add(txtContentsScrolled,c);
c.gridy = 6;
c.weighty = 0;
drawArea.add(btnSend,c);
}
if (e.getActionCommand().equals("send")) {
if (!txtDestinationKernel.getText().equals("") && !txtDestinationModule.getText().equals("") && !txtContents.getText().equals("")) {
MbPacket p = new MbPacket();
p.setDestination(new MbLocation(txtDestinationKernel.getText(), txtDestinationModule.getText()));
p.setContents(txtContents.getText());
sendPacket(p);
}
}
}
}
}