source: tmcsimulator-scriptbuilder/trunk/src/scriptbuilder/gui/panels/IncidentNumberPanel.java @ 79

Revision 79, 3.4 KB checked in by bmcguffin, 9 years ago (diff)

Renamed ScriptBuilderTimelinePanel? to IncidentTimelinePanel?. Renamed ScriptBuilderNumberPanel? to IncidentNumberPanel?.

Line 
1package scriptbuilder.gui.panels;
2
3import java.awt.Dimension;
4import java.awt.Graphics;
5import java.awt.Graphics2D;
6import java.awt.Image;
7import java.awt.Rectangle;
8import java.awt.Shape;
9import java.awt.event.MouseEvent;
10import java.io.IOException;
11import java.util.logging.Level;
12import java.util.logging.Logger;
13import javax.imageio.ImageIO;
14import javax.swing.JPanel;
15import javax.swing.event.MouseInputAdapter;
16import scriptbuilder.gui.ScriptBuilderFrame;
17import scriptbuilder.gui.ScriptBuilderGuiConstants;
18import scriptbuilder.structures.ScriptIncident;
19import scriptbuilder.structures.TimeSlice;
20
21/**
22 * Displays the Incident ID number and name. Holds the button to toggle
23 * collapsed state.
24 *
25 * @author Greg Eddington <geddingt@calpoly.edu>
26 * @author Bryan McGuffin
27 */
28public class IncidentNumberPanel extends JPanel
29{
30
31    ScriptIncident incident;
32    boolean visible;
33
34    /**
35     * Listener for the mouse. Receives notifications if the mouse is clicked
36     * inside the button.
37     */
38    private class IncidentNumberMouseListener extends MouseInputAdapter
39    {
40
41        /**
42         * If the click occurs inside the icon borders, toggle the collapsed
43         * state.
44         *
45         * @param e the mouse event
46         */
47        @Override
48        public void mouseClicked(MouseEvent e)
49        {
50
51        }
52    }
53
54    /**
55     * Constructor. Sets up the mouse listener.
56     */
57    public IncidentNumberPanel()
58    {
59        super();
60
61        // Add the mouse listener
62        IncidentNumberMouseListener mouseListener
63                = new IncidentNumberMouseListener();
64        addMouseMotionListener(mouseListener);
65        addMouseListener(mouseListener);
66    }
67
68    /**
69     * Update the dimensions of the panel.
70     *
71     * @param incident The incident to be represented by this panel.
72     */
73    public void update(ScriptIncident incident)
74    {
75        this.incident = incident;
76        this.visible = incident != null;
77
78        Dimension newSize;
79        if (visible)
80        {
81
82            newSize = new Dimension(ScriptBuilderGuiConstants.INCIDENT_NUMBER_WIDTH,
83                    ScriptBuilderGuiConstants.TIMELINE_COLLAPSED_HEIGHT
84                    + ScriptBuilderGuiConstants.SCRIPT_EVENT_ICON_STEP * 2);
85
86        }
87        else
88        {
89            newSize = new Dimension(0, 0);
90        }
91        this.setSize(newSize);
92        this.setPreferredSize(newSize);
93
94        if (incident != null)
95        {
96            this.setToolTipText(incident.name);
97        }
98
99        invalidate();
100    }
101
102    /**
103     * Refresh the panel. Choose button icon depending on collapsed state.
104     *
105     * @param g the graphics component
106     */
107    @Override
108    public void paint(Graphics g)
109    {
110        super.paint(g);
111
112        if (!visible)
113        {
114            return;
115        }
116
117        Graphics2D g2d = (Graphics2D) g;
118        g2d.setColor(incident.color);
119        g2d.setFont(ScriptBuilderGuiConstants.INCIDENT_NUMBER_FONT);
120        g2d.drawString(Integer.toString(incident.number),
121                ScriptBuilderGuiConstants.INCIDENT_NUMBER_LEFT_MARGIN,
122                ScriptBuilderGuiConstants.INCIDENT_NUMBER_TOP_MARGIN);
123
124        int y = ScriptBuilderGuiConstants.INCIDENT_NUMBER_TOP_MARGIN * 2 - 14;
125        g2d.setFont(ScriptBuilderGuiConstants.INCIDENT_NAME_FONT);
126        for (String line : incident.name.split(" "))
127        {
128            g2d.drawString(line, 20, y);
129            y += 12;
130        }
131
132    }
133}
Note: See TracBrowser for help on using the repository browser.