source: trunk/src/org/apollo/gui/OverdubbedFrameTimeAxis.java@ 1059

Last change on this file since 1059 was 1059, checked in by davidb, 8 years ago

Timeline semi-transparent; more careful use of audience mode

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