1 | package org.apollo.items;
|
---|
2 |
|
---|
3 | import java.awt.Color;
|
---|
4 | import java.awt.GradientPaint;
|
---|
5 | import java.awt.Graphics2D;
|
---|
6 | import java.awt.Paint;
|
---|
7 | import java.awt.Polygon;
|
---|
8 | import java.awt.Stroke;
|
---|
9 |
|
---|
10 | import org.apollo.ApolloSystem;
|
---|
11 | import org.apollo.gui.Strokes;
|
---|
12 | import org.apollo.io.IconRepository;
|
---|
13 | import org.apollo.widgets.SampleRecorder;
|
---|
14 | import org.expeditee.gui.Browser;
|
---|
15 | import org.expeditee.gui.DisplayIO;
|
---|
16 | import org.expeditee.gui.Frame;
|
---|
17 | import org.expeditee.items.Item;
|
---|
18 | import org.expeditee.items.ItemParentStateChangedEvent;
|
---|
19 | import org.expeditee.items.Text;
|
---|
20 |
|
---|
21 | public class RecordOverdubLauncher extends Item {
|
---|
22 |
|
---|
23 | private static int WIDTH = 80;
|
---|
24 | private static int HEIGHT = 80;
|
---|
25 | private static Stroke BORDER_STOKE = Strokes.SOLID_1;
|
---|
26 | private int countdown;
|
---|
27 |
|
---|
28 | private static final Color BASE_COLOR = new Color(255, 100, 100);
|
---|
29 | private static final Color HIGHLIGHT_COLOR = new Color(253, 255, 201);
|
---|
30 |
|
---|
31 | public RecordOverdubLauncher(int countdown) {
|
---|
32 | this.setID(getParentOrCurrentFrame().getNextItemID());
|
---|
33 | this.countdown = countdown;
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Override
|
---|
37 | public Item copy() {
|
---|
38 | RecordOverdubLauncher copy = new RecordOverdubLauncher(countdown);
|
---|
39 |
|
---|
40 | DuplicateItem(this, copy);
|
---|
41 |
|
---|
42 | return copy;
|
---|
43 | }
|
---|
44 |
|
---|
45 | @Override
|
---|
46 | public Item merge(Item merger, int mouseX, int mouseY) {
|
---|
47 | return null;
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override
|
---|
51 | public void paint(Graphics2D g) {
|
---|
52 | if (Browser._theBrowser == null) return;
|
---|
53 |
|
---|
54 | Paint restore = g.getPaint();
|
---|
55 |
|
---|
56 | if (ApolloSystem.useQualityGraphics) {
|
---|
57 | GradientPaint gp = new GradientPaint(
|
---|
58 | _x + (WIDTH / 2), _y, HIGHLIGHT_COLOR,
|
---|
59 | _x + (WIDTH / 2), _y + HEIGHT - (HEIGHT / 5), BASE_COLOR);
|
---|
60 | g.setPaint(gp);
|
---|
61 | } else {
|
---|
62 | g.setColor(BASE_COLOR);
|
---|
63 | }
|
---|
64 |
|
---|
65 | g.fillRect((int)_x, (int)_y, WIDTH, HEIGHT);
|
---|
66 |
|
---|
67 | g.setPaint(restore);
|
---|
68 |
|
---|
69 | g.setColor(Color.BLACK);
|
---|
70 | g.setStroke(BORDER_STOKE);
|
---|
71 | g.drawRect((int)_x, (int)_y, WIDTH, HEIGHT);
|
---|
72 |
|
---|
73 | IconRepository.getIcon("recordplay.png").paintIcon(
|
---|
74 | Browser._theBrowser.getContentPane(), g, getX() + 25, getY() + 25);
|
---|
75 |
|
---|
76 | }
|
---|
77 |
|
---|
78 | @Override
|
---|
79 | public void setAnnotation(boolean val) {
|
---|
80 | }
|
---|
81 |
|
---|
82 |
|
---|
83 | @Override
|
---|
84 | public int getHeight() {
|
---|
85 | return HEIGHT;
|
---|
86 | }
|
---|
87 |
|
---|
88 | @Override
|
---|
89 | public Integer getWidth() {
|
---|
90 | return WIDTH;
|
---|
91 | }
|
---|
92 |
|
---|
93 | @Override
|
---|
94 | public void updatePolygon() {
|
---|
95 |
|
---|
96 | _poly = new Polygon();
|
---|
97 |
|
---|
98 | int x = (int)_x;
|
---|
99 | int y = (int)_y;
|
---|
100 |
|
---|
101 | _poly.addPoint(x, y);
|
---|
102 | _poly.addPoint(x + WIDTH, y);
|
---|
103 | _poly.addPoint(x + WIDTH, y + HEIGHT);
|
---|
104 | _poly.addPoint(x, y + HEIGHT);
|
---|
105 |
|
---|
106 | }
|
---|
107 |
|
---|
108 | @Override
|
---|
109 | public void onParentStateChanged(ItemParentStateChangedEvent e) {
|
---|
110 | super.onParentStateChanged(e);
|
---|
111 |
|
---|
112 | switch (e.getEventType()) {
|
---|
113 |
|
---|
114 | case ItemParentStateChangedEvent.EVENT_TYPE_ADDED:
|
---|
115 | case ItemParentStateChangedEvent.EVENT_TYPE_ADDED_VIA_OVERLAY:
|
---|
116 | case ItemParentStateChangedEvent.EVENT_TYPE_SHOWN:
|
---|
117 | case ItemParentStateChangedEvent.EVENT_TYPE_SHOWN_VIA_OVERLAY:
|
---|
118 | // TODO: Invoke later for concurrent modification possibility?
|
---|
119 | selfDestruct();
|
---|
120 | break;
|
---|
121 |
|
---|
122 | }
|
---|
123 | }
|
---|
124 |
|
---|
125 | private void selfDestruct() {
|
---|
126 |
|
---|
127 | Frame parent = getParent();
|
---|
128 | parent.removeItem(this);
|
---|
129 |
|
---|
130 | Frame currentFrame = DisplayIO.getCurrentFrame();
|
---|
131 |
|
---|
132 | if (currentFrame != null) {
|
---|
133 |
|
---|
134 | Text source = new Text(currentFrame.getNextItemID());
|
---|
135 | source.setParent(currentFrame);
|
---|
136 | SampleRecorder destructableRecorder = new SampleRecorder(source, null, true);
|
---|
137 | destructableRecorder.setCountdown(countdown);
|
---|
138 | destructableRecorder.setPosition((int)_x, (int)_y);
|
---|
139 | currentFrame.addAllItems(destructableRecorder.getItems());
|
---|
140 | destructableRecorder.commenceOverdubRecording();
|
---|
141 |
|
---|
142 |
|
---|
143 | }
|
---|
144 | }
|
---|
145 |
|
---|
146 |
|
---|
147 |
|
---|
148 | }
|
---|