Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

Line Class Reference

List of all members.

Public Methods

 Line (Node left, Node right, int capacity)
 Line (Node left, Node right, int leftCapacity, int rightCapacity)
void transmitAll ()
int getCapacity ()
int getLeftToRightCapacity ()
int getRightToLeftCapacity ()
void setCapacity (int capacity)
void setLeftToRightCapacity (int capacity)
void setRightToLeftCapacity (int capacity)
void delete ()
boolean isDisconnected ()
boolean areEndingNodes (Node first_node, Node second_node)
void paint (Graphics g, FontMetrics metrics, Color line_color)
void paint (Graphics g, FontMetrics metrics, Color line_color, Color left_packet_color, Color right_packet_color, Color traced_packet_color, boolean show_line_capacity, boolean show_all_packets)

Public Attributes

LineEnd left_end
LineEnd right_end

Protected Attributes

boolean show_capacity = true
boolean deleted = false
Node left_node
Node right_node
int left_capacity
int right_capacity

Detailed Description

Line class The Line class implements a generic line for connecting two nodes in a network. Each line has two ends, and both must be connected to already existing nodes.
Author(s):
Darko Vasić , Tomislav Petković , Zvonko Kostanjčar

Definition at line 22 of file Line.java.


Constructor & Destructor Documentation

Line::Line ( Node left,
Node right,
int capacity ) [inline]
 

Default constructor. Line can be created only if both starting and ending nodes are known. Line capacity must also be specified (symmetric line is assumed).

Parameters:
left   Node at left end.
rignt   Node at right end.
capcacity   Line capacity (symmetric line).

Definition at line 78 of file Line.java.

00079     {
00080         left_end = new LineEnd(this);
00081         right_end = new LineEnd(this);
00082         left_node = left;
00083         right_node = right;
00084         left_node.attach(left_end, right_node);
00085         right_node.attach(right_end, left_node);
00086         left_capacity = capacity;
00087         right_capacity = capacity;
00088         left_end.setCapacity(left_capacity);
00089         right_end.setCapacity(right_capacity);
00090     }

Line::Line ( Node left,
Node right,
int leftCapacity,
int rightCapacity ) [inline]
 

Normal constructor. Line can be created only if both starting and ending nodes are known (left and right node). Asymmetric line is created.

Parameters:
left   Node at left end.
rignt   Node at right end.
left_capcacity   Line capacity for left-to-right transfer.
right_capcacity   Line capacity for left-to-right transfer.

Definition at line 102 of file Line.java.

00103     {
00104         left_end = new LineEnd(this);
00105         right_end = new LineEnd(this);
00106         left_node = left;
00107         right_node = right;
00108         left_end.setCapacity(left_capacity);
00109         right_end.setCapacity(right_capacity);
00110         left_node.attach(left_end, right_node);
00111         right_node.attach(right_end, left_node);
00112         this.left_capacity = left_capacity;
00113         this.right_capacity = right_capacity;
00114     }


Member Function Documentation

boolean Line::areEndingNodes ( Node first_node,
Node second_node ) [inline]
 

Test if ending nodes are equal to given nodes.

Parameters:
first_node   First node reference.
second_node   Second node reference.
Returns:
Returns true if nodes match.

Definition at line 238 of file Line.java.

Referenced by CyclopsSimulator::deleteLine().

00239     {
00240         if (left_node == first_node)
00241             {
00242                 if (right_node == second_node)
00243                     {
00244                         return true;
00245                     }
00246             }
00247         else if (right_node == first_node)
00248             {
00249                 if (left_node == second_node)
00250                     {
00251                         return true;
00252                     }
00253             }
00254         return false;
00255     }

void Line::delete ( ) [inline]
 

Deletes line.

Definition at line 215 of file Line.java.

Referenced by LineEnd::delete(), and CyclopsSimulator::deleteLine().

00216     {
00217         right_node.detach(right_end);
00218         left_node.detach(left_end);
00219         deleted = true;
00220     }

int Line::getCapacity ( ) [inline]
 

Gets line capacity. If line is asymmetric returns minimal capacity.

Returns:
Minimal line capacity.

Definition at line 142 of file Line.java.

00143     {
00144         if (left_capacity < right_capacity)
00145             {
00146                 return left_capacity;
00147             }
00148         else
00149             {
00150                 return right_capacity;
00151             }
00152     }

int Line::getLeftToRightCapacity ( ) [inline]
 

Gets line capacity for left-to-right transfer.

Returns:
Line capacity.

Definition at line 159 of file Line.java.

00160     {
00161         return left_capacity;
00162     }

int Line::getRightToLeftCapacity ( ) [inline]
 

Gets line capacity for right-to-left transfer.

Returns:
Line capacity.

Definition at line 170 of file Line.java.

00171     {
00172         return right_capacity;
00173     }

boolean Line::isDisconnected ( ) [inline]
 

Test if line is disconnected.

Definition at line 226 of file Line.java.

Referenced by CyclopsSimulator::deleteNode().

00227     {
00228         return deleted;
00229     }

void Line::paint ( Graphics g,
FontMetrics metrics,
Color line_color,
Color left_packet_color,
Color right_packet_color,
Color traced_packet_color,
boolean show_line_capacity,
boolean show_all_packets ) [inline]
 

Draws line on screen.

Parameters:
g   Graphics reference.
metrics   Font metrics required for capacity.
line_color   Color.
left_packet_color   Color for packets traveling form left to right.
right_packet_color   Color for packets traveling form right to left.
show_line_capacity   Capacity flag.
show_all_packets   Show all packets flag.

Definition at line 304 of file Line.java.

00309     {
00310         int x1;
00311         int y1;
00312         int x2;
00313         int y2;
00314         int x;
00315         int y;
00316         int i;
00317         Packet packet;
00318 
00319         x1 = left_node.getXCoordinate();
00320         y1 = left_node.getYCoordinate();
00321         x2 = right_node.getXCoordinate();
00322         y2 = right_node.getYCoordinate();
00323         g.setColor(line_color);
00324         g.drawLine(x1, y1, x2, y2);
00325         x = x1 + (x2 - x1) / 2;
00326         y = y1 + (y2 - y1) / 2;
00327         if (show_line_capacity)
00328             {
00329                 String capacity;
00330                 if (left_capacity < right_capacity)
00331                     {
00332                         capacity = String.valueOf(left_capacity);
00333                     }
00334                 else
00335                     {
00336                         capacity = String.valueOf(left_capacity);
00337                     }
00338                 g.setColor(Color.black);
00339                 g.drawString(capacity, x, y);
00340             }
00341         /* if */ /* show_line_capacity */
00342         boolean axis = Math.abs(y2 - y1) > Math.abs(x2 - x1);
00343         if (show_all_packets)
00344             {
00345                 x = x1 + (x2 - x1) / 2;
00346                 y = y1 + (y2 - y1) / 2;
00347                 for (i=0; i<left_end.size(); i++)
00348                     {
00349                         if (axis) y = y + 6;
00350                         else x = x + 6;
00351                         packet = (Packet)left_end.elementAt(i);
00352                         if (packet.getDrawingFlag())
00353                             {
00354                                 packet.paint(g, metrics, traced_packet_color, x, y);
00355                             }
00356                         else
00357                             {
00358                                 packet.paint(g, metrics, left_packet_color, x, y);
00359                             }
00360                     }
00361                 /* for */
00362                 for (i=0; i<right_end.size(); i++)
00363                     {
00364                         if (axis) y = y + 6;
00365                         else x = x + 6;
00366                         packet = (Packet)right_end.elementAt(i);
00367                         if (packet.getDrawingFlag())
00368                             {
00369                                 packet.paint(g, metrics, traced_packet_color, x, y);
00370                             }
00371                         else
00372                             {
00373                                 packet.paint(g, metrics, right_packet_color, x, y);
00374                             }
00375                     }
00376                 /* for */
00377             }
00378         else
00379             {
00380                 x = x1 + (x2 - x1) / 2;
00381                 y = y1 + (y2 - y1) / 2;
00382                 for (i=0; i<left_end.size(); i++)
00383                     {
00384                         packet = (Packet)left_end.elementAt(i);
00385                         if (packet.getDrawingFlag())
00386                             {
00387                                 if (axis) y = y + 6;
00388                                 else x = x + 6;
00389                                 packet.paint(g, metrics, traced_packet_color, x, y);
00390                             }
00391                     }
00392                 /* for */
00393                 for (i=0; i<right_end.size(); i++)
00394                     {
00395                         packet = (Packet)right_end.elementAt(i);
00396                         if (packet.getDrawingFlag())
00397                             {
00398                                 if (axis) y = y + 6;
00399                                 else x = x + 6;
00400                                 packet.paint(g, metrics, traced_packet_color, x, y);
00401                             }
00402                     }
00403                 /* for */
00404             }
00405         /* if else */ /* show_all_packets */
00406     }

void Line::paint ( Graphics g,
FontMetrics metrics,
Color line_color ) [inline]
 

Draws line on screen.

Parameters:
g   Graphics reference.
metrics   Font metrics required for capacity.
line_color   Color.

Definition at line 264 of file Line.java.

Referenced by CyclopsSimulator::paint().

00265     {
00266         int x1;
00267         int y1;
00268         int x2;
00269         int y2;
00270 
00271         x1 = left_node.getXCoordinate();
00272         y1 = left_node.getYCoordinate();
00273         x2 = right_node.getXCoordinate();
00274         y2 = right_node.getYCoordinate();
00275         g.setColor(line_color);
00276         g.drawLine(x1, y1, x2, y2);
00277         if (show_capacity)
00278             {
00279                 String capacity;
00280                 if (left_capacity < right_capacity)
00281                     {
00282                         capacity = String.valueOf(left_capacity);
00283                     }
00284                 else
00285                     {
00286                         capacity = String.valueOf(left_capacity);
00287                     }
00288                 g.setColor(Color.black);
00289                 g.drawString(capacity, x1 + (x2 - x1) / 2, y1 + (y2 - y1) / 2);
00290             }
00291     }

void Line::setCapacity ( int capacity ) [inline]
 

Sets line capacity (forces symmetric line).

Parameters:
capacity   Line capacity.

Definition at line 181 of file Line.java.

00182     {
00183         left_capacity = capacity;
00184         right_capacity = capacity;
00185         left_end.setCapacity(left_capacity);
00186         right_end.setCapacity(right_capacity);
00187     }

void Line::setLeftToRightCapacity ( int capacity ) [inline]
 

Sets line capacity for left-to-right transfer.

Parameters:
capacity   Line capacity.

Definition at line 194 of file Line.java.

00195     {
00196         left_capacity = capacity;
00197         left_end.setCapacity(left_capacity);
00198     }

void Line::setRightToLeftCapacity ( int capacity ) [inline]
 

Sets line capacity for right-to-left transfer.

Parameters:
capacity   Line capacity.

Definition at line 205 of file Line.java.

00206     {
00207         right_capacity = capacity;
00208         right_end.setCapacity(right_capacity);
00209     }

void Line::transmitAll ( ) [inline]
 

Passes all packets to appropriate nodes. This function is used in simulation.

Definition at line 121 of file Line.java.

Referenced by CyclopsSimulator::simulate().

00122     {
00123         Object packet;
00124         while ( !left_end.isEmpty() )
00125             {
00126                 packet = left_end.get();
00127                 right_node.receive(packet);
00128             }
00129         while ( !right_end.isEmpty() )
00130             {
00131                 packet = right_end.get();
00132                 left_node.receive(packet);
00133             }
00134     }


Member Data Documentation

boolean Line::deleted = false [protected]
 

Disconnect flag.

Definition at line 32 of file Line.java.

int Line::left_capacity [protected]
 

Line capacity is maximum number of packets that can pass through the line in one simulation cycle. Asyimmetric connections between node are possible.

Definition at line 61 of file Line.java.

LineEnd Line::left_end
 

Left line end. When line is created, node must know is it connected to left or right end.

Definition at line 38 of file Line.java.

Node Line::left_node [protected]
 

Node at left end. Line must know to which nodes it is connected.

Definition at line 49 of file Line.java.

int Line::right_capacity [protected]
 

Line capacity is maximum number of packets that can pass through the line in one simulation cycle. Asyimmetric connections between node are possible.

Definition at line 68 of file Line.java.

LineEnd Line::right_end
 

Right line end. When line is created, node must know is it connected to left or right end.

Definition at line 44 of file Line.java.

Node Line::right_node [protected]
 

Node at right end. Line must know to which nodes it is connected.

Definition at line 54 of file Line.java.

boolean Line::show_capacity = true [protected]
 

Show capacity flag. If set, minimum capacity will be diplayed on screen.

Definition at line 29 of file Line.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