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 @ 118

Revision 118, 5.8 KB checked in by bmcguffin, 9 years ago (diff)

Added a pair of radio buttons under the +15 button on IncidentEditorFrame? which can be toggled between. If "to start" is selected, then pressing the +15 button will add (up to) 15 minutes of screen space to the beginning of the incident. If "to end" is selected, then pressing the +15 button will add 15 minutes of screen space to the end of the incident. Selecting one button deselects the other.

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