entorno.grafo
Class DrawingArea

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by entorno.grafo.DrawingArea
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.print.Printable, java.io.Serializable

public class DrawingArea
extends javax.swing.JPanel
implements java.awt.print.Printable

Clase: DrawingArea Funcion: Clase del area de dibujo.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 int ADD_EDGE
           
 int ADD_NODE
           
private  int clickAction
          the current action to take when a click occurs in this drawing area
private  GraphGUI controller
           
 int DIRECTED_PROPERTY
           
private  int EDGE_ARROW_SIZE
           
private  double escala
           
 Graph graph
           
private  int maxAction
           
 int MOVE_NODE
           
private  int MULTI_EDGE_SEP_SIZE
           
private  int nextNodeIndex
           
 int NO_ACTION
           
private  int nodeRadius
           
private  java.util.HashSet nodos_selecc
           
 int PREDEFINIR
           
private  java.awt.Dimension preferredSize
           
private  java.awt.print.PageFormat printerPageFormat
           
private  java.awt.Point pto_click_nodo
           
private  java.awt.Point pto_final
           
private  java.awt.Point pto_origen
           
 int REMOVE_EDGE
           
 int REMOVE_NODE
           
 int RENOMBRAR
           
private  boolean seleccionando
           
private  Graph.Node startNode
           
 java.lang.String[] statusTexts
          the messages to display in the status bar for each click action
private  Graph.Node stopNode
           
 boolean verDefinicionFull
           
 boolean verInc_BOOL
           
 boolean verInc_UP
           
 boolean verPredefinidos
           
 
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 java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
DrawingArea(GraphGUI controller)
          Constructor.
 
Method Summary
private  void actualizarNodosSelecc(java.awt.Point pto_destino)
           
 boolean addEdge(Graph.Node n1, Graph.Node n2)
          Añade una arista al Grafo n1 : nodo comienzo n2 : nodo final Devuelve true si la arista se ha añadido bien
 boolean addNode(java.awt.Point position)
          Añade un nodo al grafo Devuelve true si el nodo se ha añadido bien
private  float distance(java.awt.Point point1, java.awt.Point point2)
          Devuelve la distancia entre 2 puntos
private  void drawCurve(java.awt.Graphics g, java.awt.Point start, java.awt.Point mid, java.awt.Point stop)
          Dibuja una curva desde start, pasando por mid y terminando en stop
private  void drawEdge(java.awt.Graphics g, Graph.Node node, Graph.Edge edge)
          Dibuja 1 arista en el grafo.
private  void drawNode(java.awt.Graphics g, Graph.Node node)
          Dibuja un nodo en el grafo
private  boolean estaNodoEnArea(Graph.Node n, java.awt.Rectangle a)
           
private  Graph.Node findNodeAtPosition(java.awt.Point position)
          Encuentro el nodo dado en la posición Devuelve el nodo encontrado o null si no lo ha encontrado
 double getEscala()
           
 java.awt.Dimension getPreferredSize()
           
 int getRadioNodo()
           
private  boolean isSeleccionando()
           
private  java.awt.Point keepNodeInside(java.awt.Point position)
          Ajusta la posición del nodo si es necesario para que quepa en el area.
private  void moverNodosSelecc(int dist_x, int dist_y)
           
 void newGraph()
           
 void paintComponent(java.awt.Graphics g)
          Método que pinta en el area de dibujo el grafico 'g'
 int print(java.awt.Graphics g, java.awt.print.PageFormat pf, int pi)
          Imprime el grafo g con el formato de pagina pf y el nº de pagina pi.
 void printerSetup()
           
 void printThis()
           
 boolean randomGraph()
           
 boolean removeNode(java.awt.Point position)
          Borra un nodo del grafo que esté en la posición dada Devuelve true si el nodo ha sido borrado
 void resetGraph()
           
 void setClickAction(int action)
           
 void setEscala(double newEscala)
           
 void setGraph(Graph g)
           
 void setNextNodeIndex()
           
 void setProperty(int prop, boolean state)
          Establece las propiedades del grafo.
 void setRadioNodo(int r)
           
private  void setSeleccionando(boolean v)
           
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, 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, 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, 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, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, 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, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, 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

controller

private GraphGUI controller

graph

public Graph graph

verPredefinidos

public boolean verPredefinidos

verDefinicionFull

public boolean verDefinicionFull

verInc_BOOL

public boolean verInc_BOOL

verInc_UP

public boolean verInc_UP

escala

private double escala

startNode

private Graph.Node startNode

stopNode

private Graph.Node stopNode

nextNodeIndex

private int nextNodeIndex

preferredSize

private java.awt.Dimension preferredSize

nodeRadius

private int nodeRadius

pto_click_nodo

private java.awt.Point pto_click_nodo

pto_origen

private java.awt.Point pto_origen

pto_final

private java.awt.Point pto_final

nodos_selecc

private java.util.HashSet nodos_selecc

seleccionando

private boolean seleccionando

EDGE_ARROW_SIZE

private final int EDGE_ARROW_SIZE
See Also:
Constant Field Values

MULTI_EDGE_SEP_SIZE

private final int MULTI_EDGE_SEP_SIZE
See Also:
Constant Field Values

printerPageFormat

private java.awt.print.PageFormat printerPageFormat

DIRECTED_PROPERTY

public final int DIRECTED_PROPERTY
See Also:
Constant Field Values

NO_ACTION

public final int NO_ACTION
See Also:
Constant Field Values

ADD_NODE

public final int ADD_NODE
See Also:
Constant Field Values

ADD_EDGE

public final int ADD_EDGE
See Also:
Constant Field Values

MOVE_NODE

public final int MOVE_NODE
See Also:
Constant Field Values

REMOVE_NODE

public final int REMOVE_NODE
See Also:
Constant Field Values

REMOVE_EDGE

public final int REMOVE_EDGE
See Also:
Constant Field Values

RENOMBRAR

public final int RENOMBRAR
See Also:
Constant Field Values

PREDEFINIR

public final int PREDEFINIR
See Also:
Constant Field Values

maxAction

private final int maxAction
See Also:
Constant Field Values

clickAction

private int clickAction
the current action to take when a click occurs in this drawing area


statusTexts

public final java.lang.String[] statusTexts
the messages to display in the status bar for each click action

Constructor Detail

DrawingArea

public DrawingArea(GraphGUI controller)
Constructor. El controller es el frame padre

Method Detail

setSeleccionando

private void setSeleccionando(boolean v)

isSeleccionando

private boolean isSeleccionando()

moverNodosSelecc

private void moverNodosSelecc(int dist_x,
                              int dist_y)

estaNodoEnArea

private boolean estaNodoEnArea(Graph.Node n,
                               java.awt.Rectangle a)

actualizarNodosSelecc

private void actualizarNodosSelecc(java.awt.Point pto_destino)

setEscala

public void setEscala(double newEscala)

getEscala

public double getEscala()

setRadioNodo

public void setRadioNodo(int r)

getRadioNodo

public int getRadioNodo()

setGraph

public void setGraph(Graph g)

paintComponent

public void paintComponent(java.awt.Graphics g)
Método que pinta en el area de dibujo el grafico 'g'

Overrides:
paintComponent in class javax.swing.JComponent

getPreferredSize

public java.awt.Dimension getPreferredSize()
Overrides:
getPreferredSize in class javax.swing.JComponent

printerSetup

public void printerSetup()

printThis

public void printThis()

print

public int print(java.awt.Graphics g,
                 java.awt.print.PageFormat pf,
                 int pi)
          throws java.awt.print.PrinterException
Imprime el grafo g con el formato de pagina pf y el nº de pagina pi. Devuelve si será impresa o no la pagina

Specified by:
print in interface java.awt.print.Printable
Throws:
java.awt.print.PrinterException

newGraph

public void newGraph()

randomGraph

public boolean randomGraph()

setClickAction

public void setClickAction(int action)

resetGraph

public void resetGraph()

setProperty

public void setProperty(int prop,
                        boolean state)
Establece las propiedades del grafo. prop : la propiedad state : estado de la propiedad


setNextNodeIndex

public void setNextNodeIndex()

keepNodeInside

private java.awt.Point keepNodeInside(java.awt.Point position)
Ajusta la posición del nodo si es necesario para que quepa en el area. position: la posicion Devuelve la posición ajustada


addNode

public boolean addNode(java.awt.Point position)
Añade un nodo al grafo Devuelve true si el nodo se ha añadido bien


addEdge

public boolean addEdge(Graph.Node n1,
                       Graph.Node n2)
Añade una arista al Grafo n1 : nodo comienzo n2 : nodo final Devuelve true si la arista se ha añadido bien


removeNode

public boolean removeNode(java.awt.Point position)
Borra un nodo del grafo que esté en la posición dada Devuelve true si el nodo ha sido borrado


findNodeAtPosition

private Graph.Node findNodeAtPosition(java.awt.Point position)
Encuentro el nodo dado en la posición Devuelve el nodo encontrado o null si no lo ha encontrado


distance

private float distance(java.awt.Point point1,
                       java.awt.Point point2)
Devuelve la distancia entre 2 puntos


drawNode

private void drawNode(java.awt.Graphics g,
                      Graph.Node node)
Dibuja un nodo en el grafo


drawEdge

private void drawEdge(java.awt.Graphics g,
                      Graph.Node node,
                      Graph.Edge edge)
Dibuja 1 arista en el grafo. La arista comienza en el nodo dado


drawCurve

private void drawCurve(java.awt.Graphics g,
                       java.awt.Point start,
                       java.awt.Point mid,
                       java.awt.Point stop)
Dibuja una curva desde start, pasando por mid y terminando en stop