7 import java
.awt
.Dimension
;
8 import java
.awt
.FlowLayout
;
9 import java
.awt
.Graphics
;
10 import java
.awt
.GraphicsEnvironment
;
11 import java
.awt
.GridLayout
;
12 import java
.awt
.Image
;
13 import java
.awt
.Toolkit
;
14 import java
.awt
.event
.ActionListener
;
15 import java
.awt
.event
.MouseEvent
;
16 import java
.awt
.event
.MouseMotionListener
;
17 import java
.awt
.event
.WindowEvent
;
18 import java
.awt
.event
.WindowListener
;
20 import javax
.swing
.JButton
;
21 import javax
.swing
.JComboBox
;
22 import javax
.swing
.JFrame
;
23 import javax
.swing
.JLabel
;
24 import javax
.swing
.JPanel
;
25 import javax
.swing
.JSpinner
;
26 import javax
.swing
.SpinnerNumberModel
;
29 Copyright (c) 2008, Ryan M. Hope
32 Redistribution and use in source and binary forms, with or without modification,
33 are permitted provided that the following conditions are met:
35 * Redistributions of source code must retain the above copyright notice,
36 this list of conditions and the following disclaimer.
37 * Redistributions in binary form must reproduce the above copyright notice,
38 this list of conditions and the following disclaimer in the documentation
39 and/or other materials provided with the distribution.
40 * Neither the name of the project nor the names of its contributors may be
41 used to endorse or promote products derived from this software without
42 specific prior written permission.
44 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
45 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
46 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
47 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
48 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
49 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
51 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
53 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56 public class MOTSIM_View
{
61 ActionListener startActionListener
;
62 Dimension screen_size
;
64 public MOTSIM_View(MOTSIM_Model model
) {
66 screen_size
= Toolkit
.getDefaultToolkit().getScreenSize();
69 public void startControlPanel() {
70 cp
= new ControlPanel();
71 cp
.fontsize_spinner
.setValue(cp
.getFont().getSize());
74 public void startTrial() {
75 tp
= new TrialPanel();
78 @SuppressWarnings("serial")
79 class ControlPanel
extends JFrame
{
83 JSpinner targets_spinner
;
87 JPanel borderstyle_panel
;
88 JLabel borderstyle_label
;
89 JComboBox borderstyle_combobox
;
92 JComboBox entropy_combobox
;
93 JPanel fontsize_panel
;
94 JLabel fontsize_label
;
95 JSpinner fontsize_spinner
;
97 String
[] borderStyles
= { "Reflect", "Spawn"};
98 String
[] entropyStyles
= { "None", "Low", "Medium", "High"};
100 public ControlPanel() {
101 setDefaultCloseOperation(EXIT_ON_CLOSE
);
102 setPreferredSize(new Dimension(275, 120));
103 setTitle("MOTSIM Control Panel");
105 setLocationRelativeTo(null);
106 setLayout(new FlowLayout());
107 options_panel
= new JPanel(new GridLayout(4,2));
110 //targets_panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
111 targets_label
= new JLabel("Number of targets: ");
113 new JSpinner(new SpinnerNumberModel(10, 1, 50, 1));
114 targets_spinner
.setFocusable(false);
115 options_panel
.add(targets_label
);
116 options_panel
.add(targets_spinner
);
117 //add(targets_panel);
118 //fontsize_panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
119 fontsize_label
= new JLabel("Font size: ");
121 new JSpinner(new SpinnerNumberModel(10, 1, 38, 1));
122 fontsize_spinner
.setFocusable(false);
123 options_panel
.add(fontsize_label
);
124 options_panel
.add(fontsize_spinner
);
125 //add(fontsize_panel);
126 //borderstyle_panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
127 borderstyle_label
= new JLabel("Border Style: ");
128 borderstyle_combobox
= new JComboBox(borderStyles
);
129 options_panel
.add(borderstyle_label
);
130 options_panel
.add(borderstyle_combobox
);
131 //add(borderstyle_panel);
132 //entropy_panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
133 entropy_label
= new JLabel("Entropy: ");
134 entropy_combobox
= new JComboBox(entropyStyles
);
135 options_panel
.add(entropy_label
);
136 options_panel
.add(entropy_combobox
);
137 //add(entropy_panel);
138 start_panel
= new JPanel(new FlowLayout(FlowLayout
.CENTER
));
139 start_button
= new JButton("Start");
140 start_button
.setActionCommand("START");
141 start_button
.setSelected(true);
142 start_panel
.add(start_button
);
147 void addStartListener(ActionListener l
) {
148 start_button
.addActionListener(l
);
153 @SuppressWarnings("serial")
154 class TrialPanel
extends JFrame
155 implements MouseMotionListener
, WindowListener
{
157 Graphics bufferGraphics
;
162 public TrialPanel() {
163 setPreferredSize(screen_size
);
165 setLocationRelativeTo(null);
166 setUndecorated(true);
167 GraphicsEnvironment
.getLocalGraphicsEnvironment().
168 getDefaultScreenDevice().setFullScreenWindow(this);
169 addWindowListener(this);
170 addMouseMotionListener(this);
171 setBackground(Color
.black
);
172 offscreen
= createImage(screen_size
.width
, screen_size
.height
);
173 bufferGraphics
= offscreen
.getGraphics();
176 public void drawTargets(Graphics g
) {
177 for (Target t
: model
.targets
) {
178 /*String s = t.coordinate.x + "," + t.coordinate.y + " - " +
180 bufferGraphics.drawString(s, t.coordinate.x,
182 bufferGraphics
.drawString(t
.callsign
, t
.coordinate
.x
,
188 public void paint(Graphics g
) {
189 bufferGraphics
.clearRect(0, 0, screen_size
.width
,
191 bufferGraphics
.setColor(Color
.red
);
193 bufferGraphics
.fillRect(curX
, curY
, 20, 20);
194 g
.drawImage(offscreen
, 0, 0, this);
197 public void update(Graphics g
) {
201 public void mouseDragged(MouseEvent e
) {
204 public void mouseMoved(MouseEvent e
) {
210 public void windowActivated(WindowEvent e
) {
213 public void windowClosed(WindowEvent e
) {
216 public void windowClosing(WindowEvent e
) {
219 public void windowDeactivated(WindowEvent e
) {
220 model
.move_targets
= false;
223 public void windowDeiconified(WindowEvent e
) {
226 public void windowIconified(WindowEvent e
) {
229 public void windowOpened(WindowEvent e
) {