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