verinec.gui.core
Class PCNode

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JLabel
                  extended by verinec.gui.core.NwComponent
                      extended by verinec.gui.core.NwNode
                          extended by verinec.gui.core.PCNode
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, SwingConstants

public class PCNode
extends NwNode

Represents a node of the network. Do not create directly, but use VerinecStudio.addNode(int,int)

A node must know its interfaces and be able to calculate the positions for new interfaces.
A node can be created from XML definition or as a new node that is added to the XML.

Author:
Renato Loeffel, david.buchmann at unifr.ch
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class verinec.gui.core.NwNode
NwNode.MoveKeyListener
 
Nested classes/interfaces inherited from class verinec.gui.core.NwComponent
NwComponent.Mouse
 
Nested classes/interfaces inherited from class javax.swing.JLabel
JLabel.AccessibleJLabel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
private static String defaultIcon
           
private  boolean deleting
          To know if the node is currently being deleted.
static int IF_ABOVE
          Interface is to be placed above node.
static int IF_BELOW
          Interface is to be placed below node.
static int IF_LEFT
          Interface is to be placed on the left side of node.
static int IF_RIGHT
          Interface is to be placed on the right side of node.
private  Vector[] interfaces
          array of the 4 sides of the node for interfaces.
 
Fields inherited from class verinec.gui.core.NwNode
dragged
 
Fields inherited from class verinec.gui.core.NwComponent
componentIcon, componentIconNeg, config, drawPanel, gui, pos, selection, type
 
Fields inherited from class javax.swing.JLabel
labelFor
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
PCNode(Element config, VerinecStudio gui)
          Use to create a node from a JDom definition element.
PCNode(int posX, int posY, VerinecStudio gui)
          Do not use outside VerinecStudio, but use VerinecStudio.addNode(int,int) Creates a new node with no interfaces and a random number as name.
 
Method Summary
protected static Element createElement(int posX, int posY)
          Creates a skeleton of a minimal node Element.
 NwInterface createInterface(int type)
          Creates and adds an interface of the specified type to the node.
 void delete()
          Deletes the component and all its interfaces.
 String getDomain()
          The domain this host is in.
private  Point getInterfacePosition(int side, int pos, int sidecount)
          Get the location for the pos-th interface on specified side of the node.
 Vector getInterfaces()
          Returns a Vector containing all the interfaces attached to this node.
private  int getMaxInterfaceCount()
          Get the largest number of interfaces found on one side.
 String getName()
          Get the name of this node.
private  int getNextInterfaceSide()
          Get the next side to put an interface at.
 int getType()
          Get the network type - which is invalid for a node.
protected  void guiAddInterface(NwInterface iface, int side)
          Add an interface to the graphical representation of the node.
protected  void guiRemoveInterface(NwInterface iface, int side)
          Remove an interface to the graphical representation of the node.
protected  void removeInterface(NwInterface nwInterface)
          Removes the specified interface from the node and - if needed - resizes the node.
private  void scale(int correction)
          Changes the size of the node by 2*correction pixels.
 void setBounds(int x, int y, int w, int h)
          Moves the node and all its interfaces.
 void setInterfaceSide(NwInterface i, int oldside, int newside)
          Set on which side an interface should be located.
 
Methods inherited from class verinec.gui.core.NwNode
addNodeinfoElement, createNodeInfo, getLayoutChild, initialize, resizeComponent
 
Methods inherited from class verinec.gui.core.NwComponent
addContextMenu, addContextMenuSeparator, changeIcon, getAbsX, getAbsY, getConfig, getDefaultSize, getRandomId, isSelected, moveComponent, resizeDefaultSize, setBounds, setLocation, setLocation, setSelected, showIcon
 
Methods inherited from class javax.swing.JLabel
checkHorizontalKey, checkVerticalKey, getAccessibleContext, getDisabledIcon, getDisplayedMnemonic, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getLabelFor, getText, getUI, getUIClassID, getVerticalAlignment, getVerticalTextPosition, imageUpdate, paramString, setDisabledIcon, setDisplayedMnemonic, setDisplayedMnemonic, setDisplayedMnemonicIndex, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabelFor, setText, setUI, setVerticalAlignment, setVerticalTextPosition, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

defaultIcon

private static String defaultIcon

interfaces

private Vector[] interfaces
array of the 4 sides of the node for interfaces.


IF_RIGHT

public static final int IF_RIGHT
Interface is to be placed on the right side of node.

See Also:
Constant Field Values

IF_BELOW

public static final int IF_BELOW
Interface is to be placed below node.

See Also:
Constant Field Values

IF_LEFT

public static final int IF_LEFT
Interface is to be placed on the left side of node.

See Also:
Constant Field Values

IF_ABOVE

public static final int IF_ABOVE
Interface is to be placed above node.

See Also:
Constant Field Values

deleting

private boolean deleting
To know if the node is currently being deleted. Avoids problems when removing the interfaces.

Constructor Detail

PCNode

public PCNode(int posX,
              int posY,
              VerinecStudio gui)
Do not use outside VerinecStudio, but use VerinecStudio.addNode(int,int) Creates a new node with no interfaces and a random number as name.

Parameters:
posX - The horizontal postition of the node.
posY - The vertical postition of the node.
gui - The main application.

PCNode

public PCNode(Element config,
              VerinecStudio gui)
Use to create a node from a JDom definition element. This is the case when the node is loaded from file. Namespace of config must be VerinecNamespaces.NS_NODE Does not register the XML in the VerinecStudio node tree.

Parameters:
config - The XML element containing the node.
gui - The main application.
Method Detail

getType

public int getType()
Get the network type - which is invalid for a node.

Overrides:
getType in class NwComponent
Returns:
Never returns correctly, because you should never call this method on a node.
Throws:
RuntimeException - Always throws a RuntimeException.
See Also:
NetworkTypes

createElement

protected static Element createElement(int posX,
                                       int posY)
Creates a skeleton of a minimal node Element. The node name is set to an arbitrary number to be unique and should be changed later.

Parameters:
posX - the x postition of the node.
posY - the y postition of the node.
Returns:
the element of the node.

setBounds

public final void setBounds(int x,
                            int y,
                            int w,
                            int h)
Moves the node and all its interfaces.

Overrides:
setBounds in class NwNode
Parameters:
x - Top left corner x coordinate
y - Top left corner y coordinate
w - With of component
h - Height of component

delete

public final void delete()
Deletes the component and all its interfaces.

Overrides:
delete in class NwComponent

getInterfaces

public final Vector getInterfaces()
Returns a Vector containing all the interfaces attached to this node.

Returns:
All interfaces of the node.

setInterfaceSide

public void setInterfaceSide(NwInterface i,
                             int oldside,
                             int newside)
Set on which side an interface should be located.

Parameters:
i - The interface to change.
oldside - The side the interface is currently located on.
newside - The side to move the interface to.

getName

public final String getName()
Get the name of this node. Overwrites the JComponent method. Use the XML configuration to set the host name and tell the gui with VerinecStudio.nwComponentStateChanged(NwComponent).

Overrides:
getName in class Component
Returns:
hostname attribute value of the configuration.

getDomain

public final String getDomain()
The domain this host is in.

Returns:
Absolute Domain Name of this Host, or null if not specified

removeInterface

protected final void removeInterface(NwInterface nwInterface)
Removes the specified interface from the node and - if needed - resizes the node.

Parameters:
nwInterface - the interface that shall be removed.

createInterface

public final NwInterface createInterface(int type)
Creates and adds an interface of the specified type to the node.

Parameters:
type - The network type. Must be one of NetworkTypes.getTypes()
Returns:
The newly created interface
See Also:
NetworkTypes

guiAddInterface

protected void guiAddInterface(NwInterface iface,
                               int side)
Add an interface to the graphical representation of the node. Do never manipulate the vectors in interfaces directly!

Parameters:
iface - The interface to add.
side - The side to add the interface on (one of IF_ABOVE, IF_RIGHT, IF_BELOW, IF_LEFT).

guiRemoveInterface

protected void guiRemoveInterface(NwInterface iface,
                                  int side)
Remove an interface to the graphical representation of the node. Do never manipulate the vectors in interfaces directly!

Parameters:
iface - The interface to remove.
side - The side the interface is located (one of IF_ABOVE, IF_RIGHT, IF_BELOW, IF_LEFT).

getNextInterfaceSide

private final int getNextInterfaceSide()
Get the next side to put an interface at. Returns the right side if all sides are full, but guiAddInterface takes care of scaling the node.

Returns:
The side to add the interface.

scale

private void scale(int correction)
Changes the size of the node by 2*correction pixels. (Scaling from the center point.)

Parameters:
correction - Modification of node size in pixels, may be negative to make node smaller.

getInterfacePosition

private Point getInterfacePosition(int side,
                                   int pos,
                                   int sidecount)
Get the location for the pos-th interface on specified side of the node. If there is only one interface, we center it. Otherwise, they are arranged clockwise in slots (it is too complicated to arrange them evenly and it results in less shifting around the interfaces.).

Parameters:
side - Side of the node.
pos - Position in the list on that side.
sidecount - The number of nodes this side will have. (Needed in case the interface is to be added.)
Returns:
Top left corner for the interface.

getMaxInterfaceCount

private int getMaxInterfaceCount()
Get the largest number of interfaces found on one side.

Returns:
The number of interfaces on the largest side.

Copyright © 2005 Verinec, DIUF