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

source: tmcsimulator-scriptbuilder/trunk/src/scriptbuilder/gui/drawers/CursorDrawer.java @ 145

Revision 145, 3.3 KB checked in by sdanthin, 6 years ago (diff)

Move from Git to Svn (LARGE COMMIT)

RevLine 
1package scriptbuilder.gui.drawers;
2
3import java.awt.Graphics2D;
4import java.awt.Image;
5import java.io.File;
6import java.io.IOException;
7import java.util.logging.Level;
8import java.util.logging.Logger;
9import javax.imageio.ImageIO;
10import scriptbuilder.gui.ScriptBuilderGuiConstants;
11
12/**
13 * Draws the cursor which marks the X position on the currently focused incident
14 * timeline.
15 *
16 * @author Greg Eddington <geddingt@calpoly.edu>
17 * @author Bryan McGuffin
18 */
19public class CursorDrawer
20{
21
22    /**
23     * The working copy of the cursor icon to use.
24     */
25    private static Image cursorIconImage = null;
26
27    /**
28     * Gets the image to use for the cursor and stores it for faster subsequent
29     * lookups.
30     *
31     * @return Cursor.png
32     */
33    private static Image getCursorIconImage()
34    {
35        if (cursorIconImage == null)
36        {
37            try
38            {
39                cursorIconImage = ImageIO.read(images.Images.getImage("Cursor.png"));
40            }
41            catch (IOException ex)
42            {
43                Logger.getLogger(EventIconDrawer.class.getName()).log(Level.SEVERE, null, ex);
44            }
45        }
46
47        return cursorIconImage;
48    }
49
50    /**
51     * Sets up the box for the cursor timestamp text, then draws the cursor at
52     * the given position.
53     *
54     * @param g2d the graphics component
55     * @param x current offset of the mouse from the center of the cursor
56     * @param locked if true, timestamp is a different color
57     */
58    public static void DrawCursor(Graphics2D g2d, int x,
59            boolean locked)
60    {
61        // Timestamp Border
62        g2d.setColor(ScriptBuilderGuiConstants.CURSOR_TIMESTAMP_BORDER_COLOR);
63        g2d.fillRect(x - ScriptBuilderGuiConstants.CURSOR_TIMESTAMP_BORDER_HORIZONTAL_CENTER,
64                ScriptBuilderGuiConstants.CURSOR_TIMESTAMP_BORDER_TOP_MARGIN,
65                2 * ScriptBuilderGuiConstants.CURSOR_TIMESTAMP_BORDER_HORIZONTAL_CENTER,
66                ScriptBuilderGuiConstants.CURSOR_TIMESTAMP_BORDER_HEIGHT);
67
68        // Timestamp Center
69        g2d.setColor(locked ? ScriptBuilderGuiConstants.CURSOR_TIMESTAMP_LOCKED_COLOR
70                : ScriptBuilderGuiConstants.CURSOR_TIMESTAMP_ACTIVE_COLOR);
71        g2d.fillRect(x - ScriptBuilderGuiConstants.CURSOR_TIMESTAMP_HORIZONTAL_CENTER,
72                ScriptBuilderGuiConstants.CURSOR_TIMESTAMP_TOP_MARGIN,
73                2 * ScriptBuilderGuiConstants.CURSOR_TIMESTAMP_HORIZONTAL_CENTER,
74                ScriptBuilderGuiConstants.CURSOR_TIMESTAMP_HEIGHT);
75
76        // Timestamp Text
77        g2d.setColor(ScriptBuilderGuiConstants.CURSOR_TIMESTAMP_TEXT_COLOR);
78        int seconds = x / ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK
79                * ScriptBuilderGuiConstants.HORIZONTAL_TICK_RESOLUTION;
80        g2d.drawString(seconds / 3600 + ":"
81                + (seconds / 60 % 60 > 9 ? seconds / 60 % 60
82                : "0" + seconds / 60 % 60)
83                + ":" + (seconds % 60)/10  + "0",
84                x - ScriptBuilderGuiConstants.CURSOR_TIMESTAMP_TEXT_CENTER,
85                ScriptBuilderGuiConstants.CURSOR_TIMESTAMP_TEXT_TOP_MARGIN);
86
87        // Timestamp Cursor
88        g2d.drawImage(getCursorIconImage(),
89                x - ScriptBuilderGuiConstants.CURSOR_TIMESTAMP_ICON_CENTER,
90                ScriptBuilderGuiConstants.CURSOR_TIMESTAMP_ICON_TOP_MARGIN,
91                null);
92    }
93}
Note: See TracBrowser for help on using the repository browser.