Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: Louismac/KeirKids
base: 7a61e09bdd
...
head fork: Louismac/KeirKids
compare: c8dc2a453c
  • 1 commit
  • 12 files changed
  • 0 commit comments
  • 1 contributor
Commits on Oct 22, 2012
LouisMcCallum code bastardised for stupid processing c8dc2a4
View
BIN  .DS_Store
Binary file not shown
View
404 src/FileSystem.java
@@ -3,208 +3,208 @@
import java.util.HashMap;
public class FileSystem {
-
- File toLoad;
- File toSave;
- String dir;
- File[] associationFiles;
- long lastMod;
- File lastModFile;
- FilenameFilter mediaFilter;
- String types[] = { "aif", "jpg", "jpeg", "png", "wav", "aiff" };
- ArrayList<String> paths;
- ImportWindow importWin;
- LoadWindow loadWin;
- NewWindow newWin;
- HashMap<String, String> associations;
- int mediaPtr;
+
+ File toLoad;
+ File toSave;
+ String dir;
+ File[] associationFiles;
+ long lastMod;
+ File lastModFile;
+ FilenameFilter mediaFilter;
+ String types[] = { "aif", "jpg", "jpeg", "png", "wav", "aiff" };
+ ArrayList<String> paths;
+ ImportWindow importWin;
+ LoadWindow loadWin;
+ NewWindow newWin;
+ HashMap<String, String> associations;
+ int mediaPtr;
- public FileSystem() {
- dir=new File("").getAbsolutePath();
- if(!new File(dir+"/media/").exists()) {
- new File(dir+"/media/").mkdir();
- }
- if(!new File(dir+"/recordings/").exists()) {
- new File(dir+"/recordings/").mkdir();
- }
- lastModFile=new File(dir+"/media/");
- lastMod=lastModFile.lastModified();
- mediaFilter = new MediaFilter(types);
- importWin = new ImportWindow();
- newWin = new NewWindow();
- loadWin = new LoadWindow();
- associations = new HashMap<String, String>();
- mediaPtr = 0;
- }
-
- public String[] shiftFocus(int dir,int bufferSize) {
- if (paths.size() > 0) {
- mediaPtr+=dir;
- mediaPtr=mediaPtr % (paths.size());
- String[] items = new String[bufferSize];
- for(int i=0;i<bufferSize;i++) {
- int temp=(mediaPtr+(i-(bufferSize/2)))%paths.size();
- if(temp<0) {
- temp=paths.size()+temp;
- }
- items[i]=paths.get(temp);
- }
- return items;
- } else {
- return null;
- }
- }
-
- public String getItem(String key) {
- return associations.get(key);
- }
-
- public void associateItem(String key,String item) {
- if (associations.containsKey(key)) {
- associations.remove(key);
- }
- associations.put(key, item);
- System.out.println("Associating:" + item + " with:" + key);
- }
-
- public Boolean checkImport() {
- if(importWin.loaded) {
- return true;
- } else {
- return false;
- }
- }
-
- public Boolean checkNew(String name) {
- if(newWin.dir != null && name!=null) {
- newProject(newWin.dir,name);
- newWin.dir=null;
- return true;
- } else {
- return false;
- }
- }
-
- public Boolean checkLoad() {
- if(loadWin.dir != null) {
- if(loadWin.dir.endsWith(".keir")) {
- loadProject(loadWin.dir);
- loadWin.dir=null;
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
-
- public void launchNew() {
- newWin.launchChooser();
- }
-
- public void launchLoad() {
- loadWin.launchChooser();
- }
-
- public void launchImport(ModalView mv) {
- importWin.launchChooser(dir + "/media/",mv);
- }
-
- public void updatePaths() {
- File[] files = new File(dir + "/media/").listFiles(mediaFilter);
- paths = new ArrayList<String>();
- for (int i = 0; i < files.length; i++) {
- String item = files[i].getAbsolutePath();
- paths.add(item);
- System.out.println("ADDED:" + paths.get(i));
- }
- }
-
- public Boolean updateRequired() {
- long newMod = lastModFile.lastModified();
- if (lastMod != newMod) {
- lastMod = newMod;
- return true;
- } else {
- return false;
- }
- }
-
- public void deleteFile(String dir) {
- new File(dir).delete();
- }
-
- public void deleteFolderContents(String dir) {
- File[] files = new File(dir).listFiles(mediaFilter);
- for (int i = 0; i < files.length; i++) {
- files[i].delete();
- }
- }
-
- public void newProject(String dir,String projectName) {
- if(new File(dir+"/"+projectName+"/").exists()) {
- deleteFolderContents(dir+"/"+projectName+"/media/");
- deleteFolderContents(dir+"/"+projectName+"/recordings/");
- System.out.println("OVERWRITE");
- }
- new File(dir+"/"+projectName).mkdir();
- System.out.println(this.dir);
- this.dir=dir+"/"+projectName;
- System.out.println(this.dir);
- new File(this.dir+"/media/").mkdir();
- new File(this.dir+"/recordings/").mkdir();
- lastModFile = new File(this.dir + "/media/");
- lastMod = lastModFile.lastModified();
- saveFile(associations,projectName);
- }
-
- public void loadProject(String dir) {
- System.out.println("LOADING:"+dir);
- associations=loadFile(dir);
- String sep[]=dir.split("/");
- String newDir="";
- for (int i = 0; i < sep.length - 1; i++) {
- newDir+=sep[i];
- if(i<sep.length-2) {
- newDir+="/";
- }
- }
- this.dir=newDir;
- System.out.println("New parent directory:"+this.dir);
- lastModFile = new File(this.dir + "/media/");
- lastMod = lastModFile.lastModified();
- }
-
- public void saveProject() {
- String sep[]=dir.split("/");
- saveFile(associations,sep[sep.length-1]);
- }
-
- public File[] getSavedFiles() {
- associationFiles=new File(dir).listFiles();
- return associationFiles;
- }
-
- public void saveFile(HashMap<String,String> associations,String name) {
- try{
- FileOutputStream fos = new FileOutputStream(dir+"/"+name+".keir");
- ObjectOutputStream oos = new ObjectOutputStream(fos);
- oos.writeObject(associations);
- oos.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
+ public FileSystem() {
+ dir=new File("").getAbsolutePath();
+ if(!new File(dir+"/media/").exists()) {
+ new File(dir+"/media/").mkdir();
+ }
+ if(!new File(dir+"/recordings/").exists()) {
+ new File(dir+"/recordings/").mkdir();
+ }
+ lastModFile=new File(dir+"/media/");
+ lastMod=lastModFile.lastModified();
+ mediaFilter = new MediaFilter(types);
+ importWin = new ImportWindow();
+ newWin = new NewWindow();
+ loadWin = new LoadWindow();
+ associations = new HashMap<String, String>();
+ mediaPtr = 0;
+ }
+
+ public String[] shiftFocus(int dir,int bufferSize) {
+ if (paths.size() > 0) {
+ mediaPtr+=dir;
+ mediaPtr=mediaPtr % (paths.size());
+ String[] items = new String[bufferSize];
+ for(int i=0;i<bufferSize;i++) {
+ int temp=(mediaPtr+(i-(bufferSize/2)))%paths.size();
+ if(temp<0) {
+ temp=paths.size()+temp;
+ }
+ items[i]=paths.get(temp);
+ }
+ return items;
+ } else {
+ return null;
+ }
+ }
+
+ public String getItem(String key) {
+ return associations.get(key);
+ }
+
+ public void associateItem(String key,String item) {
+ if (associations.containsKey(key)) {
+ associations.remove(key);
+ }
+ associations.put(key, item);
+ System.out.println("Associating:" + item + " with:" + key);
+ }
+
+ public Boolean checkImport() {
+ if(importWin.loaded) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public Boolean checkNew(String name) {
+ if(newWin.dir != null && name!=null) {
+ newProject(newWin.dir,name);
+ newWin.dir=null;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public Boolean checkLoad() {
+ if(loadWin.dir != null) {
+ if(loadWin.dir.endsWith(".keir")) {
+ loadProject(loadWin.dir);
+ loadWin.dir=null;
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ public void launchNew() {
+ newWin.launchChooser();
+ }
+
+ public void launchLoad() {
+ loadWin.launchChooser();
+ }
+
+ public void launchImport(ModalView mv) {
+ importWin.launchChooser(dir + "/media/",mv);
+ }
+
+ public void updatePaths() {
+ File[] files = new File(dir + "/media/").listFiles(mediaFilter);
+ paths = new ArrayList<String>();
+ for (int i = 0; i < files.length; i++) {
+ String item = files[i].getAbsolutePath();
+ paths.add(item);
+ System.out.println("ADDED:" + paths.get(i));
+ }
+ }
+
+ public Boolean updateRequired() {
+ long newMod = lastModFile.lastModified();
+ if (lastMod != newMod) {
+ lastMod = newMod;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public void deleteFile(String dir) {
+ new File(dir).delete();
+ }
+
+ public void deleteFolderContents(String dir) {
+ File[] files = new File(dir).listFiles(mediaFilter);
+ for (int i = 0; i < files.length; i++) {
+ files[i].delete();
+ }
+ }
+
+ public void newProject(String dir,String projectName) {
+ if(new File(dir+"/"+projectName+"/").exists()) {
+ deleteFolderContents(dir+"/"+projectName+"/media/");
+ deleteFolderContents(dir+"/"+projectName+"/recordings/");
+ System.out.println("OVERWRITE");
+ }
+ new File(dir+"/"+projectName).mkdir();
+ System.out.println(this.dir);
+ this.dir=dir+"/"+projectName;
+ System.out.println(this.dir);
+ new File(this.dir+"/media/").mkdir();
+ new File(this.dir+"/recordings/").mkdir();
+ lastModFile = new File(this.dir + "/media/");
+ lastMod = lastModFile.lastModified();
+ saveFile(associations,projectName);
+ }
+
+ public void loadProject(String dir) {
+ System.out.println("LOADING:"+dir);
+ associations=loadFile(dir);
+ String sep[]=dir.split("/");
+ String newDir="";
+ for (int i = 0; i < sep.length - 1; i++) {
+ newDir+=sep[i];
+ if(i<sep.length-2) {
+ newDir+="/";
+ }
+ }
+ this.dir=newDir;
+ System.out.println("New parent directory:"+this.dir);
+ lastModFile = new File(this.dir + "/media/");
+ lastMod = lastModFile.lastModified();
+ }
+
+ public void saveProject() {
+ String sep[]=dir.split("/");
+ saveFile(associations,sep[sep.length-1]);
+ }
+
+ public File[] getSavedFiles() {
+ associationFiles=new File(dir).listFiles();
+ return associationFiles;
+ }
+
+ public void saveFile(HashMap<String,String> associations,String name) {
+ try{
+ FileOutputStream fos = new FileOutputStream(dir+"/"+name+".keir");
+ ObjectOutputStream oos = new ObjectOutputStream(fos);
+ oos.writeObject(associations);
+ oos.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
- public HashMap<String,String> loadFile(String name) {
- try{
- FileInputStream fis = new FileInputStream(name);
- ObjectInputStream ois = new ObjectInputStream(fis);
- return (HashMap<String,String>)ois.readObject();
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- }
+ public HashMap<String,String> loadFile(String name) {
+ try{
+ FileInputStream fis = new FileInputStream(name);
+ ObjectInputStream ois = new ObjectInputStream(fis);
+ return (HashMap<String,String>)ois.readObject();
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
}
View
154 src/ImportWindow.java
@@ -6,86 +6,86 @@
public class ImportWindow {
- public String dir;
- public Boolean loaded;
- public String selectedPath;
- ModalView modalView;
+ public String dir;
+ public Boolean loaded;
+ public String selectedPath;
+ ModalView modalView;
- ImportWindow() {
- loaded=false;
- }
-
+ ImportWindow() {
+ loaded=false;
+ }
+
public boolean isAudio(String item) {
- if (item.toLowerCase().endsWith("wav") || item.toLowerCase().endsWith("aif") || item.toLowerCase().endsWith("aiff")) {
- return true;
- } else {
- return false;
- }
- }
+ if (item.toLowerCase().endsWith("wav") || item.toLowerCase().endsWith("aif") || item.toLowerCase().endsWith("aiff")) {
+ return true;
+ } else {
+ return false;
+ }
+ }
public boolean isImage(String item) {
- if (item.toLowerCase().endsWith("jpeg") || item.toLowerCase().endsWith("jpg") || item.toLowerCase().endsWith("png")) {
- return true;
- } else {
- return false;
- }
- }
+ if (item.toLowerCase().endsWith("jpeg") || item.toLowerCase().endsWith("jpg") || item.toLowerCase().endsWith("png")) {
+ return true;
+ } else {
+ return false;
+ }
+ }
- void launchChooser(String mediaPath, ModalView mv) {
- modalView=mv;
- dir=mediaPath;
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- try {
- JFileChooser fc = new JFileChooser();
- fc.setMultiSelectionEnabled(true);
- int returnVal = fc.showOpenDialog(null);
- if (returnVal == JFileChooser.APPROVE_OPTION) {
- File[] files = fc.getSelectedFiles();
- for(int i=0;i<files.length;i++) {
- String path = files[i].getAbsolutePath();
- System.out.println("Selected file:"+path);
- String copyPath=dir+files[i].getName();
- Boolean lastCopy=false;
- if(i==files.length-1) {
- lastCopy=true;
- }
- copy(path,copyPath,lastCopy);
- }
- } else if(returnVal==JFileChooser.CANCEL_OPTION) {
- modalView.close();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
-
- public void copy(String originalPath,String copyPath,Boolean lastCopy) {
- try {
- System.out.println("Copying:"+originalPath+" to:"+copyPath);
- File srcFile = new File(originalPath);
- File dstFile = new File(copyPath);
- if(srcFile.length()<307200 || isAudio(originalPath)) {
- FileInputStream in = new FileInputStream(srcFile);
- FileOutputStream out = new FileOutputStream(dstFile);
- byte[] buf = new byte[1024];
- int len;
- while ((len = in.read(buf)) > 0) {
- out.write(buf, 0, len);
- }
- in.close();
- out.close();
- } else if (isImage(originalPath)) {
- Thumbnailator.createThumbnail(srcFile,dstFile,1920,1080);
- }
- selectedPath=copyPath;
- if(lastCopy) {
- loaded=true;
- }
- } catch ( Exception e ) {
- e.printStackTrace();
- }
- }
+ void launchChooser(String mediaPath, ModalView mv) {
+ modalView=mv;
+ dir=mediaPath;
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ try {
+ JFileChooser fc = new JFileChooser();
+ fc.setMultiSelectionEnabled(true);
+ int returnVal = fc.showOpenDialog(null);
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ File[] files = fc.getSelectedFiles();
+ for(int i=0;i<files.length;i++) {
+ String path = files[i].getAbsolutePath();
+ System.out.println("Selected file:"+path);
+ String copyPath=dir+files[i].getName();
+ Boolean lastCopy=false;
+ if(i==files.length-1) {
+ lastCopy=true;
+ }
+ copy(path,copyPath,lastCopy);
+ }
+ } else if(returnVal==JFileChooser.CANCEL_OPTION) {
+ modalView.close();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ }
+
+ public void copy(String originalPath,String copyPath,Boolean lastCopy) {
+ try {
+ System.out.println("Copying:"+originalPath+" to:"+copyPath);
+ File srcFile = new File(originalPath);
+ File dstFile = new File(copyPath);
+ if(srcFile.length()<307200 || isAudio(originalPath)) {
+ FileInputStream in = new FileInputStream(srcFile);
+ FileOutputStream out = new FileOutputStream(dstFile);
+ byte[] buf = new byte[1024];
+ int len;
+ while ((len = in.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+ in.close();
+ out.close();
+ } else if (isImage(originalPath)) {
+ Thumbnailator.createThumbnail(srcFile,dstFile,1920,1080);
+ }
+ selectedPath=copyPath;
+ if(lastCopy) {
+ loaded=true;
+ }
+ } catch ( Exception e ) {
+ e.printStackTrace();
+ }
+ }
}
View
214 src/KeirGUI.java
@@ -5,112 +5,112 @@
import processing.core.PFont;
public class KeirGUI {
-
- ControlP5 cp5;
- int height;
- int width;
- int viewerHeight;
- int viewerWidth;
- int viewerX;
- int viewerY;
- int btnWidth=100;
- HashMap <String, Controller> controls;
- PFont font;
-
- public KeirGUI(KeirsKidsMain processing) {
- cp5=new ControlP5(processing);
- height=processing.height;
- width=processing.width;
- viewerHeight=(int)(height*0.6);
- viewerWidth=(int)(width*0.6);
- viewerX=(width/2)-(viewerWidth/2);
- viewerY=(height/2)-(viewerHeight/2);
- font=processing.createFont("FFScala",14);
-
- controls=new HashMap <String, Controller>();
-
- initViewer();
- }
-
- public String getNewProjectName() {
- Textfield tf=(Textfield)controls.get("tfNewProject");
- return tf.getText();
- }
-
- public void clearGUI() {
- Iterator it = controls.entrySet().iterator();
- while (it.hasNext()) {
- Map.Entry<String,Controller> pairs = (Map.Entry<String,Controller>)it.next();
- cp5.remove(pairs.getValue().getName());
- // System.out.println(pairs.getKey() + " = " + pairs.getValue());
- it.remove();
- }
- controls.clear();
- }
-
- public void initPlayer() {
- clearGUI();
- controls.put("record", cp5.addButton("record")
- .setPosition(0,0)
- .setSize(btnWidth,btnWidth)
- .activateBy(ControlP5Constants.PRESSED));
- controls.put("playItem",cp5.addButton("playItem")
- .setPosition(300,0)
- .setSize(btnWidth,btnWidth));
- controls.put("fullScreen", cp5.addButton("fullScreen")
- .setPosition(100,0)
- .setSize(btnWidth,btnWidth));
- controls.put("associateItem", cp5.addButton("associateItem")
- .setPosition(200,0)
- .setSize(btnWidth,btnWidth));
- controls.put("linkToken", cp5.addTextlabel("linkToken")
- .setPosition(400,0)
- .setSize(btnWidth,btnWidth)
- .setColor(0)
- .setFont(font));
- controls.put("prevItem",cp5.addButton("prevItem")
- .setPosition(viewerX-btnWidth,(viewerX+viewerHeight/2))
- .setSize(btnWidth,btnWidth));
- controls.put("nextItem",cp5.addButton("nextItem")
- .setPosition(viewerX+viewerWidth,(viewerX+viewerHeight/2))
- .setSize(btnWidth,btnWidth));
- controls.put("initPlayer",cp5.addButton("player")
- .setPosition(600,0)
- .setSize(btnWidth,btnWidth));
- controls.put("initViewer",cp5.addButton("viewer")
- .setPosition(700,0)
- .setSize(btnWidth,btnWidth));
- }
-
- public void initViewer() {
- clearGUI();
- controls.put("importMedia", cp5.addButton("importMedia")
- .setPosition(0,0)
- .setSize(btnWidth,btnWidth));
- controls.put("deleteFromProject",cp5.addButton("deleteFromProject")
- .setPosition(100,0)
- .setSize(btnWidth,btnWidth));
- controls.put("saveProject", cp5.addButton("saveProject")
- .setPosition(400,0)
- .setSize(btnWidth,btnWidth));
- controls.put("loadProject",cp5.addButton("loadProject")
- .setPosition(200,0)
- .setSize(btnWidth,btnWidth));
- controls.put("newProject",cp5.addButton("newProject")
- .setPosition(300,0)
- .setSize(btnWidth,btnWidth));
- controls.put("initPlayer",cp5.addButton("player")
- .setPosition(600,0)
- .setSize(btnWidth,btnWidth));
- controls.put("initViewer",cp5.addButton("viewer")
- .setPosition(700,0)
- .setSize(btnWidth,btnWidth));
- controls.put("prevItem",cp5.addButton("prevItem")
- .setPosition(viewerX-btnWidth,(viewerX+viewerHeight/2))
- .setSize(btnWidth,btnWidth));
- controls.put("nextItem",cp5.addButton("nextItem")
- .setPosition(viewerX+viewerWidth,(viewerX+viewerHeight/2))
- .setSize(btnWidth,btnWidth));
- }
+
+ ControlP5 cp5;
+ int height;
+ int width;
+ int viewerHeight;
+ int viewerWidth;
+ int viewerX;
+ int viewerY;
+ int btnWidth=100;
+ HashMap <String, controlP5.Controller> controls;
+ PFont font;
+
+ public KeirGUI(int width,int height,PFont font,ControlP5 cp5) {
+ this.cp5=cp5;
+ this.height=height;
+ this.width=width;
+ viewerHeight=(int)(height*0.6);
+ viewerWidth=(int)(width*0.6);
+ viewerX=(width/2)-(viewerWidth/2);
+ viewerY=(height/2)-(viewerHeight/2);
+ this.font=font;
+ controls=new HashMap <String, controlP5.Controller>();
+
+ initViewer();
+ }
+
+ public String getNewProjectName() {
+ Textfield tf=(Textfield)controls.get("tfNewProject");
+ return tf.getText();
+ }
+
+ public void clearGUI() {
+
+ Iterator it = controls.values().iterator();
+ while (it.hasNext()) {
+ controlP5.Controller val = (controlP5.Controller)it.next();
+ cp5.remove(val.getName());
+ // System.out.println(pairs.getKey() + " = " + pairs.getValue());
+ it.remove();
+ }
+ controls.clear();
+ }
+
+ public void initPlayer() {
+ clearGUI();
+ controls.put("record", cp5.addButton("record")
+ .setPosition(0,0)
+ .setSize(btnWidth,btnWidth)
+ .activateBy(ControlP5Constants.PRESSED));
+ controls.put("playItem",cp5.addButton("playItem")
+ .setPosition(300,0)
+ .setSize(btnWidth,btnWidth));
+ controls.put("fullScreen", cp5.addButton("fullScreen")
+ .setPosition(100,0)
+ .setSize(btnWidth,btnWidth));
+ controls.put("associateItem", cp5.addButton("associateItem")
+ .setPosition(200,0)
+ .setSize(btnWidth,btnWidth));
+ controls.put("linkToken", cp5.addTextlabel("linkToken")
+ .setPosition(400,0)
+ .setSize(btnWidth,btnWidth)
+ .setColor(0)
+ .setFont(font));
+ controls.put("prevItem",cp5.addButton("prevItem")
+ .setPosition(viewerX-btnWidth,(viewerX+viewerHeight/2))
+ .setSize(btnWidth,btnWidth));
+ controls.put("nextItem",cp5.addButton("nextItem")
+ .setPosition(viewerX+viewerWidth,(viewerX+viewerHeight/2))
+ .setSize(btnWidth,btnWidth));
+ controls.put("initPlayer",cp5.addButton("player")
+ .setPosition(600,0)
+ .setSize(btnWidth,btnWidth));
+ controls.put("initViewer",cp5.addButton("viewer")
+ .setPosition(700,0)
+ .setSize(btnWidth,btnWidth));
+ }
+
+ public void initViewer() {
+ clearGUI();
+ controls.put("importMedia", cp5.addButton("importMedia")
+ .setPosition(0,0)
+ .setSize(btnWidth,btnWidth));
+ controls.put("deleteFromProject",cp5.addButton("deleteFromProject")
+ .setPosition(100,0)
+ .setSize(btnWidth,btnWidth));
+ controls.put("saveProject", cp5.addButton("saveProject")
+ .setPosition(400,0)
+ .setSize(btnWidth,btnWidth));
+ controls.put("loadProject",cp5.addButton("loadProject")
+ .setPosition(200,0)
+ .setSize(btnWidth,btnWidth));
+ controls.put("newProject",cp5.addButton("newProject")
+ .setPosition(300,0)
+ .setSize(btnWidth,btnWidth));
+ controls.put("initPlayer",cp5.addButton("player")
+ .setPosition(600,0)
+ .setSize(btnWidth,btnWidth));
+ controls.put("initViewer",cp5.addButton("viewer")
+ .setPosition(700,0)
+ .setSize(btnWidth,btnWidth));
+ controls.put("prevItem",cp5.addButton("prevItem")
+ .setPosition(viewerX-btnWidth,(viewerX+viewerHeight/2))
+ .setSize(btnWidth,btnWidth));
+ controls.put("nextItem",cp5.addButton("nextItem")
+ .setPosition(viewerX+viewerWidth,(viewerX+viewerHeight/2))
+ .setSize(btnWidth,btnWidth));
+ }
}
View
881 src/KeirsKidsMain.java
@@ -5,455 +5,478 @@
import java.util.*;
import java.awt.Desktop;
-import controlP5.Textlabel;
+import controlP5.*;
public class KeirsKidsMain extends PApplet {
- Minim minim;
- AudioPlayer player;
- AudioRecorder recorder;
- AudioInput in;
- Desktop desktop;
- KeirGUI cp5;
- int bufferSize=15;
- ImageBufferThread thread;
- String[] currentItems;
- Boolean buffered=true;
- PImage displayImage;
- String recordPath;
- String currentItem;
- FileSystem fileSystem;
- HashMap<String, PImage> images;
- Boolean loading=false;
- PImage threadIm=null;
- String threadPath=null;
- String linkToken;
- int dir=1;
- Boolean viewer=true;
- ModalView modalView;
- String newName;
+ Minim minim;
+ AudioPlayer player;
+ AudioRecorder recorder;
+ AudioInput in;
+ Desktop desktop;
+ ControlP5 cont;
+ KeirGUI cp5;
+ int bufferSize=15;
+ ImageBufferThread thread;
+ String[] currentItems;
+ Boolean buffered=true;
+ PImage displayImage;
+ String recordPath;
+ String currentItem;
+ FileSystem fileSystem;
+ HashMap<String, PImage> images;
+ Boolean loading=false;
+ PImage threadIm=null;
+ String threadPath=null;
+ String linkToken;
+ int dir=1;
+ Boolean viewer=true;
+ ModalView modalView;
+ String newName;
- public void setup() {
- size(1024, 780,OPENGL);
- background(255,255,255);
- fileSystem = new FileSystem();
- desktop = Desktop.getDesktop();
- images = new HashMap<String, PImage>();
- thread = null;
- updateMedia();
- minim = new Minim(this);
- cp5 = new KeirGUI(this);
- currentItems = fileSystem.shiftFocus(1,bufferSize);
- in = minim.getLineIn(Minim.STEREO, 2048);
- recorder = minim.createRecorder(in, "test.wav", true);
- fill(0);
- noStroke();
- rect(cp5.viewerX-50,cp5.viewerY-50,cp5.viewerWidth+100,cp5.viewerHeight+100);
- }
-
- public void openModalView(String title, String message) {
- cp5.clearGUI();
- fill(255,255,255,100);
- rect(0,0,width,height);
- PFont font=createFont("FFScala",14);
- modalView.setSize(width,height);
- modalView.setCP5(cp5.cp5);
- modalView.init(title,message);
- }
-
- public void keyPressed() {
- linkToken=Character.toString(key);
- try {
- Textlabel lbl = (Textlabel)cp5.controls.get("linkToken");
- lbl.setText("Your current token is \n"+linkToken);
- fill(255);
- rect(lbl.getPosition().x,lbl.getPosition().y,lbl.getWidth(),100);
- } catch (NullPointerException e) {
-
- }
- System.out.println("Link token:"+linkToken);
- }
+ public void setup() {
+ size(1024, 780,OPENGL);
+ background(255,255,255);
+ fileSystem = new FileSystem();
+ desktop = Desktop.getDesktop();
+ images = new HashMap<String, PImage>();
+ thread = null;
+ updateMedia();
+ minim = new Minim(this);
+ cont=new ControlP5(this);
+ PFont font=createFont("FFScala",14);
+ cp5 = new KeirGUI(width,height,font,cont);
+ currentItems = fileSystem.shiftFocus(1,bufferSize);
+ in = minim.getLineIn(Minim.STEREO, 2048);
+ recorder = minim.createRecorder(in, "test.wav", true);
+ fill(0);
+ noStroke();
+ rect(cp5.viewerX-50,cp5.viewerY-50,cp5.viewerWidth+100,cp5.viewerHeight+100);
+ }
+
+ public void openModalView(String title, String message) {
+ cp5.clearGUI();
+ fill(255,255,255,100);
+ rect(0,0,width,height);
+ PFont font=createFont("FFScala",14);
+ modalView.font=font;
+ modalView.setSize(width,height);
+ modalView.setCP5(cp5.cp5);
+ modalView.init(title,message);
+ }
+
+ public void keyPressed() {
+ linkToken=Character.toString(key);
+ try {
+ Textlabel lbl = (Textlabel)(cp5.controls.get("linkToken"));
+ lbl.setText("Your current token is \n"+linkToken);
+ fill(255);
+ rect(lbl.getPosition().x,lbl.getPosition().y,lbl.getWidth(),100);
+ } catch (NullPointerException e) {
+
+ }
+ System.out.println("Link token:"+linkToken);
+ }
- public boolean isAudio(String item) {
- if (item.toLowerCase().endsWith("wav") || item.toLowerCase().endsWith("aif") || item.toLowerCase().endsWith("aiff")) {
- return true;
- } else {
- return false;
- }
- }
-
- public void importMedia() {
- modalView=new ModalView(null);
- openModalView("Please Wait", "Your Files are being imported");
- fileSystem.launchImport(modalView);
- }
-
- public void record() {
- modalView=new RecordView(millis(),"rec");
- openModalView("Recording", "Recording will begin after countdown");
- }
-
- public void deleteFromProject() {
- clearViewer();
- fileSystem.deleteFile(currentItem);
- updateMedia();
- nextItem();
- }
-
- public void clearViewer() {
- fill(0);
- rect(cp5.viewerX, cp5.viewerY, cp5.viewerWidth, cp5.viewerHeight);
- }
-
- public void fullScreen(int theValue) {
- System.out.println(theValue);
- }
-
- public void clearScreen() {
- fill(255);
- rect(0,0,width,height);
- fill(0);
- rect(cp5.viewerX-50,cp5.viewerY-50,cp5.viewerWidth+100,cp5.viewerHeight+100);
- System.out.println("clear screen");
- }
+ public boolean isAudio(String item) {
+ if (item.toLowerCase().endsWith("wav") || item.toLowerCase().endsWith("aif") || item.toLowerCase().endsWith("aiff")) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public void importMedia() {
+ modalView=new ModalView(null);
+ openModalView("Please Wait", "Your Files are being imported");
+ fileSystem.launchImport(modalView);
+ }
+
+ public void record() {
+ modalView=new RecordView(millis(),"rec");
+ openModalView("Recording", "Recording will begin after countdown");
+ }
+
+ public void deleteFromProject() {
+ clearViewer();
+ fileSystem.deleteFile(currentItem);
+ updateMedia();
+ nextItem();
+ }
+
+ public void clearViewer() {
+ fill(0);
+ rect(cp5.viewerX, cp5.viewerY, cp5.viewerWidth, cp5.viewerHeight);
+ }
+
+ public void fullScreen(int theValue) {
+ System.out.println(theValue);
+ }
+
+ public void clearScreen() {
+ fill(255);
+ rect(0,0,width,height);
+ fill(0);
+ rect(cp5.viewerX-50,cp5.viewerY-50,cp5.viewerWidth+100,cp5.viewerHeight+100);
+ System.out.println("clear screen");
+ }
- public void openMediaFolder() {
- try {
- desktop.open(new File(fileSystem.dir + "/media/"));
- } catch (Exception e) {
- System.out.println("desktop exception: " + e);
- }
- }
-
- public void close() {
- modalView.close();
- }
-
- public void done() {
- modalView.done();
- }
-
- public void saveProject() {
- fileSystem.saveProject();
- }
-
- public void redraw() {
- System.out.println("redraw");
- if(viewer) {
- viewer();
- } else {
- player();
- }
- }
-
- public void player() {
- viewer=false;
- cp5.initPlayer();
- clearScreen();
- try {
- showMedia(currentItems[(int)Math.ceil(bufferSize/2)]);
- } catch (NullPointerException e) {
-
- }
- }
-
- public void viewer() {
- viewer=true;
- cp5.initViewer();
- clearScreen();
- try {
- showMedia(currentItems[(int)Math.ceil(bufferSize/2)]);
- } catch (NullPointerException e) {
-
- }
- }
-
- public void loadProject() {
- fileSystem.launchLoad();
- }
+ public void openMediaFolder() {
+ try {
+ desktop.open(new File(fileSystem.dir + "/media/"));
+ } catch (Exception e) {
+ System.out.println("desktop exception: " + e);
+ }
+ }
+
+ public void close() {
+ modalView.close();
+ }
+
+ public void done() {
+ modalView.done();
+ }
+
+ public void saveProject() {
+ fileSystem.saveProject();
+ }
+
+ public void redraw() {
+ System.out.println("redraw");
+ if(viewer) {
+ viewer();
+ } else {
+ player();
+ }
+ }
+
+ public void player() {
+ viewer=false;
+ cp5.initPlayer();
+ clearScreen();
+ try {
+ showMedia(currentItems[(int)Math.ceil(bufferSize/2)]);
+ } catch (NullPointerException e) {
+
+ }
+ }
+
+ public void viewer() {
+ viewer=true;
+ cp5.initViewer();
+ clearScreen();
+ try {
+ showMedia(currentItems[(int)Math.ceil(bufferSize/2)]);
+ } catch (NullPointerException e) {
+
+ }
+ }
+
+ public void loadProject() {
+ fileSystem.launchLoad();
+ }
- public void newProject() {
- modalView=new NewProjectView("new");
- openModalView("New Project","Please enter project name");
- }
+ public void newProject() {
+ modalView=new NewProjectView("new");
+ openModalView("New Project","Please enter project name");
+ }
- public String mediaToRecordPath(String item) {
- String[] sep = item.split("/");
- String recPath = "";
- for (int i = 0; i < sep.length - 2; i++) {
- recPath = recPath + sep[i] + "/";
- }
- recPath = recPath + "recordings/";
- recPath = recPath + sep[sep.length - 1] + ".wav";
- return recPath;
- }
+ public String mediaToRecordPath(String item) {
+ String[] sep = item.split("/");
+ String recPath = "";
+ for (int i = 0; i < sep.length - 2; i++) {
+ recPath = recPath + sep[i] + "/";
+ }
+ recPath = recPath + "recordings/";
+ recPath = recPath + sep[sep.length - 1] + ".wav";
+ return recPath;
+ }
- public void startRecord() {
- if (currentItem != null) {
- String item = currentItem;
- if (!isAudio(item)) {
- if (recorder.isRecording()) {
- recorder.endRecord();
- } else {
- recordPath = mediaToRecordPath(item);
- recorder = minim.createRecorder(in, recordPath, true);
- recorder.beginRecord();
- modalView.close();
- modalView= new ModalView(null);
- openModalView("Recording","Release record button to stop recording");
- }
- }
- }
- }
+ public void startRecord() {
+ if (currentItem != null) {
+ String item = currentItem;
+ if (!isAudio(item)) {
+ if (recorder.isRecording()) {
+ recorder.endRecord();
+ } else {
+ recordPath = mediaToRecordPath(item);
+ recorder = minim.createRecorder(in, recordPath, true);
+ recorder.beginRecord();
+ modalView.close();
+ modalView= new ModalView(null);
+ openModalView("Recording","Release record button to stop recording");
+ }
+ }
+ }
+ }
- public void endRecord() {
- if (recorder.isRecording()) {
- recorder.endRecord();
- recorder.save();
- modalView.close();
- modalView=new ModalView(null);
- openModalView("Recording","Recording Finished");
- String item = currentItem;
- if (new File(recordPath).exists()) {
- }
- System.out.println("Associating:" + recordPath + " with" + item);
- }
- }
+ public void endRecord() {
+ if (recorder.isRecording()) {
+ recorder.endRecord();
+ recorder.save();
+ modalView.close();
+ modalView=new ModalView(null);
+ openModalView("Recording","Recording Finished");
+ String item = currentItem;
+ if (new File(recordPath).exists()) {
+ }
+ System.out.println("Associating:" + recordPath + " with" + item);
+ }
+ }
- public void playItem() {
- String item = fileSystem.getItem(linkToken);
- if (item != null) {
- showMedia(item);
- }
- }
+ public void playItem() {
+ String item = fileSystem.getItem(linkToken);
+ if (item != null) {
+ showMedia(item);
+ }
+ }
- public void associateItem() {
- modalView=new LinkWindow(millis(),"link");
- openModalView("Link token to media","Place token on reader");
-
- }
-
- public String doLinkItem() {
- fileSystem.associateItem(linkToken,currentItem);
- String[] sep=currentItem.split("/");
- return "Linking: "+linkToken +" to " +sep[sep.length-1];
- }
+ public void associateItem() {
+ modalView=new LinkWindow(millis(),"link");
+ openModalView("Link token to media","Place token on reader");
+ }
+
+ public String doLinkItem() {
+ fileSystem.associateItem(linkToken,currentItem);
+ String[] sep=currentItem.split("/");
+ return "Linking: "+linkToken +" to " +sep[sep.length-1];
+ }
- public float scaleImage(int target,int current) {
- if (displayImage != null) {
- float multiplier;
- multiplier = (float) target / (float) current;
- return multiplier;
- }
- return 4;
- }
+ public float scaleImage(int target,int current) {
+ if (displayImage != null) {
+ float multiplier;
+ multiplier = (float) target / (float) current;
+ return multiplier;
+ }
+ return 4;
+ }
- public void display() {
+ public void display() {
float wMul = scaleImage(cp5.viewerWidth,displayImage.width);
float hMul = scaleImage(cp5.viewerHeight,displayImage.height);
image(displayImage, cp5.viewerX, cp5.viewerY, (int) (displayImage.width * wMul),
(int) (displayImage.height * hMul));
- }
-
- public void showMedia(String item) {
- if (fileSystem.paths.contains(item)) {
- currentItem = item;
- if (displayImage != null) {
- clearViewer();
- }
- if (player != null) {
- player.pause();
- }
- if (isAudio(item)) {
- player = minim.loadFile(item);
- //Remove item if minim can't load it
- if(player==null) {
- deleteFromProject();
- } else {
- player.play();
- }
- } else {
- if(buffered) {
- displayImage = images.get(item);
- } else {
- displayImage = loadImage(item);
- }
- System.out.println("Displaying Image:" + displayImage);
- try{
- display();
- } catch (Exception e) {
- System.out.println("show media fail");
- displayImage = loadImage(item);
- display();
- }
- String recPath = mediaToRecordPath(item);
- //If there is audio associated with the image, play it
- if (new File(recPath).exists()) {
- player = minim.loadFile(recPath);
- player.play();
- }
- }
- } else {
- System.out.println("Associated Media Removed");
- }
- }
+ }
+
+ public void showMedia(String item) {
+ if (fileSystem.paths.contains(item)) {
+ currentItem = item;
+ if (displayImage != null) {
+ clearViewer();
+ }
+ if (player != null) {
+ player.pause();
+ }
+ if (isAudio(item)) {
+ player = minim.loadFile(item);
+ //Remove item if minim can't load it
+ if(player==null) {
+ deleteFromProject();
+ } else {
+ player.play();
+ }
+ } else {
+ if(buffered) {
+ displayImage = images.get(item);
+ } else {
+ displayImage = loadImage(item);
+ }
+ System.out.println("Displaying Image:" + displayImage);
+ try{
+ display();
+ } catch (Exception e) {
+ System.out.println("show media fail");
+ displayImage = loadImage(item);
+ display();
+ }
+ String recPath = mediaToRecordPath(item);
+ //If there is audio associated with the image, play it
+ if (new File(recPath).exists()) {
+ player = minim.loadFile(recPath);
+ player.play();
+ }
+ }
+ } else {
+ System.out.println("Associated Media Removed");
+ }
+ }
- public void nextItem() {
- dir=1;
- //Get new list of paths
- currentItems = fileSystem.shiftFocus(dir,bufferSize);
- //Dont remove the image if theres only 1! Do remove if not as buffer has moved
- if(fileSystem.paths.size()>1) {
- images.remove(currentItems[0]);
- }
- try{
- //show the middle item
- String midItem=currentItems[(int)Math.ceil(bufferSize/2)];
- showMedia(midItem);
- } catch (Exception e) {
-
- }
- }
-
- public void prevItem() {
- dir=-1;
- currentItems = fileSystem.shiftFocus(dir,bufferSize);
- if(fileSystem.paths.size()>1) {
- images.remove(currentItems[currentItems.length-1]);
- }
- try{
- String midItem=currentItems[(int)Math.ceil(bufferSize/2)];
- showMedia(midItem);
- } catch (Exception e) {
-
- }
- }
+ public void nextItem() {
+ dir=1;
+ //Get new list of paths
+ currentItems = fileSystem.shiftFocus(dir,bufferSize);
+ //Dont remove the image if theres only 1! Do remove if not as buffer has moved
+ if(fileSystem.paths.size()>1) {
+ images.remove(currentItems[0]);
+ }
+ try{
+ //show the middle item
+ String midItem=currentItems[(int)Math.ceil(bufferSize/2)];
+ showMedia(midItem);
+ } catch (Exception e) {
+
+ }
+ }
+
+ public void prevItem() {
+ dir=-1;
+ currentItems = fileSystem.shiftFocus(dir,bufferSize);
+ if(fileSystem.paths.size()>1) {
+ images.remove(currentItems[currentItems.length-1]);
+ }
+ try{
+ String midItem=currentItems[(int)Math.ceil(bufferSize/2)];
+ showMedia(midItem);
+ } catch (Exception e) {
+
+ }
+ }
- public void updateMedia() {
- fileSystem.updatePaths();
- }
-
- public void reset() {
- images = new HashMap<String, PImage>();
- clearViewer();
- updateMedia();
- }
+ public void updateMedia() {
+ fileSystem.updatePaths();
+ }
+
+ public void reset() {
+ images = new HashMap<String, PImage>();
+ clearViewer();
+ updateMedia();
+ }
- public void draw() {
- if(viewer) {
- //If new files have been added
- if(fileSystem.updateRequired()) {
- fileSystem.updatePaths();
- }
- //If a file has been selected by the import window and copying is finished
- if (fileSystem.checkImport()) {
- updateMedia();
- modalView.close();
- fileSystem.importWin.loaded=false;
- }
- //If a new file has been created by the new window
- try{
- if(fileSystem.checkNew(newName)) {
- reset();
- }
- } catch (NullPointerException e) {
-
- }
- //If a new file has been loaded from the load window
- if(fileSystem.checkLoad()) {
- reset();
- }
- } else {
- if(modalView!=null) {
- if(modalView.redraw) {
- redraw();
- modalView.redraw=false;
- }
- if(modalView.complete) {
- switch()
- }
- if(recorder.isRecording() && !mousePressed) {
- endRecord();
- }
- if(modalView.isCounting) {
- ((TimedWindow) modalView).isNextStep(millis());
- }
- }
- }
- //If the imagebuffer thread has finished loading
- if(!loading && threadIm!=null && threadPath!=null) {
- System.out.println("Adding to buffer:"+threadPath);
- thread.quit();
- thread=null;
- images.put(threadPath,threadIm);
- threadIm=null;
- threadPath=null;
- }
- if(currentItems!=null && buffered) {
- //If we are not currently loading a file on a thread
- if(thread==null) {
- int ptr=(int)Math.ceil(bufferSize/2);
- Boolean notFound=false;
- //If moving left
- if(dir<0) {
- //Start looking from the middle and move left in list
- while(ptr>0 && !notFound) {
- if(!images.containsKey(currentItems[ptr]) && !isAudio(currentItems[ptr])) {
- thread=new ImageBufferThread(currentItems[ptr]);
- thread.start();
- notFound=true;
- }
- ptr--;
- }
- } else {
- //Start looking from the middle and move right in list
- while(ptr<currentItems.length && !notFound) {
- if(!images.containsKey(currentItems[ptr]) && !isAudio(currentItems[ptr])) {
- thread=new ImageBufferThread(currentItems[ptr]);
- thread.start();
- notFound=true;
- }
- ptr++;
- }
- }
- }
- }
- }
+ public void draw() {
+ if(viewer) {
+ //If new files have been added
+ if(fileSystem.updateRequired()) {
+ fileSystem.updatePaths();
+ }
+ //If a file has been selected by the import window and copying is finished
+ if (fileSystem.checkImport()) {
+ updateMedia();
+ modalView.close();
+ fileSystem.importWin.loaded=false;
+ }
+ //If a new file has been created by the new window
+ try{
+ if(fileSystem.checkNew(newName)) {
+ reset();
+ }
+ } catch (NullPointerException e) {
+
+ }
+ //If a new file has been loaded from the load window
+ if(fileSystem.checkLoad()) {
+ reset();
+ }
+ }
+ if(modalView!=null) {
+ if(modalView.redraw) {
+ redraw();
+ modalView.redraw=false;
+ }
+ if(modalView.clearModal) {
+ fill(0);
+ rect(modalView.x,modalView.y,modalView.w,modalView.h);
+ modalView.clearModal=false;
+ }
+ if(modalView.complete) {
+ if(modalView.key=="link") {
+ Textlabel lbl = (Textlabel) modalView.controls.get("message");
+ lbl.setText(doLinkItem());
+ } else if(modalView.key=="rec") {
+ Textlabel lbl = (Textlabel) modalView.controls.get("message");
+ lbl.setText("Recording");
+ startRecord();
+ } else if(modalView.key=="new") {
+ Textfield tf = (Textfield) modalView.controls.get("name");
+ String name=tf.getText();
+ if(!name.isEmpty()) {
+ close();
+ newName=name;
+ fileSystem.launchNew();
+ }
+ }
+ modalView.complete=false;
+ }
+ if(recorder.isRecording() && !mousePressed) {
+ endRecord();
+ }
+ if(modalView.isCounting) {
+ ((TimedWindow) modalView).isNextStep(millis());
+ }
+ }
+ //If the imagebuffer thread has finished loading
+ if(!loading && threadIm!=null && threadPath!=null) {
+ System.out.println("Adding to buffer:"+threadPath);
+ thread.quit();
+ thread=null;
+ images.put(threadPath,threadIm);
+ threadIm=null;
+ threadPath=null;
+ }
+ if(currentItems!=null && buffered) {
+ //If we are not currently loading a file on a thread
+ if(thread==null) {
+ int ptr=(int)Math.ceil(bufferSize/2);
+ Boolean notFound=false;
+ //If moving left
+ if(dir<0) {
+ //Start looking from the middle and move left in list
+ while(ptr>0 && !notFound) {
+ if(!images.containsKey(currentItems[ptr]) && !isAudio(currentItems[ptr])) {
+ thread=new ImageBufferThread(currentItems[ptr]);
+ thread.start();
+ notFound=true;
+ }
+ ptr--;
+ }
+ } else {
+ //Start looking from the middle and move right in list
+ while(ptr<currentItems.length && !notFound) {
+ if(!images.containsKey(currentItems[ptr]) && !isAudio(currentItems[ptr])) {
+ thread=new ImageBufferThread(currentItems[ptr]);
+ thread.start();
+ notFound=true;
+ }
+ ptr++;
+ }
+ }
+ }
+ }
+ }
- public class ImageBufferThread extends Thread {
-
- String item;
- boolean running;
-
- ImageBufferThread(String item) {
- this.item=item;
- running=false;
- }
-
- public void start() {
- running=true;
- super.start();
- }
-
- public synchronized void run() {
- loading=true;
- try{
- System.out.println("Thread running:"+item);
- threadPath=item;
- threadIm=loadImage(item);
- } catch (Exception e) {
-
- }
- running=false;
- loading=false;
- System.out.println("Finished loading");
- }
-
- public void quit() {
- System.out.println("Quitting.");
- running = false;
- interrupt();
- }
+ public class ImageBufferThread extends Thread {
+
+ String item;
+ boolean running;
+
+ ImageBufferThread(String item) {
+ this.item=item;
+ running=false;
+ }
+
+ public void start() {
+ running=true;
+ super.start();
+ }
+
+ public synchronized void run() {
+ loading=true;
+ try{
+ System.out.println("Thread running:"+item);
+ threadPath=item;
+ threadIm=loadImage(item);
+ } catch (Exception e) {
+
+ }
+ running=false;
+ loading=false;
+ System.out.println("Finished loading");
+ }
+
+ public void quit() {
+ System.out.println("Quitting.");
+ running = false;
+ interrupt();
+ }
- }
-}
+ }
+}
View
16 src/LinkWindow.java
@@ -5,14 +5,12 @@
public class LinkWindow extends TimedWindow {
- public LinkWindow(float now,String key) {
- super(now,key);
- }
+ public LinkWindow(float now,String key) {
+ super(now,key);
+ }
- public void completionAction() {
- Textlabel lbl = (Textlabel) controls.get("message");
- complete=true;
- lbl.setText(mainApp.doLinkItem());
- }
-
+ public void completionAction() {
+ complete=true;
+ }
+
}
View
58 src/LoadWindow.java
@@ -3,34 +3,34 @@
import javax.swing.*;
public class LoadWindow {
-
- String dir;
-
- public LoadWindow() {
-
- }
-
- void launchChooser() {
- dir=null;
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- try {
- JFileChooser fc = new JFileChooser();
- ChooserFilter filter = new ChooserFilter();
- filter.addExtension("keir");
- fc.setFileSelectionMode(JFileChooser.FILES_ONLY );
- fc.setFileFilter(filter);
- fc.setCurrentDirectory(new File("/Users/LouisMcc/Documents/programming/Eclipse"));
- int returnVal = fc.showOpenDialog(null);
- if (returnVal == JFileChooser.APPROVE_OPTION) {
- File file = fc.getSelectedFile();
- dir = file.getAbsolutePath();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
+
+ String dir;
+
+ public LoadWindow() {
+
+ }
+
+ void launchChooser() {
+ dir=null;
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ try {
+ JFileChooser fc = new JFileChooser();
+// ChooserFilter filter = new ChooserFilter();
+// filter.addExtension("keir");
+// fc.setFileSelectionMode(JFileChooser.FILES_ONLY );
+// fc.setFileFilter(filter);
+ fc.setCurrentDirectory(new File("/Users/LouisMcc/Documents/programming/Eclipse"));
+ int returnVal = fc.showOpenDialog(null);
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ File file = fc.getSelectedFile();
+ dir = file.getAbsolutePath();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ }
}
View
155 src/ModalView.java
@@ -8,84 +8,85 @@
import controlP5.*;
public class ModalView {
-
- ControlP5 cp5;
- HashMap <String, Controller> controls;
- int x,y,w,h;
- Boolean isCounting=false;
- PFont font;
- Boolean redraw;
- Boolean complete=false;
- String key;
-
- public ModalView(String key) {
- w=400;
- h=200;
- controls=new HashMap<String, Controller>();
- clearWindow();
- this.key=key;
- }
-
- public void setSize(int mainW,int mainH) {
- x=(mainW/2)-(w/2);
- y=(mainH/2)-(h/2);
- }
-
- public void setCP5(ControlP5 cp5) {
- this.cp5=cp5;
- }
-
- public void init (String titleTxt, String messageTxt) {
- addLabels(titleTxt,messageTxt);
- addButtons();
- System.out.println("showing modal view");
- redraw=false;
- }
+
+ ControlP5 cp5;
+ HashMap <String, controlP5.Controller> controls;
+ int x,y,w,h;
+ Boolean isCounting=false;
+ PFont font;
+ Boolean redraw;
+ Boolean complete=false;
+ String key;
+ Boolean clearModal=false;
+
+ public ModalView(String key) {
+ w=400;
+ h=200;
+ controls=new HashMap<String, controlP5.Controller>();
+ clearWindow();
+ this.key=key;
+ }
+
+ public void setSize(int mainW,int mainH) {
+ x=(mainW/2)-(w/2);
+ y=(mainH/2)-(h/2);
+ }
+
+ public void setCP5(ControlP5 cp5) {
+ this.cp5=cp5;
+ }
+
+ public void init (String titleTxt, String messageTxt) {
+ addLabels(titleTxt,messageTxt);
+ addButtons();
+ System.out.println("showing modal view");
+ redraw=false;
+ }
- protected void clearWindow() {
-// mainApp.fill(0);
-// mainApp.rect(x,y,w,h);
- }
-
- private void addLabels(String titleTxt, String messageTxt) {
- controls.put("title",cp5.addTextlabel("title")
- .setText(titleTxt)
- .setPosition(x,y)
- .setSize(w,h/4)
- .setFont(font)
- );
- controls.put("message",cp5.addTextlabel("message")
- .setText(messageTxt)
- .setPosition(x,y+(h/4))
- .setSize(w,h/2)
- .setFont(font)
- );
- }
-
- private void addButtons() {
- controls.put("cancel",cp5.addButton("close")
- .setPosition((float)(x+(w*0.75)),y)
- .setSize(w/4,h/4)
- );
- }
-
- public void done() {
+ protected void clearWindow() {
+ clearModal=true;
+ }
+
+ private void addLabels(String titleTxt, String messageTxt) {
+ controls.put("title",cp5.addTextlabel("title")
+ .setText(titleTxt)
+ .setPosition(x,y)
+ .setSize(w,h/4)
+ .setFont(font)
+ );
+ controls.put("message",cp5.addTextlabel("message")
+ .setText(messageTxt)
+ .setPosition(x,y+(h/4))
+ .setSize(w,h/2)
+ .setFont(font)
+ );
+ }
+
+ private void addButtons() {
+ controls.put("cancel",cp5.addButton("close")
+ .setPosition((float)(x+(w*0.75)),y)
+ .setSize(w/4,h/4)
+ .activateBy(ControlP5Constants.PRESSED)
+ );
+ }
+
+ public void done() {
- }
-
- public void close() {
- System.out.println("Closed modal view");
- isCounting=false;
- Iterator it = controls.entrySet().iterator();
- while (it.hasNext()) {
- Map.Entry<String,Controller> pairs = (Map.Entry<String,Controller>)it.next();
- cp5.remove(pairs.getValue().getName());
- // System.out.println(pairs.getKey() + " = " + pairs.getValue());
- it.remove();
- }
- controls.clear();
- redraw=true;
- }
-}
+ }
+
+ public void close() {
+ System.out.println("Closed modal view");
+ isCounting=false;
+ Iterator it = controls.values().iterator();
+ while (it.hasNext()) {
+ controlP5.Controller val = (controlP5.Controller)it.next();
+ cp5.remove(val.getName());
+ // System.out.println(pairs.getKey() + " = " + pairs.getValue());
+ it.remove();
+ }
+ controls.clear();
+ redraw=true;
+ }
+}
View
42 src/NewProjectView.java
@@ -4,26 +4,24 @@
public class NewProjectView extends ModalView {
- public NewProjectView(String key) {
- super(key);
- controls.put("name",cp5.addTextfield("New Project")
- .setPosition(x,(float)(y+(h*0.75)))
- .setSize(w/2,h/4)
- .setCaptionLabel(" ")
- );
- controls.put("done",cp5.addButton("done")
- .setPosition(x+(3*(w/4)),(float)(y+(h*0.75)))
- .setSize(w/4,h/4)
- );
- }
-
- public void done() {
- Textfield tf = (Textfield) controls.get("name");
- String name=tf.getText();
- if(!name.isEmpty()) {
- close();
- mainApp.newName=name;
- mainApp.fileSystem.launchNew();
- }
- }
+ public NewProjectView(String key) {
+ super(key);
+ }
+
+ public void init(String titleTxt, String messageTxt) {
+ super.init(titleTxt,messageTxt);
+ controls.put("name",cp5.addTextfield("New Project")
+ .setPosition(x,(float)(y+(h*0.75)))
+ .setSize(w/2,h/4)
+ .setCaptionLabel(" ")
+ );
+ controls.put("done",cp5.addButton("done")
+ .setPosition(x+(3*(w/4)),(float)(y+(h*0.75)))
+ .setSize(w/4,h/4)
+ );
+ }
+
+ public void done() {
+ complete=true;
+ }
}
View
50 src/NewWindow.java
@@ -3,30 +3,30 @@
import javax.swing.*;
public class NewWindow {
-
- String dir;
-
- public NewWindow() {
-
- }
-
- void launchChooser() {
- dir=null;
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- try {
- JFileChooser fc = new JFileChooser();
- fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY );
- int returnVal = fc.showOpenDialog(null);
- if (returnVal == JFileChooser.APPROVE_OPTION) {
- File file = fc.getSelectedFile();
- dir = file.getAbsolutePath();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
+
+ String dir;
+
+ public NewWindow() {
+
+ }
+
+ void launchChooser() {
+ dir=null;
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ try {
+ JFileChooser fc = new JFileChooser();
+ fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY );
+ int returnVal = fc.showOpenDialog(null);
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ File file = fc.getSelectedFile();
+ dir = file.getAbsolutePath();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ }
}
View
16 src/RecordView.java
@@ -5,14 +5,12 @@
public class RecordView extends TimedWindow {
- public RecordView(float now,String key) {
- super(now,key);
- }
+ public RecordView(float now,String key) {
+ super(now,key);
+ }
- public void completionAction() {
- Textlabel lbl = (Textlabel) controls.get("message");
- lbl.setText("Recording");
- mainApp.startRecord();
- }
-
+ public void completionAction() {
+ complete=true;
+ }
+
}
View
98 src/TimedWindow.java
@@ -4,54 +4,54 @@
public class TimedWindow extends ModalView {
-
- float nextTime;
- float interval;
- int step=0;
-
+
+ float nextTime;
+ float interval;
+ int step=0;
+
- public TimedWindow(float now,String key) {
- super(key);
- interval=1000;
- nextTime=now+interval;
- isCounting=true;
- }
-
- public void isNextStep(float now) {
- if(now>nextTime) {
- nextTime=now+interval;
- stepAction();
- }
- }
-
- public void completionAction() {
- System.out.println("Completion action not implemented");
- }
-
- public void stepAction() {
- Textlabel lbl = (Textlabel) controls.get("message");
- switch(step) {
- case 0:
- clearWindow();
- lbl.setText("3");
- break;
- case 1:
- clearWindow();
- lbl.setText("2");
- break;
- case 2:
- clearWindow();
- lbl.setText("1");
- break;
- case 3:
- clearWindow();
- completionAction();
- break;
- case 4:
- close();
- isCounting=false;
- break;
- }
- step++;
- }
+ public TimedWindow(float now,String key) {
+ super(key);
+ interval=1000;
+ nextTime=now+interval;
+ isCounting=true;
+ }
+
+ public void isNextStep(float now) {
+ if(now>nextTime) {
+ nextTime=now+interval;
+ stepAction();
+ }
+ }
+
+ public void completionAction() {
+ System.out.println("Completion action not implemented");
+ }
+
+ public void stepAction() {
+ Textlabel lbl = (Textlabel) controls.get("message");
+ switch(step) {
+ case 0:
+ clearWindow();
+ lbl.setText("3");
+ break;
+ case 1:
+ clearWindow();
+ lbl.setText("2");
+ break;
+ case 2:
+ clearWindow();
+ lbl.setText("1");
+ break;
+ case 3:
+ clearWindow();
+ completionAction();
+ break;
+ case 4:
+ close();
+ isCounting=false;
+ break;
+ }
+ step++;
+ }
}

No commit comments for this range

Something went wrong with that request. Please try again.