chordDiagrams
Class DiagramDrawer

java.lang.Object
  extended by chordDiagrams.DiagramDrawer

public class DiagramDrawer
extends java.lang.Object

This class provides graphical representations of diagrams (draws diagrams to a bitmap), and provides means to draw collections of diagrams and saving them to files.

Author:
Romwell

Field Summary
(package private)  java.awt.BasicStroke dashedStroke
          Dashed stroke for drawing
(package private)  int dspace
          Spacing between diagrams
(package private)  java.awt.Graphics2D g2
          Graphics object to draw on the image
(package private)  java.awt.image.BufferedImage image
          Data structure to store image
(package private)  int numcols
          Number of columns on the contact sheet
(package private)  int numrows
          Number of rows on the contact sheet
(package private)  int r
          circle radius
(package private)  java.awt.BasicStroke solidStroke
           
(package private)  int space
          spacing between circles
 
Constructor Summary
DiagramDrawer(int r, int space)
          Creates a diagram drawer instance
DiagramDrawer(int r, int space, int numrows, int numcols, int dspace)
          Creates a diagram drawer instance
 
Method Summary
 void clearImage()
          Blanks the image
 java.lang.String coefToString(double c)
          Returns number as a string, with 1 being empty string and -1 being "-".
 int diagHeight(diagram g)
          Returns the height of the diagram, in pixels
 int diagWidth(diagram g)
          Returns the width of the diagram, in pixels
 void DrawAndSave(diagram g, java.lang.String filename)
          Draws and saves a diagram
 void DrawAndSave(java.util.HashMap<java.lang.String,diagram> hm, java.lang.Iterable keySet, java.lang.String name)
          Draws and saves a subset of a collection of diagrams The filenames are formed using the pattern "name_n-k_#.png", where # stays for index in the list
 void drawChord(diagram g, int i, int off_x, int off_y)
          Draws straight chord in the diagram g emanating from endpoint t
 void drawCircles(int k, int off_x, int off_y)
          Draws k properly spaced circles
 void drawCurvedChord(diagram g, int i, int off_x, int off_y)
          Draws curved chord in the diagram g emanating from endpoint t
 void drawCurvedInnerChord(diagram g, int i, int off_x, int off_y)
          Draws curved inner chord in the diagram g emanating from endpoint t (inner = not between links)
 void drawDiagram(diagram g, int off_x, int off_y, boolean drawframe)
          Draws a diagram on the image.
 void drawDot(diagram g, int t, int off_x, int off_y)
          Draws a dot that represents an endpoint on a diagram
 void DrawRelation(Relation relation, java.util.ArrayList<java.lang.String> keySet, java.util.HashMap<java.lang.String,diagram> diags, int off_x, int off_y)
          Draws a relation on the image canvas
 java.awt.geom.Point2D getCircleCenter(diagram g, int t, int off_x, int off_y)
          Gets the center of the circle that represents the ring t
private  int getOffX(int i, int dw)
          Gets X offset of the diagram on the contact sheet
private  int getOffY(int i, int dh)
          Gets Y offset of the diagram on the contact sheet
 java.awt.geom.Point2D getPoint(diagram g, int t, int off_x, int off_y)
          Takes an index of a chord endpoint and produces a point
 void initImage(int dw, int dh)
          Initializes image and the graphics object and blanks the image
 int relationDiagramHeight(Relation relation, java.util.ArrayList<java.lang.String> keySet, java.util.HashMap<java.lang.String,diagram> diags)
          Returns the relation depiction height
 int relationDiagramWidth(Relation relation, java.util.ArrayList<java.lang.String> keySet, java.util.HashMap<java.lang.String,diagram> diags)
          Returns the relation depiction width
 void Save(java.lang.String filename)
          Saves the diagram to a file
 void setFontByMinHeight(java.lang.Double pixelheight)
          Sets font for the graphics 2D object to match the specified pixelheight The font will have the smallest point size that will result in font pixel height exceeding pixelheight parameter
 void setFontByWidth(java.lang.String S, double pixelwidth, double pixelheight)
          Sets font for the graphics 2D object so that a string has length not exceeding pixel width and height The font size is largest value so that the string width does not exceed the set pixelwidth/pixelheight
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

image

java.awt.image.BufferedImage image
Data structure to store image


g2

java.awt.Graphics2D g2
Graphics object to draw on the image


r

int r
circle radius


space

int space
spacing between circles


numrows

int numrows
Number of rows on the contact sheet


numcols

int numcols
Number of columns on the contact sheet


dspace

int dspace
Spacing between diagrams


dashedStroke

java.awt.BasicStroke dashedStroke
Dashed stroke for drawing


solidStroke

java.awt.BasicStroke solidStroke
Constructor Detail

DiagramDrawer

public DiagramDrawer(int r,
                     int space,
                     int numrows,
                     int numcols,
                     int dspace)
Creates a diagram drawer instance

Parameters:
r - diagram radius
space - spacing on the sides and between diagrams
numrows - number of rows on contact sheet
numcols - number of columns on contact sheet
dspace - spacing between diagrams

DiagramDrawer

public DiagramDrawer(int r,
                     int space)
Creates a diagram drawer instance

Parameters:
r - diagram radius
space - spacing on the sides and between diagrams
Method Detail

initImage

public void initImage(int dw,
                      int dh)
Initializes image and the graphics object and blanks the image

Parameters:
w - diagram width
h - diagram height

clearImage

public void clearImage()
Blanks the image


drawCircles

public void drawCircles(int k,
                        int off_x,
                        int off_y)
Draws k properly spaced circles

Parameters:
k - number of circles
offset_x - X coordinate of the leftmost circle (UL corner)
offset_y - Y coordinate of the leftmost circle (UL corner)

diagWidth

public int diagWidth(diagram g)
Returns the width of the diagram, in pixels

Parameters:
g - the diagram
Returns:
its width in pixels

diagHeight

public int diagHeight(diagram g)
Returns the height of the diagram, in pixels

Parameters:
g - the diagram
Returns:
its height in pixels

drawDiagram

public void drawDiagram(diagram g,
                        int off_x,
                        int off_y,
                        boolean drawframe)
Draws a diagram on the image. Does not erase nor itialize it. Must call initImage() before calling this method.

Parameters:
g - the diagram to draw
off_x - x offset
off_y - y offset
drawframe - draw frame around diagram ?

drawChord

public void drawChord(diagram g,
                      int i,
                      int off_x,
                      int off_y)
Draws straight chord in the diagram g emanating from endpoint t

Parameters:
g - the diagram
t - endpoint index
off_x - X offset
off_y - Y offset

drawCurvedChord

public void drawCurvedChord(diagram g,
                            int i,
                            int off_x,
                            int off_y)
Draws curved chord in the diagram g emanating from endpoint t

Parameters:
g -
t -

drawCurvedInnerChord

public void drawCurvedInnerChord(diagram g,
                                 int i,
                                 int off_x,
                                 int off_y)
Draws curved inner chord in the diagram g emanating from endpoint t (inner = not between links)

Parameters:
g -
t -

getCircleCenter

public java.awt.geom.Point2D getCircleCenter(diagram g,
                                             int t,
                                             int off_x,
                                             int off_y)
Gets the center of the circle that represents the ring t

Parameters:
t - index of the link
Returns:
coordinates of the center

getPoint

public java.awt.geom.Point2D getPoint(diagram g,
                                      int t,
                                      int off_x,
                                      int off_y)
Takes an index of a chord endpoint and produces a point

Parameters:
g - the diagram that contains the point
t - index of the point
off_x - X offset
off_y - Y offset
Returns:
point that can be drawn in Graphics2D

drawDot

public void drawDot(diagram g,
                    int t,
                    int off_x,
                    int off_y)
Draws a dot that represents an endpoint on a diagram

Parameters:
g - the diagram
t - endpoint index

Save

public void Save(java.lang.String filename)
Saves the diagram to a file

Parameters:
filename - The name of the file to save the diagram to (without extension, just the name) Saves to PNG.

DrawAndSave

public void DrawAndSave(diagram g,
                        java.lang.String filename)
Draws and saves a diagram

Parameters:
g - the diagram to be saved
filename -

DrawAndSave

public void DrawAndSave(java.util.HashMap<java.lang.String,diagram> hm,
                        java.lang.Iterable keySet,
                        java.lang.String name)
Draws and saves a subset of a collection of diagrams The filenames are formed using the pattern "name_n-k_#.png", where # stays for index in the list

Parameters:
hm - hashmap with the diagrams
keySet - keys for the diagrams to draw and save
name - base for the filename

getOffX

private int getOffX(int i,
                    int dw)
Gets X offset of the diagram on the contact sheet

Parameters:
i - number of the diagram
dw - width of the diagram
Returns:
X offset

getOffY

private int getOffY(int i,
                    int dh)
Gets Y offset of the diagram on the contact sheet

Parameters:
i - number of the diagram
dh - height of the diagram
Returns:
Y offset

relationDiagramWidth

public int relationDiagramWidth(Relation relation,
                                java.util.ArrayList<java.lang.String> keySet,
                                java.util.HashMap<java.lang.String,diagram> diags)
Returns the relation depiction width

Parameters:
relation - the Arraylist that stores relation
diags - data structure with diagrams diagram
Returns:
width of the relation depiction

coefToString

public java.lang.String coefToString(double c)
Returns number as a string, with 1 being empty string and -1 being "-".

Parameters:
c - coefficient
Returns:
string representation of coefficient

relationDiagramHeight

public int relationDiagramHeight(Relation relation,
                                 java.util.ArrayList<java.lang.String> keySet,
                                 java.util.HashMap<java.lang.String,diagram> diags)
Returns the relation depiction height

Parameters:
relation - the Arraylist that stores relation
diags - data structure with diagrams diagram
Returns:
height of the relation depiction

setFontByMinHeight

public void setFontByMinHeight(java.lang.Double pixelheight)
Sets font for the graphics 2D object to match the specified pixelheight The font will have the smallest point size that will result in font pixel height exceeding pixelheight parameter

Parameters:
pixelheight - desired height

DrawRelation

public void DrawRelation(Relation relation,
                         java.util.ArrayList<java.lang.String> keySet,
                         java.util.HashMap<java.lang.String,diagram> diags,
                         int off_x,
                         int off_y)
Draws a relation on the image canvas

Parameters:
relation - the relation to draw - an arraylist of relation entries
keySet - data structure with keys; indices in the relation must correspond to entries in keySet
diags - data structure with diagrams
off_x - x offset
off_y - y offset

setFontByWidth

public void setFontByWidth(java.lang.String S,
                           double pixelwidth,
                           double pixelheight)
Sets font for the graphics 2D object so that a string has length not exceeding pixel width and height The font size is largest value so that the string width does not exceed the set pixelwidth/pixelheight

Parameters:
S - the string you want to fit in pixelwidth
pixelwidth - desired string pixel width