Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 1 commit
  • 12 files changed
  • 0 comments
  • 1 contributor
Oct 22, 2012
code bastardised for stupid processing c8dc2a4
BIN  .DS_Store
Binary file not shown
404  src/FileSystem.java
@@ -3,208 +3,208 @@
3 3
 import java.util.HashMap;
4 4
 
5 5
 public class FileSystem {
6  
-	
7  
-	File toLoad;
8  
-	File toSave;
9  
-	String dir;
10  
-	File[] associationFiles;
11  
-	long lastMod;
12  
-	File lastModFile;
13  
-	FilenameFilter mediaFilter;
14  
-	String types[] = { "aif", "jpg", "jpeg", "png", "wav", "aiff" };
15  
-	ArrayList<String> paths;
16  
-	ImportWindow importWin;
17  
-	LoadWindow loadWin;
18  
-	NewWindow newWin;
19  
-	HashMap<String, String> associations;
20  
-	int mediaPtr;
  6
+  
  7
+  File toLoad;
  8
+  File toSave;
  9
+  String dir;
  10
+  File[] associationFiles;
  11
+  long lastMod;
  12
+  File lastModFile;
  13
+  FilenameFilter mediaFilter;
  14
+  String types[] = { "aif", "jpg", "jpeg", "png", "wav", "aiff" };
  15
+  ArrayList<String> paths;
  16
+  ImportWindow importWin;
  17
+  LoadWindow loadWin;
  18
+  NewWindow newWin;
  19
+  HashMap<String, String> associations;
  20
+  int mediaPtr;
21 21
 
22  
-	public FileSystem() {
23  
-		dir=new File("").getAbsolutePath();
24  
-		if(!new File(dir+"/media/").exists()) {
25  
-			new File(dir+"/media/").mkdir();
26  
-		}
27  
-		if(!new File(dir+"/recordings/").exists()) {
28  
-			new File(dir+"/recordings/").mkdir();
29  
-		}
30  
-		lastModFile=new File(dir+"/media/");
31  
-		lastMod=lastModFile.lastModified();
32  
-		mediaFilter = new MediaFilter(types);
33  
-		importWin = new ImportWindow();
34  
-		newWin = new NewWindow();
35  
-		loadWin = new LoadWindow();
36  
-		associations = new HashMap<String, String>();
37  
-		mediaPtr = 0;
38  
-	}
39  
-	
40  
-	public String[] shiftFocus(int dir,int bufferSize) {
41  
-		if (paths.size() > 0) {
42  
-			mediaPtr+=dir;
43  
-			mediaPtr=mediaPtr % (paths.size());
44  
-			String[] items = new String[bufferSize];
45  
-			for(int i=0;i<bufferSize;i++) {
46  
-				int temp=(mediaPtr+(i-(bufferSize/2)))%paths.size();
47  
-				if(temp<0) {
48  
-					temp=paths.size()+temp;
49  
-				}
50  
-				items[i]=paths.get(temp);
51  
-			}
52  
-			return items;
53  
-		} else {
54  
-			return null;
55  
-		}
56  
-	}
57  
-	
58  
-	public String getItem(String key) {
59  
-		return associations.get(key);
60  
-	}
61  
-	
62  
-	public void associateItem(String key,String item) {
63  
-		if (associations.containsKey(key)) {
64  
-			associations.remove(key);
65  
-		}
66  
-		associations.put(key, item);
67  
-		System.out.println("Associating:" + item + " with:" + key);
68  
-	}
69  
-	
70  
-	public Boolean checkImport() {
71  
-		if(importWin.loaded) {
72  
-			return true;
73  
-		} else {
74  
-			return false;
75  
-		}
76  
-	}
77  
-	
78  
-	public Boolean checkNew(String name) {
79  
-		if(newWin.dir != null && name!=null) {
80  
-			newProject(newWin.dir,name);
81  
-			newWin.dir=null;
82  
-			return true;
83  
-		} else {
84  
-			return false;
85  
-		}
86  
-	}
87  
-	
88  
-	public Boolean checkLoad() {
89  
-		if(loadWin.dir != null) {
90  
-			if(loadWin.dir.endsWith(".keir")) {
91  
-				loadProject(loadWin.dir);
92  
-				loadWin.dir=null;
93  
-				return true;
94  
-			} else {
95  
-				return false;
96  
-			}
97  
-		} else {
98  
-			return false;
99  
-		}
100  
-	}
101  
-	
102  
-	public void launchNew() {
103  
-		newWin.launchChooser();
104  
-	}
105  
-	
106  
-	public void launchLoad() {
107  
-		loadWin.launchChooser();
108  
-	}
109  
-	
110  
-	public void launchImport(ModalView mv) {
111  
-		importWin.launchChooser(dir + "/media/",mv);
112  
-	}
113  
-	
114  
-	public void updatePaths() {
115  
-		File[] files = new File(dir + "/media/").listFiles(mediaFilter);
116  
-		paths = new ArrayList<String>();
117  
-		for (int i = 0; i < files.length; i++) {
118  
-			String item = files[i].getAbsolutePath();
119  
-			paths.add(item);
120  
-			System.out.println("ADDED:" + paths.get(i));
121  
-		}
122  
-	}
123  
-	
124  
-	public Boolean updateRequired() {
125  
-		long newMod = lastModFile.lastModified();
126  
-		if (lastMod != newMod) {
127  
-			lastMod = newMod;
128  
-			return true;
129  
-		} else {
130  
-			return false;
131  
-		}
132  
-	}
133  
-	
134  
-	public void deleteFile(String dir) {
135  
-		new File(dir).delete();
136  
-	}
137  
-	
138  
-	public void deleteFolderContents(String dir) {
139  
-		File[] files = new File(dir).listFiles(mediaFilter);
140  
-		for (int i = 0; i < files.length; i++) {
141  
-			files[i].delete();
142  
-		}
143  
- 	}
144  
-	
145  
-	public void newProject(String dir,String projectName) {
146  
-		if(new File(dir+"/"+projectName+"/").exists()) {
147  
-			deleteFolderContents(dir+"/"+projectName+"/media/");
148  
-			deleteFolderContents(dir+"/"+projectName+"/recordings/");
149  
-			System.out.println("OVERWRITE");
150  
-		}
151  
-		new File(dir+"/"+projectName).mkdir();
152  
-		System.out.println(this.dir);
153  
-		this.dir=dir+"/"+projectName;
154  
-		System.out.println(this.dir);
155  
-	    new File(this.dir+"/media/").mkdir();
156  
-	    new File(this.dir+"/recordings/").mkdir();
157  
-		lastModFile = new File(this.dir + "/media/");
158  
-		lastMod = lastModFile.lastModified();
159  
-		saveFile(associations,projectName);
160  
-	}
161  
-	
162  
-	public void loadProject(String dir) {
163  
-		System.out.println("LOADING:"+dir);
164  
-		associations=loadFile(dir);
165  
-		String sep[]=dir.split("/");
166  
-		String newDir="";
167  
-		for (int i = 0; i < sep.length - 1; i++) {
168  
-			newDir+=sep[i]; 
169  
-			if(i<sep.length-2) {
170  
-				newDir+="/";
171  
-			}
172  
-		}
173  
-		this.dir=newDir;
174  
-		System.out.println("New parent directory:"+this.dir);
175  
-		lastModFile = new File(this.dir + "/media/");
176  
-		lastMod = lastModFile.lastModified();
177  
-	}
178  
-	
179  
-	public void saveProject() {
180  
-		String sep[]=dir.split("/");
181  
-		saveFile(associations,sep[sep.length-1]);
182  
-	}
183  
-	
184  
-	public File[] getSavedFiles() {
185  
-		associationFiles=new File(dir).listFiles();
186  
-		return associationFiles;
187  
-	}
188  
-	
189  
-	public void saveFile(HashMap<String,String> associations,String name) {
190  
-		try{
191  
-			FileOutputStream fos = new FileOutputStream(dir+"/"+name+".keir");
192  
-			ObjectOutputStream oos = new ObjectOutputStream(fos);
193  
-			oos.writeObject(associations);
194  
-			oos.close();
195  
-		} catch (Exception e) {
196  
-			e.printStackTrace();
197  
-		}
198  
-	}
  22
+  public FileSystem() {
  23
+    dir=new File("").getAbsolutePath();
  24
+    if(!new File(dir+"/media/").exists()) {
  25
+      new File(dir+"/media/").mkdir();
  26
+    }
  27
+    if(!new File(dir+"/recordings/").exists()) {
  28
+      new File(dir+"/recordings/").mkdir();
  29
+    }
  30
+    lastModFile=new File(dir+"/media/");
  31
+    lastMod=lastModFile.lastModified();
  32
+    mediaFilter = new MediaFilter(types);
  33
+    importWin = new ImportWindow();
  34
+    newWin = new NewWindow();
  35
+    loadWin = new LoadWindow();
  36
+    associations = new HashMap<String, String>();
  37
+    mediaPtr = 0;
  38
+  }
  39
+  
  40
+  public String[] shiftFocus(int dir,int bufferSize) {
  41
+    if (paths.size() > 0) {
  42
+      mediaPtr+=dir;
  43
+      mediaPtr=mediaPtr % (paths.size());
  44
+      String[] items = new String[bufferSize];
  45
+      for(int i=0;i<bufferSize;i++) {
  46
+        int temp=(mediaPtr+(i-(bufferSize/2)))%paths.size();
  47
+        if(temp<0) {
  48
+          temp=paths.size()+temp;
  49
+        }
  50
+        items[i]=paths.get(temp);
  51
+      }
  52
+      return items;
  53
+    } else {
  54
+      return null;
  55
+    }
  56
+  }
  57
+  
  58
+  public String getItem(String key) {
  59
+    return associations.get(key);
  60
+  }
  61
+  
  62
+  public void associateItem(String key,String item) {
  63
+    if (associations.containsKey(key)) {
  64
+      associations.remove(key);
  65
+    }
  66
+    associations.put(key, item);
  67
+    System.out.println("Associating:" + item + " with:" + key);
  68
+  }
  69
+  
  70
+  public Boolean checkImport() {
  71
+    if(importWin.loaded) {
  72
+      return true;
  73
+    } else {
  74
+      return false;
  75
+    }
  76
+  }
  77
+  
  78
+  public Boolean checkNew(String name) {
  79
+    if(newWin.dir != null && name!=null) {
  80
+      newProject(newWin.dir,name);
  81
+      newWin.dir=null;
  82
+      return true;
  83
+    } else {
  84
+      return false;
  85
+    }
  86
+  }
  87
+  
  88
+  public Boolean checkLoad() {
  89
+    if(loadWin.dir != null) {
  90
+      if(loadWin.dir.endsWith(".keir")) {
  91
+        loadProject(loadWin.dir);
  92
+        loadWin.dir=null;
  93
+        return true;
  94
+      } else {
  95
+        return false;
  96
+      }
  97
+    } else {
  98
+      return false;
  99
+    }
  100
+  }
  101
+  
  102
+  public void launchNew() {
  103
+    newWin.launchChooser();
  104
+  }
  105
+  
  106
+  public void launchLoad() {
  107
+    loadWin.launchChooser();
  108
+  }
  109
+  
  110
+  public void launchImport(ModalView mv) {
  111
+    importWin.launchChooser(dir + "/media/",mv);
  112
+  }
  113
+  
  114
+  public void updatePaths() {
  115
+    File[] files = new File(dir + "/media/").listFiles(mediaFilter);
  116
+    paths = new ArrayList<String>();
  117
+    for (int i = 0; i < files.length; i++) {
  118
+      String item = files[i].getAbsolutePath();
  119
+      paths.add(item);
  120
+      System.out.println("ADDED:" + paths.get(i));
  121
+    }
  122
+  }
  123
+  
  124
+  public Boolean updateRequired() {
  125
+    long newMod = lastModFile.lastModified();
  126
+    if (lastMod != newMod) {
  127
+      lastMod = newMod;
  128
+      return true;
  129
+    } else {
  130
+      return false;
  131
+    }
  132
+  }
  133
+  
  134
+  public void deleteFile(String dir) {
  135
+    new File(dir).delete();
  136
+  }
  137
+  
  138
+  public void deleteFolderContents(String dir) {
  139
+    File[] files = new File(dir).listFiles(mediaFilter);
  140
+    for (int i = 0; i < files.length; i++) {
  141
+      files[i].delete();
  142
+    }
  143
+   }
  144
+  
  145
+  public void newProject(String dir,String projectName) {
  146
+    if(new File(dir+"/"+projectName+"/").exists()) {
  147
+      deleteFolderContents(dir+"/"+projectName+"/media/");
  148
+      deleteFolderContents(dir+"/"+projectName+"/recordings/");
  149
+      System.out.println("OVERWRITE");
  150
+    }
  151
+    new File(dir+"/"+projectName).mkdir();
  152
+    System.out.println(this.dir);
  153
+    this.dir=dir+"/"+projectName;
  154
+    System.out.println(this.dir);
  155
+      new File(this.dir+"/media/").mkdir();
  156
+      new File(this.dir+"/recordings/").mkdir();
  157
+    lastModFile = new File(this.dir + "/media/");
  158
+    lastMod = lastModFile.lastModified();
  159
+    saveFile(associations,projectName);
  160
+  }
  161
+  
  162
+  public void loadProject(String dir) {
  163
+    System.out.println("LOADING:"+dir);
  164
+    associations=loadFile(dir);
  165
+    String sep[]=dir.split("/");
  166
+    String newDir="";
  167
+    for (int i = 0; i < sep.length - 1; i++) {
  168
+      newDir+=sep[i]; 
  169
+      if(i<sep.length-2) {
  170
+        newDir+="/";
  171
+      }
  172
+    }
  173
+    this.dir=newDir;
  174
+    System.out.println("New parent directory:"+this.dir);
  175
+    lastModFile = new File(this.dir + "/media/");
  176
+    lastMod = lastModFile.lastModified();
  177
+  }
  178
+  
  179
+  public void saveProject() {
  180
+    String sep[]=dir.split("/");
  181
+    saveFile(associations,sep[sep.length-1]);
  182
+  }
  183
+  
  184
+  public File[] getSavedFiles() {
  185
+    associationFiles=new File(dir).listFiles();
  186
+    return associationFiles;
  187
+  }
  188
+  
  189
+  public void saveFile(HashMap<String,String> associations,String name) {
  190
+    try{
  191
+      FileOutputStream fos = new FileOutputStream(dir+"/"+name+".keir");
  192
+      ObjectOutputStream oos = new ObjectOutputStream(fos);
  193
+      oos.writeObject(associations);
  194
+      oos.close();
  195
+    } catch (Exception e) {
  196
+      e.printStackTrace();
  197
+    }
  198
+  }
199 199
 
200  
-	public HashMap<String,String> loadFile(String name) {
201  
-		try{
202  
-			FileInputStream fis = new FileInputStream(name);
203  
-			ObjectInputStream ois = new ObjectInputStream(fis);
204  
-			return (HashMap<String,String>)ois.readObject();
205  
-		} catch (Exception e) { 
206  
-			e.printStackTrace();
207  
-			return null;
208  
-		}
209  
-	}
  200
+  public HashMap<String,String> loadFile(String name) {
  201
+    try{
  202
+      FileInputStream fis = new FileInputStream(name);
  203
+      ObjectInputStream ois = new ObjectInputStream(fis);
  204
+      return (HashMap<String,String>)ois.readObject();
  205
+    } catch (Exception e) { 
  206
+      e.printStackTrace();
  207
+      return null;
  208
+    }
  209
+  }
210 210
 }
154  src/ImportWindow.java
@@ -6,86 +6,86 @@
6 6
 
7 7
 public class ImportWindow {
8 8
 
9  
-	public String dir;
10  
-	public Boolean loaded;
11  
-	public String selectedPath;
12  
-	ModalView modalView;
  9
+  public String dir;
  10
+  public Boolean loaded;
  11
+  public String selectedPath;
  12
+  ModalView modalView;
13 13
 
14  
-	ImportWindow() {
15  
-		loaded=false;
16  
-	}
17  
-	
  14
+  ImportWindow() {
  15
+    loaded=false;
  16
+  }
  17
+  
18 18
   public boolean isAudio(String item) {
19  
-	    if (item.toLowerCase().endsWith("wav") || item.toLowerCase().endsWith("aif") || item.toLowerCase().endsWith("aiff")) {
20  
-	      return true;
21  
-	    } else {
22  
-	      return false;
23  
-	    }
24  
-	  }
  19
+      if (item.toLowerCase().endsWith("wav") || item.toLowerCase().endsWith("aif") || item.toLowerCase().endsWith("aiff")) {
  20
+        return true;
  21
+      } else {
  22
+        return false;
  23
+      }
  24
+    }
25 25
   
26 26
   public boolean isImage(String item) {
27  
-	    if (item.toLowerCase().endsWith("jpeg") || item.toLowerCase().endsWith("jpg") || item.toLowerCase().endsWith("png")) {
28  
-	      return true;
29  
-	    } else {
30  
-	      return false;
31  
-	    }
32  
-	  }
  27
+      if (item.toLowerCase().endsWith("jpeg") || item.toLowerCase().endsWith("jpg") || item.toLowerCase().endsWith("png")) {
  28
+        return true;
  29
+      } else {
  30
+        return false;
  31
+      }
  32
+    }
33 33
 
34  
-	void launchChooser(String mediaPath, ModalView mv) {
35  
-		modalView=mv;
36  
-		dir=mediaPath;
37  
-		SwingUtilities.invokeLater(new Runnable() {
38  
-			public void run() {
39  
-				try {
40  
-					JFileChooser fc = new JFileChooser();
41  
-					fc.setMultiSelectionEnabled(true);
42  
-					int returnVal = fc.showOpenDialog(null);
43  
-					if (returnVal == JFileChooser.APPROVE_OPTION) {
44  
-						File[] files = fc.getSelectedFiles();
45  
-						for(int i=0;i<files.length;i++) {
46  
-							String path = files[i].getAbsolutePath();
47  
-							System.out.println("Selected file:"+path);
48  
-							String copyPath=dir+files[i].getName();
49  
-							Boolean lastCopy=false;
50  
-							if(i==files.length-1) {
51  
-								lastCopy=true;
52  
-							}
53  
-							copy(path,copyPath,lastCopy);
54  
-						}
55  
-					} else if(returnVal==JFileChooser.CANCEL_OPTION) {
56  
-						modalView.close();
57  
-					}
58  
-				} catch (Exception e) {
59  
-					e.printStackTrace();
60  
-				}
61  
-			}
62  
-		});
63  
-	}
64  
-	
65  
-	public void copy(String originalPath,String copyPath,Boolean lastCopy) {
66  
-		 try {
67  
-			  System.out.println("Copying:"+originalPath+" to:"+copyPath);
68  
-		      File srcFile = new File(originalPath);
69  
-		      File dstFile = new File(copyPath);
70  
-		      if(srcFile.length()<307200 || isAudio(originalPath)) {
71  
-			      FileInputStream in = new FileInputStream(srcFile);
72  
-			      FileOutputStream out = new FileOutputStream(dstFile);
73  
-			      byte[] buf = new byte[1024];
74  
-			      int len;
75  
-			      while ((len = in.read(buf)) > 0) { 
76  
-			    	  out.write(buf, 0, len);
77  
-			      }
78  
-			      in.close();
79  
-			      out.close();
80  
-		      } else if (isImage(originalPath)) {
81  
-		    	  Thumbnailator.createThumbnail(srcFile,dstFile,1920,1080);
82  
-		      }
83  
-		      selectedPath=copyPath;
84  
-		      if(lastCopy) {
85  
-		    	  loaded=true;
86  
-		      }
87  
-		   } catch ( Exception e ) {
88  
-			   e.printStackTrace();
89  
-		   }
90  
-	}
  34
+  void launchChooser(String mediaPath, ModalView mv) {
  35
+    modalView=mv;
  36
+    dir=mediaPath;
  37
+    SwingUtilities.invokeLater(new Runnable() {
  38
+      public void run() {
  39
+        try {
  40
+          JFileChooser fc = new JFileChooser();
  41
+          fc.setMultiSelectionEnabled(true);
  42
+          int returnVal = fc.showOpenDialog(null);
  43
+          if (returnVal == JFileChooser.APPROVE_OPTION) {
  44
+            File[] files = fc.getSelectedFiles();
  45
+            for(int i=0;i<files.length;i++) {
  46
+              String path = files[i].getAbsolutePath();
  47
+              System.out.println("Selected file:"+path);
  48
+              String copyPath=dir+files[i].getName();
  49
+              Boolean lastCopy=false;
  50
+              if(i==files.length-1) {
  51
+                lastCopy=true;
  52
+              }
  53
+              copy(path,copyPath,lastCopy);
  54
+            }
  55
+          } else if(returnVal==JFileChooser.CANCEL_OPTION) {
  56
+            modalView.close();
  57
+          }
  58
+        } catch (Exception e) {
  59
+          e.printStackTrace();
  60
+        }
  61
+      }
  62
+    });
  63
+  }
  64
+  
  65
+  public void copy(String originalPath,String copyPath,Boolean lastCopy) {
  66
+     try {
  67
+        System.out.println("Copying:"+originalPath+" to:"+copyPath);
  68
+          File srcFile = new File(originalPath);
  69
+          File dstFile = new File(copyPath);
  70
+          if(srcFile.length()<307200 || isAudio(originalPath)) {
  71
+            FileInputStream in = new FileInputStream(srcFile);
  72
+            FileOutputStream out = new FileOutputStream(dstFile);
  73
+            byte[] buf = new byte[1024];
  74
+            int len;
  75
+            while ((len = in.read(buf)) > 0) { 
  76
+              out.write(buf, 0, len);
  77
+            }
  78
+            in.close();
  79
+            out.close();
  80
+          } else if (isImage(originalPath)) {
  81
+            Thumbnailator.createThumbnail(srcFile,dstFile,1920,1080);
  82
+          }
  83
+          selectedPath=copyPath;
  84
+          if(lastCopy) {
  85
+            loaded=true;
  86
+          }
  87
+       } catch ( Exception e ) {
  88
+         e.printStackTrace();
  89
+       }
  90
+  }
91 91
 }
214  src/KeirGUI.java
@@ -5,112 +5,112 @@
5 5
 import processing.core.PFont;
6 6
 
7 7
 public class KeirGUI {
8  
-	
9  
-	ControlP5 cp5;
10  
-	int height;
11  
-	int width;
12  
-	int viewerHeight;
13  
-	int viewerWidth;
14  
-	int viewerX;
15  
-	int viewerY;
16  
-	int btnWidth=100;
17  
-	HashMap <String, Controller> controls;
18  
-	PFont font;
19  
-	
20  
-	public KeirGUI(KeirsKidsMain processing) {
21  
-		cp5=new ControlP5(processing);
22  
-		height=processing.height;
23  
-		width=processing.width;
24  
-		viewerHeight=(int)(height*0.6);
25  
-		viewerWidth=(int)(width*0.6);
26  
-		viewerX=(width/2)-(viewerWidth/2);
27  
-		viewerY=(height/2)-(viewerHeight/2);
28  
-		font=processing.createFont("FFScala",14);
29  
-		
30  
-		controls=new HashMap <String, Controller>();
31  
-		
32  
-	    initViewer();
33  
-	}
34  
-	
35  
-	public String getNewProjectName() {
36  
-		Textfield tf=(Textfield)controls.get("tfNewProject");
37  
-		return tf.getText();
38  
-	}
39  
-	
40  
-	public void clearGUI() {
41  
-		Iterator it = controls.entrySet().iterator();
42  
-	    while (it.hasNext()) {
43  
-	        Map.Entry<String,Controller> pairs = (Map.Entry<String,Controller>)it.next();
44  
-	        cp5.remove(pairs.getValue().getName());
45  
-	       // System.out.println(pairs.getKey() + " = " + pairs.getValue());
46  
-	        it.remove();
47  
-	    }
48  
-	    controls.clear();
49  
-	}
50  
-	
51  
-	public void initPlayer() {
52  
-		clearGUI();
53  
-	    controls.put("record", cp5.addButton("record")
54  
-	    .setPosition(0,0)
55  
-	    .setSize(btnWidth,btnWidth)
56  
-	    .activateBy(ControlP5Constants.PRESSED));
57  
-	    controls.put("playItem",cp5.addButton("playItem")
58  
-	    .setPosition(300,0)
59  
-	    .setSize(btnWidth,btnWidth));
60  
-	    controls.put("fullScreen", cp5.addButton("fullScreen")
61  
-	    .setPosition(100,0)
62  
-	    .setSize(btnWidth,btnWidth));
63  
-	    controls.put("associateItem", cp5.addButton("associateItem")
64  
-	    .setPosition(200,0)
65  
-	    .setSize(btnWidth,btnWidth));
66  
-	    controls.put("linkToken", cp5.addTextlabel("linkToken")
67  
-	    .setPosition(400,0)
68  
-	    .setSize(btnWidth,btnWidth)
69  
-	    .setColor(0)
70  
-	    .setFont(font));
71  
-	    controls.put("prevItem",cp5.addButton("prevItem")
72  
-	    .setPosition(viewerX-btnWidth,(viewerX+viewerHeight/2))
73  
-	    .setSize(btnWidth,btnWidth));
74  
-	    controls.put("nextItem",cp5.addButton("nextItem")
75  
-	    .setPosition(viewerX+viewerWidth,(viewerX+viewerHeight/2))
76  
-	    .setSize(btnWidth,btnWidth));
77  
-	    controls.put("initPlayer",cp5.addButton("player")
78  
-	    .setPosition(600,0)
79  
-	    .setSize(btnWidth,btnWidth));
80  
-	    controls.put("initViewer",cp5.addButton("viewer")
81  
-	    .setPosition(700,0)
82  
-	    .setSize(btnWidth,btnWidth));
83  
-	}
84  
-	
85  
-	public void initViewer() {
86  
-		clearGUI();
87  
-	    controls.put("importMedia", cp5.addButton("importMedia")
88  
-	    .setPosition(0,0)
89  
-	    .setSize(btnWidth,btnWidth));
90  
-	    controls.put("deleteFromProject",cp5.addButton("deleteFromProject")
91  
-	    .setPosition(100,0)
92  
-	    .setSize(btnWidth,btnWidth));
93  
-	    controls.put("saveProject", cp5.addButton("saveProject")
94  
-	    .setPosition(400,0)
95  
-	    .setSize(btnWidth,btnWidth));
96  
-	    controls.put("loadProject",cp5.addButton("loadProject")
97  
-	    .setPosition(200,0)
98  
-	    .setSize(btnWidth,btnWidth));
99  
-	    controls.put("newProject",cp5.addButton("newProject")
100  
-	    .setPosition(300,0)
101  
-	    .setSize(btnWidth,btnWidth));
102  
-	    controls.put("initPlayer",cp5.addButton("player")
103  
-	    .setPosition(600,0)
104  
-	    .setSize(btnWidth,btnWidth));
105  
-	    controls.put("initViewer",cp5.addButton("viewer")
106  
-	    .setPosition(700,0)
107  
-	    .setSize(btnWidth,btnWidth));
108  
-	    controls.put("prevItem",cp5.addButton("prevItem")
109  
-	    .setPosition(viewerX-btnWidth,(viewerX+viewerHeight/2))
110  
-	    .setSize(btnWidth,btnWidth));
111  
-	    controls.put("nextItem",cp5.addButton("nextItem")
112  
-	    .setPosition(viewerX+viewerWidth,(viewerX+viewerHeight/2))
113  
-	    .setSize(btnWidth,btnWidth));
114  
-	}
  8
+  
  9
+  ControlP5 cp5;
  10
+  int height;
  11
+  int width;
  12
+  int viewerHeight;
  13
+  int viewerWidth;
  14
+  int viewerX;
  15
+  int viewerY;
  16
+  int btnWidth=100;
  17
+  HashMap <String, controlP5.Controller> controls;
  18
+  PFont font;
  19
+  
  20
+  public KeirGUI(int width,int height,PFont font,ControlP5 cp5) {
  21
+    this.cp5=cp5;
  22
+    this.height=height;
  23
+    this.width=width;
  24
+    viewerHeight=(int)(height*0.6);
  25
+    viewerWidth=(int)(width*0.6);
  26
+    viewerX=(width/2)-(viewerWidth/2);
  27
+    viewerY=(height/2)-(viewerHeight/2);
  28
+    this.font=font;
  29
+    controls=new HashMap <String, controlP5.Controller>();
  30
+    
  31
+      initViewer();
  32
+  }
  33
+  
  34
+  public String getNewProjectName() {
  35
+    Textfield tf=(Textfield)controls.get("tfNewProject");
  36
+    return tf.getText();
  37
+  }
  38
+  
  39
+  public void clearGUI() {
  40
+    
  41
+    Iterator it = controls.values().iterator();
  42
+      while (it.hasNext()) {
  43
+          controlP5.Controller val = (controlP5.Controller)it.next();
  44
+          cp5.remove(val.getName());
  45
+         // System.out.println(pairs.getKey() + " = " + pairs.getValue());
  46
+          it.remove();
  47
+      }
  48
+      controls.clear();
  49
+  }
  50
+  
  51
+  public void initPlayer() {
  52
+    clearGUI();
  53
+      controls.put("record", cp5.addButton("record")
  54
+      .setPosition(0,0)
  55
+      .setSize(btnWidth,btnWidth)
  56
+      .activateBy(ControlP5Constants.PRESSED));
  57
+      controls.put("playItem",cp5.addButton("playItem")
  58
+      .setPosition(300,0)
  59
+      .setSize(btnWidth,btnWidth));
  60
+      controls.put("fullScreen", cp5.addButton("fullScreen")
  61
+      .setPosition(100,0)
  62
+      .setSize(btnWidth,btnWidth));
  63
+      controls.put("associateItem", cp5.addButton("associateItem")
  64
+      .setPosition(200,0)
  65
+      .setSize(btnWidth,btnWidth));
  66
+      controls.put("linkToken", cp5.addTextlabel("linkToken")
  67
+      .setPosition(400,0)
  68
+      .setSize(btnWidth,btnWidth)
  69
+      .setColor(0)
  70
+      .setFont(font));
  71
+      controls.put("prevItem",cp5.addButton("prevItem")
  72
+      .setPosition(viewerX-btnWidth,(viewerX+viewerHeight/2))
  73
+      .setSize(btnWidth,btnWidth));
  74
+      controls.put("nextItem",cp5.addButton("nextItem")
  75
+      .setPosition(viewerX+viewerWidth,(viewerX+viewerHeight/2))
  76
+      .setSize(btnWidth,btnWidth));
  77
+      controls.put("initPlayer",cp5.addButton("player")
  78
+      .setPosition(600,0)
  79
+      .setSize(btnWidth,btnWidth));
  80
+      controls.put("initViewer",cp5.addButton("viewer")
  81
+      .setPosition(700,0)
  82
+      .setSize(btnWidth,btnWidth));
  83
+  }
  84
+  
  85
+  public void initViewer() {
  86
+    clearGUI();
  87
+      controls.put("importMedia", cp5.addButton("importMedia")
  88
+      .setPosition(0,0)
  89
+      .setSize(btnWidth,btnWidth));
  90
+      controls.put("deleteFromProject",cp5.addButton("deleteFromProject")
  91
+      .setPosition(100,0)
  92
+      .setSize(btnWidth,btnWidth));
  93
+      controls.put("saveProject", cp5.addButton("saveProject")
  94
+      .setPosition(400,0)
  95
+      .setSize(btnWidth,btnWidth));
  96
+      controls.put("loadProject",cp5.addButton("loadProject")
  97
+      .setPosition(200,0)
  98
+      .setSize(btnWidth,btnWidth));
  99
+      controls.put("newProject",cp5.addButton("newProject")
  100
+      .setPosition(300,0)
  101
+      .setSize(btnWidth,btnWidth));
  102
+      controls.put("initPlayer",cp5.addButton("player")
  103
+      .setPosition(600,0)
  104
+      .setSize(btnWidth,btnWidth));
  105
+      controls.put("initViewer",cp5.addButton("viewer")
  106
+      .setPosition(700,0)
  107
+      .setSize(btnWidth,btnWidth));
  108
+      controls.put("prevItem",cp5.addButton("prevItem")
  109
+      .setPosition(viewerX-btnWidth,(viewerX+viewerHeight/2))
  110
+      .setSize(btnWidth,btnWidth));
  111
+      controls.put("nextItem",cp5.addButton("nextItem")
  112
+      .setPosition(viewerX+viewerWidth,(viewerX+viewerHeight/2))
  113
+      .setSize(btnWidth,btnWidth));
  114
+  }
115 115
 
116 116
 }
881  src/KeirsKidsMain.java
@@ -5,455 +5,478 @@
5 5
 import java.util.*;
6 6
 import java.awt.Desktop;
7 7
 
8  
-import controlP5.Textlabel;
  8
+import controlP5.*;
9 9
 
10 10
 public class KeirsKidsMain extends PApplet {
11 11
 
12  
-	  Minim minim;
13  
-	  AudioPlayer player;
14  
-	  AudioRecorder recorder;
15  
-	  AudioInput in;
16  
-	  Desktop desktop;
17  
-	  KeirGUI cp5;
18  
-	  int bufferSize=15;
19  
-	  ImageBufferThread thread;
20  
-	  String[] currentItems;
21  
-	  Boolean buffered=true;
22  
-	  PImage displayImage;
23  
-	  String recordPath;
24  
-	  String currentItem;
25  
-	  FileSystem fileSystem;
26  
-	  HashMap<String, PImage> images;
27  
-	  Boolean loading=false;
28  
-	  PImage threadIm=null;
29  
-	  String threadPath=null;
30  
-	  String linkToken;
31  
-	  int dir=1;
32  
-	  Boolean viewer=true;
33  
-	  ModalView modalView;
34  
-	  String newName;
  12
+    Minim minim;
  13
+    AudioPlayer player;
  14
+    AudioRecorder recorder;
  15
+    AudioInput in;
  16
+    Desktop desktop;
  17
+    ControlP5 cont;
  18
+    KeirGUI cp5;
  19
+    int bufferSize=15;
  20
+    ImageBufferThread thread;
  21
+    String[] currentItems;
  22
+    Boolean buffered=true;
  23
+    PImage displayImage;
  24
+    String recordPath;
  25
+    String currentItem;
  26
+    FileSystem fileSystem;
  27
+    HashMap<String, PImage> images;
  28
+    Boolean loading=false;
  29
+    PImage threadIm=null;
  30
+    String threadPath=null;
  31
+    String linkToken;
  32
+    int dir=1;
  33
+    Boolean viewer=true;
  34
+    ModalView modalView;
  35
+    String newName;
35 36
 
36  
-	  public void setup() {
37  
-	    size(1024, 780,OPENGL);
38  
-	    background(255,255,255);
39  
-	    fileSystem = new FileSystem();
40  
-	    desktop = Desktop.getDesktop();
41  
-	    images = new HashMap<String, PImage>();
42  
-	    thread = null;
43  
-	    updateMedia();
44  
-	    minim = new Minim(this);
45  
-	    cp5 = new KeirGUI(this);
46  
-	    currentItems = fileSystem.shiftFocus(1,bufferSize);
47  
-	    in = minim.getLineIn(Minim.STEREO, 2048);
48  
-	    recorder = minim.createRecorder(in, "test.wav", true);
49  
-	    fill(0);
50  
-	    noStroke();
51  
-	    rect(cp5.viewerX-50,cp5.viewerY-50,cp5.viewerWidth+100,cp5.viewerHeight+100);
52  
-	  }
53  
-	  
54  
-	  public void openModalView(String title, String message) {
55  
-			cp5.clearGUI();
56  
-			fill(255,255,255,100);
57  
-			rect(0,0,width,height);
58  
-			PFont font=createFont("FFScala",14);
59  
-			modalView.setSize(width,height);
60  
-			modalView.setCP5(cp5.cp5);
61  
-			modalView.init(title,message);
62  
-	  }
63  
-	  
64  
-	  public void keyPressed() {
65  
-		  linkToken=Character.toString(key);
66  
-		  try {
67  
-			  Textlabel lbl = (Textlabel)cp5.controls.get("linkToken");
68  
-			  lbl.setText("Your current token is \n"+linkToken);
69  
-			  fill(255);
70  
-			  rect(lbl.getPosition().x,lbl.getPosition().y,lbl.getWidth(),100);
71  
-		  } catch (NullPointerException e) {
72  
-			  
73  
-		  }
74  
-		  System.out.println("Link token:"+linkToken);
75  
-	  }
  37
+    public void setup() {
  38
+      size(1024, 780,OPENGL);
  39
+      background(255,255,255);
  40
+      fileSystem = new FileSystem();
  41
+      desktop = Desktop.getDesktop();
  42
+      images = new HashMap<String, PImage>();
  43
+      thread = null;
  44
+      updateMedia();
  45
+      minim = new Minim(this);
  46
+      cont=new ControlP5(this);
  47
+      PFont font=createFont("FFScala",14);
  48
+      cp5 = new KeirGUI(width,height,font,cont);
  49
+      currentItems = fileSystem.shiftFocus(1,bufferSize);
  50
+      in = minim.getLineIn(Minim.STEREO, 2048);
  51
+      recorder = minim.createRecorder(in, "test.wav", true);
  52
+      fill(0);
  53
+      noStroke();
  54
+      rect(cp5.viewerX-50,cp5.viewerY-50,cp5.viewerWidth+100,cp5.viewerHeight+100);
  55
+    }
  56
+    
  57
+    public void openModalView(String title, String message) {
  58
+      cp5.clearGUI();
  59
+      fill(255,255,255,100);
  60
+      rect(0,0,width,height);
  61
+      PFont font=createFont("FFScala",14);
  62
+      modalView.font=font;
  63
+      modalView.setSize(width,height);
  64
+      modalView.setCP5(cp5.cp5);
  65
+      modalView.init(title,message);
  66
+    }
  67
+    
  68
+    public void keyPressed() {
  69
+      linkToken=Character.toString(key);
  70
+      try {
  71
+        Textlabel lbl = (Textlabel)(cp5.controls.get("linkToken"));
  72
+        lbl.setText("Your current token is \n"+linkToken);
  73
+        fill(255);
  74
+        rect(lbl.getPosition().x,lbl.getPosition().y,lbl.getWidth(),100);
  75
+      } catch (NullPointerException e) {
  76
+        
  77
+      }
  78
+      System.out.println("Link token:"+linkToken);
  79
+    }
76 80
 
77  
-	  public boolean isAudio(String item) {
78  
-	    if (item.toLowerCase().endsWith("wav") || item.toLowerCase().endsWith("aif") || item.toLowerCase().endsWith("aiff")) {
79  
-	      return true;
80  
-	    } else {
81  
-	      return false;
82  
-	    }
83  
-	  }
84  
-	  
85  
-	  public void importMedia() {
86  
-	    modalView=new ModalView(null);
87  
-	    openModalView("Please Wait", "Your Files are being imported");
88  
-	    fileSystem.launchImport(modalView);
89  
-	  }
90  
-	  
91  
-	  public void record() {
92  
-		  modalView=new RecordView(millis(),"rec");
93  
-		  openModalView("Recording", "Recording will begin after countdown");
94  
-	  }
95  
-	  
96  
-	  public void deleteFromProject() {
97  
-	    clearViewer();
98  
-	    fileSystem.deleteFile(currentItem);
99  
-	    updateMedia();
100  
-	    nextItem();
101  
-	  }
102  
-	  
103  
-	  public void clearViewer() {
104  
-	    fill(0);
105  
-	    rect(cp5.viewerX, cp5.viewerY, cp5.viewerWidth, cp5.viewerHeight);
106  
-	  }
107  
-	  
108  
-	  public void fullScreen(int theValue) {
109  
-		  System.out.println(theValue);
110  
-	  }
111  
-	  
112  
-	  public void clearScreen() {
113  
-		  fill(255);
114  
-		  rect(0,0,width,height);
115  
-		  fill(0);
116  
-		  rect(cp5.viewerX-50,cp5.viewerY-50,cp5.viewerWidth+100,cp5.viewerHeight+100);
117  
-		  System.out.println("clear screen");
118  
-	  }
  81
+    public boolean isAudio(String item) {
  82
+      if (item.toLowerCase().endsWith("wav") || item.toLowerCase().endsWith("aif") || item.toLowerCase().endsWith("aiff")) {
  83
+        return true;
  84
+      } else {
  85
+        return false;
  86
+      }
  87
+    }
  88
+    
  89
+    public void importMedia() {
  90
+      modalView=new ModalView(null);
  91
+      openModalView("Please Wait", "Your Files are being imported");
  92
+      fileSystem.launchImport(modalView);
  93
+    }
  94
+    
  95
+    public void record() {
  96
+      modalView=new RecordView(millis(),"rec");
  97
+      openModalView("Recording", "Recording will begin after countdown");
  98
+    }
  99
+    
  100
+    public void deleteFromProject() {
  101
+      clearViewer();
  102
+      fileSystem.deleteFile(currentItem);
  103
+      updateMedia();
  104
+      nextItem();
  105
+    }
  106
+    
  107
+    public void clearViewer() {
  108
+      fill(0);
  109
+      rect(cp5.viewerX, cp5.viewerY, cp5.viewerWidth, cp5.viewerHeight);
  110
+    }
  111
+    
  112
+    public void fullScreen(int theValue) {
  113
+      System.out.println(theValue);
  114
+    }
  115
+    
  116
+    public void clearScreen() {
  117
+      fill(255);
  118
+      rect(0,0,width,height);
  119
+      fill(0);
  120
+      rect(cp5.viewerX-50,cp5.viewerY-50,cp5.viewerWidth+100,cp5.viewerHeight+100);
  121
+      System.out.println("clear screen");
  122
+    }
119 123
 
120  
-	  public void openMediaFolder() {
121  
-	    try {
122  
-	      desktop.open(new File(fileSystem.dir + "/media/"));
123  
-	    } catch (Exception e) {
124  
-	      System.out.println("desktop exception: " + e);
125  
-	    }
126  
-	  }
127  
-	  
128  
-	  public void close() {
129  
-		  modalView.close();
130  
-	  }
131  
-	  
132  
-	  public void done() {
133  
-		  modalView.done();
134  
-	  }
135  
-	  
136  
-	  public void saveProject() {
137  
-	    fileSystem.saveProject();
138  
-	  }
139  
-	  
140  
-	  public void redraw() {
141  
-		  System.out.println("redraw");
142  
-			if(viewer) {
143  
-				viewer();
144  
-			} else  {
145  
-				player();
146  
-			}
147  
-	  }
148  
-	  
149  
-	  public void player() {
150  
-		  viewer=false;
151  
-		  cp5.initPlayer();
152  
-		  clearScreen();
153  
-			try {
154  
-				showMedia(currentItems[(int)Math.ceil(bufferSize/2)]);
155  
-			} catch (NullPointerException e) {
156  
-				
157  
-			}
158  
-	  }
159  
-	  
160  
-	  public void viewer() {
161  
-		  viewer=true;
162  
-		  cp5.initViewer();
163  
-		  clearScreen();
164  
-			try {
165  
-				showMedia(currentItems[(int)Math.ceil(bufferSize/2)]);
166  
-			} catch (NullPointerException e) {
167  
-				
168  
-			}
169  
-	  }
170  
-	  
171  
-	  public void loadProject() {
172  
-	    fileSystem.launchLoad();
173  
-	  }
  124
+    public void openMediaFolder() {
  125
+      try {
  126
+        desktop.open(new File(fileSystem.dir + "/media/"));
  127
+      } catch (Exception e) {
  128
+        System.out.println("desktop exception: " + e);
  129
+      }
  130
+    }
  131
+    
  132
+    public void close() {
  133
+      modalView.close();
  134
+    }
  135
+    
  136
+    public void done() {
  137
+      modalView.done();
  138
+    }
  139
+    
  140
+    public void saveProject() {
  141
+      fileSystem.saveProject();
  142
+    }
  143
+    
  144
+    public void redraw() {
  145
+      System.out.println("redraw");
  146
+      if(viewer) {
  147
+        viewer();
  148
+      } else  {
  149
+        player();
  150
+      }
  151
+    }
  152
+    
  153
+    public void player() {
  154
+      viewer=false;
  155
+      cp5.initPlayer();
  156
+      clearScreen();
  157
+      try {
  158
+        showMedia(currentItems[(int)Math.ceil(bufferSize/2)]);
  159
+      } catch (NullPointerException e) {
  160
+        
  161
+      }
  162
+    }
  163
+    
  164
+    public void viewer() {
  165
+      viewer=true;
  166
+      cp5.initViewer();
  167
+      clearScreen();
  168
+      try {
  169
+        showMedia(currentItems[(int)Math.ceil(bufferSize/2)]);
  170
+      } catch (NullPointerException e) {
  171
+        
  172
+      }
  173
+    }
  174
+    
  175
+    public void loadProject() {
  176
+      fileSystem.launchLoad();
  177
+    }
174 178
 
175  
-	   public void newProject() {
176  
-	    	modalView=new NewProjectView("new");
177  
-	    	openModalView("New Project","Please enter project name");
178  
-	   }
  179
+     public void newProject() {
  180
+        modalView=new NewProjectView("new");
  181
+        openModalView("New Project","Please enter project name");
  182
+     }
179 183
 
180  
-	  public String mediaToRecordPath(String item) {
181  
-	    String[] sep = item.split("/");
182  
-	    String recPath = "";
183  
-	    for (int i = 0; i < sep.length - 2; i++) {
184  
-	      recPath = recPath + sep[i] + "/";
185  
-	    }
186  
-	    recPath = recPath + "recordings/";
187  
-	    recPath = recPath + sep[sep.length - 1] + ".wav";
188  
-	    return recPath;
189  
-	  }
  184
+    public String mediaToRecordPath(String item) {
  185
+      String[] sep = item.split("/");
  186
+      String recPath = "";
  187
+      for (int i = 0; i < sep.length - 2; i++) {
  188
+        recPath = recPath + sep[i] + "/";
  189
+      }
  190
+      recPath = recPath + "recordings/";
  191
+      recPath = recPath + sep[sep.length - 1] + ".wav";
  192
+      return recPath;
  193
+    }
190 194
 
191  
-	  public void startRecord() {
192  
-	    if (currentItem != null) {
193  
-	      String item = currentItem;
194  
-	      if (!isAudio(item)) {
195  
-	        if (recorder.isRecording()) {
196  
-	          recorder.endRecord();
197  
-	        } else {
198  
-	          recordPath = mediaToRecordPath(item);
199  
-	          recorder = minim.createRecorder(in, recordPath, true);
200  
-	          recorder.beginRecord();
201  
-	          modalView.close();
202  
-	          modalView= new ModalView(null);
203  
-	          openModalView("Recording","Release record button to stop recording");
204  
-	        }
205  
-	      }
206  
-	    }
207  
-	  }
  195
+    public void startRecord() {
  196
+      if (currentItem != null) {
  197
+        String item = currentItem;
  198
+        if (!isAudio(item)) {
  199
+          if (recorder.isRecording()) {
  200
+            recorder.endRecord();
  201
+          } else {
  202
+            recordPath = mediaToRecordPath(item);
  203
+            recorder = minim.createRecorder(in, recordPath, true);
  204
+            recorder.beginRecord();
  205
+            modalView.close();
  206
+            modalView= new ModalView(null);
  207
+            openModalView("Recording","Release record button to stop recording");
  208
+          }
  209
+        }
  210
+      }
  211
+    }
208 212
 
209  
-	  public void endRecord() {
210  
-	    if (recorder.isRecording()) {
211  
-	      recorder.endRecord();
212  
-	      recorder.save();
213  
-	      modalView.close();
214  
-	      modalView=new ModalView(null);
215  
-	      openModalView("Recording","Recording Finished");
216  
-	      String item = currentItem;
217  
-	      if (new File(recordPath).exists()) {
218  
-	      }
219  
-	      System.out.println("Associating:" + recordPath + " with" + item);
220  
-	    }
221  
-	  }
  213
+    public void endRecord() {
  214
+      if (recorder.isRecording()) {
  215
+        recorder.endRecord();
  216
+        recorder.save();
  217
+        modalView.close();
  218
+        modalView=new ModalView(null);
  219
+        openModalView("Recording","Recording Finished");
  220
+        String item = currentItem;
  221
+        if (new File(recordPath).exists()) {
  222
+        }
  223
+        System.out.println("Associating:" + recordPath + " with" + item);
  224
+      }
  225
+    }
222 226
 
223  
-	  public void playItem() {
224  
-	    String item = fileSystem.getItem(linkToken);
225  
-	    if (item != null) {
226  
-	      showMedia(item);
227  
-	    }
228  
-	  }
  227
+    public void playItem() {
  228
+      String item = fileSystem.getItem(linkToken);
  229
+      if (item != null) {
  230
+        showMedia(item);
  231
+      }
  232
+    }
229 233
 
230  
-	  public void associateItem() {
231  
-		modalView=new LinkWindow(millis(),"link");
232  
-		openModalView("Link token to media","Place token on reader");
233  
-	    
234  
-	  }
235  
-	  
236  
-	  public String doLinkItem() {
237  
-		  fileSystem.associateItem(linkToken,currentItem);
238  
-		  String[] sep=currentItem.split("/");
239  
-		  return "Linking: "+linkToken +" to " +sep[sep.length-1];
240  
-	  }
  234
+    public void associateItem() {
  235
+    modalView=new LinkWindow(millis(),"link");
  236
+    openModalView("Link token to media","Place token on reader");
  237
+    }
  238
+    
  239
+    public String doLinkItem() {
  240
+      fileSystem.associateItem(linkToken,currentItem);
  241
+      String[] sep=currentItem.split("/");
  242
+      return "Linking: "+linkToken +" to " +sep[sep.length-1];
  243
+    }
241 244
 
242  
-	  public float scaleImage(int target,int current) {
243  
-	    if (displayImage != null) {
244  
-	      float multiplier;
245  
-	      multiplier = (float) target / (float) current;
246  
-	      return multiplier;
247  
-	    }
248  
-	    return 4;
249  
-	  }
  245
+    public float scaleImage(int target,int current) {
  246
+      if (displayImage != null) {
  247
+        float multiplier;
  248
+        multiplier = (float) target / (float) current;
  249
+        return multiplier;
  250
+      }
  251
+      return 4;
  252
+    }
250 253
 
251  
-	  public void display() {
  254
+    public void display() {
252 255
           float wMul = scaleImage(cp5.viewerWidth,displayImage.width);
253 256
           float hMul = scaleImage(cp5.viewerHeight,displayImage.height);
254 257
           image(displayImage, cp5.viewerX, cp5.viewerY, (int) (displayImage.width * wMul),
255 258
               (int) (displayImage.height * hMul));
256  
-	  }
257  
-	  
258  
-	  public void showMedia(String item) {
259  
-	    if (fileSystem.paths.contains(item)) {
260  
-	      currentItem = item;
261  
-	      if (displayImage != null) {
262  
-	        clearViewer();
263  
-	      }
264  
-	      if (player != null) {
265  
-	        player.pause();
266  
-	      }
267  
-	      if (isAudio(item)) {
268  
-	        player = minim.loadFile(item);
269  
-	        //Remove item if minim can't load it
270  
-	        if(player==null) {
271  
-	        	deleteFromProject();
272  
-	        } else {
273  
-	        	player.play();
274  
-	        }
275  
-	      } else {
276  
-	        if(buffered) {
277  
-	        	displayImage = images.get(item);
278  
-	        } else {
279  
-	        	displayImage = loadImage(item);
280  
-	        }
281  
-	        System.out.println("Displaying Image:" + displayImage);
282  
-	        try{
283  
-	        	display();
284  
-	        } catch (Exception e) {
285  
-	          System.out.println("show media fail");
286  
-	          displayImage = loadImage(item);
287  
-	          display();
288  
-	        }
289  
-	        String recPath = mediaToRecordPath(item);
290  
-	        //If there is audio associated with the image, play it
291  
-	        if (new File(recPath).exists()) {
292  
-	          player = minim.loadFile(recPath);
293  
-	          player.play();
294  
-	        }
295  
-	      }
296  
-	    } else {
297  
-	      System.out.println("Associated Media Removed");
298  
-	    }
299  
-	  }
  259
+    }
  260
+    
  261
+    public void showMedia(String item) {
  262
+      if (fileSystem.paths.contains(item)) {
  263
+        currentItem = item;
  264
+        if (displayImage != null) {
  265
+          clearViewer();
  266
+        }
  267
+        if (player != null) {
  268
+          player.pause();
  269
+        }
  270
+        if (isAudio(item)) {
  271
+          player = minim.loadFile(item);
  272
+          //Remove item if minim can't load it
  273
+          if(player==null) {
  274
+            deleteFromProject();
  275
+          } else {
  276
+            player.play();
  277
+          }
  278
+        } else {
  279
+          if(buffered) {
  280
+            displayImage = images.get(item);
  281
+          } else {
  282
+            displayImage = loadImage(item);
  283
+          }
  284
+          System.out.println("Displaying Image:" + displayImage);
  285
+          try{
  286
+            display();
  287
+          } catch (Exception e) {
  288
+            System.out.println("show media fail");
  289
+            displayImage = loadImage(item);
  290
+            display();
  291
+          }
  292
+          String recPath = mediaToRecordPath(item);
  293
+          //If there is audio associated with the image, play it
  294
+          if (new File(recPath).exists()) {
  295
+            player = minim.loadFile(recPath);
  296
+            player.play();
  297
+          }
  298
+        }
  299
+      } else {
  300
+        System.out.println("Associated Media Removed");
  301
+      }
  302
+    }
300 303
 
301  
-	  public void nextItem() {
302  
-		dir=1;
303  
-		//Get new list of paths
304  
-		currentItems = fileSystem.shiftFocus(dir,bufferSize);
305  
-	    //Dont remove the image if theres only 1! Do remove if not as buffer has moved
306  
-		if(fileSystem.paths.size()>1) {
307  
-	    	images.remove(currentItems[0]);
308  
-	    }
309  
-	    try{
310  
-	    //show the middle item
311  
-	      String midItem=currentItems[(int)Math.ceil(bufferSize/2)];
312  
-	      showMedia(midItem);
313  
-	    } catch (Exception e) {
314  
-	      
315  
-	    }
316  
-	  }
317  
-	  
318  
-	  public void prevItem() {
319  
-		dir=-1;
320  
-	    currentItems = fileSystem.shiftFocus(dir,bufferSize);
321  
-	    if(fileSystem.paths.size()>1) {
322  
-	    	images.remove(currentItems[currentItems.length-1]);
323  
-	    }
324  
-	    try{
325  
-	      String midItem=currentItems[(int)Math.ceil(bufferSize/2)];
326  
-	      showMedia(midItem);
327  
-	    } catch (Exception e) {
328  
-	      
329  
-	    }
330  
-	  }
  304
+    public void nextItem() {
  305
+    dir=1;
  306
+    //Get new list of paths
  307
+    currentItems = fileSystem.shiftFocus(dir,bufferSize);
  308
+      //Dont remove the image if theres only 1! Do remove if not as buffer has moved
  309
+    if(fileSystem.paths.size()>1) {
  310
+        images.remove(currentItems[0]);
  311
+      }
  312
+      try{
  313
+      //show the middle item
  314
+        String midItem=currentItems[(int)Math.ceil(bufferSize/2)];
  315
+        showMedia(midItem);
  316
+      } catch (Exception e) {
  317
+        
  318
+      }
  319
+    }
  320
+    
  321
+    public void prevItem() {
  322
+    dir=-1;
  323
+      currentItems = fileSystem.shiftFocus(dir,bufferSize);
  324
+      if(fileSystem.paths.size()>1) {
  325
+        images.remove(currentItems[currentItems.length-1]);
  326
+      }
  327
+      try{
  328
+        String midItem=currentItems[(int)Math.ceil(bufferSize/2)];
  329
+        showMedia(midItem);
  330
+      } catch (Exception e) {
  331
+        
  332
+      }
  333
+    }
331 334
 
332  
-	  public void updateMedia() {
333  
-	    fileSystem.updatePaths();
334  
-	  }
335  
-	  
336  
-	  public void reset() {
337  
-	    images = new HashMap<String, PImage>();
338  
-	    clearViewer();
339  
-	    updateMedia();
340  
-	  }
  335
+    public void updateMedia() {
  336
+      fileSystem.updatePaths();
  337
+    }
  338
+    
  339
+    public void reset() {
  340
+      images = new HashMap<String, PImage>();
  341
+      clearViewer();
  342
+      updateMedia();
  343
+    }
341 344
 
342  
-	  public void draw() {
343  
-		  if(viewer) {
344  
-			//If new files have been added
345  
-		    if(fileSystem.updateRequired()) {
346  
-		      fileSystem.updatePaths();
347  
-		    }
348  
-		    //If a file has been selected by the import window and copying is finished
349  
-		    if (fileSystem.checkImport()) {
350  
-		      updateMedia();
351  
-		      modalView.close();
352  
-		      fileSystem.importWin.loaded=false;
353  
-		    }
354  
-		    //If a new file has been created by the new window
355  
-		    try{
356  
-			    if(fileSystem.checkNew(newName)) {
357  
-			      reset();
358  
-			    }
359  
-		    } catch (NullPointerException e) {
360  
-		    	
361  
-		    }
362  
-		    //If a new file has been loaded from the load window
363  
-		    if(fileSystem.checkLoad()) {
364  
-		      reset();
365  
-		    }
366  
-		  } else {
367  
-			  if(modalView!=null) {
368  
-				  if(modalView.redraw) {
369  
-					  redraw();
370  
-					  modalView.redraw=false;
371  
-				  }
372  
-				  if(modalView.complete) {
373  
-					  switch()
374  
-				  }
375  
-				  if(recorder.isRecording() && !mousePressed) {
376  
-					  endRecord();
377  
-				  }
378  
-				  if(modalView.isCounting) {
379  
-					  ((TimedWindow) modalView).isNextStep(millis());
380  
-				  }
381  
-			  }
382  
-		  }
383  
-	    //If the imagebuffer thread has finished loading
384  
-	    if(!loading && threadIm!=null && threadPath!=null) {
385  
-	    	System.out.println("Adding to buffer:"+threadPath);
386  
-	    	thread.quit();
387  
-	    	thread=null;
388  
-	    	images.put(threadPath,threadIm);
389  
-	    	threadIm=null;
390  
-	    	threadPath=null;	
391  
-	    }
392  
-	    if(currentItems!=null && buffered) {
393  
-	    	//If we are not currently loading a file on a thread
394  
-	    	if(thread==null) {
395  
-    			int ptr=(int)Math.ceil(bufferSize/2);
396  
-	    		Boolean notFound=false;
397  
-	    		//If moving left
398  
-	    		if(dir<0) {
399  
-	    			//Start looking from the middle and move left in list
400  
-		    		while(ptr>0 && !notFound) {
401  
-		    			if(!images.containsKey(currentItems[ptr]) && !isAudio(currentItems[ptr])) {
402  
-		    				thread=new ImageBufferThread(currentItems[ptr]);
403  
-		    				thread.start();
404  
-		    				notFound=true;
405  
-		    			}
406  
-		    			ptr--;
407  
-		    		}
408  
-	    		} else {
409  
-	    			//Start looking from the middle and move right in list
410  
-		    		while(ptr<currentItems.length && !notFound) {
411  
-		    			if(!images.containsKey(currentItems[ptr]) && !isAudio(currentItems[ptr])) {
412  
-		    				thread=new ImageBufferThread(currentItems[ptr]);
413  
-		    				thread.start();
414  
-		    				notFound=true;
415  
-		    			}
416  
-		    			ptr++;
417  
-		    		}
418  
-	    		}
419  
-	    	}
420  
-	    }
421  
-	  }
  345
+    public void draw() {
  346
+      if(viewer) {
  347
+      //If new files have been added
  348
+        if(fileSystem.updateRequired()) {
  349
+          fileSystem.updatePaths();
  350
+        }
  351
+        //If a file has been selected by the import window and copying is finished
  352
+        if (fileSystem.checkImport()) {
  353
+          updateMedia();
  354
+          modalView.close();
  355
+          fileSystem.importWin.loaded=false;
  356
+        }
  357
+        //If a new file has been created by the new window
  358
+        try{
  359
+          if(fileSystem.checkNew(newName)) {
  360
+            reset();
  361
+          }
  362
+        } catch (NullPointerException e) {
  363
+          
  364
+        }
  365
+        //If a new file has been loaded from the load window
  366
+        if(fileSystem.checkLoad()) {
  367
+          reset();
  368
+        }
  369
+      } 
  370
+      if(modalView!=null) {
  371
+        if(modalView.redraw) {
  372
+          redraw();
  373
+          modalView.redraw=false;
  374
+        }
  375
+        if(modalView.clearModal) {
  376
+          fill(0);
  377
+          rect(modalView.x,modalView.y,modalView.w,modalView.h);
  378
+          modalView.clearModal=false;
  379
+        }
  380
+        if(modalView.complete) {
  381
+          if(modalView.key=="link") {
  382
+            Textlabel lbl = (Textlabel) modalView.controls.get("message");
  383
+            lbl.setText(doLinkItem());
  384
+          } else if(modalView.key=="rec") {
  385
+            Textlabel lbl = (Textlabel) modalView.controls.get("message");
  386
+            lbl.setText("Recording");
  387
+            startRecord();
  388
+          } else if(modalView.key=="new") {
  389
+            Textfield tf = (Textfield) modalView.controls.get("name");
  390
+            String name=tf.getText();
  391
+            if(!name.isEmpty()) {
  392
+              close();
  393
+              newName=name;
  394
+                fileSystem.launchNew();
  395
+            }
  396
+          }
  397
+          modalView.complete=false;
  398
+        }
  399
+        if(recorder.isRecording() && !mousePressed) {
  400
+          endRecord();
  401
+        }
  402
+        if(modalView.isCounting) {
  403
+          ((TimedWindow) modalView).isNextStep(millis());
  404
+        }
  405
+      }
  406
+      //If the imagebuffer thread has finished loading
  407
+      if(!loading && threadIm!=null && threadPath!=null) {
  408
+        System.out.println("Adding to buffer:"+threadPath);
  409
+        thread.quit();
  410
+        thread=null;
  411
+        images.put(threadPath,threadIm);
  412
+        threadIm=null;
  413
+        threadPath=null;  
  414
+      }
  415
+      if(currentItems!=null && buffered) {
  416
+        //If we are not currently loading a file on a thread
  417
+        if(thread==null) {
  418
+          int ptr=(int)Math.ceil(bufferSize/2);
  419
+          Boolean notFound=false;
  420
+          //If moving left
  421
+          if(dir<0) {
  422
+            //Start looking from the middle and move left in list
  423
+            while(ptr>0 && !notFound) {
  424
+              if(!images.containsKey(currentItems[ptr]) && !isAudio(currentItems[ptr])) {
  425
+                thread=new ImageBufferThread(currentItems[ptr]);
  426
+                thread.start();
  427
+                notFound=true;
  428
+              }
  429
+              ptr--;
  430
+            }
  431
+          } else {
  432
+            //Start looking from the middle and move right in list
  433
+            while(ptr<currentItems.length && !notFound) {
  434
+              if(!images.containsKey(currentItems[ptr]) && !isAudio(currentItems[ptr])) {
  435
+                thread=new ImageBufferThread(currentItems[ptr]);
  436
+                thread.start();
  437
+                notFound=true;
  438
+              }
  439
+              ptr++;
  440
+            }
  441
+          }
  442
+        }
  443
+      }
  444
+    }
422 445
 
423  
-	  public class ImageBufferThread extends Thread {
424  
-	    
425  
-	    String item;
426  
-	    boolean running;
427  
-	    
428  
-	    ImageBufferThread(String item) {
429  
-	      this.item=item;
430  
-	      running=false;
431  
-	    }
432  
-	    
433  
-	    public void start() {
434  
-	      running=true;
435  
-	      super.start();
436  
-	    }
437  
-	    
438  
-	    public synchronized void run() {
439  
-    	  loading=true;
440  
-	      try{
441  
-	        System.out.println("Thread running:"+item);
442  
-	        threadPath=item;
443  
-	        threadIm=loadImage(item);
444  
-	      } catch (Exception e) {
445  
-	    	  
446  
-	      }
447  
-	      running=false;
448  
-	      loading=false;
449  
-	      System.out.println("Finished loading");
450  
-    	}
451  
-	    
452  
-	    public void quit() {
453  
-	        System.out.println("Quitting."); 
454  
-	        running = false; 
455  
-	        interrupt();
456  
-	      }
  446
+    public class ImageBufferThread extends Thread {
  447
+      
  448
+      String item;
  449
+      boolean running;
  450
+