/Users/petercappello/NetBeansProjects/56-2014/56-2014-1-Clique-OO/src/clique/Clique.java
package clique;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

/**
 *
 * @author Peter Cappello
 */
public class Clique 
{    
    /* If Clique is used by other classes, these attributes may best be thought 
     * of as NOT being attributes of Clique.
     */
    private static final int IMAGE_SIZE = Node.IMAGE_SIZE; // units: pixels
    private final Image image;
    private final ImageIcon imageIcon;
    private final JLabel jLabel;
    private final JFrame jFrame;
    
    private final int nNodes;          // # of nodes in the clique 
    private final Node[] nodeArray;
    
    Clique()
    {
        image = new BufferedImage( IMAGE_SIZE, IMAGE_SIZE, BufferedImage.TYPE_INT_ARGB );
        imageIcon = new ImageIcon( image );
        jLabel = new JLabel( imageIcon );
        jFrame = new JFrame( "Clique" );
        jFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        Container container = jFrame.getContentPane();
        container.setLayout( new BorderLayout() );
        container.add( jLabel, BorderLayout.CENTER );
        jFrame.pack();
        
        // set image parameters
        nNodes = getInt( "What is the size of the clique [3 - 30]?" );
        Node.initialize( nNodes ); // set Node class variables
        nodeArray = new Node[ nNodes ];
        for (int nodeN = 0; nodeN < nNodes; nodeN++ )
        {
            nodeArray[ nodeN ] = new Node( nodeN );
        }
    }
    
    private int getInt( String promptString )
    {
        String intString = JOptionPane.showInputDialog( promptString );
        return Integer.parseInt( intString );
    }
    
    /**
     * Paint the clique representation onto the Image.
     */
    private void paint()
    {
        Graphics graphics = image.getGraphics();
        
        // paint edges
        for ( Node node : nodeArray )
        {
            node.drawEdges( graphics, nodeArray );
        }
        
        // paint nodes circles, ensuring they obscure part edges that overlaps with the circle.
        for ( Node node : nodeArray )
        {
            node.draw( graphics );
        }
    }
    
    /**
     * @param args the command line arguments: Unused.
     */
    public static void main(String[] args) 
    {
        Clique clique = new Clique();
        clique.paint();
        clique.view();
    }
    
    private void view() { jFrame.setVisible( true ); }
}