medusa.display
Class BasicGraphPanel
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- medusa.display.BasicGraphRenderer
-
- medusa.display.BasicGraphPanel
-
- All Implemented Interfaces:
- java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.lang.Runnable, java.util.EventListener, javax.accessibility.Accessible
- Direct Known Subclasses:
- DisplayPanel, EditableGraphPanel, ExamplePanel, MedusaAppletPanel, SamplePanel
public class BasicGraphPanel extends BasicGraphRenderer implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.lang.Runnable
A panel that handles graphs, loads and saves them (I may move this to a higher level soon) and displays them Most often, any extending classes will override the display methods, especiallypaintNodeandpaintEdge.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Field Summary
Fields Modifier and Type Field and Description static doubleoffsetOffset for drawing labelsbooleanrunning-
Fields inherited from class medusa.display.BasicGraphRenderer
alpha, arrow, basicEdgeColor, dims, fontColor, fontSize, graph, hideWhenMove, label, nodeFont, nodeSize, pretty, showAnnotation, showConfidence
-
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
-
Constructor Summary
Constructors Constructor and Description BasicGraphPanel()BasicGraphPanel(MedusaSettings stringSettings)Constructs a newBasicGraphPanelwith settings
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidautoFixOrientation()Automatically fixes orientationsvoidcalculateEdgeLength()voidchangeFont(int size)Set font sizevoidchangeNodeColor(java.awt.Color color)voidchangeNodeColor(int red, int green, int blue)java.lang.StringcolorToString(java.awt.Color color)Gets a color as a stringvoidenergy()booleanfindLabel(java.lang.String expression)Finds the node matching the regular expressionjava.awt.ColorgetColor(java.lang.Integer i)Returns the color for interaction ijava.awt.RectanglegetCurrentRect()doublegetEdgeLen()Returns the current edge lengthNodegetPick()java.lang.StringgetToolTipText(java.awt.event.MouseEvent e)GraphgetVisibleGraph()voidhandleLeftMouseDragged(java.awt.event.MouseEvent e)voidhandlePressLeftButton_backup(java.awt.event.MouseEvent e)voidhandlePressLeftButton(java.awt.event.MouseEvent e)voidinitEdges()Inits edges, fixes orientationvoidinvertFix()booleanisBox()booleanisRunning()voidmirror(boolean xFlip, boolean yFlip)Mirrors graph vertically or horizontally (or both)voidmouseClicked(java.awt.event.MouseEvent e)voidmouseDragged(java.awt.event.MouseEvent e)voidmouseEntered(java.awt.event.MouseEvent e)voidmouseExited(java.awt.event.MouseEvent e)voidmouseMoved(java.awt.event.MouseEvent e)voidmousePressed(java.awt.event.MouseEvent e)voidmouseReleased(java.awt.event.MouseEvent e)voidpaintComponent(java.awt.Graphics g)Paints the componentvoidpaintPick(java.awt.Graphics2D g)Paints the selected nodevoidrandomGraph(int nNodes, int nEdges)Creates a random graphvoidrotate(double t)Rotates graphvoidrun()voidsaveImage(java.lang.String path, int param)Saves graph as an imagevoidsetAbsoluteScale(double scale)voidsetAlpha(boolean trueOrFalse)Setting this to true results in a composite effect on edges based on the confidence level of the edge.voidsetAnnotation(boolean trueOrFalse)Show annotation instead of node namesvoidsetArrows(boolean trueOrFalse)Settrueif you want to show edges as directed.voidsetBackgroundColor(java.awt.Color c)Background colorvoidsetBasicEdgeColor(java.awt.Color color)Sets the basic edge color.voidsetColor(java.lang.Integer i, java.awt.Color color)Sets the color for interaction i inMedusaSettings.voidsetConfidence(boolean trueOrFalse)Show confidence of edges using either alpha or patternsvoidsetCool(boolean trueOrFalse)Allows cooling of relaxation.voidsetEdgeLen(double newEdgeLen)Manually sets the edge length.voidsetFix(boolean trueOrFalse)Fix or unfix all nodesvoidsetFontColor(java.awt.Color color)Sets the font colorvoidsetGraph(Graph g)todo: move all load functions to the frame!!! enough to set the graphvoidsetHideWhenMove(boolean trueOrFalse)If true, only the moving nodes will be displayed.voidsetLabel(boolean trueOrFalse)Show labels or hide themvoidsetNodeFixed(java.lang.String lbl, boolean fixed)voidsetNodeSize(int nodeSize)Set node sizevoidsetPretty(boolean trueOrFalse)If pretty is selected, multiple edges will be drawn in colors.voidsetScale(double scale)Sets the scale of the graph.voidsetTimeFrameXY(java.awt.Dimension d)voidsetTimeFrameXY(int x, int y)Sets the x and y parameters for the drawing areavoidstart()voidstop()voidupdateNodes()Updates the nodes for quicker repaintingvoidupdateStringSettings(MedusaSettings ss)Sets newMedusaSettings-
Methods inherited from class medusa.display.BasicGraphRenderer
clear, getCurrentNodeColorSet, getFontColor, getGraph, getGraphData, getMinimumSize, getNodeColorSet, getPanelHeight, getPanelWidth, getPreferredSize, getStringSettings, paintEdge, paintNet, paintNode, setCurrentNodeColorSet, setNodeColorSet, setPanelHeight, setPanelWidth, setStringSettings
-
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, 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, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, 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, 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, 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, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
running
public boolean running
-
offset
public static final double offset
Offset for drawing labels- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BasicGraphPanel
public BasicGraphPanel(MedusaSettings stringSettings)
Constructs a newBasicGraphPanelwith settings- Parameters:
stringSettings- settings
-
BasicGraphPanel
public BasicGraphPanel()
-
-
Method Detail
-
setGraph
public void setGraph(Graph g)
todo: move all load functions to the frame!!! enough to set the graph
-
updateNodes
public void updateNodes()
Updates the nodes for quicker repainting
-
getPick
public Node getPick()
-
isRunning
public boolean isRunning()
-
setHideWhenMove
public void setHideWhenMove(boolean trueOrFalse)
If true, only the moving nodes will be displayed. This can be good if you have a large graph, since repainting will occur.- Parameters:
trueOrFalse- True if hide, False (default) if show all nodes while moving
-
setAlpha
public void setAlpha(boolean trueOrFalse)
Setting this to true results in a composite effect on edges based on the confidence level of the edge.- Parameters:
trueOrFalse- True if edges are displayed with alpha
-
changeFont
public void changeFont(int size)
Set font size- Parameters:
size- Font size
-
setNodeSize
public void setNodeSize(int nodeSize)
Set node size- Parameters:
nodeSize- Node size in pixels
-
setBackgroundColor
public void setBackgroundColor(java.awt.Color c)
Background color- Parameters:
c- Color c
-
colorToString
public java.lang.String colorToString(java.awt.Color color)
Gets a color as a string- Parameters:
color- Color color- Returns:
- String representation of color
-
setPretty
public void setPretty(boolean trueOrFalse)
If pretty is selected, multiple edges will be drawn in colors. If not selected, edges are drawn as unique edges and in grey.- Parameters:
trueOrFalse- Boolean pretty
-
setArrows
public void setArrows(boolean trueOrFalse)
Settrueif you want to show edges as directed.- Parameters:
trueOrFalse- Boolean arrows or not
-
setLabel
public void setLabel(boolean trueOrFalse)
Show labels or hide them- Parameters:
trueOrFalse- Boolean true if show labels
-
setConfidence
public void setConfidence(boolean trueOrFalse)
Show confidence of edges using either alpha or patterns- Parameters:
trueOrFalse- true if confidence is to be shown
-
setAnnotation
public void setAnnotation(boolean trueOrFalse)
Show annotation instead of node names- Parameters:
trueOrFalse- true: shows annotation. false: shows node label
-
setBasicEdgeColor
public void setBasicEdgeColor(java.awt.Color color)
Sets the basic edge color.- Parameters:
color- The color that will be used when interactions are not shown
-
setFontColor
public void setFontColor(java.awt.Color color)
Sets the font color- Parameters:
color- Font color
-
getColor
public java.awt.Color getColor(java.lang.Integer i)
Returns the color for interaction i- Parameters:
i- Interaction type- Returns:
- The color as defined
-
setColor
public void setColor(java.lang.Integer i, java.awt.Color color)Sets the color for interaction i inMedusaSettings. This should really be handled at a higher level...- Parameters:
i- Interaction typecolor- Edge color for interaction i
-
getEdgeLen
public double getEdgeLen()
Returns the current edge length- Returns:
- edge length
-
calculateEdgeLength
public void calculateEdgeLength()
-
setEdgeLen
public void setEdgeLen(double newEdgeLen)
Manually sets the edge length. This is the steady-state length between two nodes. Don't expect this as an exact value, since most graphs are more complex than two nodes connected by an edge.- Parameters:
newEdgeLen- New edge length
-
setScale
public void setScale(double scale)
Sets the scale of the graph. large scales will zoom in on the graph, while scales < 1 zoom out.- Parameters:
scale- scale factor
-
setAbsoluteScale
public void setAbsoluteScale(double scale)
-
setTimeFrameXY
public void setTimeFrameXY(int x, int y)Sets the x and y parameters for the drawing area- Parameters:
x- widthy- height
-
setTimeFrameXY
public void setTimeFrameXY(java.awt.Dimension d)
- Parameters:
d-
-
getToolTipText
public java.lang.String getToolTipText(java.awt.event.MouseEvent e)
- Overrides:
getToolTipTextin classjavax.swing.JComponent
-
initEdges
public void initEdges()
Inits edges, fixes orientation
-
updateStringSettings
public void updateStringSettings(MedusaSettings ss)
Sets newMedusaSettings- Parameters:
ss- new settings
-
run
public void run()
- Specified by:
runin interfacejava.lang.Runnable
-
start
public void start()
-
stop
public void stop()
-
energy
public void energy()
-
setFix
public void setFix(boolean trueOrFalse)
Fix or unfix all nodes- Parameters:
trueOrFalse- true fixes all nodes. false unfixes all
-
invertFix
public void invertFix()
-
setCool
public void setCool(boolean trueOrFalse)
Allows cooling of relaxation. If cooling is on, attraction and repellation energies will slow if the mouse is not dragging nodes.- Parameters:
trueOrFalse- true: cooling
-
rotate
public void rotate(double t)
Rotates graph- Parameters:
t- rotation factor
-
mirror
public void mirror(boolean xFlip, boolean yFlip)Mirrors graph vertically or horizontally (or both)- Parameters:
xFlip- true if flipyFlip- true if flip
-
changeNodeColor
public void changeNodeColor(int red, int green, int blue)
-
changeNodeColor
public void changeNodeColor(java.awt.Color color)
-
saveImage
public void saveImage(java.lang.String path, int param)Saves graph as an image- Parameters:
path- file to save asparam- type of picture. Currently, 0=jpg 1=png
-
setNodeFixed
public void setNodeFixed(java.lang.String lbl, boolean fixed)
-
mouseClicked
public void mouseClicked(java.awt.event.MouseEvent e)
- Specified by:
mouseClickedin interfacejava.awt.event.MouseListener
-
mousePressed
public void mousePressed(java.awt.event.MouseEvent e)
- Specified by:
mousePressedin interfacejava.awt.event.MouseListener
-
handlePressLeftButton
public void handlePressLeftButton(java.awt.event.MouseEvent e)
-
handlePressLeftButton_backup
public void handlePressLeftButton_backup(java.awt.event.MouseEvent e)
-
findLabel
public boolean findLabel(java.lang.String expression)
Finds the node matching the regular expression- Parameters:
expression- pattern to match- Returns:
- true if nodes were found, false if no nodes matched the pattern
-
mouseReleased
public void mouseReleased(java.awt.event.MouseEvent e)
- Specified by:
mouseReleasedin interfacejava.awt.event.MouseListener
-
mouseEntered
public void mouseEntered(java.awt.event.MouseEvent e)
- Specified by:
mouseEnteredin interfacejava.awt.event.MouseListener
-
mouseExited
public void mouseExited(java.awt.event.MouseEvent e)
- Specified by:
mouseExitedin interfacejava.awt.event.MouseListener
-
mouseDragged
public void mouseDragged(java.awt.event.MouseEvent e)
- Specified by:
mouseDraggedin interfacejava.awt.event.MouseMotionListener
-
handleLeftMouseDragged
public void handleLeftMouseDragged(java.awt.event.MouseEvent e)
-
mouseMoved
public void mouseMoved(java.awt.event.MouseEvent e)
- Specified by:
mouseMovedin interfacejava.awt.event.MouseMotionListener
-
autoFixOrientation
public void autoFixOrientation()
Automatically fixes orientations
-
randomGraph
public void randomGraph(int nNodes, int nEdges)Creates a random graph- Parameters:
nNodes- number of nodesnEdges- number of edges
-
paintComponent
public void paintComponent(java.awt.Graphics g)
Paints the component- Overrides:
paintComponentin classBasicGraphRenderer- Parameters:
g- current graphics
-
paintPick
public void paintPick(java.awt.Graphics2D g)
Paints the selected node- Parameters:
g- Graphics2D
-
getCurrentRect
public java.awt.Rectangle getCurrentRect()
-
isBox
public boolean isBox()
-
getVisibleGraph
public Graph getVisibleGraph()
-
-
DMelt 3.0 © DataMelt by jWork.ORG