pqrtreeapplet
Class PQRController

java.lang.Object
  extended by pqrtreeapplet.PQRController
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener

public class PQRController
extends java.lang.Object
implements java.awt.event.ActionListener

The controller component of the model/view/controller for this application This class starts the execution and either loads the GUI. Based in the PQController class of Jon Harris' Graphical Implementation of PQ Tree Data Structure. PQ Tree link.

Version:
0.1
Author:
Bruno Dilly

Field Summary
 java.util.concurrent.locks.Lock addSetLock
           
private  java.util.concurrent.ExecutorService application
           
 java.util.concurrent.locks.Condition canAddSet
           
 java.util.concurrent.locks.Condition canBePainted
           
private  int delayInSeconds
           
private  boolean drawAllSteps
           
 java.util.concurrent.locks.Condition nextStep
           
private  PQRTree pqrTree
           
 boolean setToBePainted
           
private  javax.swing.Timer timer
           
private  PQRWindow window
           
 
Constructor Summary
PQRController(int universeSize)
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          button click handlers for the gui.
 void destroy()
          Kills the thread.
private  int[] getConstraintsFromGUI()
          Reduces the tree using the constraints provided by the GUI.
 Node getLeafAt(int index)
          Gets the leaf at a specific position of the leaves vector.
 PQRWindow getWindow()
          Gets the window created by the controller.
 void init()
          Creates a new window.
 void reduceTree(int[] constraints)
          Reduce the tree using the constraints provided in a vector.
 void reduceTreeByStep()
          Reduces the tree by one step.
 void resetTree()
          Resets the tree back to the universal tree.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pqrTree

private PQRTree pqrTree

window

private PQRWindow window

timer

private javax.swing.Timer timer

addSetLock

public java.util.concurrent.locks.Lock addSetLock

canAddSet

public java.util.concurrent.locks.Condition canAddSet

canBePainted

public java.util.concurrent.locks.Condition canBePainted

nextStep

public java.util.concurrent.locks.Condition nextStep

setToBePainted

public boolean setToBePainted

application

private java.util.concurrent.ExecutorService application

drawAllSteps

private boolean drawAllSteps

delayInSeconds

private int delayInSeconds
Constructor Detail

PQRController

public PQRController(int universeSize)
              throws java.lang.Exception
Throws:
java.lang.Exception
Method Detail

init

public void init()
          throws java.lang.Exception
Creates a new window. Adds listeners to the buttons.

Throws:
java.lang.Exception

getWindow

public PQRWindow getWindow()
Gets the window created by the controller.

Returns:
The window created.

getConstraintsFromGUI

private int[] getConstraintsFromGUI()
Reduces the tree using the constraints provided by the GUI.

Returns:
An array of constraints.

reduceTree

public void reduceTree(int[] constraints)
                throws java.lang.Exception
Reduce the tree using the constraints provided in a vector.

Parameters:
constraints - The set to be added to the tree.
Throws:
java.lang.Exception

reduceTreeByStep

public void reduceTreeByStep()
                      throws java.lang.Exception
Reduces the tree by one step.

Throws:
java.lang.Exception

resetTree

public void resetTree()
               throws java.lang.Exception
Resets the tree back to the universal tree. Concludes atual reduction, if necessary, for thread consistency.

Throws:
java.lang.Exception

getLeafAt

public Node getLeafAt(int index)
Gets the leaf at a specific position of the leaves vector.

Parameters:
index - Position of the vector.
Returns:
Leaf at the position index.

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
button click handlers for the gui.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
e - The action event occurred.

destroy

public void destroy()
Kills the thread.