uk.org.arlott.simon.hw.f24.lbsta
Class NetworkEdit

java.lang.Object
  extended by uk.org.arlott.simon.hw.f24.lbsta.NetworkEdit
All Implemented Interfaces:
java.util.EventListener, javax.swing.event.ChangeListener, CommonInterface

public class NetworkEdit
extends java.lang.Object
implements CommonInterface, javax.swing.event.ChangeListener

Network editing mode.


Field Summary
private  LAN from
          LAN when placing a Host.
private  java.awt.Point lastPos
          Placement last position.
private  boolean lastTest
          Last add test result.
private  MainWindow mainWindow
          The MainWindow.
static int MODIFY_OBJECT
          Modifying object state.
private  boolean mouseDown
          Mouse up/down state.
private  int mouseOrtho
          Host horizontal/vertical type.
private  java.awt.Point mousePos
          Placement current position.
private  java.awt.Point mouseStart
          Placement start position.
private  java.lang.Object moved
          Component being moved.
private  java.util.HashSet<Host> movedHosts
          Hosts being moved with a LAN.
private  LAN moveLAN
          Original LAN when moving a Host.
private  java.awt.Point movePos
          Movement current position.
private  java.awt.Point moveStart
          Movement start position.
private  boolean moving
          Moving status.
private  Network network
          The Network.
static int NONE
          "NONE"
static int ORTHO_HORIZ
          Horizontal Host.
static int ORTHO_VERTI
          Vertical Host.
static int PLACING_BRIDGE
          Placing Bridge state.
static int PLACING_HOST
          Placing Host state.
static int PLACING_LAN
          Placing LAN state.
private  int state
          Current state.
private  boolean validMove
          Valid move flag.
 
Fields inherited from interface uk.org.arlott.simon.hw.f24.lbsta.CommonInterface
MOUSE_PRIMARY, MOUSE_SECONDARY
 
Constructor Summary
NetworkEdit(Network network, MainWindow mainWindow)
          Creates a new NetworkEdit object.
 
Method Summary
private  void abort(boolean all)
          Aborts the current operation.
private  void finishMove(boolean abort)
          Finish moving components.
private static java.awt.Point getOrthoLine(java.awt.Point start, java.awt.Point finish)
          Gets an orthognonal line for two positions.
 int getState()
          Gets the current state.
 void hide()
          Switches from this mode.
 boolean keyPressed(int keyCode)
          Handles keyboard input.
 boolean mouseClick(int button, java.lang.Object hover)
          Handles mouse clicks.
 boolean mouseMoved(java.awt.Point position, java.lang.Object hover)
          Handles mouse movement.
 void paint(java.awt.Graphics g, java.awt.Dimension size)
          Draws additional information on the network.
 void setState(int state)
          Sets the current state and updates the status text.
 void show()
          Switches to this mode.
 void stateChanged(javax.swing.event.ChangeEvent ce)
          Handles the setting of component being edited changing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NONE

public static final int NONE
"NONE"

See Also:
Constant Field Values

MODIFY_OBJECT

public static final int MODIFY_OBJECT
Modifying object state.

See Also:
Constant Field Values

PLACING_LAN

public static final int PLACING_LAN
Placing LAN state.

See Also:
Constant Field Values

PLACING_HOST

public static final int PLACING_HOST
Placing Host state.

See Also:
Constant Field Values

PLACING_BRIDGE

public static final int PLACING_BRIDGE
Placing Bridge state.

See Also:
Constant Field Values

ORTHO_HORIZ

public static final int ORTHO_HORIZ
Horizontal Host.

See Also:
Constant Field Values

ORTHO_VERTI

public static final int ORTHO_VERTI
Vertical Host.

See Also:
Constant Field Values

network

private Network network
The Network.


mainWindow

private MainWindow mainWindow
The MainWindow.


mouseDown

private boolean mouseDown
Mouse up/down state.


mouseStart

private java.awt.Point mouseStart
Placement start position.


mousePos

private java.awt.Point mousePos
Placement current position.


lastPos

private java.awt.Point lastPos
Placement last position.


lastTest

private boolean lastTest
Last add test result.


mouseOrtho

private int mouseOrtho
Host horizontal/vertical type.


state

private int state
Current state.


from

private LAN from
LAN when placing a Host.


moving

private boolean moving
Moving status.


moveStart

private java.awt.Point moveStart
Movement start position.


movePos

private java.awt.Point movePos
Movement current position.


moveLAN

private LAN moveLAN
Original LAN when moving a Host.


validMove

private boolean validMove
Valid move flag.


moved

private java.lang.Object moved
Component being moved.


movedHosts

private java.util.HashSet<Host> movedHosts
Hosts being moved with a LAN.

Constructor Detail

NetworkEdit

public NetworkEdit(Network network,
                   MainWindow mainWindow)
Creates a new NetworkEdit object.

Parameters:
network - The Network.
mainWindow - The MainWindow.
Method Detail

show

public void show()
Switches to this mode.

Specified by:
show in interface CommonInterface

hide

public void hide()
Switches from this mode.

Specified by:
hide in interface CommonInterface

stateChanged

public void stateChanged(javax.swing.event.ChangeEvent ce)
Handles the setting of component being edited changing.

Specified by:
stateChanged in interface javax.swing.event.ChangeListener
Parameters:
ce - Ignored.

mouseClick

public boolean mouseClick(int button,
                          java.lang.Object hover)
Handles mouse clicks.

Specified by:
mouseClick in interface CommonInterface
Parameters:
button - The mouse button used.
hover - The network component that the mouse pointer is over.
Returns:
true if the network should be redrawn.

mouseMoved

public boolean mouseMoved(java.awt.Point position,
                          java.lang.Object hover)
Handles mouse movement.

Specified by:
mouseMoved in interface CommonInterface
Parameters:
position - The mouse position.
hover - The network component that the mouse pointer is over.
Returns:
true if the network should be redrawn.

keyPressed

public boolean keyPressed(int keyCode)
Handles keyboard input.

Specified by:
keyPressed in interface CommonInterface
Parameters:
keyCode - The key pressed.
Returns:
true if the network should be redrawn.

abort

private void abort(boolean all)
Aborts the current operation.

Parameters:
all - true to completely abort including removing the side panel.

finishMove

private void finishMove(boolean abort)
Finish moving components.

Parameters:
abort - true to abort the move and return the components to their original positions.

getState

public int getState()
Gets the current state.

Returns:
The state of this mode.

setState

public void setState(int state)
Sets the current state and updates the status text.

Parameters:
state - The new state of this mode.

paint

public void paint(java.awt.Graphics g,
                  java.awt.Dimension size)
Draws additional information on the network.

Specified by:
paint in interface CommonInterface
Parameters:
g - The Graphics object to draw on.
size - The size of the area available.

getOrthoLine

private static java.awt.Point getOrthoLine(java.awt.Point start,
                                           java.awt.Point finish)
Gets an orthognonal line for two positions.

Parameters:
start - The start point.
finish - The finish point.
Returns:
The new finish point.