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

source: tmcsimulator-scriptbuilder/trunk/src/scriptbuilder/gui/panels/TimelineTickPanel.java @ 146

Revision 146, 9.1 KB checked in by jdalbey, 6 years ago (diff)

Remove reference to JUnit 3 from TimelineTickPanel?.java, remove junit 3.8 library. This should fix the "Resolve Problems" error.

RevLine 
1package scriptbuilder.gui.panels;
2
3import java.awt.BorderLayout;
4import java.awt.Dimension;
5import java.awt.Graphics;
6import java.awt.Graphics2D;
7import java.awt.event.MouseEvent;
8import java.io.File;
9import javax.swing.JFrame;
10import javax.swing.JPanel;
11import javax.swing.event.MouseInputAdapter;
12import scriptbuilder.gui.IncidentEditorFrame;
13import scriptbuilder.gui.ScriptBuilderFrame;
14import scriptbuilder.gui.ScriptBuilderGuiConstants;
15import scriptbuilder.gui.drawers.EventIconDrawer;
16import scriptbuilder.structures.ScriptIncident;
17import scriptbuilder.structures.SimulationScript;
18
19/**
20 * Represents the underlying panel on the main timeline. All the
21 * IncidentTimelinePanel objects sit over it. This panel draws all the
22 * per-minute ticks on the timeline, and adjusts and scales them as necessary.
23 *
24 * @author Greg Eddington <geddingt@calpoly.edu>
25 * @author Bryan McGuffin
26 */
27public class TimelineTickPanel extends JPanel
28{
29
30    private int longestLength = ScriptBuilderGuiConstants.TICK_TIMELINE_SMALLEST_LENGTH;
31    private int x, y;
32    private boolean focused = false;
33
34//    public void setZoom(float zoom)
35//    {
36//        repaint();
37//    }
38    /**
39     * Listener for the mouse. Is notified when the mouse enters, exits, or
40     * moves around on the panel.
41     */
42    public class TimelineTickMouseListener extends MouseInputAdapter
43    {
44
45        /**
46         * When the mouse enters the panel, the panel gets focus.
47         *
48         * @param e the mouse event
49         */
50        @Override
51        public void mouseEntered(MouseEvent e)
52        {
53            focused = true;
54        }
55
56        /**
57         * When the mouse leaves the panel, the panel loses focus and refreshes.
58         *
59         * @param e the mouse event
60         */
61        @Override
62        public void mouseExited(MouseEvent e)
63        {
64            focused = false;
65            repaint();
66        }
67
68        /**
69         * When the mouse moves around in the panel, the panel refreshes and
70         * updates its mouse tracker.
71         *
72         * @param e
73         */
74        @Override
75        public void mouseMoved(MouseEvent e)
76        {
77            x = e.getX();
78            y = e.getY();
79
80            repaint();
81        }
82    }
83
84    /**
85     * Constructor. Set up the mouse listener.
86     */
87    public TimelineTickPanel()
88    {
89        super();
90
91        TimelineTickMouseListener mouseListener
92                = new TimelineTickMouseListener();
93        addMouseMotionListener(mouseListener);
94        addMouseListener(mouseListener);
95    }
96
97    /**
98     * Update the panel's dimensions based on number of events, zoom level, and
99     * which events are collapsed. The version of the method is used in the main
100     * script builder.
101     *
102     * @param script The main script model
103     */
104    public void update(SimulationScript script)
105    {
106        longestLength = ScriptBuilderGuiConstants.TICK_TIMELINE_SMALLEST_LENGTH;
107
108        // Get the stats on the incidents
109        int height = ScriptBuilderGuiConstants.TICK_TOP_MARGIN * 4;
110        for (ScriptIncident incident : script.incidents)
111        {
112            if (incident != null)
113            {
114                height += incident.collapsed
115                        ? ScriptBuilderGuiConstants.TIMELINE_OPENED_HEIGHT
116                        : ScriptBuilderGuiConstants.TIMELINE_OPENED_HEIGHT;
117                if ((incident.length + incident.offset) > longestLength)
118                {
119                    longestLength = incident.length + incident.offset + IncidentTimelinePanel.requestedScriptBuilderFillerTime;
120                }
121            }
122        }
123
124        Dimension newSize = new Dimension(longestLength
125                / ScriptBuilderGuiConstants.HORIZONTAL_TICK_RESOLUTION
126                * ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK
127                + ScriptBuilderGuiConstants.TICK_TIMELINE_LEFT_MARGIN + 50,
128                height);
129        this.setPreferredSize(newSize);
130        this.setSize(newSize);
131
132        this.invalidate();
133    }
134
135    /**
136     * Update the panel's dimensions based on number of events, zoom level, and
137     * which events are collapsed. This version of the method is used in the
138     * individual incident editor.
139     *
140     * @param incident the incident being edited
141     */
142    public void update(ScriptIncident incident, IncidentTimelinePanel timeline)
143    {
144        longestLength = ScriptBuilderGuiConstants.TICK_TIMELINE_SMALLEST_LENGTH;
145
146        // Get the stats on the incidents
147        int height = ScriptBuilderGuiConstants.TICK_TOP_MARGIN * 4;
148
149        if (incident != null)
150        {
151            height += incident.collapsed
152                    ? ScriptBuilderGuiConstants.TIMELINE_OPENED_HEIGHT
153                    : ScriptBuilderGuiConstants.TIMELINE_OPENED_HEIGHT;
154            if ((incident.length + incident.offset + timeline.requestedEditorFillerTime) > longestLength)
155            {
156                longestLength = incident.length + incident.offset + timeline.requestedEditorFillerTime;
157            }
158
159        }
160
161        Dimension newSize = new Dimension(longestLength
162                / ScriptBuilderGuiConstants.HORIZONTAL_TICK_RESOLUTION
163                * ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK
164                + ScriptBuilderGuiConstants.TICK_TIMELINE_LEFT_MARGIN + 50,
165                height);
166        this.setPreferredSize(newSize);
167        this.setSize(newSize);
168
169        this.invalidate();
170    }
171
172    /**
173     * Refresh the panel. Redraw the ticks based on zoom level, panel
174     * dimensions, and offset. If the user is trying to add an event, draw that
175     * event's icon under the mouse.
176     *
177     * @param g The graphics component
178     */
179    @Override
180    public void paint(Graphics g)
181    {
182        super.paint(g);
183
184        Graphics2D g2d = (Graphics2D) g;
185
186        // Draw the horizontal line
187        g2d.setFont(ScriptBuilderGuiConstants.TIMELINE_TICK_TIME_FONT);
188        g2d.setColor(ScriptBuilderGuiConstants.TIMELINE_TICK_COLOR);
189        g2d.fillRect(0, ScriptBuilderGuiConstants.TICK_TIMELINE_TOP_MARGIN,
190                longestLength, ScriptBuilderGuiConstants.TICK_TIMELINE_HEIGHT);
191
192        // Draw the ticks
193        int longestLengthPlusMargin = longestLength
194                / ScriptBuilderGuiConstants.HORIZONTAL_TICK_RESOLUTION
195                * ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK
196                + ScriptBuilderGuiConstants.TICK_TIMELINE_LEFT_MARGIN;
197
198        // Minutes
199        g2d.setColor(ScriptBuilderGuiConstants.MINOR_TICK_COLOR);
200        int seconds = 0;
201        for (int i = ScriptBuilderGuiConstants.TICK_TIMELINE_LEFT_MARGIN;
202                i <= longestLengthPlusMargin;
203                i += ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK, seconds += ScriptBuilderGuiConstants.HORIZONTAL_TICK_RESOLUTION)
204        {
205            g2d.drawLine(i, ScriptBuilderGuiConstants.TICK_TOP_MARGIN,
206                    i, ScriptBuilderGuiConstants.TICK_HEIGHT);
207        }
208
209        // Major Ticks
210        g2d.setColor(ScriptBuilderGuiConstants.TIMELINE_TICK_COLOR);
211        seconds = 0;
212        for (int i = ScriptBuilderGuiConstants.TICK_TIMELINE_LEFT_MARGIN;
213                i <= longestLengthPlusMargin;
214                i += ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK
215                * ScriptBuilderGuiConstants.TICKS_PER_MAJOR_TICK, seconds += ScriptBuilderGuiConstants.HORIZONTAL_TICK_RESOLUTION
216                * ScriptBuilderGuiConstants.TICKS_PER_MAJOR_TICK)
217        {
218            g2d.drawLine(i, ScriptBuilderGuiConstants.TICK_TOP_MARGIN,
219                    i, ScriptBuilderGuiConstants.TICK_HEIGHT);
220
221        }
222
223        paintChildren(g);
224
225        if (this.getTopLevelAncestor() instanceof ScriptBuilderFrame)
226        {
227            if (focused
228                    && ((ScriptBuilderFrame) this.getTopLevelAncestor()).currentEventType != null)
229            {
230                EventIconDrawer.DrawEventIcon(g2d,
231                        ((ScriptBuilderFrame) this.getTopLevelAncestor()).currentEventType,
232                        x, y);
233            }
234        }
235        if (this.getTopLevelAncestor() instanceof IncidentEditorFrame)
236        {
237            if (focused
238                    && ((IncidentEditorFrame) this.getTopLevelAncestor()).currentEventType != null)
239            {
240                EventIconDrawer.DrawEventIcon(g2d,
241                        ((IncidentEditorFrame) this.getTopLevelAncestor()).currentEventType,
242                        x, y);
243            }
244        }
245    }
246
247    /**
248     * Local main for viewing this panel only.
249     *
250     * @author jdalbey
251     * @param args not used
252     */
253    public static void main(String[] args)
254    {
255        JFrame frame = new JFrame("FrameDemo");
256
257        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
258
259        TimelineTickPanel pnl = new TimelineTickPanel();
260        // Create a script
261        File inFile = new File("test/scriptbuilder/structures/test_input_file.xml");
262        SimulationScript instance = new SimulationScript();
263        instance.loadScriptFromFile(inFile);
264        // update this panel with the script
265        pnl.update(instance);
266        frame.getContentPane().add(pnl, BorderLayout.CENTER);
267        frame.setSize(300, 500);
268        frame.pack();
269
270        frame.setVisible(true);
271
272    }
273}
Note: See TracBrowser for help on using the repository browser.