public TimelineBodyPanel(Timeline timeLine) { this.timeLine = timeLine; Dimension dim = new Dimension( TimelinePanel.FRAME_WIDTH * timeLine.getFrameCount() + 1, TimelinePanel.FRAME_HEIGHT * timeLine.getMaxDepth()); setSize(dim); setPreferredSize(dim); addMouseListener(this); }
@Override public void mousePressed(MouseEvent e) { Point p = e.getPoint(); p.x = p.x / TimelinePanel.FRAME_WIDTH; p.y = p.y / TimelinePanel.FRAME_HEIGHT; if (p.x >= timeLine.getFrameCount()) { p.x = timeLine.getFrameCount() - 1; } int maxDepth = timeLine.getMaxDepth(); if (p.y > maxDepth) { p.y = maxDepth; } frameSelect(p.x, p.y); }
@Override public void keyPressed(KeyEvent e) { switch (e.getKeyCode()) { case 37: // left if (cursor.x > 0) { frameSelect(cursor.x - 1, cursor.y); } break; case 39: // right if (cursor.x < timeLine.frames.size() - 1) { frameSelect(cursor.x + 1, cursor.y); } break; case 38: // up if (cursor.y > 0) { frameSelect(cursor.x, cursor.y - 1); } break; case 40: // down if (cursor.y < timeLine.getMaxDepth()) { frameSelect(cursor.x, cursor.y + 1); } break; } }
@Override public void resetTimeline() { if (timeline != null) { timeline.reset(swf, this, subTags, spriteId, getRect()); } }
@Override protected void paintComponent(Graphics g1) { Graphics2D g = (Graphics2D) g1; g.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(TimelinePanel.backgroundColor); g.fillRect(0, 0, getWidth(), getHeight()); Rectangle clip = g.getClipBounds(); int start_f = clip.x / TimelinePanel.FRAME_WIDTH; int start_d = clip.y / TimelinePanel.FRAME_HEIGHT; int end_f = (clip.x + clip.width) / TimelinePanel.FRAME_WIDTH; int end_d = (clip.y + clip.height) / TimelinePanel.FRAME_HEIGHT; int max_d = timeLine.getMaxDepth(); if (max_d < end_d) { end_d = max_d; } int max_f = timeLine.getFrameCount() - 1; if (max_f < end_f) { end_f = max_f; } if (end_d - start_d + 1 < 0) { return; } boolean keyfound[] = new boolean[end_d - start_d + 1]; for (int f = start_f; f <= end_f; f++) { for (int d = start_d; d <= end_d; d++) { DepthState fl = timeLine.frames.get(f).layers.get(d); if (fl == null) { if ((f + 1) % 5 == 0) { g.setColor(emptyFrameSecondColor); } else { g.setColor(emptyFrameColor); } g.fillRect( f * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT, TimelinePanel.FRAME_WIDTH, TimelinePanel.FRAME_HEIGHT); g.setColor(emptyBorderColor); g.drawRect( f * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT, TimelinePanel.FRAME_WIDTH, TimelinePanel.FRAME_HEIGHT); } } } for (int f = start_f; f <= end_f; f++) { for (int d = start_d; d <= end_d; d++) { DepthState fl = timeLine.frames.get(f).layers.get(d); boolean motionTween = fl == null ? false : fl.motionTween; DepthState flNext = null; if (f < max_f) { flNext = timeLine.frames.get(f + 1).layers.get(d); } DepthState flPrev = null; if (f > 0) { flPrev = timeLine.frames.get(f - 1).layers.get(d); } CharacterTag cht = fl == null ? null : timeLine.swf.characters.get(fl.characterId); boolean shapeTween = cht != null && (cht instanceof MorphShapeTag); boolean motionTweenStart = (!motionTween) && (flNext != null && flNext.motionTween); boolean motionTweenEnd = (!motionTween) && (flPrev != null && flPrev.motionTween); // boolean shapeTweenStart = shapeTween && (flPrev == null || flPrev.characterId != // fl.characterId); // boolean shapeTweenEnd = shapeTween && (flNext == null || flNext.characterId != // fl.characterId); if (motionTweenStart || motionTweenEnd) { motionTween = true; } boolean selected = false; if (cursor != null) { if (f == cursor.x && d == cursor.y) { selected = true; } } if (selected) { // if (!(fl != null && (flNext == null || flNext.key))) { g.setColor(selectedColor); g.fillRect( f * TimelinePanel.FRAME_WIDTH + 1, d * TimelinePanel.FRAME_HEIGHT + 1, TimelinePanel.FRAME_WIDTH - 1, TimelinePanel.FRAME_HEIGHT - 1); // } } if (fl == null) { if (timeLine.depthMaxFrame.containsKey(d) && f < timeLine.depthMaxFrame.get(d)) { int draw_f = f; DepthState prev_ds = f < 1 ? null : timeLine.frames.get(f - 1).layers.get(d); if (f == 0 || prev_ds != null) { draw_f = f; keyfound[d - start_d] = true; } else if (!keyfound[d - start_d]) { for (; draw_f >= 0; draw_f--) { if (timeLine.frames.get(draw_f).layers.get(d) != null) { if (timeLine.frames.get(draw_f).layers.get(d).characterId != -1) { break; } } } } else { continue; } int num_frames = 1; for (int i = draw_f + 1; i < timeLine.frames.size(); i++) { if (timeLine.frames.get(i).layers.get(d) != null) { if (timeLine.frames.get(i).layers.get(d).characterId != -1) { break; } } num_frames++; } g.setColor(emptyFrameColor); g.fillRect( draw_f * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT, num_frames * TimelinePanel.FRAME_WIDTH, TimelinePanel.FRAME_HEIGHT); g.setColor(borderColor); g.drawRect( draw_f * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT, num_frames * TimelinePanel.FRAME_WIDTH, TimelinePanel.FRAME_HEIGHT); if (selected) { g.setColor(selectedColor); g.fillRect( draw_f * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT, TimelinePanel.FRAME_WIDTH, TimelinePanel.FRAME_HEIGHT); } g.setColor(keyColor); g.drawOval( draw_f * TimelinePanel.FRAME_WIDTH + TimelinePanel.FRAME_WIDTH / 4, d * TimelinePanel.FRAME_HEIGHT + TimelinePanel.FRAME_HEIGHT * 3 / 4 - TimelinePanel.FRAME_WIDTH / 2 / 2, TimelinePanel.FRAME_WIDTH / 2, TimelinePanel.FRAME_WIDTH / 2); if (num_frames > 1) { if (cursor != null && cursor.y == d && cursor.x == f + num_frames - 1) { g.setColor(selectedColor); g.fillRect( (f + num_frames - 1) * TimelinePanel.FRAME_WIDTH + 1, d * TimelinePanel.FRAME_HEIGHT + 1, TimelinePanel.FRAME_WIDTH - 1, TimelinePanel.FRAME_HEIGHT - 1); } g.setColor(stopColor); g.fillRect( (draw_f + num_frames - 1) * TimelinePanel.FRAME_WIDTH + TimelinePanel.FRAME_WIDTH / 4, d * TimelinePanel.FRAME_HEIGHT + TimelinePanel.FRAME_HEIGHT / 2 - 2, TimelinePanel.FRAME_WIDTH / 2, TimelinePanel.FRAME_HEIGHT / 2); g.setColor(stopBorderColor); g.drawRect( (draw_f + num_frames - 1) * TimelinePanel.FRAME_WIDTH + TimelinePanel.FRAME_WIDTH / 4, d * TimelinePanel.FRAME_HEIGHT + TimelinePanel.FRAME_HEIGHT / 2 - 2, TimelinePanel.FRAME_WIDTH / 2, TimelinePanel.FRAME_HEIGHT / 2); g.setColor(borderLinesColor); for (int n = draw_f + 1; n < draw_f + num_frames; n++) { g.drawLine( n * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT + 1, n * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT + borderLinesLength); g.drawLine( n * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT + TimelinePanel.FRAME_HEIGHT - 1, n * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT + TimelinePanel.FRAME_HEIGHT - borderLinesLength); } } } if (d == 0) { if (timeLine.frames.get(f).action != null) { g.setColor(aColor); g.setFont(getFont().deriveFont(fontSize)); int awidth = g.getFontMetrics().stringWidth("a"); g.drawString( "a", f * TimelinePanel.FRAME_WIDTH + TimelinePanel.FRAME_WIDTH / 2 - awidth / 2, d * TimelinePanel.FRAME_HEIGHT + TimelinePanel.FRAME_HEIGHT / 2 + fontSize / 2); } } continue; } else { int draw_f = 0; if (fl.key) { draw_f = f; keyfound[d - start_d] = true; } else if (!keyfound[d - start_d]) { for (int k = f - 1; k >= 0; k--) { fl = timeLine.frames.get(k).layers.get(d); if (fl == null) { break; } if (fl.key) { keyfound[d - start_d] = true; draw_f = k; break; } } } else { continue; } int num_frames = 1; for (int n = draw_f + 1; n < timeLine.getFrameCount(); n++) { fl = timeLine.frames.get(n).layers.get(d); if (fl == null) { break; } if (fl.key) { break; } num_frames++; } g.setColor(frameColor); g.fillRect( draw_f * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT, num_frames * TimelinePanel.FRAME_WIDTH, TimelinePanel.FRAME_HEIGHT); if (motionTween) { g.setColor(motionTweenColor); g.fillRect( draw_f * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT, num_frames * TimelinePanel.FRAME_WIDTH, TimelinePanel.FRAME_HEIGHT); } if (shapeTween) { g.setColor(shapeTweenColor); g.fillRect( draw_f * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT, num_frames * TimelinePanel.FRAME_WIDTH, TimelinePanel.FRAME_HEIGHT); } if (selected) { g.setColor(selectedColor); g.fillRect( draw_f * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT, TimelinePanel.FRAME_WIDTH, TimelinePanel.FRAME_HEIGHT); } g.setColor(borderColor); g.drawRect( draw_f * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT, num_frames * TimelinePanel.FRAME_WIDTH, TimelinePanel.FRAME_HEIGHT); // } if ((motionTween || shapeTween)) { g.drawLine( draw_f * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT + TimelinePanel.FRAME_HEIGHT * 3 / 4, draw_f * TimelinePanel.FRAME_WIDTH + num_frames * TimelinePanel.FRAME_WIDTH - TimelinePanel.FRAME_WIDTH / 2, d * TimelinePanel.FRAME_HEIGHT + TimelinePanel.FRAME_HEIGHT * 3 / 4); } g.setColor(keyColor); g.fillOval( draw_f * TimelinePanel.FRAME_WIDTH + TimelinePanel.FRAME_WIDTH / 4, d * TimelinePanel.FRAME_HEIGHT + TimelinePanel.FRAME_HEIGHT * 3 / 4 - TimelinePanel.FRAME_WIDTH / 2 / 2, TimelinePanel.FRAME_WIDTH / 2, TimelinePanel.FRAME_WIDTH / 2); if ((motionTween || shapeTween)) { g.fillOval( (draw_f + num_frames - 1) * TimelinePanel.FRAME_WIDTH + TimelinePanel.FRAME_WIDTH / 4, d * TimelinePanel.FRAME_HEIGHT + TimelinePanel.FRAME_HEIGHT * 3 / 4 - TimelinePanel.FRAME_WIDTH / 2 / 2, TimelinePanel.FRAME_WIDTH / 2, TimelinePanel.FRAME_WIDTH / 2); } if (num_frames > 1) { if (cursor != null && cursor.y == d && cursor.x == f + num_frames - 1) { g.setColor(selectedColor); g.fillRect( (f + num_frames - 1) * TimelinePanel.FRAME_WIDTH + 1, d * TimelinePanel.FRAME_HEIGHT + 1, TimelinePanel.FRAME_WIDTH - 1, TimelinePanel.FRAME_HEIGHT - 1); } if (!(motionTween || shapeTween)) { g.setColor(stopColor); g.fillRect( (draw_f + num_frames - 1) * TimelinePanel.FRAME_WIDTH + TimelinePanel.FRAME_WIDTH / 4, d * TimelinePanel.FRAME_HEIGHT + TimelinePanel.FRAME_HEIGHT / 2 - 2, TimelinePanel.FRAME_WIDTH / 2, TimelinePanel.FRAME_HEIGHT / 2); g.setColor(stopBorderColor); g.drawRect( (draw_f + num_frames - 1) * TimelinePanel.FRAME_WIDTH + TimelinePanel.FRAME_WIDTH / 4, d * TimelinePanel.FRAME_HEIGHT + TimelinePanel.FRAME_HEIGHT / 2 - 2, TimelinePanel.FRAME_WIDTH / 2, TimelinePanel.FRAME_HEIGHT / 2); } g.setColor(borderLinesColor); for (int n = draw_f + 1; n < draw_f + num_frames; n++) { g.drawLine( n * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT + 1, n * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT + borderLinesLength); g.drawLine( n * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT + TimelinePanel.FRAME_HEIGHT - 1, n * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT + TimelinePanel.FRAME_HEIGHT - borderLinesLength); } } } } } if (cursor != null && cursor.x >= start_f && cursor.x <= end_f) { g.setColor(TimelinePanel.selectedBorderColor); g.drawLine( cursor.x * TimelinePanel.FRAME_WIDTH + TimelinePanel.FRAME_WIDTH / 2, 0, cursor.x * TimelinePanel.FRAME_WIDTH + TimelinePanel.FRAME_WIDTH / 2, getHeight()); } }
@Override protected void paintComponent(Graphics g1) { Graphics2D g = (Graphics2D) g1; g.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(TimelinePanel.backgroundColor); g.fillRect(0, 0, getWidth(), getHeight()); Rectangle clip = g.getClipBounds(); int start_f = clip.x / TimelinePanel.FRAME_WIDTH; int start_d = clip.y / TimelinePanel.FRAME_HEIGHT; int end_f = (clip.x + clip.width) / TimelinePanel.FRAME_WIDTH; int end_d = (clip.y + clip.height) / TimelinePanel.FRAME_HEIGHT; int max_d = timeLine.getMaxDepth(); if (max_d < end_d) { end_d = max_d; } int max_f = timeLine.getFrameCount() - 1; if (max_f < end_f) { end_f = max_f; } if (end_d - start_d + 1 < 0) { return; } boolean keyfound[] = new boolean[end_d - start_d + 1]; for (int f = start_f; f <= end_f; f++) { for (int d = start_d; d <= end_d; d++) { DepthState fl = timeLine.frames.get(f).layers.get(d); if (fl == null) { if ((f + 1) % 5 == 0) { g.setColor(emptyFrameSecondColor); } else { g.setColor(emptyFrameColor); } g.fillRect( f * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT, TimelinePanel.FRAME_WIDTH, TimelinePanel.FRAME_HEIGHT); g.setColor(emptyBorderColor); g.drawRect( f * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT, TimelinePanel.FRAME_WIDTH, TimelinePanel.FRAME_HEIGHT); } } } for (int f = start_f; f <= end_f; f++) { for (int d = start_d; d <= end_d; d++) { DepthState fl = timeLine.frames.get(f).layers.get(d); DepthState flNext = null; if (f < max_f) { flNext = timeLine.frames.get(f + 1).layers.get(d); } boolean selected = false; if (cursor != null) { if (f == cursor.x && d == cursor.y) { selected = true; } } if (selected) { if (!(fl != null && (flNext == null || flNext.key))) { g.setColor(selectedColor); g.fillRect( f * TimelinePanel.FRAME_WIDTH + 1, d * TimelinePanel.FRAME_HEIGHT + 1, TimelinePanel.FRAME_WIDTH - 1, TimelinePanel.FRAME_HEIGHT - 1); } } if (fl == null) { if (d == 0) { if (timeLine.frames.get(f).action != null) { g.setColor(aColor); g.setFont(getFont().deriveFont(fontSize)); int awidth = g.getFontMetrics().stringWidth("a"); g.drawString( "a", f * TimelinePanel.FRAME_WIDTH + TimelinePanel.FRAME_WIDTH / 2 - awidth / 2, d * TimelinePanel.FRAME_HEIGHT + TimelinePanel.FRAME_HEIGHT / 2 + fontSize / 2); } } continue; } else { int draw_f = 0; if (fl.key) { draw_f = f; keyfound[d - start_d] = true; } else if (!keyfound[d - start_d]) { for (int k = f - 1; k >= 0; k--) { fl = timeLine.frames.get(k).layers.get(d); if (fl == null) { break; } if (fl.key) { keyfound[d - start_d] = true; draw_f = k; break; } } } else { continue; } int num_frames = 1; for (int n = draw_f + 1; n < timeLine.getFrameCount(); n++) { fl = timeLine.frames.get(n).layers.get(d); if (fl == null) { break; } if (fl.key) { break; } num_frames++; } g.setColor(frameColor); g.fillRect( draw_f * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT, num_frames * TimelinePanel.FRAME_WIDTH, TimelinePanel.FRAME_HEIGHT); if (selected) { g.setColor(selectedColor); g.fillRect( draw_f * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT, TimelinePanel.FRAME_WIDTH, TimelinePanel.FRAME_HEIGHT); } g.setColor(borderColor); g.drawRect( draw_f * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT, num_frames * TimelinePanel.FRAME_WIDTH, TimelinePanel.FRAME_HEIGHT); g.setColor(keyColor); g.fillOval( draw_f * TimelinePanel.FRAME_WIDTH + TimelinePanel.FRAME_WIDTH / 4, d * TimelinePanel.FRAME_HEIGHT + TimelinePanel.FRAME_HEIGHT * 3 / 4 - TimelinePanel.FRAME_WIDTH / 2 / 2, TimelinePanel.FRAME_WIDTH / 2, TimelinePanel.FRAME_WIDTH / 2); if (num_frames > 1) { if (cursor != null && cursor.y == d && cursor.x == f + num_frames - 1) { g.setColor(selectedColor); g.fillRect( (f + num_frames - 1) * TimelinePanel.FRAME_WIDTH + 1, d * TimelinePanel.FRAME_HEIGHT + 1, TimelinePanel.FRAME_WIDTH - 1, TimelinePanel.FRAME_HEIGHT - 1); } g.setColor(stopColor); g.fillRect( (draw_f + num_frames - 1) * TimelinePanel.FRAME_WIDTH + TimelinePanel.FRAME_WIDTH / 4, d * TimelinePanel.FRAME_HEIGHT + TimelinePanel.FRAME_HEIGHT / 2 - 2, TimelinePanel.FRAME_WIDTH / 2, TimelinePanel.FRAME_HEIGHT / 2); g.setColor(stopBorderColor); g.drawRect( (draw_f + num_frames - 1) * TimelinePanel.FRAME_WIDTH + TimelinePanel.FRAME_WIDTH / 4, d * TimelinePanel.FRAME_HEIGHT + TimelinePanel.FRAME_HEIGHT / 2 - 2, TimelinePanel.FRAME_WIDTH / 2, TimelinePanel.FRAME_HEIGHT / 2); g.setColor(borderLinesColor); for (int n = draw_f + 1; n < draw_f + num_frames; n++) { g.drawLine( n * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT + 1, n * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT + borderLinesLength); g.drawLine( n * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT + TimelinePanel.FRAME_HEIGHT - 1, n * TimelinePanel.FRAME_WIDTH, d * TimelinePanel.FRAME_HEIGHT + TimelinePanel.FRAME_HEIGHT - borderLinesLength); } } } } } if (cursor != null && cursor.x >= start_f && cursor.x <= end_f) { g.setColor(TimelinePanel.selectedBorderColor); g.drawLine( cursor.x * TimelinePanel.FRAME_WIDTH + TimelinePanel.FRAME_WIDTH / 2, 0, cursor.x * TimelinePanel.FRAME_WIDTH + TimelinePanel.FRAME_WIDTH / 2, getHeight()); } }