www.pudn.com > JAVIS-0.3.zip > Queue.java
package animation;
import java.awt.*;
import animation.VisualElement;
//import math.Vector;
import java.util.Vector;
/**
This class handles queues on the network. Each queue corrseponds to a
different node and will be displayed on the correct node.
@author Steven Vischer
@version 1.0
*/
public class Queue extends VisualElement {
int m_src;
int m_dest;
int nodeX; // x and y coordinates of the corresponding node
int nodeY; // for this queue
Vector queuedPackets;
public Queue() {
nodeX=0;
nodeY=0;
queuedPackets=new Vector();
}
public int getSource() {
return m_src;
}
public int getDest() {
return m_dest;
}
public int getEndX() {
int endx=nodeX+6;
return endx;
}
public int getEndY() {
int endy=nodeY-10-(8*(queuedPackets.size()-1));
return endy;
}
/**
Method called to add a packet to the queue.
@param queuedPackets the Vector of packets currently in the queue.
*/
public void enqueue(Packet p) {
p.setStatus(Packet.PACKET_QUEUED);
queuedPackets.addElement(p);
}
/**
Method called to remove a packet from the queue.
*/
public void dequeue(Packet p) {
p.setStatus(Packet.PACKET_FREE);
if(queuedPackets.size()>0) {
for(int i=0; i0) {
for(int i=0; i0) {
g.setColor(Color.red);
int coordX=nodeX+6;
int coordY=nodeY-10;
for(int i=0; i