| 1 | package scriptbuilder.gui.panels; |
|---|
| 2 | |
|---|
| 3 | import java.awt.Dimension; |
|---|
| 4 | import java.awt.Graphics; |
|---|
| 5 | import java.awt.Graphics2D; |
|---|
| 6 | import java.awt.Image; |
|---|
| 7 | import java.awt.Rectangle; |
|---|
| 8 | import java.awt.Shape; |
|---|
| 9 | import java.awt.event.MouseEvent; |
|---|
| 10 | import java.io.IOException; |
|---|
| 11 | import java.util.logging.Level; |
|---|
| 12 | import java.util.logging.Logger; |
|---|
| 13 | import javax.imageio.ImageIO; |
|---|
| 14 | import javax.swing.JPanel; |
|---|
| 15 | import javax.swing.event.MouseInputAdapter; |
|---|
| 16 | import scriptbuilder.gui.ScriptBuilderFrame; |
|---|
| 17 | import scriptbuilder.gui.ScriptBuilderGuiConstants; |
|---|
| 18 | import scriptbuilder.structures.ScriptIncident; |
|---|
| 19 | import 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 | */ |
|---|
| 28 | public 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 | } |
|---|