1 | package org.apollo.gui;
|
---|
2 |
|
---|
3 | import java.awt.BasicStroke;
|
---|
4 | import java.awt.Color;
|
---|
5 | import java.awt.Graphics;
|
---|
6 | import java.awt.Graphics2D;
|
---|
7 | import java.awt.Rectangle;
|
---|
8 | import java.awt.Stroke;
|
---|
9 | import java.awt.event.ComponentEvent;
|
---|
10 | import java.awt.event.ComponentListener;
|
---|
11 |
|
---|
12 | import javax.swing.SwingUtilities;
|
---|
13 |
|
---|
14 | import org.apollo.audio.util.FrameLayoutDaemon;
|
---|
15 | import org.apollo.audio.util.Timeline;
|
---|
16 | import org.apollo.mvc.Observer;
|
---|
17 | import org.apollo.mvc.Subject;
|
---|
18 | import org.apollo.mvc.SubjectChangedEvent;
|
---|
19 | import org.expeditee.gui.Browser;
|
---|
20 | import org.expeditee.gui.DisplayIO;
|
---|
21 | import org.expeditee.gui.FrameGraphics;
|
---|
22 | import org.expeditee.gui.MessageBay;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * The global timeline on the current overdubbed frame
|
---|
26 | *
|
---|
27 | * @author Brook Novak
|
---|
28 | *
|
---|
29 | */
|
---|
30 | public class OverdubbedFrameTimeAxis implements Observer { //, DisplayIOObserver {
|
---|
31 |
|
---|
32 | private TimeAxis timeAxis = null;
|
---|
33 | private Rectangle lastInvalidated;
|
---|
34 | private Timeline lastTimeline = null;
|
---|
35 |
|
---|
36 | private static OverdubbedFrameTimeAxis instance = new OverdubbedFrameTimeAxis();
|
---|
37 |
|
---|
38 | private static final int GLOBAL_TIMELINE_HEIGHT = 30;
|
---|
39 | private static final Color GLOBAL_TIMELINE_BACKCOLOR = new Color(220, 220, 220);
|
---|
40 | private static final Color GLOBAL_EMPTY_TIMELINE_BACKCOLOR = new Color(240, 240, 240);
|
---|
41 |
|
---|
42 | public static final Stroke TRACK_TIMELINE_STROKE = new BasicStroke(
|
---|
43 | 1.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, 0.0f, new float[] { 5.0f, 5.0f }, 0.0f);
|
---|
44 |
|
---|
45 | private static final Stroke TIMELINE_BORDER_STROKE = new BasicStroke(1.0f);
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Singleton constructor,
|
---|
49 | */
|
---|
50 | private OverdubbedFrameTimeAxis() {
|
---|
51 |
|
---|
52 | FrameLayoutDaemon.getInstance().addObserver(this);
|
---|
53 |
|
---|
54 | //DisplayIO.addDisplayIOObserver(this);
|
---|
55 |
|
---|
56 | // Listen for resize events
|
---|
57 | SwingUtilities.invokeLater(new Runnable() {
|
---|
58 | public void run() {
|
---|
59 |
|
---|
60 | // Keep expanded view centered to the browser window
|
---|
61 | if (Browser._theBrowser != null) {
|
---|
62 | Browser._theBrowser.addComponentListener(new ComponentListener() {
|
---|
63 |
|
---|
64 | public void componentHidden(ComponentEvent e) {
|
---|
65 | }
|
---|
66 |
|
---|
67 | public void componentMoved(ComponentEvent e) {
|
---|
68 | }
|
---|
69 |
|
---|
70 | public void componentResized(ComponentEvent e) {
|
---|
71 | updateAxis();
|
---|
72 | }
|
---|
73 |
|
---|
74 | public void componentShown(ComponentEvent e) {
|
---|
75 | }
|
---|
76 |
|
---|
77 | });
|
---|
78 | }
|
---|
79 |
|
---|
80 | }
|
---|
81 | });
|
---|
82 | }
|
---|
83 |
|
---|
84 |
|
---|
85 | /**
|
---|
86 | *
|
---|
87 | * @return
|
---|
88 | * The singleton instance.
|
---|
89 | */
|
---|
90 | public static OverdubbedFrameTimeAxis getInstance() {
|
---|
91 | return instance;
|
---|
92 | }
|
---|
93 |
|
---|
94 | public void setObservedSubject(Subject parent) {
|
---|
95 | }
|
---|
96 |
|
---|
97 | public Subject getObservedSubject() {
|
---|
98 | return FrameLayoutDaemon.getInstance();
|
---|
99 | }
|
---|
100 |
|
---|
101 | public void modelChanged(Subject source, SubjectChangedEvent event) {
|
---|
102 | updateAxis();
|
---|
103 | }
|
---|
104 |
|
---|
105 | /*public void frameChanged() {
|
---|
106 | updateAxis();
|
---|
107 | }*/
|
---|
108 |
|
---|
109 | private void updateAxis() {
|
---|
110 |
|
---|
111 | if (Browser._theBrowser == null)
|
---|
112 | return;
|
---|
113 |
|
---|
114 | lastTimeline = FrameLayoutDaemon.getInstance().getLastComputedTimeline();
|
---|
115 | if (lastTimeline == null ||
|
---|
116 | FrameLayoutDaemon.getInstance().getTimelineOwner() != DisplayIO.getCurrentFrame()) {
|
---|
117 |
|
---|
118 | // The frame layout daemon only lays out frames once - unless the user rearranges tracks
|
---|
119 | // on a frame then the daemon we re-calc the timeline... thus a timeline must be infferred
|
---|
120 |
|
---|
121 | lastTimeline = FrameLayoutDaemon.inferTimeline(DisplayIO.getCurrentFrame());
|
---|
122 |
|
---|
123 | if (lastTimeline == null) { // no widgets
|
---|
124 | if (timeAxis != null && lastInvalidated != null) {
|
---|
125 | FrameGraphics.invalidateArea(lastInvalidated); // old position
|
---|
126 | }
|
---|
127 |
|
---|
128 | timeAxis = null;
|
---|
129 | return;
|
---|
130 | }
|
---|
131 |
|
---|
132 | }
|
---|
133 |
|
---|
134 | timeAxis = new TimeAxis();
|
---|
135 |
|
---|
136 | timeAxis.setAxis(
|
---|
137 | 0,
|
---|
138 | lastTimeline.getRunningTime(),
|
---|
139 | -1,
|
---|
140 | lastTimeline.getRunningTime(),
|
---|
141 | lastTimeline.getPixelWidth());
|
---|
142 |
|
---|
143 |
|
---|
144 | Rectangle newBounds = getCurrentTimelineArea();
|
---|
145 | if (lastInvalidated != null && !lastInvalidated.equals(newBounds)) {
|
---|
146 | FrameGraphics.invalidateArea(lastInvalidated); // old position
|
---|
147 | }
|
---|
148 |
|
---|
149 | FrameGraphics.invalidateArea(newBounds);
|
---|
150 |
|
---|
151 | lastInvalidated = newBounds;
|
---|
152 |
|
---|
153 | FrameGraphics.refresh(true);
|
---|
154 |
|
---|
155 | }
|
---|
156 |
|
---|
157 | public Rectangle getCurrentTimelineArea() {
|
---|
158 | assert(Browser._theBrowser != null);
|
---|
159 | int y = Browser._theBrowser.getContentPane().getHeight() - GLOBAL_TIMELINE_HEIGHT;
|
---|
160 | if (FrameGraphics.getMode() != FrameGraphics.MODE_AUDIENCE)
|
---|
161 | y -= MessageBay.MESSAGE_BUFFER_HEIGHT;
|
---|
162 |
|
---|
163 | if (y < 0) y = 0;
|
---|
164 |
|
---|
165 | return new Rectangle(0, y, Browser._theBrowser.getContentPane().getWidth(), GLOBAL_TIMELINE_HEIGHT);
|
---|
166 | }
|
---|
167 |
|
---|
168 |
|
---|
169 | public void paint(Graphics g) {
|
---|
170 | if (Browser._theBrowser == null) return;
|
---|
171 |
|
---|
172 | if (timeAxis != null && lastTimeline != null) {
|
---|
173 |
|
---|
174 | Rectangle r = getCurrentTimelineArea();
|
---|
175 |
|
---|
176 | g.setColor(GLOBAL_EMPTY_TIMELINE_BACKCOLOR);
|
---|
177 | g.fillRect(0, r.y, Browser._theBrowser.getContentPane().getWidth(), r.height);
|
---|
178 |
|
---|
179 | timeAxis.paint(g,
|
---|
180 | lastTimeline.getInitiationXPixel(),
|
---|
181 | r.y,
|
---|
182 | r.height,
|
---|
183 | GLOBAL_TIMELINE_BACKCOLOR);
|
---|
184 |
|
---|
185 |
|
---|
186 | g.setColor(Color.DARK_GRAY);
|
---|
187 |
|
---|
188 | ((Graphics2D)g).setStroke(TIMELINE_BORDER_STROKE);
|
---|
189 | g.drawLine(0, r.y, Browser._theBrowser.getContentPane().getWidth(), r.y);
|
---|
190 |
|
---|
191 | }
|
---|
192 |
|
---|
193 |
|
---|
194 | }
|
---|
195 |
|
---|
196 |
|
---|
197 | public Timeline getLastTimeline() {
|
---|
198 | return lastTimeline;
|
---|
199 | }
|
---|
200 |
|
---|
201 |
|
---|
202 | public TimeAxis getTimeAxis() {
|
---|
203 | return timeAxis;
|
---|
204 | }
|
---|
205 |
|
---|
206 |
|
---|
207 |
|
---|
208 | }
|
---|