2 * Copyright (c) 2010 The Desert team
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use,
8 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
26 package org
.sourceforge
.desert
;
28 import java
.awt
.BorderLayout
;
29 import java
.awt
.Component
;
30 import java
.awt
.Label
;
31 import java
.awt
.Panel
;
32 import java
.awt
.event
.ActionEvent
;
33 import java
.awt
.event
.ActionListener
;
34 import javax
.swing
.Box
;
38 * @author codistmonk (creation 2010-04-15)
40 public class DesertPanel
extends Panel
{
42 private final Timer timer
;
44 private final DrawingBoard drawingBoard
;
46 public DesertPanel() {
47 super(new BorderLayout());
48 this.timer
= new Timer(FRAMERATE
);
49 this.drawingBoard
= new DrawingBoard();
51 final FramerateLabel framerateLabel
= new FramerateLabel();
52 final ParticleCountLabel particleCountLabel
= this.new ParticleCountLabel();
54 this.add(this.getDrawingBoard(), BorderLayout
.CENTER
);
55 this.add(horizontalBox(framerateLabel
, particleCountLabel
), BorderLayout
.SOUTH
);
57 this.getTimer().addActionListener(this.getDrawingBoard());
58 this.getTimer().addActionListener(framerateLabel
);
59 this.getTimer().addActionListener(particleCountLabel
);
65 * <br>A non-null value
68 public final Timer
getTimer() {
75 * <br>A non-null value
78 public final DrawingBoard
getDrawingBoard() {
79 return this.drawingBoard
;
84 * @author codistmonk (creation 2010-04-15)
86 private final class ParticleCountLabel
extends Label
implements ActionListener
{
89 public final void actionPerformed(final ActionEvent event
) {
90 this.setText("Particle count: " + DesertPanel
.this.getDrawingBoard().getParticleCount());
95 public static final Integer FRAMERATE
= 30;
100 * <br> Should not be null
103 * <br>A non-null value
105 private static final Box
horizontalBox(final Component
... components
) {
106 final Box result
= Box
.createHorizontalBox();
108 for (final Component component
: components
) {
109 result
.add(component
);
117 * @author codistmonk (creation 2010-04-15)
119 private static final class FramerateLabel
extends Label
implements ActionListener
{
122 public final void actionPerformed(final ActionEvent event
) {
123 this.setText("Framerate: " + String
.format("%.1f", 1.0 / ((Timer
.Event
) event
).getDeltaTime()));