Browse files

Converted SimUI over to java

  • Loading branch information...
1 parent b246439 commit 79fa2238ae0a969b1acfecf56e685dd49b393787 Zachary Kim committed May 6, 2009
View
17 neurons
@@ -9,8 +9,21 @@
</color>
<mediaFile>./neuron_media_files/thalamus.wav</mediaFile>
<location class="java.awt.geom.Point2D$Double">
- <x>54.82310182985435</x>
- <y>-166.9813321847627</y>
+ <x>46.468766858290735</x>
+ <y>-187.97748109104162</y>
+ </location>
+ </napplelabs.dbssim.neuron.NeuronPathRep>
+ <napplelabs.dbssim.neuron.NeuronPathRep>
+ <color>
+ <red>255</red>
+ <green>0</green>
+ <blue>0</blue>
+ <alpha>255</alpha>
+ </color>
+ <mediaFile>./neuron_media_files/stn.wav</mediaFile>
+ <location class="java.awt.geom.Point2D$Double">
+ <x>69.30791570133613</x>
+ <y>-184.2738353327099</y>
</location>
</napplelabs.dbssim.neuron.NeuronPathRep>
</list>
View
38 src/main/groovy/napplelabs/dbssim/ui/MacFrame.java
@@ -51,29 +51,29 @@
private List<JButton> toolbarButtons = new ArrayList<JButton>();
public MacFrame(int width, int height) {
- frame = new JFrame("MockDBS");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ setFrame(new JFrame("MockDBS"));
+ getFrame().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setSize(width, height);
- frame.setLocationRelativeTo(null);
+ getFrame().setSize(width, height);
+ getFrame().setLocationRelativeTo(null);
toolbar = MacWidgetFactory.createUnifiedToolBar();
- frame.getContentPane().add(toolbar.getComponent(), BorderLayout.NORTH);
+ getFrame().getContentPane().add(toolbar.getComponent(), BorderLayout.NORTH);
bottombar = MacWidgetFactory.createBottomBar(BottomBarSize.LARGE);
- frame.getContentPane().add(bottombar.getComponent(), BorderLayout.SOUTH);
- content = new JPanel();
- content.setLayout(new BorderLayout());
- frame.getContentPane().add(content, BorderLayout.CENTER);
+ getFrame().getContentPane().add(bottombar.getComponent(), BorderLayout.SOUTH);
+ setContent(new JPanel());
+ getContent().setLayout(new BorderLayout());
+ getFrame().getContentPane().add(getContent(), BorderLayout.CENTER);
}
public void setVisisble(boolean vis) {
- frame.setVisible(vis);
+ getFrame().setVisible(vis);
}
public boolean getVisible() {
- return frame.isVisible();
+ return getFrame().isVisible();
}
public void addToolbarComponentRight(JComponent comp) {
@@ -118,4 +118,20 @@ public void addBottombarComponentCenter(JComponent comp) {
public void addBottombarComponentRight(JComponent comp) {
bottombar.addComponentToRight(comp);
}
+
+ public void setContent(JPanel content) {
+ this.content = content;
+ }
+
+ public JPanel getContent() {
+ return content;
+ }
+
+ public void setFrame(JFrame frame) {
+ this.frame = frame;
+ }
+
+ public JFrame getFrame() {
+ return frame;
+ }
}
View
167 src/main/groovy/napplelabs/dbssim/ui/SimUI.groovy
@@ -1,167 +0,0 @@
-/*
- MockDBS: Deep Brain Stimulation Simulator
- Copyright (C) 2009 Zachary Kim
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-package napplelabs.dbssim.ui
-
-import ddf.minim.Minim
-import ddf.minim.AudioOutput
-import napplelabs.dbssim.NeuronSignal
-import ddf.minim.signals.PinkNoise
-import java.awt.BorderLayout
-import com.explodingpixels.macwidgets.MacButtonFactory
-import javax.swing.AbstractButton
-import javax.swing.JButton
-import javax.swing.ImageIcon
-import javax.swing.JToggleButton
-import javax.swing.ButtonGroup
-import com.explodingpixels.macwidgets.LabeledComponentGroup
-import java.awt.event.ActionListener
-import javax.swing.SwingUtilities
-import java.lang.Runnable
-import javax.swing.JComponent
-import javax.swing.JPanel
-import javax.swing.JLabel
-import com.explodingpixels.macwidgets.HudWindow
-import java.awt.Dimension
-import ddf.minim.AudioPlayer
-import processing.core.PApplet
-import java.awt.Component
-import java.awt.Font
-import javax.swing.JCheckBox
-import javax.swing.JSlider
-import javax.swing.event.ChangeListener
-import javax.swing.UIManager
-import com.explodingpixels.painter.Painter
-import com.explodingpixels.painter.GradientPainter
-import com.explodingpixels.painter.FocusStatePainter
-import com.explodingpixels.swingx.EPPanel
-import com.explodingpixels.macwidgets.MacColorUtils
-import java.awt.event.KeyListener
-import java.awt.event.KeyAdapter
-import java.awt.event.KeyEvent
-import java.awt.KeyboardFocusManager
-import java.awt.KeyEventDispatcher
-import napplelabs.dbssim.canvasviews.Probe
-
-/**
- * Responsible for initializing the program and creating the main UI frame.
- *
- * The layout looks something like this:
- *
- * |------------------------|----|
- * | a |
- * |------------------------|----|
- * | | |
- * | | |
- * | | |
- * | | |
- * | b | c |
- * | | |
- * | | |
- * | | |
- * |------------------------|----|
- * | d |
- * |------------------------|----|
- *
- * Where:
- * a = Top Bar (see MacFrame)
- * b = CanvasPanel
- * c = Control Panel
- * d = Bottom Bar (see MacFrame)
- */
-class SimUI {
- MacFrame mf
- Component currentComponent = new JPanel()
- Component tracePanel = new JPanel()
-
- PinkNoise pink
-
- public SimUI() {
-
-
- mf = new MacFrame(1200, 800)
-
- //Top bar setup
-
- //Bottom bar setup
- JLabel depthLabel = new JLabel("0.00 mm")
- depthLabel.font = new Font("Arial", Font.PLAIN, 30)
- mf.addBottombarComponentCenter(depthLabel)
-
- EPPanel noisePanel = createNoisePanel()
- mf.addBottombarComponentRight(noisePanel)
-
- Minim minim = new Minim(new PApplet());
- def canvasPanel = new CanvasPanel(minim, depthLabel)
- mf.content.add(canvasPanel, BorderLayout.CENTER)
-
- double one = (float) (1.1*Math.PI / 100);
- int sin_size = 100;
- float[] sin = new float[sin_size];
- for(int i=0; i < sin_size; i++) {
- sin[i] = (float) Math.sin(one * i);
- }
-
-
- AudioOutput out = minim.getLineOut(Minim.MONO);
- pink = new PinkNoise(0.0f);
- out.addSignal(pink)
-
- mf.frame.visible = true
- }
-
- private EPPanel createNoisePanel() {
- EPPanel noisePanel = new EPPanel()
- noisePanel.layout = new BorderLayout()
- Painter<Component> focusedPainter =
- new GradientPainter(
- MacColorUtils.OS_X_BOTTOM_BAR_ACTIVE_TOP_COLOR,
- MacColorUtils.OS_X_BOTTOM_BAR_ACTIVE_BOTTOM_COLOR);
- Painter<Component> unfocusedPainter =
- new GradientPainter(
- MacColorUtils.OS_X_BOTTOM_BAR_INACTIVE_TOP_COLOR,
- MacColorUtils.OS_X_BOTTOM_BAR_INACTIVE_BOTTOM_COLOR);
-
- Painter<Component> painter = new FocusStatePainter(focusedPainter, focusedPainter,
- unfocusedPainter);
- noisePanel.backgroundPainter = painter
-
- JSlider noiseSlider = new JSlider();
- noiseSlider.minimum = 0
- noiseSlider.maximum = 100
- noiseSlider.value = 0
- noiseSlider.addChangeListener({
- float val = noiseSlider.value as float
- val /= 100
- pink.amp = val
- } as ChangeListener)
-
-
- noisePanel.add(noiseSlider, BorderLayout.CENTER)
- noisePanel.add(new JLabel("Noise"), BorderLayout.WEST)
-
- return noisePanel;
- }
-
- public JComponent getCurrentComponent() {
- return currentComponent
- }
-
- public static void main(String[] args) {
-
View
153 src/main/groovy/napplelabs/dbssim/ui/SimUI.java
@@ -0,0 +1,153 @@
+/*
+ MockDBS: Deep Brain Stimulation Simulator
+ Copyright (C) 2009 Zachary Kim
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package napplelabs.dbssim.ui;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Font;
+
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JSlider;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+import processing.core.PApplet;
+
+import com.explodingpixels.macwidgets.MacColorUtils;
+import com.explodingpixels.painter.FocusStatePainter;
+import com.explodingpixels.painter.GradientPainter;
+import com.explodingpixels.painter.Painter;
+import com.explodingpixels.swingx.EPPanel;
+
+import ddf.minim.AudioOutput;
+import ddf.minim.Minim;
+import ddf.minim.signals.PinkNoise;
+
+
+/**
+ * Responsible for initializing the program and creating the main UI frame.
+ *
+ * The layout looks something like this:
+ *
+ * |------------------------|----|
+ * | a |
+ * |------------------------|----|
+ * | | |
+ * | | |
+ * | | |
+ * | | |
+ * | b | c |
+ * | | |
+ * | | |
+ * | | |
+ * |------------------------|----|
+ * | d |
+ * |------------------------|----|
+ *
+ * Where:
+ * a = Top Bar (see MacFrame)
+ * b = CanvasPanel
+ * c = Control Panel
+ * d = Bottom Bar (see MacFrame)
+ */
+public class SimUI {
+
+ private MacFrame mf;
+ private Component currentComponent = new JPanel();
+ private Component tracePanel = new JPanel();
+
+ //Fakes the signal interference found during DBS surgery.
+ PinkNoise pink;
+
+ public SimUI() {
+ mf = new MacFrame(1200, 800);
+
+ // Top bar setup
+
+ //Bottom bar setup
+ JLabel depthLabel = new JLabel("0.00 mm");
+ depthLabel.setFont(new Font("Arial", Font.PLAIN, 30));
+ mf.addBottombarComponentCenter(depthLabel);
+
+ EPPanel noisePanel = createNoisePanel();
+ mf.addBottombarComponentRight(noisePanel);
+
+ Minim minim = new Minim(new PApplet());
+ CanvasPanel canvasPanel = new CanvasPanel(minim, depthLabel);
+ mf.getContent().add(canvasPanel, BorderLayout.CENTER);
+
+ double one = (float) (1.1*Math.PI / 100);
+ int sin_size = 100;
+ float[] sin = new float[sin_size];
+ for(int i=0; i < sin_size; i++) {
+ sin[i] = (float) Math.sin(one * i);
+ }
+
+
+ AudioOutput out = minim.getLineOut(Minim.MONO);
+ pink = new PinkNoise(0.0f);
+ out.addSignal(pink);
+
+ mf.getFrame().setVisible(true);
+ }
+
+ private EPPanel createNoisePanel() {
+ EPPanel noisePanel = new EPPanel();
+ noisePanel.setLayout(new BorderLayout());
+ Painter<Component> focusedPainter =
+ new GradientPainter(
+ MacColorUtils.OS_X_BOTTOM_BAR_ACTIVE_TOP_COLOR,
+ MacColorUtils.OS_X_BOTTOM_BAR_ACTIVE_BOTTOM_COLOR);
+ Painter<Component> unfocusedPainter =
+ new GradientPainter(
+ MacColorUtils.OS_X_BOTTOM_BAR_INACTIVE_TOP_COLOR,
+ MacColorUtils.OS_X_BOTTOM_BAR_INACTIVE_BOTTOM_COLOR);
+
+ Painter<Component> painter = new FocusStatePainter(focusedPainter, focusedPainter,
+ unfocusedPainter);
+ noisePanel.setBackgroundPainter(painter);
+
+ final JSlider noiseSlider = new JSlider();
+ noiseSlider.setMinimum( 0 );
+ noiseSlider.setMaximum( 100 );
+ noiseSlider.setValue( 0 );
+ noiseSlider.addChangeListener(new ChangeListener() {
+
+ public void stateChanged(ChangeEvent e) {
+ float val = noiseSlider.getValue();
+ val /= 100;
+ pink.setAmp(val);
+ }
+
+ });
+
+
+ noisePanel.add(noiseSlider, BorderLayout.CENTER);
+ noisePanel.add(new JLabel("Noise"), BorderLayout.WEST);
+
+ return noisePanel;
+ }
+
+ public static void main(String[] args) {
+ new SimUI();
+ }
+
+}

0 comments on commit 79fa223

Please sign in to comment.