Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added persistence of neuron types

  • Loading branch information...
commit 49e6555c29b7643dab56c4d3e20da00e233854c6 1 parent 054e556
Zachary Kim authored
View
14 neuron_types.xstream.xml
@@ -0,0 +1,14 @@
+<object-stream>
+ <list>
+ <napplelabs.dbssim.neuron.NeuronType>
+ <name>asdf</name>
+ <mediaPath>/Users/zkim/Desktop/6KnowYourEnemy.mp3</mediaPath>
+ <color>
+ <red>255</red>
+ <green>255</green>
+ <blue>255</blue>
+ <alpha>255</alpha>
+ </color>
+ </napplelabs.dbssim.neuron.NeuronType>
+ </list>
+</object-stream>
View
57 neurons
@@ -17,25 +17,16 @@
<napplelabs.dbssim.neuron.NeuronPathRep>
<color>
<red>255</red>
- <green>0</green>
- <blue>0</blue>
+ <green>255</green>
+ <blue>255</blue>
<alpha>255</alpha>
</color>
- <mediaFile>./neuron_media_files/stn.wav</mediaFile>
- <location class="java.awt.geom.Point2D$Double">
- <x>499.6380902050415</x>
- <y>-1869.851652578137</y>
- </location>
- <name>STN</name>
- </napplelabs.dbssim.neuron.NeuronPathRep>
- <napplelabs.dbssim.neuron.NeuronPathRep>
- <color reference="../../napplelabs.dbssim.neuron.NeuronPathRep[2]/color"/>
- <mediaFile>./neuron_media_files/stn.wav</mediaFile>
+ <mediaFile>/Users/zkim/Desktop/6KnowYourEnemy.mp3</mediaFile>
<location class="java.awt.geom.Point2D$Double">
- <x>456.6380902050415</x>
- <y>-1708.851652578137</y>
+ <x>17.5</x>
+ <y>-71.5</y>
</location>
- <name>STN</name>
+ <name>asdf</name>
</napplelabs.dbssim.neuron.NeuronPathRep>
<napplelabs.dbssim.neuron.NeuronPathRep>
<color>
@@ -46,8 +37,8 @@
</color>
<mediaFile>./neuron_media_files/stn.wav</mediaFile>
<location class="java.awt.geom.Point2D$Double">
- <x>-64.5</x>
- <y>264.5</y>
+ <x>451.5615879903679</x>
+ <y>-1685.2507891265373</y>
</location>
<name>STN</name>
</napplelabs.dbssim.neuron.NeuronPathRep>
@@ -60,38 +51,10 @@
</color>
<mediaFile>./neuron_media_files/snr.wav</mediaFile>
<location class="java.awt.geom.Point2D$Double">
- <x>432.6419157933737</x>
- <y>-1614.6416112248066</y>
+ <x>351.32097182216165</x>
+ <y>-1311.1477166047814</y>
</location>
<name>SNr</name>
</napplelabs.dbssim.neuron.NeuronPathRep>
- <napplelabs.dbssim.neuron.NeuronPathRep>
- <color>
- <red>255</red>
- <green>255</green>
- <blue>255</blue>
- <alpha>255</alpha>
- </color>
- <mediaFile>/Users/zkim/Music/iTunes/iTunes Music/Lady Gaga/Top 40 Singles/13 Just Dance.mp3</mediaFile>
- <location class="java.awt.geom.Point2D$Double">
- <x>-3.5</x>
- <y>16.5</y>
- </location>
- <name>Unknown</name>
- </napplelabs.dbssim.neuron.NeuronPathRep>
- <napplelabs.dbssim.neuron.NeuronPathRep>
- <color>
- <red>31</red>
- <green>20</green>
- <blue>20</blue>
- <alpha>255</alpha>
- </color>
- <mediaFile>/Users/zkim/Desktop/6KnowYourEnemy.mp3</mediaFile>
- <location class="java.awt.geom.Point2D$Double">
- <x>22.112921893940836</x>
- <y>-66.15348105304298</y>
- </location>
- <name>Rage</name>
- </napplelabs.dbssim.neuron.NeuronPathRep>
</list>
</object-stream>
View
113 src/main/groovy/napplelabs/dbssim/ui/ContentPanel.java
@@ -38,6 +38,7 @@
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
@@ -95,6 +96,8 @@
private JPanel featurePanel;
private JButton newNeuronButton;
+
+ private List<NeuronType> userNeuronTypes = new ArrayList<NeuronType>();
public ContentPanel(final List<NeuronType> neuronTypes, final Minim minim,
final JLabel label) {
@@ -111,6 +114,8 @@ public ContentPanel(final List<NeuronType> neuronTypes, final Minim minim,
PLayer backgroundLayer = new PLayer();
canvas.getCamera().addLayer(1, backgroundLayer);
+ load();
+
probe = new Probe();
panel.add(createFeaturePanel(), BorderLayout.CENTER);
@@ -129,6 +134,7 @@ public ContentPanel(final List<NeuronType> neuronTypes, final Minim minim,
canvas.getLayer().addInputEventListener(new PBasicInputEventHandler() {
@Override
public void mouseClicked(PInputEvent evt) {
+ if(evt.getButton() != 3) return;
PNode picked = evt.getPickedNode();
final NeuronPath path = findNeuronPath(picked);
@@ -147,7 +153,7 @@ public void mouseClicked(PInputEvent evt) {
});
- load();
+
// Birds eye stuff
BirdsEyeView view = new BirdsEyeView();
@@ -220,6 +226,7 @@ private void removeNeuronPath(final NeuronPath path) {
path.removeFromParent();
path.setPlaying(false);
neurons.remove(path);
+ persistNeuronsOnCanvas();
}
/**
@@ -287,8 +294,10 @@ public void actionPerformed(ActionEvent e) {
nnd.setVisisble(true);
NeuronType nt = nnd.getNeuronType();
if(nt != null) {
+ userNeuronTypes.add(nt);
featurePanel.add(createNeuronPanel(nt), "wrap");
featurePanel.validate();
+ persistNeuronTypes();
}
}
@@ -306,24 +315,14 @@ public void actionPerformed(ActionEvent e) {
featurePanel.add(np, "wrap");
}
+ for(final NeuronType nt: userNeuronTypes) {
+ JPanel np = createNeuronPanel(nt);
+
+ //button.setFont(new Font("Arial", Font.PLAIN, 8));
+
+ featurePanel.add(np, "wrap");
+ }
-
- /*
- * JButton importButton = new JButton("Import Media");
- * panel.add(importButton, "wrap");
- *
- * JComboBox userNeuronsCombo = new JComboBox();
- * userNeuronsCombo.addItem("hello world this is zack");
- * userNeuronsCombo.addItem("qwer asdf zxcv ");
- * panel.add(userNeuronsCombo, "wrap");
- *
- * JButton addButton = new JButton("Add");
- * addButton.addActionListener(new ActionListener() {
- *
- * public void actionPerformed(ActionEvent e) { new AddMediaHud(); }
- *
- * }); panel.add(addButton, "wrap");
- */
return featurePanel;
}
@@ -391,7 +390,7 @@ public void mouseClicked(final PInputEvent evt) {
});
- persist();
+ persistNeuronsOnCanvas();
}
private Component createDepthPanel() {
@@ -453,10 +452,10 @@ public void recalcDistances() {
}
}
- public void persist() {
+ public void persistNeuronsOnCanvas() {
XStream xs = new XStream();
- // Write to a file in the file system
+ // Write neurons on canvas
try {
List<NeuronPathRep> reps = new ArrayList<NeuronPathRep>();
@@ -478,6 +477,21 @@ public void persist() {
// TODO Auto-generated catch block
e.printStackTrace();
}
+
+ }
+
+ private void persistNeuronTypes() {
+
+ XStream xs = new XStream();
+
+ //Write neuron types
+ try {
+ ObjectOutputStream os = xs.createObjectOutputStream(new FileWriter(new File("./neuron_types.xstream.xml")));
+ os.writeObject(userNeuronTypes);
+ os.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
public void load() {
@@ -485,28 +499,45 @@ public void load() {
// Write to a file in the file system
- if (!new File("./neurons").exists())
- return;
-
- try {
- ObjectInputStream is = xs.createObjectInputStream(new FileReader(
- new File("./neurons")));
- List<NeuronPathRep> paths = (List<NeuronPathRep>) is.readObject();
-
- for (NeuronPathRep r : paths) {
- NeuronPath np = new NeuronPath(r.color, r.name, r.mediaFile, minim);
- np.setOffset(r.location);
- addNeuronPath(np);
+ if (new File("./neurons").exists()) {
+
+ try {
+ ObjectInputStream is = xs.createObjectInputStream(new FileReader(
+ new File("./neurons")));
+ List<NeuronPathRep> paths = (List<NeuronPathRep>) is.readObject();
+
+ for (NeuronPathRep r : paths) {
+ NeuronPath np = new NeuronPath(r.color, r.name, r.mediaFile, minim);
+ np.setOffset(r.location);
+ addNeuronPath(np);
+ }
+
+ is.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
}
-
- is.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
}
+
+ if(new File("./neuron_types.xstream.xml").exists()) {
+ try {
+ ObjectInputStream is = xs.createObjectInputStream(new FileReader(new File("./neuron_types.xstream.xml")));
+ userNeuronTypes = (List<NeuronType>) is.readObject();
+ } catch (FileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
}
}
View
2  src/main/groovy/napplelabs/dbssim/ui/NodeDragHandler.java
@@ -59,6 +59,6 @@ public void drag(PInputEvent e) {
n.translate(e.getDelta().width, e.getDelta().height);
cp.recalcDistances();
- cp.persist();
+ cp.persistNeuronsOnCanvas();
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.