java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
org.unifi.mecvirtualresourceallocation.graph.visualization.GraphPanel
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible
Direct Known Subclasses:
ConflictGraphPanel, HyperGraphPanel

public abstract class GraphPanel extends JPanel
Base class for panels visualizing graphs with vertices and edges. This is an abstract class and should be subclassed to implement specific graph visualization logic.
See Also:
  • Field Details

    • vertexPositions

      protected final Map<Vertex,Point> vertexPositions
      Map to store positions of vertices.
  • Constructor Details

    • GraphPanel

      public GraphPanel()
      Constructs a GraphPanel initializing vertexPositions as an empty HashMap.
  • Method Details

    • calculateVertexPositions

      protected abstract void calculateVertexPositions()
      Abstract method to be implemented by subclasses for calculating vertex positions.
    • drawEdges

      protected abstract void drawEdges(Graphics2D g2d)
      Abstract method to be implemented by subclasses for drawing edges between vertices.
      Parameters:
      g2d - The Graphics2D context used for drawing
    • drawVertices

      protected abstract void drawVertices(Graphics2D g2d)
      Abstract method to be implemented by subclasses for drawing vertices with labels.
      Parameters:
      g2d - The Graphics2D context used for drawing
    • paintComponent

      protected void paintComponent(Graphics graphics)
      Overrides JPanel's paintComponent method to draw the graph.
      Overrides:
      paintComponent in class JComponent
      Parameters:
      graphics - The Graphics context used for painting
    • getGraphSize

      public Dimension getGraphSize()
      Calculates the size of the graph based on the positions of its vertices. It determines the minimum bounding box that contains all vertices and adds padding.
      Returns:
      A Dimension object representing the width and height of the graph including padding
    • saveToSvg

      protected void saveToSvg(String filePath) throws IOException
      Saves the current graph as an SVG file at the specified file path. It uses an SVGGraphics2D context to render the graph and writes the SVG content to the file.
      Parameters:
      filePath - The file path where the SVG file will be saved
      Throws:
      IOException - If an error occurs during file writing