From 68aa564d6295158b20cc31b184e7cee6c1f5bc31 Mon Sep 17 00:00:00 2001 From: rmh3093 Date: Wed, 20 Aug 2008 18:00:12 -0400 Subject: [PATCH] at end of trial select a random target and make it blink --- motsim/MOTSIM_Controller.java | 72 ++++++++++++++++++++++++++++++++----------- motsim/MOTSIM_Model.java | 20 ++++++------ motsim/MOTSIM_View.java | 24 +++++++++------ motsim/Target.java | 2 ++ 4 files changed, 81 insertions(+), 37 deletions(-) diff --git a/motsim/MOTSIM_Controller.java b/motsim/MOTSIM_Controller.java index 9aed583..e0d815e 100755 --- a/motsim/MOTSIM_Controller.java +++ b/motsim/MOTSIM_Controller.java @@ -31,10 +31,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import java.awt.Color; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.HashSet; +import java.util.Iterator; import java.util.Random; public class MOTSIM_Controller { @@ -46,8 +48,6 @@ public class MOTSIM_Controller { Random rand; - Thread targetMoverThread = null; - public MOTSIM_Controller(MOTSIM_Model model, MOTSIM_View view) { rand = new Random(); this.model = model; @@ -59,6 +59,17 @@ public class MOTSIM_Controller { view.cp.addStartListener(new StartListener()); } + private void pickTargetTarget() { + int count = 0; + int target = rand.nextInt(model.targets.size()); + for (Target t : model.targets) { + if (count==target) + model.target = t; + else + count++; + } + } + protected synchronized void moveTargets() { int sleep = 20; int[] entropy = null; @@ -128,21 +139,46 @@ public class MOTSIM_Controller { } + private void flipTargetColor() { + if (model.blink) + model.blink = false; + else + model.blink = true; + } + class TargetMover implements Runnable { public void run() { while (true) { - if ((model.move_targets == true) && (model.duration < model.maxduration)) { - moveTargets(); - } else { - synchronized (targetMoverThread) { - try { - model.mask_targets = true; - view.tp.repaint(); - targetMoverThread.wait(); - model.mask_targets = false; - } catch (InterruptedException e) { - } + while (model.move_targets) { + if (model.duration < model.maxduration) { + moveTargets(); + } else { + model.move_targets = false; + model.mask_targets = true; + } + } + if (model.mask_targets) { + view.tp.repaint(); + try { + Thread.sleep(2000); + } catch (InterruptedException e1) { + } + pickTargetTarget(); + model.blink_targets = true; + } + while (model.blink_targets && model.mask_targets) { + flipTargetColor(); + view.tp.repaint(); + try { + Thread.sleep(500); + } catch (InterruptedException e1) { + } + } + synchronized (model.targetMoverThread) { + try { + model.targetMoverThread.wait(); + } catch (InterruptedException e1) { } } } @@ -189,12 +225,12 @@ public class MOTSIM_Controller { model.duration = 0; model.borderstyle = view.cp.borderstyle_combobox.getSelectedItem().toString(); - if (targetMoverThread == null) { - targetMoverThread = new Thread(new TargetMover()); - targetMoverThread.start(); + if (model.targetMoverThread == null) { + model.targetMoverThread = new Thread(new TargetMover()); + model.targetMoverThread.start(); } else { - synchronized (targetMoverThread) { - targetMoverThread.notifyAll(); + synchronized (model.targetMoverThread) { + model.targetMoverThread.notifyAll(); } } } diff --git a/motsim/MOTSIM_Model.java b/motsim/MOTSIM_Model.java index 4f5a070..cc7bff6 100755 --- a/motsim/MOTSIM_Model.java +++ b/motsim/MOTSIM_Model.java @@ -31,6 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import java.awt.Color; import java.awt.DisplayMode; import java.awt.Font; import java.awt.GraphicsDevice; @@ -40,25 +41,24 @@ import java.util.HashSet; public class MOTSIM_Model { HashSet targets; - boolean move_targets; - boolean mask_targets; + boolean move_targets = false; + boolean mask_targets = false; + boolean blink_targets = false; String borderstyle; Font target_font; String defaultvelocities; String entropy; - int duration; + int duration = 0; int maxduration; GraphicsEnvironment ge; GraphicsDevice gd; DisplayMode display_mode_default; DisplayMode display_mode_preferred; DisplayMode[] display_mode_available; + Target target = null; + boolean blink = false; + Color target_color = Color.red; + Color target_blink_color = Color.yellow; + Thread targetMoverThread = null; - - public MOTSIM_Model() { - move_targets = true; - mask_targets = false; - duration = 0; - } - } diff --git a/motsim/MOTSIM_View.java b/motsim/MOTSIM_View.java index 743cf12..f0db775 100755 --- a/motsim/MOTSIM_View.java +++ b/motsim/MOTSIM_View.java @@ -196,14 +196,18 @@ public class MOTSIM_View { } public void drawTargets(Graphics g) { - for (Target t : model.targets ) { - /*String s = t.x + "," + t.y + " - " + t.moveAngle; - bufferGraphics.drawString(s, (int)Math.round(t.x), - (int)Math.round(t.y));*/ - if (model.mask_targets) - bufferGraphics.drawString("XXXXXX", (int)Math.round(t.x), - (int)Math.round(t.y)); - else + bufferGraphics.setColor(model.target_color); + for (Target t : model.targets ) { + if (model.mask_targets) { + if (model.blink && (model.target == t)) { + bufferGraphics.setColor(model.target_blink_color); + bufferGraphics.drawString("XXXXXX", (int)Math.round(t.x), + (int)Math.round(t.y)); + bufferGraphics.setColor(model.target_color); + } else + bufferGraphics.drawString("XXXXXX", (int)Math.round(t.x), + (int)Math.round(t.y)); + } else bufferGraphics.drawString(t.callsign, (int)Math.round(t.x), (int)Math.round(t.y)); } @@ -213,7 +217,6 @@ public class MOTSIM_View { public void paint(Graphics g) { bufferGraphics.clearRect(0, 0, screen_size.width, screen_size.height); - bufferGraphics.setColor(Color.red); drawTargets(g); g.drawImage(offscreen, 0, 0, this); } @@ -238,6 +241,9 @@ public class MOTSIM_View { } public void windowDeactivated(WindowEvent e) { + model.mask_targets = false; + model.blink = false; + model.blink_targets = false; model.move_targets = false; //model.gd.setDisplayMode(model.display_mode_preferred); } diff --git a/motsim/Target.java b/motsim/Target.java index 46b662b..48f54f5 100755 --- a/motsim/Target.java +++ b/motsim/Target.java @@ -1,3 +1,5 @@ +import java.awt.Color; + /** * Target.java * motsim -- 2.11.4.GIT