Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

NetworkSpacePanel Class Reference

Inheritance diagram for NetworkSpacePanel::

Panel Runnable MouseListener MouseMotionListener List of all members.

Public Methods

 NetworkSpacePanel (Simulation simulation_applet)
Node addNode (String name)
Node deleteNode (String name)
void addDummyPackets (int number, int time_to_live)
void tracePackets (String start_node, String end_node)
void addLine (Node first, Node second, int capacity)
Line deleteLine (String first, String second)
void run ()
synchronized void update (Graphics g)
void mouseClicked (MouseEvent event)
void mousePressed (MouseEvent event)
void mouseReleased (MouseEvent event)
void mouseEntered (MouseEvent event)
void mouseExited (MouseEvent event)
void mouseDragged (MouseEvent event)
void mouseMoved (MouseEvent event)
void start ()
void stop ()
void startSimulation ()
void stopSimulation ()
void endSimulation ()

Private Attributes

CyclopsSimulator cyclops = new CyclopsSimulator()
Simulation simulation_applet
Node currently_manipulated
Thread simulator
boolean all_packets
boolean show_line_capacities
Image off_screen
Dimension off_screen_size
Graphics off_graphics
final Color node_color = new Color(250, 220, 100)
final Color line_color = Color.black
final Color left_packet_color = new Color(250, 200, 80)
final Color right_packet_color = new Color(250, 240, 120)

Detailed Description

NetworkSpacePanel class. This is class for drawing entire network.

Definition at line 394 of file Simulation.java.


Constructor & Destructor Documentation

NetworkSpacePanel::NetworkSpacePanel ( Simulation simulation_applet ) [inline]
 

Default constructor.

Definition at line 420 of file Simulation.java.

00421     {
00422         this.simulation_applet = simulation_applet;
00423         addMouseListener(this);
00424         addMouseMotionListener(this);
00425         cyclops.start();
00426         cyclops.setName("Cyclops simulator");
00427     }


Member Function Documentation

void NetworkSpacePanel::addDummyPackets ( int number,
int time_to_live ) [inline]
 

Adds dummy packets.

Parameters:
number   Number of packets.
time_to_live   TTL.

Definition at line 470 of file Simulation.java.

Referenced by Simulation::init().

00471     {
00472         cyclops.addDummyPackets(number, time_to_live);
00473     }

void NetworkSpacePanel::addLine ( Node first,
Node second,
int capacity ) [inline]
 

Adds line to network. Symmetric line is created.

Parameters:
first   First node referenece.
second   Second node reference.
capacity   Line capacity.

Definition at line 496 of file Simulation.java.

Referenced by Simulation::actionPerformed(), and Simulation::init().

00497     {
00498         Line new_line = new Line(first, second, capacity);
00499         cyclops.addLine(new_line);
00500     }

Node NetworkSpacePanel::addNode ( String name ) [inline]
 

Adds node to network. Node is identified by its name. If node already exists, method will return reference of existing node, otherwise a new node will be created.

Parameters:
name   Node name.
Returns:
Returns node reference.

Definition at line 437 of file Simulation.java.

Referenced by Simulation::actionPerformed(), and Simulation::init().

00438     {
00439         Node new_node;
00440         new_node = cyclops.findNode(name);
00441         if (new_node == null)
00442             {
00443                 new_node = new Node(name);
00444                 cyclops.addNode(new_node);
00445             }
00446         return new_node;
00447     }

Line NetworkSpacePanel::deleteLine ( String first,
String second ) [inline]
 

Deletes line from network.

Parameters:
first   First node name.
second   Second node name.
Returns:
Returns line reference.

Definition at line 509 of file Simulation.java.

Referenced by Simulation::actionPerformed().

00510     {
00511         Line deleted;
00512         deleted = cyclops.deleteLine(first, second);
00513         return deleted;
00514     }

Node NetworkSpacePanel::deleteNode ( String name ) [inline]
 

Deletes node from network. Node is identified by its name. If node already exists, method will return reference of existing node. Otherwise null reference will be returned.

Parameters:
name   Node name.
Returns:
Returns node reference.

Definition at line 457 of file Simulation.java.

Referenced by Simulation::actionPerformed().

00458     {
00459         Node removed_node;
00460         removed_node = cyclops.deleteNode(name);
00461         return removed_node;
00462     }

void NetworkSpacePanel::endSimulation ( ) [inline]
 

Ends simulation.

Definition at line 711 of file Simulation.java.

Referenced by Simulation::destroy().

00712     {
00713         cyclops.endSimulation();
00714     }

void NetworkSpacePanel::mouseClicked ( MouseEvent event ) [inline]
 

Empty event.

Parameters:
event   Mouse event.

Definition at line 582 of file Simulation.java.

00583     {
00584     }

void NetworkSpacePanel::mouseDragged ( MouseEvent event ) [inline]
 

Moves node.

Parameters:
event   Mouse event.

Definition at line 654 of file Simulation.java.

00655     {
00656         currently_manipulated.setCoordinates(event.getX(), event.getY());
00657         repaint();
00658         event.consume();
00659     }

void NetworkSpacePanel::mouseEntered ( MouseEvent event ) [inline]
 

Empty event.

Parameters:
event   Mouse event.

Definition at line 636 of file Simulation.java.

00637     {
00638     }

void NetworkSpacePanel::mouseExited ( MouseEvent event ) [inline]
 

Empty event.

Parameters:
event   Mouse event.

Definition at line 645 of file Simulation.java.

00646     {
00647     }

void NetworkSpacePanel::mouseMoved ( MouseEvent event ) [inline]
 

Empty event.

Parameters:
event   Mouse event.

Definition at line 666 of file Simulation.java.

00667     {
00668     }

void NetworkSpacePanel::mousePressed ( MouseEvent event ) [inline]
 

Findes closes node to mouse pointer and selects it.

Parameters:
event   Mouse event.

Definition at line 591 of file Simulation.java.

00592     {
00593         double best_distance = Double.MAX_VALUE;
00594         double distance;
00595         int n = cyclops.numberOfNodes();
00596         int x = event.getX();
00597         int y = event.getY();
00598         Node current_node;
00599         int i;
00600         for (i=0; i!=n; i++)
00601             {
00602                 current_node = cyclops.nodeAt(i);
00603                 distance = (x - current_node.getXCoordinate())
00604                     * (x - current_node.getXCoordinate())
00605                     + (y - current_node.getYCoordinate())
00606                     * (y - current_node.getYCoordinate());
00607                 if (distance < best_distance)
00608                     {
00609                         currently_manipulated = current_node;
00610                         best_distance = distance;
00611                     }
00612             }
00613         currently_manipulated.setCoordinates(x, y);
00614         repaint();
00615         event.consume();
00616     }

void NetworkSpacePanel::mouseReleased ( MouseEvent event ) [inline]
 

Releases hold on node and sets new screen coordinates.

Parameters:
event   Mouse event.

Definition at line 623 of file Simulation.java.

00624     {
00625         currently_manipulated.setCoordinates(event.getX(), event.getY());
00626         currently_manipulated = null;
00627         repaint();
00628         event.consume();
00629     }

void NetworkSpacePanel::run ( ) [inline]
 

Run method. Only updates the screen.

Definition at line 520 of file Simulation.java.

00521     {
00522         Thread me;
00523 
00524         me = Thread.currentThread();
00525         while (simulator == me)
00526             {
00527                 repaint();
00528                 try
00529                     {
00530                         Thread.sleep(100);
00531                     }
00532                 catch (InterruptedException exception)
00533                     {
00534                         break;
00535                     }
00536             }
00537     }

void NetworkSpacePanel::start ( ) [inline]
 

Starts thread.

Definition at line 674 of file Simulation.java.

Referenced by Simulation::start().

00675     {
00676         simulator = new Thread(this);
00677         simulator.start();
00678     }

void NetworkSpacePanel::startSimulation ( ) [inline]
 

Starts/resumes simulation.

Definition at line 693 of file Simulation.java.

Referenced by Simulation::actionPerformed().

00694     {
00695         cyclops.startSimulation();
00696     }

void NetworkSpacePanel::stop ( ) [inline]
 

Stops thread.

Definition at line 684 of file Simulation.java.

Referenced by Simulation::stop().

00685     {
00686         simulator = null;
00687     }

void NetworkSpacePanel::stopSimulation ( ) [inline]
 

Stops/suspends simulation.

Definition at line 702 of file Simulation.java.

Referenced by Simulation::actionPerformed().

00703     {
00704         cyclops.stopSimulation();
00705     }

void NetworkSpacePanel::tracePackets ( String start_node,
String end_node ) [inline]
 

Trace packets.

Parameters:
start_node   Name of a source node.
end_node   Name of a destination node.

Definition at line 481 of file Simulation.java.

Referenced by Simulation::actionPerformed(), and Simulation::init().

00482     {
00483         if (!start_node.equals(end_node))
00484             {
00485                 cyclops.tracePackets(start_node, end_node);
00486             }
00487     }

synchronized void NetworkSpacePanel::update ( Graphics g ) [inline]
 

Updates the screen.

Parameters:
g   Graphics reference.

Definition at line 553 of file Simulation.java.

00554     {
00555         Dimension d = getSize();
00556         if ((null == off_screen) ||
00557             (d.width != off_screen_size.width) ||
00558             (d.height != off_screen_size.height)
00559             )
00560             {
00561                 off_screen = createImage(d.width, d.height);
00562                 off_screen_size = d;
00563                 off_graphics = off_screen.getGraphics();
00564                 off_graphics.setFont(getFont());
00565             }
00566         off_graphics.setColor(getBackground());
00567         off_graphics.fillRect(0, 0, d.width, d.height);
00568         FontMetrics metrics = off_graphics.getFontMetrics();
00569         cyclops.paint(off_graphics, metrics,
00570                       node_color, line_color,
00571                       left_packet_color, right_packet_color, Color.red,
00572                       show_line_capacities, all_packets
00573                       );
00574         g.drawImage(off_screen, 0, 0, null);
00575     }


Member Data Documentation

boolean NetworkSpacePanel::all_packets [private]
 

All packets visibility flag.

Definition at line 412 of file Simulation.java.

Node NetworkSpacePanel::currently_manipulated [private]
 

Node object.

Definition at line 406 of file Simulation.java.

CyclopsSimulator NetworkSpacePanel::cyclops = new CyclopsSimulator() [private]
 

Simulator thread.

Definition at line 400 of file Simulation.java.

final Color NetworkSpacePanel::left_packet_color = new Color(250, 200, 80) [private]
 

Definition at line 546 of file Simulation.java.

final Color NetworkSpacePanel::line_color = Color.black [private]
 

Definition at line 545 of file Simulation.java.

final Color NetworkSpacePanel::node_color = new Color(250, 220, 100) [private]
 

Definition at line 544 of file Simulation.java.

Graphics NetworkSpacePanel::off_graphics [private]
 

Definition at line 542 of file Simulation.java.

Image NetworkSpacePanel::off_screen [private]
 

Definition at line 540 of file Simulation.java.

Dimension NetworkSpacePanel::off_screen_size [private]
 

Definition at line 541 of file Simulation.java.

final Color NetworkSpacePanel::right_packet_color = new Color(250, 240, 120) [private]
 

Definition at line 547 of file Simulation.java.

boolean NetworkSpacePanel::show_line_capacities [private]
 

Line capacity visibility flag.

Definition at line 415 of file Simulation.java.

Simulation NetworkSpacePanel::simulation_applet [private]
 

Simulator applet.

Definition at line 403 of file Simulation.java.

Thread NetworkSpacePanel::simulator [private]
 

Current thread.

Definition at line 409 of file Simulation.java.


The documentation for this class was generated from the following file:
Generated at Thu Jun 28 03:04:23 2001 for Cyclops Network Simulator by doxygen1.2.7 written by Dimitri van Heesch, © 1997-2001