From 3afc59258ade3bb093255731c2cdda18aba3649b Mon Sep 17 00:00:00 2001 From: rmh3093 Date: Wed, 23 Jul 2008 13:00:44 -0400 Subject: [PATCH] make generic function to generate targets, create initial fullscreen canvas for trials --- motsim/MOTSIM.class | Bin 3226 -> 4567 bytes motsim/MOTSIM.java | 122 ++++++++++++++++++++++++++++++------------ motsim/TrialDataDynamic.class | Bin 6184 -> 7067 bytes motsim/TrialDataDynamic.java | 32 ++++++++++- 4 files changed, 118 insertions(+), 36 deletions(-) rewrite motsim/MOTSIM.class (99%) diff --git a/motsim/MOTSIM.class b/motsim/MOTSIM.class dissimilarity index 99% index 38800f18a0344dc0493f52d10641e8628d9491a9..43119d28432e719ab637fdd4f601491bd9c1699a 100644 GIT binary patch literal 4567 zcwT*1349z?8UMd#(@8duHcfAOr4?wBQUZknB`w${4NXnj(1eswAxx7=GVNw2?93(< z)QSgqp`zk}Hz;_E&}<6PTD6Lxs1?Br)Ow*P;(>su;QxCw*=*9S`Tb_!d*A!scVBt% z#rqBcSff^0n5HnjWqW&DQ;UU!!puGPkX>sJhqd*#H)IDErYkJT0i7Yo3u`xahpz86 zyFuu9PFkTX=uSJ1*A=+eItp`|bLb83fa3+kty3rpdwLWqn%mQ^oocW{yJ4Sa54hdD zDjl$0uQ6>88w|T%U+q={B}$2)wA$We`t`mS67HmlaZ+ff`lp7=sUIOn#^^ zZ!&`zE@A~l4abEqHK$0#=w?$U41I50tsH>}Y&eNsa|TgJ8i0^EUM~X`z34YPbh->` z7w>xfVS1{nxQH5$o(t6i(!wV^8Rb>5?EtVm9 zudlAUqZA6OG!{e4qtzN`pq7%;Kq5CID^hq~Rdpd3TR3Z~EJhEZdbWmzk|fT=T8(pY zodWBoz5<+zE^F@FQ4@?b&@4MO4{=sh_8E42!hQwSB-r&D4Fa9s@3?*aVUkieYFvyh5z|e6#_I_btg0sdMM7=W zcmF{G((V-G8)&R1)cA}PB-V;<%wk-@Nq zAu3X+d}v&QeI!p39d;@sHFDgPCIPqa-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SVNsYV_MH=yxxrM8pAom z@k16Fg+T4raEr)TrR#~c7#awFPM{z?-L}jamKZAIB+Hg@%^AxT zCI`Z{$$Mrdaaea}(}w7pvpA<TABo<%b~Va;|b)}Svo5YoFF@iSad@bmJn zsN!n)1%AoQEaMzwYb#r*SnFJ)zpmQ$LBdfyh=&zCRLz=qJtM2(5j@HnscaF`PK;2^ zqq3oAnb_laQo$4Dtx?U^@RYa-l$;=CERn!78lJ^-q|NH?kRL1Wm=glm-)Q))z_o1= zSKD@`OpBkcg5OD4x6q_BhMi4}*tEKH=c%x&qe6r2=l+Uc%<_dbxZ=fXsCoPp0_3Cn7o4mCF~t<=`Lb_vc80#@n%(S-bLNplMN;GQt-~C5>sNd(jSv! z^#$B@oTnnrc#LL;j)!)Wk+R`vEE~W~=x>%95qjPNlNwR_Zo_Gu z;guXk2HCK-!hQq&&Xr&hwp=PsP=7kOy?}gDzJygV`4ikPQTbOxAL0R4>M=oiTEYw0 zz7e9&5A6`5^_S2ds}DslCS}Tsvix4qeBrOJ;DrKSUF4J?74a7VzwE=m2g~`JWXSsn z!hQnWLm>BKH}2p=>L7;re9o)Or%gugPuCZ_%t z-e!s$De(^8C4_rv_dU|;Xi>oPH~OE&3j7@(@asdr1(t=HAMq=Y|CsWZ$xA@KhIZ5| oC@8QLMxb!HW92nAO~V3lf!<03MZd$Y;1ix=8D7Lye2VD*0T1~~;s5{u diff --git a/motsim/MOTSIM.java b/motsim/MOTSIM.java index 785e08b..9ae8ee5 100644 --- a/motsim/MOTSIM.java +++ b/motsim/MOTSIM.java @@ -3,75 +3,129 @@ * motsim */ +import java.awt.Canvas; +import java.awt.Color; import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.GraphicsEnvironment; import java.awt.GridLayout; import java.awt.Toolkit; -import java.awt.geom.Point2D; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.util.HashSet; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; +import javax.swing.JPanel; import javax.swing.JSpinner; import javax.swing.SpinnerNumberModel; -public class MOTSIM { +public class MOTSIM extends Canvas implements ActionListener { + + private Dimension screen_size; + + private TrialDataDynamic tdd; + + private JFrame mainFrame; + private Container mainPane; + private FlowLayout targetsLayout; + private Container targetsPane; + private JLabel targetsLabel; + private SpinnerNumberModel targetsSpinnerModel; + private JSpinner targetsSpinner; + private FlowLayout startLayout; + private Container startPane; + private JButton startButton; - public MOTSIM() { + private JFrame trialContainer; + private JPanel trialPanel; + + private void create_trial_window() { + + trialContainer = new JFrame("Trial"); + + JPanel panel = (JPanel) trialContainer.getContentPane(); + panel.setPreferredSize( screen_size ); + panel.setLayout(null); + + setBounds( 0, 0, screen_size.width, screen_size.height ); + panel.add( this ); + + setIgnoreRepaint( true ); + + GraphicsEnvironment.getLocalGraphicsEnvironment(). + getDefaultScreenDevice().setFullScreenWindow( trialContainer ); + + trialContainer.pack(); + trialContainer.setResizable( false ); + trialContainer.setVisible( true ); - JFrame mainFrame = new JFrame( "MOTSIM" ); - Container mainPane = mainFrame.getContentPane(); + } + + private void print_target_info() { + HashSet targets = + tdd.generage_targets( (Integer) targetsSpinner.getValue() ); + for ( Target t : targets ) { + System.out.println( t.getCallsign() ); + System.out.println( t.getCoordinate() ); + } + } + + public void actionPerformed(ActionEvent e) { + if ( e.getActionCommand() == "START" ) { + print_target_info(); + create_trial_window(); + } + } + + public MOTSIM() { + + screen_size = Toolkit.getDefaultToolkit().getScreenSize(); + + tdd = new TrialDataDynamic(); + + mainFrame = new JFrame( "MOTSIM" ); + mainPane = mainFrame.getContentPane(); mainFrame.setPreferredSize( new Dimension( 250, 70 ) ); mainFrame.setResizable( false ); mainFrame.setLocationRelativeTo( null ); mainPane.setLayout( new GridLayout( 2, 1 ) ); mainFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); mainFrame.setVisible( true ); - - FlowLayout targetsLayout = new FlowLayout(); - Container targetsPane = new Container(); + + targetsLayout = new FlowLayout(); + targetsPane = new Container(); targetsPane.setLayout( targetsLayout ); - JLabel targetsLabel = new JLabel( "Number of Targets: " ); - SpinnerNumberModel targetsSpinnerModel = + targetsLabel = new JLabel( "Number of Targets: " ); + targetsSpinnerModel = new SpinnerNumberModel( 10, 1, 50, 1 ); - JSpinner targetsSpinner = new JSpinner(); + targetsSpinner = new JSpinner(); targetsSpinner.setModel( targetsSpinnerModel ); targetsPane.add( targetsLabel ); targetsPane.add( targetsSpinner ); mainFrame.add( targetsPane ); - - FlowLayout startLayout = new FlowLayout(); - Container startPane = new Container(); + + startLayout = new FlowLayout(); + startPane = new Container(); startPane.setLayout( startLayout ); - JButton startButton = new JButton( "Start MOTSIM"); + startButton = new JButton( "Start MOTSIM"); + startButton.addActionListener( this ); + startButton.setActionCommand("START"); startPane.add( startButton ); mainFrame.add( startPane ); - + mainFrame.pack(); - + } public static void main(String[] args) { - - TrialDataDynamic tdd = new TrialDataDynamic(); - - HashSet callsigns = tdd.generate_callsigns( 4 ); - for ( String s : callsigns ) { - System.out.println( s ); - } - - HashSet coordinates = tdd.generate_coordinates( 4 ); - for ( Point2D.Double p : coordinates ) { - System.out.println( p ); - } - - Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize(); - System.out.println( screen_size ); - + new MOTSIM(); - + } } diff --git a/motsim/TrialDataDynamic.class b/motsim/TrialDataDynamic.class index fcd194f24391baa2c4d3ff7ba131796002bf7785..f51a7e7b31a0b02fe7f60c61f03608b32f5c40b3 100644 GIT binary patch delta 1147 zcwTK(OHUI~6#nk%bOve*3bb`750O_3MGPWFiXc(&k%9>j6@1{(P9Io{w&MeQ3}T{j zr|C-Fx$&{m81a=D6BA?Hxpe0*Fmb0F@eHNJM3Ot_e)ryUzH`2FZ|3pV2Rj^J{=9t; zpo4BacYJhJtdHwyJ)_0-NkhxTbt5aVDOcxkn?2#N<&98p$N@noo#ZBug-$tXA0tv} z%1IH53KS&`rZ8qQ0v>-LJgr^O+Rq!wRQrLI{g6U20Xa{&juJGjP*R}me@`c!rj&q` z4(XQ+frkNEq%f!8==m20Gn-hQE&T( z2B{8>QW8zlb2Ll8;kWlAV84wP`&YEeDuS|xHu(v*$Uo68|Eff%VnY{|@dI;00E$HA zRKY9C3D2#zeiUO5pA107AgZt*wK#}Yo;xtiCx_S$V}#KJMsqJcQ9-#%?{woS6k(EM zr#LpsqI6Uvh9<UMJp>I_`T#zM&Sj zCx$IM*)6p#lGbfkC2Nu&q4^!@Ta`_AB$8{EagPUNo?0H0Z zj^XBV14r^juQbp?z0}7|Eyg4n)DL3DaoWwu#=Ijm#>kYIK1}E70zZO!4A4bJGN(}J z63w#R%S4@gmM588B^g*HnLvT#@+!v_$TY~2HLxvl-HHMs6jBQ#!2_uGfi}|B<;Gtl OlV|I1F+}sUfa1UP670qR delta 326 zcwP;UyD!6W6vaQ^`+HOyjXr4mt5%h^o^2>)BA$^ZYUo(c#w%Fu5{uZ#Z?qT@OJfm( zg&1r`o4-I}t3`Zsb8>Rey(j11tI3-Y-}~RwGfXEqmrc*K`q()LM=#n>5hR|)4NgJ2+ z7@zc-X)@*kS+haT{H4#DrQbSd!1`d&b{Mkj4BNNl?H>wuGtQXDpd=xEYAXsnri7(k zceu^yS$+mDb9%CX!y*ZmNKs};bCC-3tmvvx)jKt+?tN@W;Rc<<>?SR2Xm4G6xAj9i kB-tg$9tHL(X?=<#_uAQWL{@c}$eOHc_MxOA8?uG>AHU5sq5uE@ diff --git a/motsim/TrialDataDynamic.java b/motsim/TrialDataDynamic.java index 34f4e4d..c614877 100644 --- a/motsim/TrialDataDynamic.java +++ b/motsim/TrialDataDynamic.java @@ -5,6 +5,7 @@ import java.awt.geom.Point2D; import java.util.HashSet; +import java.util.Iterator; import java.util.Random; public class TrialDataDynamic { @@ -59,7 +60,7 @@ public class TrialDataDynamic { * @param count The number of callsigns to generate. * @return A HashSet of callsigns. */ - HashSet generate_callsigns( int count ) { + private HashSet generate_callsigns( int count ) { HashSet callsigns = new HashSet( count ); @@ -89,7 +90,7 @@ public class TrialDataDynamic { * @param count The number of coordinates to generate. * @return A HashSet of coordinates. */ - HashSet generate_coordinates( int count ) { + private HashSet generate_coordinates( int count ) { HashSet coordinates = new HashSet( count ); @@ -106,5 +107,32 @@ public class TrialDataDynamic { return coordinates; } + + /** + * Generate a random set of targets. + * + * @param count The number of callsigns to generate. + * @return A HashSet of coordinates. + */ + protected HashSet generage_targets( int count ) { + + HashSet targets = new HashSet( count ); + + HashSet callsigns = generate_callsigns( count ); + HashSet coordinates = generate_coordinates( count ); + + Iterator callsignsIter = callsigns.iterator(); + Iterator coordinatesIter = coordinates.iterator(); + + while ( ( targets.size() < count ) && + ( callsignsIter.hasNext() && callsignsIter.hasNext() ) ) { + Target target = + new Target( callsignsIter.next(), coordinatesIter.next() ); + targets.add( target ); + } + + return targets; + + } } -- 2.11.4.GIT