Warning: Can't use blame annotator:
svn blame failed on trunk/src/scriptbuilder/gui/panels/TimeStampPanel.java: ("Can't find a temporary directory: Internal error", 20014)

source: tmcsimulator-scriptbuilder/trunk/src/scriptbuilder/gui/panels/TimeStampPanel.java @ 76

Revision 76, 5.3 KB checked in by bmcguffin, 9 years ago (diff)

Added javadoc for several files.

RevLine 
1package scriptbuilder.gui.panels;
2
3import java.awt.Dimension;
4import java.awt.Graphics;
5import java.awt.Graphics2D;
6import javax.swing.JPanel;
7import scriptbuilder.gui.ScriptBuilderGuiConstants;
8import scriptbuilder.structures.ScriptIncident;
9import scriptbuilder.structures.SimulationScript;
10
11/**
12 * Represents the timestamp bar at the top of the GUI timeline. Displays
13 * timestamps at significant intervals. Updates based on zoom level and scroll
14 * position.
15 *
16 * @author Greg Eddington
17 * @author Bryan McGuffin
18 */
19public class TimeStampPanel extends JPanel
20{
21
22    private int longestLength = ScriptBuilderGuiConstants.TICK_TIMELINE_SMALLEST_LENGTH;
23
24    /**
25     * Just refresh the panel.
26     *
27     * @param zoom UNUSED
28     */
29    public void setZoom(float zoom)
30    {
31        repaint();
32    }
33
34    /**
35     * Constructor.
36     */
37    public TimeStampPanel()
38    {
39        super();
40    }
41
42    /**
43     * Update the length interval and the dimensions of the panel. This version
44     * of the method is used in the main script builder window.
45     *
46     * @param script The simulation script model
47     */
48    public void update(SimulationScript script)
49    {
50        longestLength = ScriptBuilderGuiConstants.TICK_TIMELINE_SMALLEST_LENGTH;
51
52        // Get the stats on the incidents
53        int height = ScriptBuilderGuiConstants.TICK_TOP_MARGIN * 4;
54        for (ScriptIncident incident : script.incidents)
55        {
56            if (incident != null)
57            {
58                height += incident.collapsed
59                        ? ScriptBuilderGuiConstants.TIMELINE_OPENED_HEIGHT
60                        : ScriptBuilderGuiConstants.TIMELINE_OPENED_HEIGHT;
61                if ((incident.length + incident.offset) > longestLength)
62                {
63                    longestLength = incident.length + incident.offset;
64                }
65            }
66        }
67        for (ScriptIncident i : script.incidents)
68        {
69            if (i != null && i.number == 100)
70            {
71                i.length = longestLength;
72                i.offset = 0;
73            }
74
75        }
76
77        Dimension newSize = new Dimension(longestLength
78                / ScriptBuilderGuiConstants.HORIZONTAL_TICK_RESOLUTION
79                * ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK
80                + ScriptBuilderGuiConstants.TICK_TIMELINE_LEFT_MARGIN + 50,
81                height);
82        this.setPreferredSize(newSize);
83        this.setSize(newSize);
84
85        this.invalidate();
86    }
87
88    /**
89     * Update the length interval and the dimensions of the panel. This version
90     * of the method is used in the individual incident editor window.
91     *
92     * @param incident the incident which this window is editing.
93     */
94    public void update(ScriptIncident incident)
95    {
96        longestLength = ScriptBuilderGuiConstants.TICK_TIMELINE_SMALLEST_LENGTH;
97
98        // Get the stats on the incidents
99        int height = ScriptBuilderGuiConstants.TICK_TOP_MARGIN * 4;
100        if (incident != null)
101        {
102            height += incident.collapsed
103                    ? ScriptBuilderGuiConstants.TIMELINE_OPENED_HEIGHT
104                    : ScriptBuilderGuiConstants.TIMELINE_OPENED_HEIGHT;
105            if ((incident.length + incident.offset) > longestLength)
106            {
107                longestLength = incident.length + incident.offset;
108            }
109        }
110
111        if (incident != null && incident.number == 100)
112        {
113            incident.length = longestLength;
114            incident.offset = 0;
115        }
116
117        Dimension newSize = new Dimension(longestLength
118                / ScriptBuilderGuiConstants.HORIZONTAL_TICK_RESOLUTION
119                * ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK
120                + ScriptBuilderGuiConstants.TICK_TIMELINE_LEFT_MARGIN + 50,
121                height);
122        this.setPreferredSize(newSize);
123        this.setSize(newSize);
124
125        this.invalidate();
126    }
127
128    /**
129     * Refresh the panel. Draw the timestamps for the appropriate intervals
130     * based on zoom level.
131     *
132     * @param g The graphics component
133     */
134    @Override
135    public void paint(Graphics g)
136    {
137        super.paint(g);
138
139        Graphics2D g2d = (Graphics2D) g;
140        g2d.setFont(ScriptBuilderGuiConstants.TIMELINE_TICK_TIME_FONT);
141        g2d.setColor(ScriptBuilderGuiConstants.TIMELINE_TICK_COLOR);
142        int longestLengthPlusMargin = longestLength
143                / ScriptBuilderGuiConstants.HORIZONTAL_TICK_RESOLUTION
144                * ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK
145                + ScriptBuilderGuiConstants.TICK_TIMELINE_LEFT_MARGIN;
146        int seconds = 0;
147
148        // Major Ticks
149        g2d.setColor(ScriptBuilderGuiConstants.TIMELINE_TICK_COLOR);
150        seconds = 0;
151        for (int i = ScriptBuilderGuiConstants.TICK_TIMELINE_LEFT_MARGIN;
152                i <= longestLengthPlusMargin;
153                i += ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK
154                * ScriptBuilderGuiConstants.TICKS_PER_MAJOR_TICK, seconds += ScriptBuilderGuiConstants.HORIZONTAL_TICK_RESOLUTION
155                * ScriptBuilderGuiConstants.TICKS_PER_MAJOR_TICK)
156        {
157            g2d.drawString(seconds / 3600 + ":"
158                    + (seconds / 60 % 60 > 9 ? seconds / 60 % 60
159                    : "0" + seconds / 60 % 60)
160                    + ":00", i - 25, 18);
161        }
162    }
163}
Note: See TracBrowser for help on using the repository browser.