Class JDialogHyperGraph

All Implemented Interfaces:
com.jogamp.newt.event.MouseListener, com.jogamp.newt.event.NEWTEventListener, ActionListener, ComponentListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, RootPaneContainer, WindowConstants

public class JDialogHyperGraph extends JFrame implements ActionListener, ComponentListener, com.jogamp.newt.event.MouseListener
Frame and user interface for displaying a HyperGraph in MIPAV.
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      generated serial id
      See Also:
    • m_kCurrentDir

      private String m_kCurrentDir
      current directory
    • m_kFileName

      private String m_kFileName
      current file name
    • fixedColor

      private static Color[] fixedColor
      set of colors for tree nodes, based on the mipav striped lut
    • m_kCurrentFont

      private org.apache.pdfbox.pdmodel.font.PDFont m_kCurrentFont
      current font
    • m_iCurrentFontSize

      private int m_iCurrentFontSize
      current font size
    • m_fPageWidth

      private float m_fPageWidth
      page width
    • m_fPageMargin

      private float m_fPageMargin
      page margin
    • graphPanel

      private MipavGraphPanel graphPanel
      Displays the graph.
    • toolbarPanel

      private JPanel toolbarPanel
    • mainPanel

      private JPanel mainPanel
    • graphPanel2

      private JPanel graphPanel2
    • centerRootNodeButton

      private JButton centerRootNodeButton
    • saveGraphButton

      private JButton saveGraphButton
    • increaseFontButton

      private JButton increaseFontButton
    • decreaseFontButton

      private JButton decreaseFontButton
    • sep

      private JButton sep
    • toolbarBuilder

      private ViewToolBarBuilder toolbarBuilder
  • Constructor Details

    • JDialogHyperGraph

      public JDialogHyperGraph()
      Default Constructor.
    • JDialogHyperGraph

      public JDialogHyperGraph(String dir, String file)
      Creates a HyperGraph visualization from the graph located in the given directory and file. If either or both are null, the constructor opens a file chooser so the user can select the graph file to open. Graphs are in .xml format, described in the MIPAVGraphXML.xsd file.
      Parameters:
      dir - directory.
      file - file name.
    • JDialogHyperGraph

      public JDialogHyperGraph(ViewJFrameImage kParent)
      Creates a HyperGraph using the ViewJFrameImage active image and menu bars as the root and tree of the graph. The graph leaves are the menu items. Double-click calls the corresponding action command for the active image.
      Parameters:
      kParent - ViewJFrameImage.
  • Method Details

    • actionPerformed

      public void actionPerformed(ActionEvent e)
      Specified by:
      actionPerformed in interface ActionListener
    • getGraphPanel

      public hypergraph.visualnet.GraphPanel getGraphPanel()
      Access to the graph panel.
      Returns:
      the graph panel.
    • getGraphXML

      public String getGraphXML()
      Returns an xml description of the graph as a String.
      Returns:
      an xml description of the graph as a String.
    • getNodeColor

      public static Color getNodeColor(int level)
    • savePreferences

      public void savePreferences()
      Saves the global graph properties (background color, text sizes) to the default mipav graph preferences file in the Preferences.getPreferencesDir directory.
    • writeGraphJPG

      public void writeGraphJPG(String dir, String file)
      Writes the current HyperGraph as a JPG image.
      Parameters:
      dir - directory.
      file - file name.
    • writeGraphPDF

      public void writeGraphPDF(String dir, String file)
      Writes the current HyperGraph as a PDF.
      Parameters:
      dir - directory.
      file - file name.
    • writeGraphTIF

      public void writeGraphTIF(String dir, String file)
      Writes the current HyperGraph as a TIF image.
      Parameters:
      dir - directory.
      file - file name.
    • writeGraphTXT

      public void writeGraphTXT(String dir, String file)
      Writes the current HyperGraph as a text file.
      Parameters:
      dir - directory.
      file - file name.
    • writeGraphXML

      public void writeGraphXML(String dir, String file)
      Writes the current HyperGraph as a xml file.
      Parameters:
      dir - directory.
      file - file name.
    • addSubTree

      private void addSubTree(hypergraph.graphApi.Graph tree, hypergraph.graphApi.Node root, hypergraph.graphApi.Node menu, Component[] menuComponents, int level)
      Function recursively creates a tree structure based on an array of menu components. Used to build a demo of the HyperGraph out of the MIPAV menus.
      Parameters:
      tree - current graph.
      root - the root of the tree
      menu - the current node, or root of the current sub-tree
      menuComponents - array of menu items to add to the current sub-tree
      level - current level of the graph (root = 0).
    • buildMenu

      private void buildMenu()
      Builds the File menu for the HyperGraph interface.
    • init

      private void init()
      Initialize the HyperGraph visualization. The input file and directory are specified in the constructor.
    • initImage

      private void initImage(ViewJFrameImage kParent)
      Initialize the HyperGraph interface based on the ViewJFrameImage parent. The graph is build recursively from the mipav menus. The leaf nodes are active, when the user double-clicks the action commands are sent to the ViewJFrameImage parent and are performed on the current active image.
      Parameters:
      kParent -
    • loadPreferences

      private void loadPreferences()
      Loads the graph preferences file from the Preferences.grtPreferencesDir directory. If the graph preferences file doesn't exist, a new one is created with the default values.
    • writeGraph

      private void writeGraph(HashSet<hypergraph.graphApi.Node> visitedSet, FileWriter kWriter, hypergraph.graphApi.Node kNode, int iLevel)
      Recursively writes a graph to the text file.
      Parameters:
      visitedSet - lists the nodes that have already been written. Prevents infinite recursion in graphs with loops.
      kWriter - output FileWriter.
      kNode - current node to write.
      iLevel - current level of the node in the graph.
    • writeGraph

      private void writeGraph(HashSet<hypergraph.graphApi.Node> visitedSet, org.apache.pdfbox.pdmodel.PDDocument doc, org.apache.pdfbox.pdmodel.edit.PDPageContentStream[] contentStream, float[] height, hypergraph.graphApi.Node kNode, int iLevel)
      Recursively writes a graph to the pdf file.
      Parameters:
      visitedSet - lists the nodes that have already been written. Prevents infinite recursion in graphs with loops.
      doc - PDDocument
      contentStream - current page stream in the document.
      height - current height on the page, where the text is written.
      kNode - current node to write.
      iLevel - level in the tree of the current node.
    • writeImage

      private String writeImage(String node, String dir, String file, String format, float width)
      Writes the HyperGraph graph panel display as an image file.
      Parameters:
      node - name of the root node.
      dir - output directory.
      file - output file name.
      format - format, may be .jpg, .tif, or null.
      width - desired width of the output image (maintains aspect ratio).
      Returns:
      the name of the output file.
    • componentHidden

      public void componentHidden(ComponentEvent e)
      Specified by:
      componentHidden in interface ComponentListener
    • componentMoved

      public void componentMoved(ComponentEvent e)
      Specified by:
      componentMoved in interface ComponentListener
    • componentResized

      public void componentResized(ComponentEvent e)
      Specified by:
      componentResized in interface ComponentListener
    • componentShown

      public void componentShown(ComponentEvent e)
      Specified by:
      componentShown in interface ComponentListener
    • mouseClicked

      public void mouseClicked(com.jogamp.newt.event.MouseEvent arg0)
      Specified by:
      mouseClicked in interface com.jogamp.newt.event.MouseListener
    • mouseDragged

      public void mouseDragged(com.jogamp.newt.event.MouseEvent arg0)
      Specified by:
      mouseDragged in interface com.jogamp.newt.event.MouseListener
    • mouseEntered

      public void mouseEntered(com.jogamp.newt.event.MouseEvent arg0)
      Specified by:
      mouseEntered in interface com.jogamp.newt.event.MouseListener
    • mouseExited

      public void mouseExited(com.jogamp.newt.event.MouseEvent arg0)
      Specified by:
      mouseExited in interface com.jogamp.newt.event.MouseListener
    • mouseMoved

      public void mouseMoved(com.jogamp.newt.event.MouseEvent arg0)
      Specified by:
      mouseMoved in interface com.jogamp.newt.event.MouseListener
    • mousePressed

      public void mousePressed(com.jogamp.newt.event.MouseEvent arg0)
      Specified by:
      mousePressed in interface com.jogamp.newt.event.MouseListener
    • mouseReleased

      public void mouseReleased(com.jogamp.newt.event.MouseEvent arg0)
      Specified by:
      mouseReleased in interface com.jogamp.newt.event.MouseListener
    • mouseWheelMoved

      public void mouseWheelMoved(com.jogamp.newt.event.MouseEvent arg0)
      Specified by:
      mouseWheelMoved in interface com.jogamp.newt.event.MouseListener