Modified:
trunk/src/wosaic/Controller.java
trunk/src/wosaic/FlickrService.java
trunk/src/wosaic/JAIProcessor.java
trunk/src/wosaic/Sources.java
trunk/src/wosaic/algorithms/AbstractAlgorithm.java
trunk/src/wosaic/algorithms/BruteForceAlgorithm.java
trunk/src/wosaic/utilities/Facebook.java
trunk/src/wosaic/utilities/ImageBuffer.java
trunk/src/wosaic/utilities/ImagePreview.java
trunk/src/wosaic/utilities/Mosaic.java
trunk/src/wosaic/utilities/MosaicEvent.java
trunk/src/wosaic/utilities/MosaicListener.java
trunk/src/wosaic/utilities/SourcePlugin.java
trunk/src/wosaic/utilities/WosaicFilter.java
Log:
Purpose: More code cleanup
Basically, remove remaining warnings in Eclipse. Mostly missing Javadocs
Modified: trunk/src/wosaic/Controller.java
==============================================================================
--- trunk/src/wosaic/Controller.java (original)
+++ trunk/src/wosaic/Controller.java Wed Sep 3 20:46:53 2008
@@ -29,22 +29,18 @@
private final ArrayList<ActionListener> _listeners;
- protected int imagesReceived;
-
private final Mosaic mosaic;
- protected static final int THREAD_WAIT_SECS = 3600;
+ private static final int THREAD_WAIT_SECS = 3600;
- protected Thread mosaicThread;
+ private Thread mosaicThread;
private final Pixel mPixel;
- protected JAIProcessor mProc;
+ private JAIProcessor mProc;
private final int numSources;
- protected int numThreads;
-
private final Parameters param;
private final Vector<SourcePlugin> Plugins;
@@ -64,22 +60,15 @@
*
* @param p The parameters associated with the mosaic
* @param sourcePixel Source image as a Pixel object
- * @param numCols the desired number of cols in the resulting mosaic
- * @param xDim the width of the final mosaic image
- * @param yDim the height of the final mosaic image
- * @param search the Flickr search string
- * @param mImage the filename of the master image
* @param mos a reference to the mosaic object which will be operated on
- * @param fb a flag that indicates whether or not to use facebook. This
- * should be replaced by a vector indicating which Plugins to
- * use, as we incorporate more Plugins.
+ * @param sources An array of source plugins to use
+ * @param stat A status object to report progress and events to
*/
Controller(final Parameters p, final Pixel sourcePixel, final Mosaic mos,
final Vector<SourcePlugin> sources, final Status stat) {
ThreadPool = Executors.newCachedThreadPool();
mPixel = sourcePixel;
- imagesReceived = 0;
mosaic = mos;
Plugins = sources;
numSources = Plugins.size();
Modified: trunk/src/wosaic/FlickrService.java
==============================================================================
--- trunk/src/wosaic/FlickrService.java (original)
+++ trunk/src/wosaic/FlickrService.java Wed Sep 3 20:46:53 2008
@@ -168,9 +168,8 @@
// Try to connect at most 'CONNECT_RETRY' times before throwing
// an exception
- ParserConfigurationException latestEx = null;
- for (int i = 0; !FlickrService.Connected
- && i < FlickrService.CONNECT_RETRY; i++)
+ int tryNum = 0;
+ while (!FlickrService.Connected)
try {
// Initialize
FlickrService.Rest = new REST();
@@ -187,19 +186,31 @@
FlickrService.PhotosInt = FlickrService.Flickr
.getPhotosInterface();
FlickrService.Connected = true;
+
} catch (final ParserConfigurationException ex) {
- latestEx = ex;
+ if (tryNum >= FlickrService.CONNECT_RETRY) throw ex;
+
+ // If we're not over out limit, simply try again
+ tryNum++;
}
- if (!FlickrService.Connected) throw latestEx;
}
// Configuration UI Code
- private JTextField NumSearchField = null;
-
- private JDialog OptionsDialog = null;
-
- private JPanel OptionsPane = null;
+ /**
+ * Text field to hold the number of photos to search fo
+ */
+ protected JTextField NumSearchField = null;
+
+ /**
+ * Dialog to present user with configuration options
+ */
+ protected JDialog OptionsDialog = null;
+
+ /**
+ * The JPanel that actually holds the configuration UI elements
+ */
+ protected JPanel OptionsPane = null;
private SearchParameters Params = null;
Modified: trunk/src/wosaic/JAIProcessor.java
==============================================================================
--- trunk/src/wosaic/JAIProcessor.java (original)
+++ trunk/src/wosaic/JAIProcessor.java Wed Sep 3 20:46:53 2008
@@ -26,7 +26,7 @@
*/
public Pixel master;
- public Mosaic mosaic;
+ private Mosaic mosaic;
/**
* A set of parameters for this mosaic. It primarily holds resolution
Modified: trunk/src/wosaic/Sources.java
==============================================================================
--- trunk/src/wosaic/Sources.java (original)
+++ trunk/src/wosaic/Sources.java Wed Sep 3 20:46:53 2008
@@ -36,6 +36,9 @@
*/
protected static final Plugin[] DEFAULT_PLUGINS = { Plugin.Flickr };
+ /**
+ * List of plugins that actually use the search string
+ */
static final Sources.Plugin[] SearchablePlugins = { Plugin.Flickr };
/**
Modified: trunk/src/wosaic/algorithms/AbstractAlgorithm.java
==============================================================================
--- trunk/src/wosaic/algorithms/AbstractAlgorithm.java (original)
+++ trunk/src/wosaic/algorithms/AbstractAlgorithm.java Wed Sep 3 20:46:53
2008
@@ -3,24 +3,57 @@
*/
package wosaic.algorithms;
-import wosaic.utilities.*;
+import wosaic.utilities.Mosaic;
+import wosaic.utilities.Pixel;
/**
- * Represents the base class for all mosaic matching algorithms.
- * Each algorithm is responsible for analyzing a pool of images from
- * a plugin and fitting them appropriately into the mosaic.
+ * Represents the base class for all mosaic matching algorithms. Each
algorithm
+ * is responsible for analyzing a pool of images from a plugin and fitting
them
+ * appropriately into the mosaic.
+ *
* @author swegner2
*/
public abstract class AbstractAlgorithm {
- public AbstractAlgorithm(Mosaic mos, int[][][] colorMap) {
- Mos = mos;
+ /**
+ * Default constructor for AbstractAlgorithm class.
+ *
+ * @param mos The mosaic object that should be filled
+ * @param colorMap Color data for the source image regions
+ */
+ public AbstractAlgorithm(Mosaic mos, int[][][] colorMap) {
+ Mos = mos;
ColorMap = colorMap;
}
+
+ /**
+ * Consider a new Pixel that has been generated from the source plugin.
Each
+ * algorithm subclass should handle this appropriately
+ *
+ * @param pixel The new pixel
+ */
abstract public void AddPixel(Pixel pixel);
+ /**
+ * The mosaic object that we will be filling
+ */
protected Mosaic Mos;
+
+ /**
+ * Color data for each Pixel region of the source image
+ */
protected int[][][] ColorMap;
-
+
+ /**
+ * Return the distance "score" for a given pixel and source region. This
+ * uses the default scoring algorithm (a linear combination of red, green,
+ * and blue channel distance). Other algorithms can override this if they
+ * prefer.
+ *
+ * @param pixel The input pixel to compare
+ * @param r The row of the pixel region in the source
+ * @param c The column of the pixel region in the source
+ * @return A positive distance "score".
+ */
protected int getMatchScore(Pixel pixel, int r, int c) {
int[] avgColors = new int[3];
pixel.getAvgImageColor(avgColors);
Modified: trunk/src/wosaic/algorithms/BruteForceAlgorithm.java
==============================================================================
--- trunk/src/wosaic/algorithms/BruteForceAlgorithm.java (original)
+++ trunk/src/wosaic/algorithms/BruteForceAlgorithm.java Wed Sep 3
20:46:53 2008
@@ -3,22 +3,36 @@
*/
package wosaic.algorithms;
-import java.awt.Point;
-import java.util.ArrayList;
-
import wosaic.utilities.Mosaic;
import wosaic.utilities.Pixel;
/**
+ * Simple "brute force" algorithm. Each time we receive a new pixel, Check
each
+ * mosaic region and see if the new distance score is better than any
existing
+ * score, and replace it if it is. This algorithm can be very slow, but is
also
+ * easy to implement
+ *
* @author swegner2
- *
*/
public class BruteForceAlgorithm extends AbstractAlgorithm {
+ /**
+ * Default constructor-- simple call our superclass constructor
+ *
+ * @param mos The mosaic to process and fill
+ * @param colorMap Color data for the source pixels
+ */
public BruteForceAlgorithm(Mosaic mos, int[][][] colorMap) {
super(mos, colorMap);
}
+ /**
+ * Process a new pixel received from a source plugin. In this algorithm,
we
+ * check it against every region in the mosaic and see if it is a better
+ * fit.
+ *
+ * @param pixel The new source pixel
+ */
@Override
public void AddPixel(Pixel pixel) {
final int[] avgColors = new int[3];
@@ -28,14 +42,14 @@
pixel.getAvgImageColor(avgColors);
final int matchScore = getMatchScore(pixel, r, c);
- if (Mos.getPixelAt(r,c) == null)
+ if (Mos.getPixelAt(r, c) == null)
// Just assign this Pixel to this spot
Mos.UpdatePixel(r, c, pixel, matchScore);
- else if (matchScore < Mos.getScoreAt(r,c))
- Mos.UpdatePixel(r,c, pixel, matchScore);
+ else if (matchScore < Mos.getScoreAt(r, c))
+ Mos.UpdatePixel(r, c, pixel, matchScore);
}
-
+
// FIXME: What does this do?
notifyAll();
}
Modified: trunk/src/wosaic/utilities/Facebook.java
==============================================================================
--- trunk/src/wosaic/utilities/Facebook.java (original)
+++ trunk/src/wosaic/utilities/Facebook.java Wed Sep 3 20:46:53 2008
@@ -28,6 +28,10 @@
*/
public class Facebook extends SourcePlugin {
+ /**
+ * Subclass to handle the event when the user clicks the "Authenticate"
+ * button
+ */
public class AuthenticationAction extends AbstractAction {
/**
@@ -35,6 +39,11 @@
*/
private static final long serialVersionUID = -6285228755908052783L;
+ /**
+ * Handle the actual event. Simply call checkAuthentication()
+ *
+ * @param e Event parameters
+ */
public void actionPerformed(final ActionEvent e) {
// Change this to be... extensible to any service needing
// authentication...
@@ -44,19 +53,15 @@
}
- public static String API_KEY = "70d85deaa9e38c122cd17bab74ce80a8";
-
- public static int BIG_SRC = 4;
+ private static String API_KEY = "70d85deaa9e38c122cd17bab74ce80a8";
- public static String LOGIN_URL = "http://www.facebook.com/login.php";
+ private static String LOGIN_URL = "http://www.facebook.com/login.php";
- public static int NUM_QUERIES = 50;
+ private static int NUM_QUERIES = 50;
- public static String SECRET = "dc48f9f413d3dc738a4536402e2a75b1";
+ private static String SECRET = "dc48f9f413d3dc738a4536402e2a75b1";
- public static int SMALL_SRC = 5;
-
- public static int SRC = 3;
+ private static int SMALL_SRC = 5;
private String auth;
@@ -176,11 +181,18 @@
} while (photo != null);
}
+ /**
+ * Return a JDialog which displays some parameters that a user can
configure
+ * for our plugin
+ */
@Override
public JDialog getOptionsDialog() {
return OptionsDialog;
}
+ /**
+ * Return the type of our plugin.
+ */
@Override
public Sources.Plugin getType() {
return Sources.Plugin.Facebook;
@@ -218,6 +230,10 @@
OptionsDialog.pack();
}
+ /**
+ * Asynchronously start doing work-- query Facebook for images and start
+ * returning them
+ */
@Override
public void run() {
try {
@@ -228,6 +244,10 @@
}
}
+ /**
+ * Validate configuration parameters-- basically, make sure we are
+ * authenticated before trying to query Facebook.
+ */
@Override
public String validateParams() {
if (!checkAuthentication())
Modified: trunk/src/wosaic/utilities/ImageBuffer.java
==============================================================================
--- trunk/src/wosaic/utilities/ImageBuffer.java (original)
+++ trunk/src/wosaic/utilities/ImageBuffer.java Wed Sep 3 20:46:53 2008
@@ -131,6 +131,12 @@
}
}
+ /**
+ * Set the number of expected results we will receive. This is for
+ * displaying a relative percentage for progress
+ *
+ * @param num Number of images we expect to grab from the source plugin
+ */
public synchronized void signalProgressCount(int num) {
progressState++;
maxSize += num;
Modified: trunk/src/wosaic/utilities/ImagePreview.java
==============================================================================
--- trunk/src/wosaic/utilities/ImagePreview.java (original)
+++ trunk/src/wosaic/utilities/ImagePreview.java Wed Sep 3 20:46:53 2008
@@ -79,6 +79,12 @@
}
}
+ /**
+ * Event handler for when a property changes. Figure out what kind of
+ * propery it is, and handle it accordingly
+ *
+ * @param e Event parameters
+ */
public void propertyChange(final PropertyChangeEvent e) {
boolean update = false;
final String prop = e.getPropertyName();
Modified: trunk/src/wosaic/utilities/Mosaic.java
==============================================================================
--- trunk/src/wosaic/utilities/Mosaic.java (original)
+++ trunk/src/wosaic/utilities/Mosaic.java Wed Sep 3 20:46:53 2008
@@ -53,6 +53,11 @@
listeners.next().mosaicUpdated(e);
}
+ /**
+ * Add a new listener for Mosaic change events
+ *
+ * @param l The new MosaicListener
+ */
public synchronized void addMosaicEventListener(final MosaicListener l) {
_listeners.add(l);
}
@@ -136,10 +141,24 @@
return imageGrid;
}
+ /**
+ * Retrieve the Pixel object at a particular coordinate of the Mosaic
object
+ *
+ * @param x The x dimension
+ * @param y The y dimension
+ * @return The Pixel at a given coordinate, or null if none exists
+ */
public synchronized Pixel getPixelAt(final int x, final int y) {
return imageGrid[x][y];
}
+ /**
+ * Retrieve the current distance score for a particular coordinate
+ *
+ * @param x The x dimension
+ * @param y The y dimension
+ * @return The current score
+ */
public synchronized int getScoreAt(final int x, final int y) {
return scoreGrid[x][y];
}
@@ -260,6 +279,14 @@
notifyAll();
}
+ /**
+ * Update the Pixel in a given coordinate with a new one.
+ *
+ * @param row The row of the given coordinate
+ * @param col The column of the given coordinate
+ * @param newPixel The new pixel object to use
+ * @param score The score of the new match
+ */
public synchronized void UpdatePixel(int row, int col,
final Pixel newPixel, int score) {
imageGrid[row][col] = newPixel;
Modified: trunk/src/wosaic/utilities/MosaicEvent.java
==============================================================================
--- trunk/src/wosaic/utilities/MosaicEvent.java (original)
+++ trunk/src/wosaic/utilities/MosaicEvent.java Wed Sep 3 20:46:53 2008
@@ -32,6 +32,7 @@
*
* @param src the object that generated this event
* @param coords A list of coordinates that were updated
+ * @param pixel The pixel object that was added to the mosaic
*/
public MosaicEvent(final Object src, final ArrayList<Point> coords,
final Pixel pixel) {
Modified: trunk/src/wosaic/utilities/MosaicListener.java
==============================================================================
--- trunk/src/wosaic/utilities/MosaicListener.java (original)
+++ trunk/src/wosaic/utilities/MosaicListener.java Wed Sep 3 20:46:53 2008
@@ -7,10 +7,14 @@
/**
* @author carl-eriksvensson
- *
*/
public interface MosaicListener extends EventListener {
+ /**
+ * Event that triggers when the Mosaic object gets updated with a new
Pixel
+ *
+ * @param e The event parameters
+ */
public void mosaicUpdated(MosaicEvent e);
}
Modified: trunk/src/wosaic/utilities/SourcePlugin.java
==============================================================================
--- trunk/src/wosaic/utilities/SourcePlugin.java (original)
+++ trunk/src/wosaic/utilities/SourcePlugin.java Wed Sep 3 20:46:53 2008
@@ -20,10 +20,16 @@
*/
protected int numResults;
+ /**
+ * The ImageBuffer where result images should be pushed to
+ */
protected ImageBuffer sourcesBuffer = null;
private Status statusObject;
+ /**
+ * A shared ThreadPool where child worker threads should be queried
+ */
protected ExecutorService ThreadPool;
/**
@@ -78,6 +84,12 @@
ThreadPool = tp;
}
+ /**
+ * Set the search string used by the given plugin. Note that not all
plugins
+ * will need to use this.
+ *
+ * @param s The new string to search for.
+ */
public void setSearchString(final String s) {
// By default, do nothing
}
Modified: trunk/src/wosaic/utilities/WosaicFilter.java
==============================================================================
--- trunk/src/wosaic/utilities/WosaicFilter.java (original)
+++ trunk/src/wosaic/utilities/WosaicFilter.java Wed Sep 3 20:46:53 2008
@@ -18,9 +18,9 @@
/**
* Determine whether we should accept directories or not
*/
- boolean acceptDirs = true;
+ private boolean acceptDirs = true;
- ArrayList<String> filters;
+ private ArrayList<String> filters;
/**
* Default constructor allows all filters accepted by ImageIO natively.
Also